LaTeXTools plugin: new features

I have recently added two simple but hopefully useful features to the LaTeXTools plugin. I hope they will make your TeX life more comfortable.

As usual, you will get the updated plugin automatically if you installed LaTeXTools using Package Control, which, as I noted earlier, I strongly encourage you to do.

Switching to the PDF viewer after compiling

By default, LaTeXTools keeps the focus on the Sublime Text 2 (ST2) window after compiling a TeX source file to PDF. This is convenient in two scenarios. First, if you have a large screen (or two monitors), you can keep ST2 and your PDF viewer side by side, and just glance at the output to see that all is OK. It would be quite annoying if the viewer window was brought to the foreground in this case: in order to continue editing, you would have to manually switch back to ST2 (using Alt-Tab or Cmd-Tab, depending on your platform). The other scenario is when you are making many small changes to the file sequentially; you compile to make sure that there are no errors or warnings, but do not need to check the PDF output every time. I also have friends and coauthors who simply don’t need to look at the PDF output all that often–they can read LaTeX easily, and would much rather not be distracted by the viewer window popping up.

That said, it is sometimes convenient to switch to the PDF output, especially if you are using a small screen and running both ST2 and your viewer in full-screen mode. In such cases, it would be nice if LaTeXTools could automatically bring up the viewer after compiling. Yet, the previous paragraph gives a few reasons why this shouldn’t be hard-wired.

Enter the Toggle Focus command (bound to Shift+Win+F on Windows and Ctrl+Cmd+F on OSX). It does what you think: every time you invoke it, it changes what the Build command does after compilation. Again, by default, the Build command refreshes the PDF viewer but makes sure that ST2 keeps the focus; so, if you invoke the Toggle Focus command, the next time around Build will actually tell the PDF viewer to grab the focus, i.e. pop us as the frontmost window. Invoke Toggle Focus again, and you get the default behavior back. Every time you switch, a short notification appears in the Status Bar (at the bottom of the ST2 window), so you know what you just did.

Note that this setting is preserved with your session; if you quit ST2 without first closing the tab you are working on, ST2 will remember the status of the focus toggle.

Wrapping existing text in LaTeX commands or environments

The current facilities for entering LaTeX commands or environments (Alt-Shift-[ and Alt-Shift-] on Windows, Cmd-Shift-[ and Cmd-Shift-] on OSX) are useful when you want to first specify the type of environment or command you want, and then enter text in it. However, sometimes you want to wrap some existing text in a command or environment. The most common use case is to emphasize text, or make it bold. I don’t use this feature that often myself, but a colleague mentioned it as one of the main reason why he was sticking with TextMate for the time being.

I have now added a nice collection of wrap commands. They are all bound to Alt-Shift-W on Windows and Option-Shift-W on OSX, followed by an additional key (i.e. you use a “key chord” to invoke them). You must select some text prior to invoking these commands.

Alt+Shift+W followed by n wraps the selected text in an environment, which by default is called “env”: that is, if “blah” is the text currently selected, it gets replaced by

\begin{env}
blah
\end{env}

and the env is highlighted. Enter your desired environment (e.g. “theorem”). When you are done, hit Tab to jump to the end of the environment.

Alt+Shift+W followed by c instead enters a command: “blah” becomes \cmd{blah}, with cmd selected so you can change it to whatever you like.

Finally, a few common commands have dedicated key bindings: Alt+Shift+W followed by e, b and u respectively give you \emph{...}, \textbf{...} and \underline{...}.

Happy TeXing!

Advertisement

16 Responses to LaTeXTools plugin: new features

  1. Thanks so much for your LatexTools plugin. Because of this, I am close to switching over to ST2 from TM, but cannot do without “Go to symbol”. Is it in ST2 somewhere? Command-R does not have the nice outline of chapters, sections, subsections, subsubsections, all indented as in TM .

    • Hi Jenny,

      yes, Cmd-R doesn’t quite match TM’s Go to Symbol. I plan on fixing it at some point soon though, because Go To Symbol was one of my favorite TM functions.

      A bit of history: Cmd-R actually piggybacks on ST2′s “go to anything” functionality. The plugin merely tells ST2 what a “label” or “section” is, but it is up to ST2 to decide how to present them (in particular, how to sort the items in the list). When I added Cmd-R support to the plugin, this was pretty much the only way I could present the user with a list of items that could be clicked on—recall ST2 is technically still beta software.

      However, plugin writers can now (finally!) access the exact same UI that Cmd-R uses, but also provide the “plumbing”, so to speak (i.e. decide what to show and how). So, the tools are there, and it’s just a matter of me finding the time to implement the Go to Symbol functionality. If only I didn’t have letters of recommendation, referee reports, tenure letters and the like to worry about. Oh yes, and pushing my own papers through the pipeline, too :-)

      • Don’t I know it! I just found out that TM2 is scheduled for a Christmas release. This could change everything. Alan Odgaard deserves full attention.

  2. Hi Marciano,

    Thanks for the wonderful plugin! May I suggest two features that would make Latex in ST2 even more awesome:
    - Making spell check Latex aware (although is aware of most Latex commands) by treating ~ as space: “Theorem~1″ would become “Theorem 1″.
    - The cite command only displays the title field. In Textmate they also display authors. For me this makes more sense since I remember authors better than titles :-p.

    Cheers

    • Re. spell-checking, that’s ST2′s job: the plugin can’t really do much about it. ST2 uses Hunspell, and I guess LaTeX support could be better….

      Re. citation command, I’m actually revamping the system. It will now use the quick panel (which looks just like the Go To Anything panel), and will display (and make searchable) both the title and the author(s). Please be patient!

  3. I just read up a bit on spell checking LaTeX documents and apparently hunspell is able to spell check TeX/LaTeX files using a parameter:

    hunspell -l -t -i utf-8 yourfile.tex

    (see http://en.wikibooks.org/wiki/LaTeX/Tips_and_Tricks)

    I do not know if parameters can be passed on to hunspell via ST2, but if it is possible, spell checking should be possible.

  4. I just tried spellchecking my tex document by pressing F6 in build 2162 and it works perfectly!

  5. First, thanks for the awesome plugin! It is making my typesetting so much more comfortable. I really like the new feature allowing me to switch focus to the pdf output immediately after compiling. While I like this behavior in general, it is a nuisance if there are errors in compiling. Would it be possible to enhance this feature so that it doesn’t automatically switch focus to the pdf if there are errors in compiling? Since you’re already parsing the log file for errors, this should be a relatively easy enhancement. Thanks again for your time and effort!

  6. Sorry, my code doesn’t work. The reason it was working when I was using it was a bizarre coincidence in error handling. Could you please delete my previous two comments giving the code so other people may not use it? Sorry again about that.

  7. OK, I finally figured out the right way to do it. It was quite easy as you said, although it requires changes in a few places in the file makePDF.py.
    First, change the definition of the function finish to:

    def finish(self, errors):
           sublime.set_timeout(functools.partial(self.do_finish, errors), 0)
    

    Next, change the signature of do_finish() to:

    def do_finish(self, errors):
    

    Then, change the last line of do_finish() to:

    if not errors:
           self.window.active_view().run_command("jump_to_pdf")
    

    And finally, change the last line of run() in CmdThread to:

    self.caller.finish(errors)
    
  8. hey,
    thanks for the great plugin. I really miss it now on linux, how are the chances of pulling the changeset on github/making it work? I’d be happy to help.

    Thanks
    Jan

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 )

Connecting to %s