How To Compile Your LaTeX Document in Emacs With Only One Key Press

January 27, 2009Tagged

Do your fingers ache after hammering C-c C-c repeatedly in Emacs just to compile and view your LaTeX document? Mine did. But you can take your hands out of harms way.

If you use the MiKTeX Windows distribution there is a neat program called texify that basically does all the work. It runs BibTeX and LaTeX until all the references have been resolved. There's even a command line parameter that will cause it to display the result. The only thing left is binding a key in Emacs. I bound C-c v to a function that saves the current buffer, runs texify, and gets rid of the shell command output buffer. (If you figure out a better way of hiding the output buffer, please tell me.)

(global-set-key "C-cv" 'one-key-latex)
  (defun one-key-latex ()
  	(interactive "")
  	(save-buffer)
  	(shell-command "texify --run-viewer c:path-to-your-tex-file file.tex")
  	(switch-to-buffer "file.tex")
  	(enlarge-window 26))