Configure forward search with Texmaker + SumatraPDF

It seems that Texmaker does not allow DDE commands, but since version 1.9 SumatraPDF supports forward search not only via DDE commands, but also via command line switches. Since version 3.2.1 Texmaker has all variables that are needed to use forward search. These are

  • % for the basename of the master file (without path and without extension),
  • ! for the full path to the directory where the master document resides,
  • # for the basename of the currently active file (without path and without extension) and
  • @ for the line number.

So usually the following should work:

""C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" -reuse-instance "!/%.pdf" -forward-search "!/#.tex" @

This will fail when including from a subdirectory. A workaround is to add the subDirName to the path manually:

""C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" -reuse-instance "!/%.pdf" -forward-search "!/subDirName/#.tex" @

But then the subDirName should be identical in all projects, so this is more a workaround than a real solution.

Here is a screenshot of my Texmaker configuration: enter image description here


This is meant to be a response to the answer from Vlastimil above. I found that inverse search works fine without the batch file. I just use the following line in Sumatra PDF Options (it came up automatically as an option). I'm using Sumatra 2.1.1 and Texmaker 3.5.

"C:\Program Files (x86)\Texmaker\texmaker.exe" "%f" -line %l

As others have stated, forward search works as well with the command line in Texmaker's options:

"C:/Program Files (x86)/SumatraPDF/SumatraPDF.exe" -reuse-instance %.pdf -forward-search "#.tex" @

I just made a doc describing how to setup Texmaker and SumatraPDF with forward and inverse search, but fully portable which is bit tricky. Link to the how-to http://goo.gl/hxDeu (without redirect: http://goo.gl/hxDeu+) or see below:

1. Configuring Texmaker to use SumatraPDF as external PDF viewer with forward search Open your portable Texmaker and set path to external viewer as follows:

./SumatraPDF/SumatraPDF.exe %.pdf -reuse-instance -forward-search %.tex @

Note that path to SumatraPDF.exe is relative to Texmaker executable and you may need to edit this path to match your folder structure.

Texmaker -> Configure Texmaker -> Commands

2. Configuring inverse search in SumatraPDF

By default SumatraPDF does not allow to configure inverse search via GUI. Run once the following command:

SumatraPDF.exe -inverse-search "texmaker.exe %f -line %l"

You should not change the path to texmaker.exe file, even if you have different folder structure than I had.

SumatraPDF option window with unhidden inverse search settings

3. Create startup batch file

Due to some limitations in SumatraPDF we have to start Texmaker with following batch file everytime we want to use SumatraPDF as external viewer. Place the following commands in texmaker-portable.bat and save this file to the same folder as Texmaker.exe. Also note that you can pass any parameter to texmaker-portable.bat that you could pass to texmaker.exe itself.

@echo off
set PATH=%~dp0;%PATH%
start /D "%~dp0" texmaker.exe %*

4. Run texmaker-portable.bat and test the settings

Troubleshooting

  • make sure you are using -synctex=1 or -synctex=-1 parameter while formatting a tex file
  • the tex file should not contain space in its name (Texmaker and SumatraPDF handles spaces just fine, but SyncTeX file may not be created even with -synctex=1 parameter)
  • make sure you started Texmaker with the batch file and SumatraPDF via Texmaker (this chain is mandatory)