Setting up a nice AucTeX environment on Mac OS X

Most people I know use TeXShop on Mac OS X. While it’s a pretty good TeX editor, I think Emacs is overall vastly superior. Of course, I’m rather biased since I already use Emacs for everything else… Perhaps this post will be useful to other Emacs-addicted astronomers.

In my setup, I use the AUCTeX package coupled with the Skim PDF viewer (if you’re not using Skim, download it, it’s brilliant!). One of the advantages of this combination is that Emacs and Skim can be kept in sync, like in the screenshot below.

Skim + Emacs/AUCTeX nirvana. Note that the current highlighted line in Skim corresponds to the cursor position in Emacs.
Skim + Emacs/AUCTeX nirvana. Note that the current highlighted line in Skim corresponds to the cursor position in Emacs.

I found it a bit difficult to set up the AUCTeX package with sensible defaults, so I’ll reproduce here my configuration in hopes that it will be useful to someone else.

The salient lines are the ones configuring latexmk and Skim. You should have latexmk installed if you are using the TeX Live distribution; Skim can be downloaded for free here. You can stick this script in your Emacs initialization file (see my dotemacs repository if you’d like to see my other Emacs configs). I shamelessly copied those lines from this Stack Overflow answer.