Blog‎ > ‎

Updated guide: writing LaTeX on Windows with Emacs

posted Jul 13, 2016, 12:18 AM by Juan Jose Garcia-Ripoll   [ updated Sep 9, 2016, 4:58 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. You should unpack it under the "Program files" folder.

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.
  • 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. Alternatively, enter "Environment variables" in the Cortana search box and edit the values. I show you below my own settings. Sorry, it's in Spanish.
  • 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. The outcome should be as follows
  • Open "runemacs.exe" by clicking on the icon on the Start page. Press Ctrl+x followed by Ctr+f and type ~/.emacs to open the file "~/.emacs". Store the following settings in it and save them pressing Ctrl-x followed by Ctrl-s
;; 1) Package repository
(require 'package)

(add-to-list 'package-archives '("melpa-stable" . ""))

;; 2) AUCTex customization
(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")))

(add-hook 'LaTeX-mode-hook
  (lambda ()
(assq-delete-all 'output-pdf TeX-view-program-selection)
(add-to-list 'TeX-view-program-selection '(output-pdf "Sumatra PDF"))))
  • The first part of the customization instructs Emacs where to look for additional software. The second set of customizations are intended for AUCTex, once we install it. 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.
  • Now press Esc followed by X and then type package-install. You should be offered with a rather large list of software. Look for AUCTex and select it, and then click Install. You will see some warnings, but installation should proceed smoothly and the package will be available the next time you open Emacs.