Technology

# LaTeX, Emacs, and Orgmode in Windows

I just reinstalled MikTeX on my Windows machine and got Emacs and Org-mode to play nice. It was almost dead simple. All you need to do is follow the installation instructions for AucTeX—the Emacs LaTeX mode.

1. Install Ghostscript and GSview.
2. Install MikTeX. Select Yes for Install missing packages on-the-fly.
4. Unzip the archive into the root Emacs directory. Make sure you haven’t installed another version of AucTeX.
5. Install the image libraries: libpng and zip as per the Emacs README. You can find them at the GnuWin32 Project Page.
6. Ensure the environment variables for Ghostscript, MikTeX, and GnuWin are set (otherwise, Emacs won’t be able to find them). Select Control Panel >> System >> Advanced >> Environment Variables. Now openPath in System variables. You should see the binary directories for Ghostscript, MikTeX and GnuWin.
7. Setup Emacs. Add the following lines to yourinit.el file:
 (setq Tex-auto-save t) ;I forget what these do, I've (setq TeX-parse-self t) ;always had them (require 'tex-mik) (load "auctex.el" nil t t) ;Now necessary with latest ;version of AucTeX (setq org-export-with-LaTeX-fragments "dvipng") ;Now necessary with ;orgmove version 7.4 ;or later 

### Hello LaTeX World

Fire up a Windows command prompt and run latex test.tex on this test file:

\documentclass{article}
\title{Hello Emacs and MikTeX}
\author{Jane Doe}
\date{May}
\begin{document}
\maketitle Hello LaTeX world!
\end{document}

Note: This may or may not won’t work in Emacs the first time. Try the Windows command prompt instead.

Did everything work? Then try to preview the file in Emacs. C-c c

Now fire up Org-mode. Enter an equation and press C-c C-x C-l to preview the equation. Enjoy.

### Troubleshooting

Did you restart your computer? Emacs won’t be able to find the MikTeX installation unless you restart the computer.

I had problems running LaTeX the very first time in the Emacs shell. It tries to load the GUI in order to download missing packages, but can’t. So you may want to test out LaTeX first using the Windows command line.

If you get a timeout error from MikTex, you may need to change the repository. Get a list of working repositorieshere. Then in the command line, type:

mpm --set-respository=URL

where URL starts with ftp:// or http://.

For more debug errors, check out the *Messages* buffer. Also, try running LaTeX from the command line.

A couple of misc. comments: these instructions are for Windows XP. I have no idea if they work in Vista or Windows 7, but I imagine that the instructions are similar. Secondly, my Windows install got trashed by a virus so I was unable to fill in some of the details (like the correct program paths). Feel free to add these to the comments.