Ever since I learned about Emacs+AUCTeX, it’s been the ultimate LaTeX editor for me. Since I don’t want to rehash everything said online about the glorious world of LaTeX editing with AUCTeX (and friends), here’s a link – Emacs as the ultimate LaTeX editor.

Until today, I used Carbon Emacs – Emacs 22 bundle for Mac OS X. It was perfect – everything important (AUCTex) was nicely bundled in, it kept me shielded from the cruel world of package installation. Until Emacs 23 came out and decided to put out its own Mac OS X bundle, which really obsoleted Carbon Emacs.

I resisted the change for a while, I said “well, people have written their PhD theses in Emacs 22 (and earlier), so WTH would I need Emacs 23”. I don’t have an answer to that question, but being a progressive ;), I decided to… progress. And update to Emacs 23. Since there are no bundled packages with the GNU distribution of Emacs for Mac OS X, I needed to update AUCTeX myself. Troubadours being gone, nobody was here to compose a song about my epic struggles, so this blogpost will be the reminder of how I did it. And learned to love the bomb.

Peel off the bandaid. Drag Emacs.app to Trash. http://emacsformacosx.com/ Download and install. Make sure .emacs is read and loaded correctly. YMMV but mine was read perfectly, except the stuff related to AUCTex (’cause I ain’t got no AUCTex yet, see). Download AUCTex. AUCTex will need to be compiled from eshell – emacs’s shell. However, without a configuration file, eshell won’t see the environment variable, by which I mean $PATH as the most important one. The configuration file, written in XML, that enables Emacs to see the variables should be in $HOME/.MacOSX/environment.plist . Now, I wanted a permanent solution, robust to installations and changes in $PATH variables. To that end I’ve written a file $HOME/.MacOSX/environment.template that contains the boilerplate with XXXX marking the spot where value of $PATH variable should be: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd";> <plist version="1.0"> <dict> <key>PATH</key> <string>XXXX</string> </dict> </plist> In my .bash_profile I added a sed-command that generates environment.plist every time .bash_profile is run. script=`sed -e "s|XXXX|${PATH}|g" ${HOME}/.MacOSX/environment.template` printf "${script}" > ${HOME}/.MacOSX/environment.plist The important part is to use vertical lines as delimiters in sed command, instead of usual slashes, as $PATH is bound to contain too many slashes for sed to be comfortable with. Using vertical line as delimiters lets sed process slashes as ordinary characters. Now it’s time to go to Emacs’s eshell and configure – make auctex. I used this configuration line: ./configure --prefix=$HOME --with-emacs=/Applications/Emacs.app/Contents/MacOS/Emacs --with-lispdir=/Applications/Emacs.app/Contents/Resources/site-lisp --without-texmf-dir After configure runs, make && make install will take care of things. Now it’s time to make Emacs play nice with AUCTeX. First thing – ~/.emacs (YMMV): ;; AUCTEX load (require 'tex-site) ;; PDFLatex mode in latex-mode (add-hook 'latex-mode-hook 'TeX-PDF-mode) (add-hook 'LaTeX-mode-hook 'TeX-PDF-mode) ;; flyspell-mode in latex-mode (add-hook 'latex-mode-hook 'flyspell-mode) (add-hook 'LaTeX-mode-hook 'flyspell-mode) (add-hook 'TeX-PDF-mode-hook 'flyspell-mode) ;; reftex load (add-hook 'latex-mode-hook 'turn-on-reftex) (add-hook 'LaTeX-mode-hook 'turn-on-reftex) (add-hook 'TeX-PDF-mode-hook 'turn-on-reftex) (setq reftex-plug-into-auctex t) (setq reftex-cite-format 'natbib) (add-hook 'bibtex-mode-hook 'turn-on-auto-revert-mode) ;; AUCTeX automatic file parsing on save and load (setq TeX-parse-self t) (setq TeX-auto-save t) The above will make everything except for PDF viewer work nice. By default AUCTeX will try to use evince as the PDF viewer. That will never do, because “it is known”™ that Skim is the best thing for PDF viewing since sliced bread. Why? Well, it has an auto-reload feature, it can highlight the line you were just editing in emacs, and it can open .tex file on the line of your choosing by CMD+SHIFT+Mouseclick. Yes, it can. Anyway, you can play around with options all night long, but this post is about shortcutting things, so here’s the end result of playing with customize-group AUCTeX . It gets saved as an entry in .emacs (custom-set-variables section. (Note the danging parenthesis 😉 . (custom-set-variables '(LaTeX-command "latex -synctex=1") '(TeX-view-program-list (quote (("Skim" "/Applications/Office/Skim.app/Contents/SharedSupport/displayline %n %o %b")))) '(TeX-view-program-selection (quote ( ((output-dvi style-pstricks) "dvips and gv") (output-dvi "xdvi") (output-pdf "Skim") (output-html "xdg-open") )) ) ) The important line is the one that sets “output-pdf” mode to “Skim” and the “TeX-view-program-list” that defines “Skim”. In the definition of Skim %n is the line where .tex file is being edited, %o is the pdf output file and %b is the name of the buffer – the .tex file that is being edited. Adding -synctex=1 to the usual latex command enables the back-searching: CMD+SHIFT+click in Skim opens the corresponding file in emacs to edit it. You can enable the support for this feature in Skim’s Preferences – Sync. Just set it to Emacs.

This should do it.

References: