LaTeX Plugin: Build system activated

This post is a quick update on the revamped LaTeX build system.

If you pull the current master branch from Github, you will now be able to invoke the custom make_pdf command using the default build system: in particular, you can hit Command+B on Mac and F5 on Windows. The temporary ctrl+alt+t shortcut no longer works: on Mac, it does nothing, whereas on Windows it errors out (I’ll fix this soon). So, just don’t use it.

This is achieved by using the “target” option in the LaTeX.sublime-build file. By default (i.e. if no “target” option is provided), the build system invokes the “exec” command. However, you can instruct it to invoke any Python-written ST2 command; in my case, I set “target” to “make_pdf”, and ST2 automagically does the right thing.

In particular, any options in the sublime-build configuration file are passed as named arguments to the make_pdf command. Even better, you can set Windows- and OSX-specific options in the sublime-build file, and make_pdf will automagically receive the settings that are appropriate to your platform!

One final bit of awesomeness. If you open the LaTeX.sublime-build file, you will see that you can pass any configuration options to the latexmk (OSX) or texify (Windows) compiler drivers, IF YOU KNOW WHAT YOU ARE DOING. For instance, on Mac, you can easily change the tex engine from pdflatex to xelatex (it’s not so easy on Windows because texify is not as flexible as latexmk). Now, I was worried that any tweaks to the sublime-build file would be lost every time the user downloads a new version of the plugin. However (and this is the above-mentioned awesomeness), it turns out that you can save a copy of the LaTeX.sublime-build file in the Packages/User directory (rather than Packages/LaTeXTools), then tweak it to your heart’s content: when you invoke the build system, the file in Packages/User will take precedence, so your tweaks will still be there! Thanks jps 🙂

There are two items on my immediate TODO list. First, I want to add an option to the sublime-build file to specify the path of TeX executables (with sane defaults that should work on most systems). This will ensure that, with a minimum of configuration (or no configuration), tex and friends will work even if the PATH is not set (or, on the Mac, you have not created an .MacOSX/environment.plist file, as per this comment). This is the main cause of grief for new users; hopefully this will solve the issue once and for all.

Second, I would like to make the viewer configurable as well. Right now it is not: you must use Skim on the Mac and Sumatra on Windows. There is an issue as to where this setting should be; the sublime-build file does not seem appropriate, strictly speaking, but on the other hand it makes sense to keep all configuration settings in the same file.

One final note: the old sublime-settings file is still available, but I appended an “.OLD” extension to it so it’s not active. However, if you really prefer the old-style build system, you can still use it (remove or rename the new sublime-build file, then remove the “.OLD” extension to the old sublime-build file). In particular, this allows you to set your favorite PDF viewer (on the Mac), although you will lose inverse and forward search.

Comments, are usual, are very welcome!

Advertisements

9 responses to “LaTeX Plugin: Build system activated

  1. Hi Marciano,

    This plugin is great, thanks a lot for its creation! Just a couple of small notes from a recent switcher from TextMate and user of BibDesk.

    Recent versions of TextMate have abandoned the key binding of “super+shift+(right|left)_bracket” in favor of what seemingly has become its standard binding on MacOS X, namely switching between tabs (is there another way to do that in Sublime Text 2? Aside from “super+digit”?). I guess it doesn’t show in TextMate’s LaTeX preference file because it’s a global binding and the lower-level settings simply are ignored. I use “ctrl” instead of “super” and it works for me, but I’m not sure whether that would create havoc elsewhere.

    BibDesk puts things like groups of articles etc. in a field called “@comment” inside the .bib-file, which causes command-completion to break. A quick hack is to replace line 151 in ‘latex_cite_completions.py’ by:

    keywords = [kp.search(line).group(1).decode('ascii','ignore') for line in bib if line.startswith('@') and not line.startswith('@comment')]
    

    Not sure whether these are of general interest, but in case somebody finds them useful…

  2. Hi Hans-Martin,

    thanks for your feedback. Re. the cmd+shift+[], I just checked, and Textmate version 1.5.10 (1631) still seems to recognize it. However, I have a tricked-out version of the LaTeX bundle, so I’m not sure about this. As for ST2, I switch tabs with cmd+opt+ and cmd+shift+[] does not pose any problems… but let me know if your experience is different.

    As for BibDesk and bib files, thanks for the fix! I’ll definitely put it in as soon as I have some time. Thanks!

  3. Thanks for the hints on the other keyboard shortcuts! But I guess I’ll stick to my keybindings so I don’t need to remember which app I’m just in :-). Here’s some discussion on the change in TextMate and some ways to override it, in case someone is interested: http://comments.gmane.org/gmane.editors.textmate.general/31637

  4. Hi Marciano!
    your plugin has come a long way! thanks for that!
    Just wanted to ask, why not also implement a latexmk solution for windows? latexmk works great in my win installation!! In fact I’ve stopped pdflatexing through winedt and now I do it only through latexmk..
    anyway, keep up the good work!!

    • Hi Sotiris, and thanks!

      I don’t have a Windows installation handy right now (I’m away from my office), but you can try copying the “cmd” option from the “osx” section to the “windows” section. It should work as-is, if latexmk is sufficiently consistent across platforms. Let me know, and I’ll add the info to the (in-progress) instructions.

  5. It does work, the thing is, I have latexmk work a bit differently: I have a latexmkrc file containing the following:
    $pdf_mode = 1;
    $pdflatex = ‘pdflatex -8bit -etex -file-line-error -halt-on-error -synctex=1’;
    $pdf_update_method = 0;
    which is called by this command:
    latexmk -r latexmkrc -pvc -quiet -pdf .tex

    which basically compiles the book everytime I save a file contained in the book. So I tried doing this in LaTeX.sublime-build
    “cmd”: [“latexmk”,
    “-e”, “\\$pdflatex = ‘pdflatex %O-8bit -etex -file-line-error -halt-on-error -synctex=1 %S'”,
    “-f”, “-pdf”],
    (I wasn’t sure how to include the other lines, and I don’t remember what they do, either)
    which does compile it, but not automatically on every change.
    Any idea how I can have the same functionality here? The ideal scenario is, I have multiple ST2 windows=projects=books loaded up, and each has its own build command. Whenever I save one file, the appropriate automatic compile should start! is this feasible?

  6. sorry the command is
    latexmk -r latexmkrc -pvc -quiet -pdf master-file.tex

    • Well, you could try passing the “-pvc” option to latexmk explicitly in the sublime build file, but I am not sure things would work. In particular, would the latexmk process stop on errors? I am not sure.

      More generally, what you want is a “watch file” functionality, where the entire file (or files) is recompiled upon every save. This is a feature I would like to incorporate at some point; it can be done without using latexmk’s pvc option, in a cross-platform way. There are also some optimizations one can implement. But, that is for a later release… please be patient, and in the meantime, let me know if adding -pvc to the build system works.

  7. works like a charm!!
    “cmd”: [“latexmk”,
    “-r”, “latexmkrc”, “-pvc”, “-quiet”,
    “-f”, “-pdf”],
    with the configuration file I’ve mentioned in my previous post. Thanks very much!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s