William Blum's website

Configuring editors with SumatraPDF

This document explains how to configure your favourite editor for synchronization with SumatraPDF.

Introduction

Synchronization technologies

SumatraPDF supports two synchronization technologies: pdfsync and the more recent SyncTeX.

To use the first one you just need to load the 'pdfsync' package in your latex document as follows:

1: 
\usepackage{pdfsync}

When compiling your source file, LaTeX will generate a .pdfsync file along with the .pdf output file. This file can then be used by SumatraPDF to perform synchronization.

With SyncTeX it is not necessary to load any package. However you need to specify the 'synctex' switch when compiling your document with pdflatex:

1: 
pdflatex -synctex=-1 document.tex

Also make sure you have updated your TeX installation as only recent releases of pdftex support this feature (TeXLive 2008 and MikTex 2.7).

For more details on the synchronization feature of SumatraPDF, check the following posts: Post 1 Post 2 Post 3.

Inverse search

With the inverse search synchronization feature, double-clicking on the PDF file in SumatraPDF brings you directly to corresponding line in the .tex source file.

By default the WinEdt editor is invoked. If you are using the build of SumatraPDF from my website, then you can change this command by choosing the Menu 'File\Set inverse search command line'. The format of the string is:

1: 
"C:\Program Files\MyEditor\MyEditor.exe" PARAMETERS

where PARAMETERS can contain the following macros: %f path to the TeX source file %l line number * %c column number

Forward search

Forward search gives you the ability to go from the source .tex file to the corresponding location in the PDF. When you invoke a forward search from your editor, SumatraPDF automatically highlights the corresponding location in the PDF. The communication between the editor and SumatraPDF relies on the DDE protocol (Supported by most editors such as WinEdt and TeXnicCenter).

Synchronization in action

Screenshot

Configuration for commonly used editors

This section explains how to configure forward and inverse search for some popular LaTeX editors. I have posted more detailed information about the DDE commands supported by SumatradPDF on the google code wiki.

WinEdt 6

Since version 6, WinEdt uses SumatraPDF as the default PDF viewer if it is installed. It automatically configures forward/inverse-search. The default shortcut for forward search is Shift+F8.

WinEdt 5

Inverse search

Inverse search command:

1: 
"C:\Program Files\WinEdt Team\WinEdt\winedt.exe" "[Open(|%f|);SelPar(%l,8)]"

Forward search

  1. Download the macro file Sumatra-Find.edt.
  2. Save it in the folder: C:\Program Files\WinEdt Team\WinEdt\Exec\
  3. Open the menu 'Option\Execution Modes', tab 'Acrobat' and set the field 'PDF viewer Executable' to the path to your local copy of SumatraPDF.EXE.
  4. Go to the menu 'Option\Menu setup'. Create a new macro menu somewhere (under 'Accessories' for instance) and fill the options as follows:
    • Name: Sumatra Find
    • Macro: Exe('%b\Exec\Sumatra-Find.edt');
    • Requires File Filter: %P\%N.pdf
    • Start in: %P
    • Shortcut: F8

Now when editing a .tex file in WinEdt, you can invoke forward search by pressing F8.

TeXnicCenter

Latex compilation

If your are using synchronization based on the pdfsync package then you can just compile your TeX file as usually. If instead you prefer to use SyncTeX-based synchronization then you need to tweak the compilation switches in TeXnicCenter as follows:

  1. Menu Build\Define output profiles...
  2. Select the profile Latex=>PDF
  3. Select the tab (La)TeX
  4. In the field 'Command line arguments to pass to the compiler' add -synctex=-1.

Inverse search

The inverse search command is:

1: 
"C:\Program Files\TeXnicCenter\TEXCNTR.EXE" /ddecmd "[goto('%f', '%l')]"

If you are using the official build of SumatraPDF this setting can be set permanently at the command-line with:

1: 
"C:\Program Files\SumatraPDF\SumatraPDF.exe" -inverse-search "\"C:\Program Files\TeXnicCenter\TEXCNTR.EXE\" /ddecmd \"[goto('%f', '%l')]\""

If you are using my own build then go to SumatraPDF setting dialog and set up the inverse search command from there. It will automatically suggests the correct command-line for TeXnicCenter if SumatraPDF-TeX detects that TeXnicCenter is installed.

Forward search

In TeXnicCenter choose menu 'Build\Define output profiles...', select the profile "Latex=>PDF", go to tab 'Viewer' and fill the options as follows:

Under Path of executable

1: 
C:\Program Files\SumatraPDF\SumatraPDF.exe -reuse-instance

Under View project's output Select option DDE command Command: [Open("%bm.pdf",0,1,1)] Server: SUMATRA Topic: control

Under Forward search Select option DDE command Command: [ForwardSearch("%bm.pdf","%Wc",%l,0,0,0)] Server: SUMATRA Topic: control

The first 0 in the parameters indicates that you want to view the result in any existing window where the given PDF document is opened; a new window will be created if the PDF is not already opened. Set this option to 1 to force the creation of a new window. The second 0 tells SumatraPDF to stay in the background and leave the focus to the text editor. Set the last parameter to 1 to force SumatraPDF to reload the PDF from disk (in case it is already opened).

I have documented the DDE commands supported by SumatraPDF on the the project wiki.

Under Close document before running (La)TeX * Do not close

(nt)Emacs

Inverse search

Set the following inverse search command in SumatraPDF (menu 'File\Set inverse search command line'):

1: 
C:\emacs\bin\emacsclientw.exe +%l "%f"

Auctex settings

Add the following lines to your .emacs file:

1: 
(custom-set-variables '(TeX-source-correlate-method (quote synctex)) '(TeX-source-correlate-mode t) '(TeX-source-correlate-start-server t) '(TeX-view-program-list (quote (("Sumatra PDF" "\"C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe\" -reuse-instance %o")))))(custom-set-faces)

Make sure to adjust the path to SumatraPDF.exe according to your installation.

Forward search

1- Save the script file sumatra-forward.el to your .emacs folder under your home directory, or to the site-lisp under the emacs directory. 2- Add the following line to your .emacs file:

1: 
(require 'sumatra-forward)

3- Make sure that you have the ddeclient tools installed (already bundled with the ntemacs distribution) 4- Restart Emacs 5- Load a .tex document and set the pdfLatex mode by checking the menu 'Commands\TeXing options\Generate PDF' 6- You can now press F8 to jump from any source line in emacs to the corresponding place in SumatraPDF.

[Update June, 8th 2012] AucTeX developers have recently improved support for external viewers. Titus Barik shared with me new instructions to set-up SumatraPDF with the latest version of AucTex (11.86). I have updated the above documentation accordingly. Check out his original write-up as well as the the AUCTeX documentation for more details. Older troubleshooting information can be found here.

Vim

Julien Cornebise and Manuel Pégourié-Gonnard have developed a patch for Vim-latex. You can download it from vim-fwdsumatra.zip. Installation instructions are provided in the zip file.

Links

DDE commands supported by SumatraPDF.