Note: LaTeXTools for Sublime Text now supports automatic engine detection if your file starts with %!TEX program = <program>
, where <program>
is any of pdflatex
, xelatex
or lualatex
. The below instructions are only necessary if you need to manually switch engines for whatever reasons.
Take the LaTeX.sublime-build
file in the LaTeXTools
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 and xelatex
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):
import sublime, sublime_plugin, os, shutil, filecmp
class SwitchCommand(sublime_plugin.ApplicationCommand):
def run(self):
folder = os.path.expanduser( \
'~/Library/Application Support/Sublime Text 2/Packages/User/')
latex_src = folder + 'LaTeX.sublime-build.latex'
xetex_src = folder + 'LaTeX.sublime-build.xetex'
dest = folder + 'LaTeX.sublime-build'
if filecmp.cmp(dest, latex_src):
sublime.status_message("Switching to XeTeX")
shutil.copy(xetex_src, dest)
else:
sublime.status_message("Switching to LaTeX")
shutil.copy(latex_src, dest)
And create a keyboard shortcut for it in Preferences » Key Bindings – User:
[ {
"keys": ["super+shift+x"], "command": "switch"
} ]
You can also add this to your menu by adding the Main.sublime-menu
file to your User
package:
[ {
"id":"tools", "children":
[ {
"command": "switch",
"caption": "Switch between LaTeX/XeTeX"
}
]
} ]
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.
Best Answer
Here's the answer if anyone is interested.
It turns out that Sublime Text 2 has a built-in functionality for switching file types in the Command Palette.
So to switch from plain text file type to xml:
1) Ctrl+Shift+P
2) type "xml"
3) select "set syntax:XML"
note: for SQL file type, type in "ssql"
It's not a single key binding answer but it certainly does the trick for my needs.