Emacs AUCTeX and PDF Synchronization on Windows

In this technical note, we’d like to setup GNU Emacs and AUCTeX so that it can do both forward searches (using Emacs to control the PDF Viewer) and inverse searches (using the PDF Viewer to control Emacs). This work is based on William’s instructions, but with some additional modifications from Miguel Frasson that remove the dependency on sumatra-forward.el, as long you primarily use pdflatex as your LaTeX target. The technique uses the command line rather than DDE to interface with Sumatra PDF.

  • Unlike on the Mac, TeX tool support on Windows is quite a challenge. With the exception of Sumatra PDF, there are basically no PDF viewers that support source synchronization. Be sure to use the full installer, and not the portable apps version of Sumatra PDF.
  • To get PDF synchronization to work, you’ll need to set a few AUCTeX variables in Emacs (M-x customize-variable). The first is TeX-view-program-list, which is perhaps the most complicated. The Name should read as Sumatra PDF, and the Choice should be set to Command parts. Then, you will need to insert (INS) two Command parts:
    1. The first Command part has a value of "C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" -reuse-instance, adjusting accordingly for your actual path.
    2. The second part is a Predicate and command part with a Predicate of mode-io-correlate and a Command part of ␣-forward-search %b %n. The character ␣ is meant to represent a leading whitespace character.
    3. The third part is a Command part with ␣%o. Once again, don’t forget the leading whitespace character.
  • Since the last step isn’t entirely obvious, the following screen capture should help you with this variable (click to enlarge). And if you’re curious about what %o, %n and so on do, then check the variable TeX-expand-list.
  • Select Save for future sessions and then restart Emacs; otherwise the next step won’t work without knowing some Emacs tricks. For the remaining variables in this recipe, remember to Save for future sessions as well.
  • The next variable is TeX-view-program-selection, where the Viewer for output-pdf should be set to Sumatra PDF.
  • Similarly, find TeX-source-correlate-mode and set this to On. Finally, set TeX-source-correlate-method to synctex.
  • You’ll probably want to setup Emacs with (server-start) ahead of time, so add this to your init.el. On Windows in particular, (server-start) is problematic and can fail by default with something like: error: The directory ‘~/.emacs.d/server' is unsafe. This is due to a permissions problem; the file ~/.emacs.d/server needs to be owned by you. The easiest way to do this is through the command-line: takeown /f server, though you can also use the GUI to take ownership of the file (Properties > Security > Advanced > Owner). If you like, you can optionally also set the variable TeX-source-correlate-start-server to Always.
  • The only thing left to do now is inverse search. Under Sumatra PDF, go to Settings > Options. Set the inverse search command-line to c:\emacs\bin\emacsclientw.exe --no-wait +%l "%f" or equivalent.

    Initially, Sumatra PDF may not have the inverse search field under Options. In this case, you can initially set it through a Command Prompt with "C:\Program Files (x86)\SumatraPDF\SumatraPDF.exe" -inverse-search "C:\emacs\bin\emacsclientw.exe --no-wait +%l \"%f\"".
  • It’s recommended that you restart Emacs at this point, unless you’re an Emacs guru.
  • Whew! To perform forward search (from within Emacs) hit AUCTeX’s built-in C-c C-v (View). To perform inverse search (from within Sumatra PDF), double-click the area of text.

If needed, you can get a quick reference of the changes to your init.el custom-set-variables for a sanity check.

2 thoughts on “Emacs AUCTeX and PDF Synchronization on Windows

  • October 12, 2012 at 11:28 am
    Permalink

    Thanks for the help! One extra step that I needed to do was set LaTeX compilation to PDF (it’s DVI) by default. This can be done by setting the variable (M-x customize-variable) TeX-PDF-mode to on (non-nil).

  • August 24, 2013 at 7:05 pm
    Permalink

    This was so amazingly helpful. I’m glad this is possible, and I’m grateful to you for putting together this awesome step-by-step walkthrough. We emacs newbies appreciate the specific directions.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>