I often switch between compiling "classic" LaTeX and XeTeX documents.
Sublime Text 2 has a package called LaTeXTools that allows you to build LaTeX documents via a simple CmdB. Neat.
The build file LaTeX.sublime-build
obviously exists in the standard package folder, and you can copy it to your User
folder to customize it. Here, it allows you to change the arguments given to latexmk
, namely to switch from pdflatex
to xelatex
, for example like this:
"cmd": ["latexmk", "-cd",
//"-e", "\\$pdflatex = 'pdflatex %O -interaction=nonstopmode -synctex=1 %S'",
"-e", "\\$pdflatex = 'xelatex %O -interaction=nonstopmode -synctex=1 %S'",
//"-silent",
"-f", "-pdf"],
Now, it's very tedious having to do that every time I open up another document – open my build preferences, comment out the one line, save, etc.
Ideally, I'd like to be able to switch the engine
-
… automatically – TextMate for example somehow does that, and I can compile both LaTeX documents and XeTeX documents with a simple CmdR, although the TextMate configuration is set to
pdflatex
. Maybe it's somelatexmk.pl
-fu, I don't know. -
… with a simple keyboard shortcut or setting – Maybe pressing CmdL, CmdX or similar. This would then toggle between
pdflatex
andxelatex
building.
How could I set that up?
Best Answer
Take the
LaTeX.sublime-build
file in theLaTeXTools
folder under~/Library/Application Support/Sublime Text 2/Packages
and copy it to~/Library/Application Support/Sublime Text 2/Packages/User/
, but do it twice and give those files the following name:LaTeX.sublime-build.latex
LaTeX.sublime-build.xetex
Change the files to use the
pdflatex
for LaTeX andxelatex
engines for XeTeX, respectively (as seen in the question).Then, create a new plugin through Tools » New Plugin… (saving it as
switch.py
to the location above):And create a keyboard shortcut for it in Preferences » Key Bindings – User:
You can also add this to your menu by adding the
Main.sublime-menu
file to yourUser
package:This will now compare the currently active build file with the build settings needed for XeTeX and LaTeX and switch them if necessary.
This could sure use some improvement, but it works for the moment.