PDF syncing in Sublime Text for LaTeX on Windows

I have moved all of my work back onto a Windows box recently, which means completing overhauling my LaTeX setup. I know there are a lot of integrated environments for LaTeX on Windows, but I prefer a straight text editor. Coming from Textmate, I landed on Sublime Text 2.

Sublime comes with a LaTeX bundle already installed (which has syntax highlighting and a number of other bells and whistles), but it takes a bit more elbow grease to achieve two-way syncing with a PDF viewer and use XeTeX. I couldn’t find anywhere else on the web that exactly details this process and confirms that it works, so for anyone searching for the solution (and for myself next time), here is how I got it working:

  • Install Sublime Text 2 and Sumatra PDF Viewer.
  • Install the Sublime Package Control package using these instructions.
  • Install the LatexTools package from these instructions.
  • Make sure SumatraPDF.exe is in your path.
  • Find the file LaTeX.sublime-build in the LatexTools directory and replace the following (in the Windows portion):

    “cmd”: [“texify”, “-b”, “-p”, “–tex-option=”–synctex=1”” ],

with

"cmd": ["latexmk",
"-e", "$pdflatex = 'xelatex %O -interaction=nonstopmode -synctex=1 %S'",
//"-silent",
"-f", "-pdf"],
  • Set Sumatra to perform inverse search in Sublime. Open a LaTeX-generated pdf that was compiled with synctex enabled, and you will see a relevant option in the Sumatra preferences. Replace that line with:

    “C:Program FilesSublime Text 2sublime_text.exe” “%f:%l”`

And you’re done. Now, you can compile any LaTeX file in Sublime Text via latexmk by ctrl+b, and it will launch the pdf in Sumatra, opened exactly at the location of your last edit. When you want to go back to the LaTeX source in Sublime Text, double-click in the pdf wherever you want the source to open.

Big improvement over opening on the title page of your dissertation every compile.

You can read more about me, follow me on Twitter, subscribe to this blog by RSS or email, and find many more posts in the archives.