Blog‎ > ‎

Writing LaTeX with Emacs on Windows

posted Jul 13, 2016, 12:18 AM by Juan Jose Garcia-Ripoll   [ updated Aug 8, 2016, 2:52 AM ]
These are the steps I followed to work with Emacs on Windows and be able to code LaTeX, view the resulting PDFs and use reverse search, that is, clicking on the PDF and telling emacs to move to the right point in the text.

Step 1: Install Emacs, AucTeX and SumatraPDF

This is not painless, but it is ok for anybody familiar with computers.
  1. SumatraPDF can be downloaded from its web page, It has a simple installer. The appearance may be simplistic, but it is very lean and I recommend it for Windows and tablets in particular.
  2. Emacs 24.5 or later can be downloaded from the GNU page, but I personally use the 64-bit optimized recompilation.
  3. AucTeX is Emacs' best plug-in for working with TeX and LaTeX files. You can download a precompiled version that matches your emacs version from their web page. Make sure you unpack it in the right place.

Step 2: Configure SumatraPDF

Open SumatraPDF and click on the top-left corner menu you have to make two changes:
  • Select "Settings" and "Advanced Options" and ensure that there is a line saying
EnableTeXEnhancements = true
  • Select "Settings" and then "Options" and enter the following text 
"C:\Program Files\emacs\bin\emacsclientw.exe" -n +%l "%f"
Make sure the path c:\Program Files\emacs corresponds to the folder where you unzipped your emacs installation. 

Step 3: Configure Emacs

This is the way I configure my Emacs.
  1. Before opening Emacs, define an environment variable "HOME" to point to your user directory. This can be done in the Control Panel > System and Security > System > Advanced System Settings > Advanced tab.
  2. Go to the folder where you unzipped the Emacs distribution. In the "bin" directory you will find an executable "runemacs.exe". Click with the right button and select "Pin to Start" to have that program available at all times.
  3. Open "runemacs.exe" and open the file "~/.emacs". Store the following settings in it
(setq TeX-PDF-mode t)
(setq TeX-source-correlate-mode t)
(setq TeX-source-correlate-method 'synctex)
(setq TeX-view-program-list
 '(("Sumatra PDF" ("\"C:/Program Files/SumatraPDF/SumatraPDF.exe\" -reuse-instance" (mode-io-correlate " -forward-search %b %n ") " %o"))))
(setq TeX-view-program-selection
'(((output-dvi style-pstricks)
"dvips and start")
(output-dvi "Yap")
(output-pdf "Sumatra PDF")
(output-html "start")))


(defun my-latex-mode ()
  (visual-line-mode +1)1
  (assq-delete-all 'output-pdf TeX-view-program-selection)
  (add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF")))

(add-hook 'LaTeX-mode-hook 'my-latex-mode)

With this you should be able to open the PDF associated to a latex file and click twice in Sumatra PDF to go back to the emacs window, right at the paragraph or line where you clicked.