latexmk

I write all my papers with LaTeX, and one nice thing about LaTeX is that it takes care of all the formatting and stuff for you: you just focus on writing in plain text and adding the necessary mark-up. My problem, however, is that I’m just too stubborn for this and usually take each trip into LaTeX-land as an opportunity to tweak away as a way to procrastinate. So this morning when I sat down to work on a memo on my dissertation for my committee, guess what I did? I tweaked LaTeX instead of writing.

However, I can justify it this time because I actually learned something that’s going to make the rest of my life with LaTeX that much easier: latexmk. The single biggest pain in using LaTeX (well, aside from remembering weird markup and searching for typos that prevent your file from compiling!) is that you have to run latex manually each time you want to look at the PDF output from your file. Even worse, if you’re using bibtex citations (which, in academic papers, you are), you have to run latex, then bibtex, then latex again every time. There are ways to streamline this, but nothing I’ve found works as well as latexmk. Basically what latexmk does is watch your .tex file for changes and then run whatever needs to be run to update your PDF automatically.

So here’s what this means: I open up my .tex file in any text editor, I start latexmk in a Terminal window, and open the PDF in a PDF viewer (You can use Preview, but Skim has one big advantage: it can auto-refresh in the background*). Every time I save my .tex file, latexmk automatically runs in the background and Skim automatically updates to display the changes in its window as well. In other words, I never have to leave my text editor and never have manually run latex at all. I just save the file. And with Leopard, since you can scroll a window by just hovering over it (without selecting the app), I can even scroll through the PDF without ever removing focus from the editor window with my .tex file.

To make all this work on a Mac, do the following:

* So, in the example above, if you use Preview, you have to select Preview before it updates itself. With Skim, you can just glance over at the window and it will update on its own. To make it do this, just look at the “Sync” tab in Skim’s preferences and set it up for your editor. I use MacVim, so I choose “Custom” and put “mvim” as the command.