LaTeX plugin: Terminating a lengthy build process.

I just pushed a few patches to GitHub. If you get a fresh copy of the LaTeX plugin for Sublime Text 2, you will now be able to stop (Unix: “kill”; Windows: “terminate”) a lengthy build process simply by invoking the build command while a build is ongoing.

To clarify: say you start a build, e.g. by hitting CMD-B on the Mac. Suppose that you are compiling a Beamer presentation, which typically takes a while. Suddenly, you realize that there is a nasty typo in a slide. Instead of waiting for the build to end, you can now issue the build command again (e.g. by hitting CMD-B on the Mac): this will stop the currently running build, and print a message to this effect in the output panel. You can then fix the typo, and launch a new build as usual.

Caveats: this is my first stab at build killing. The required code (in definitely hits the ceiling of my Python threading abilities. So far, it seems to be working (I’ve been using it myself all day, as I prepare for two upcoming conferences), but please test it yourself and let me know how things are.

Second, I have only tested this on the Mac. The Python code I use is fully cross-platform, but you never know. If you are on Windows, I’m even more curious to know if things work for you.

Final note to self and to fellow Python coders: I initially had quite a bit of trouble, because I used to execute the actual TeX commands via Popen.communicate. Trying to use Popen.kill() on a Popen object did not really work, in the sense that considerable time elapsed between the time the kill() method was called and the time the process actually exited. I am now using Popen.wait() to execute the TeX command, and the process is terminated almost instantaneously. There seems to be some funny business having to do with capturing output going to STDOUT in Popen.communicate(); using Popen.wait() avoids this (although you then have to send output to a temp file, if you need to capture it–which I don’t at the moment).


2 responses to “LaTeX plugin: Terminating a lengthy build process.

  1. I don’t know if this is related *at all*, but the other day I was using sublimetext with the latex plugin, along with winedt, and, something happened, and my system became very very slow.. I opened the task manager and noticed there were 3 pdflatex tasks open, continuously creating and destroying the pdf file of my book (it didn’t have time to grow up to its full size). What’s worse, I couldn’t kill the tasks!! it was not permitted!! (I had to restart)

    • Well, it’s odd that you could not terminate the processes… I would have looked for a “perl” process, which was probably running the latexmk script, which in turn spawned the pdflatex tasks. Anyway, yes, this is precisely what I was afraid of. I think latexmk -pvc sort of “sits in the background” until you explicitly kill it. I am not quite sure what happens if you launch a build multiple times. Anyway, I need to investigate this further. In an event, a “clean” solution would be to implement a rebuild-on-save feature within ST2. A simple-minded version shouldn’t be hard to get working, as ST2 does provide you with enough hooks. However, there are some possible optimizations, such as precompiling the preamble; the textmate latex bundle does this. I’ll see…

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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