Thursday, November 3, 2011

Working with LaTeX and Preview in OS X 10.7.2 Lion

In the past, compiling and previewing my LaTeX document from vim was as simple as running make and open as external commands:

:!make clean all; open document.pdf

open is a handy command line program that opens the file with the default Mac application for its file type.

I end up having multiple windows open for document.pdf but that was fine for me.

In OS X 10.7.2, this process broke because Preview would hang for 1-2 minutes when the LaTeX compiler is still building the pdf. A naive approach would be to make an AppleScript to close Preview's window of document.pdf before running make.

However, I found a nice trick that makes use of the way Lion handles process termination. From the Ars Technica review:
"Lion reserves the right to keep an application's process around just in case the user decides to relaunch it. Upon relaunch, the application appears to start up instantly—because it was never actually terminated, but was simply removed from all parts of the GUI normally occupied by running applications."

So we can just do:

:!make clean all; killall Preview; open document.pdf

By terminating Preview, we skip its lag in figuring out the changing document and at the same time, we get no duplicate windows for document.pdf in Preview.

That's a win-win! :)


No comments:

Post a Comment