Emacs 23 and AUCTEX

November 6th, 2009
Comments Off

The default Mac OS X install of Emacs 23 that I installed from gnu.org didn’t include the AUCTEX package by default. So, here’s my notes about what I had to do to get it running. This assumes that you’ve already installed Emacs 23 and some variant of TexLive on your machine and that both applications are behaving correctly.

First, download and install AUCTEX from the appropriate place on gnu.org. I had no problems following the standard steps in the “Configure/make/make install” cycle.

Now we start the tweaking of Emacs adding the following lines to .emacs file to load AUCTEX and Preview LaTeX when Emacs loads:

(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

(add-hook 'LaTeX-mode-hook '(lambda ()
                 (TeX-fold-mode 1)
                 (outline-minor-mode 1)
                   ))

The first two ELisp expressions load the extensions into Emacs while the second adds an additional expression to the list of expressions called whenever someone attempts to load a LaTeX file into the editor. In this particular case, we enable the AUCTEX “Folding mode” and “Outline modes”

Now we add some additional expressions that I like to add to the mode hook to make things work in cleaner fashion:

  (add-hook 'LaTeX-mode-hook '(lambda () (setq fill-column 72)))
  (add-hook 'LaTeX-mode-hook 'TeX-PDF-mode)
  (add-hook 'LaTeX-mode-hook '(lambda () (setq TeX-DVI-via-PDFTeX t)))

In this case, I’m telling Emacs to automatically word wrap at 72 characters, always use PDFlatex to generate output, and generate both DVI and PDF files for output.

A new feature in Emacs 23 is “Doc View” which is an integrated viewer for PDF, PS, and DVI files. There are some configuration adjustments you have to make to get this feature playing politely with AUCTEX. First, you need to tell Emacs to automatically start in server mode when it loads. Do this by including the following in your .emacs file:

(server-start)
(add-hook 'server-switch-hook
 	  (lambda nil
 	    (let ((sevrver-buf (current-buffer)))
	      (bury-buffer)
 	      (switch-to-buffer-other-frame server-buf))))
(add-hook 'server-done-hook (lambda nil (kill-buffer nil)))

The first expression tells this instance of Emacs to act as a server. The second expression modifies the server-switch-hook to always service new incoming client requests in a new frame while the second kills the server buffer when the server says it’s through with the current buffer.

Then you need to configure AUCTEX to use the emacsclient utility whenever Emacs attempts to open PDF, PS, or dvi files. You do this by changing the value of the TeX-output-view-style variable:

    (setq TeX-output-view-style
	  (quote
	   (
	    ("^dvi$" "." "/Applications//Applications/Emacs.app/Contents/MacOS/bin/emacsclientemacsclient %o")
	    ("^pdf$" "." "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient %o")
	    ("^html?$" "." "open -A Safari.app %o")
	    )
	   )

Using other tools (such as Preview or Skim) as a viewer just require that you change the matching value in Tex-output-view-style.

I should note that DocView doesn’t work very well in the Windows version of Emacs 23. You can make some configuration changes to make it work but it’s best to just stick with an external viewer.

Selah.

how?