Editing latex documents in emacs

NEW YEAR, new me. Now is a pretty good time to get your CVs and similar documents up to date. I wanted to have a play with typesetting it in Latex. Being a pretty lazy person, I quickly tired of the workflow of making a small change, saving the file, running latexpdf (praying I didn't break the syntax), and refreshing the resultant pdf file. I wondered whether Emacs had a pre-existing solution for me (of course it does). There are two main parts to this - 1) Get the pdflatex command on your path, and 2) Show the output from the pdflatex command in a emacs window (automatically updating when the input .tex file is updated). We'll use basictex for the pdflatex command, and latex-preview-pane for, well, the latex preview pane.

Here I'm going to describe the process I went through to get everything set up from scratch. I'm working on a Mac, using Homebrew as a package manager, but the steps are pretty much the same whatever OS you're on, once you've got the pdflatex command on your PATH. Our first step for getting things up and running is to get the pdflatex command onto your path. The full latex install takes up a fair amount of space, including a number of packages you're unlikely to ever need (at least for now), so we'll install the basictex package. To do so using Homebrew, using the commandline enter

brew install basictex

Once this completes, check everything is working by running


If it works, you should see a bunch of information about pdflatex, and it will ask you for an input file. For now just enter x to exit.


pdflatex command is successfully added to PATH

Now that we have the pdflatex command on our system, we can go looking for an appropriate Latex template for our CV, and test the install. I decided to use the Modern CV template. Download and extract it. If you downloaded Modern CV, take a look in the examples directory for template.tex file. Make a copy of this file and rename it to something friendly like jack_resume.tex, and copy it, and the file picture.jpg to the parent directory. Now we're going to test that our latex install is working. With a commandline from the moderncv folder (or the folder for whatever template you downloaded), run the pdflatex command, with the file you renamed earlier. In other words, for my example this would be

pdflatex jack_resume.tex

All going well, you should see a success message, and a pdf file spit out with the same naming convention as your .tex file. All not going well you'll need to install some packages (remember, we did a minimal latex install). Luckily this is pretty easy. Try install any missing packages using the

tlmgr install PACKAGE_NAME

command, then try again.

If all is well, open your version of jack_resume.tex in Emacs, and run latex-preview-pane mode. Emacs will render your document in another window alongside the .tex buffer. This window can be nanigated in the normal way you navigate your buffers (C-n C-p etc). Typically, I like to write the text of the document in a org-mode buffer when I am word processing. Then I open up two additional windows for the .tex file and the latex-preview-pane when it comes time to typeset. Remember to use C-x O to jump between buffers, and make liberal use of eyebrowse mode.


Use eyebrowse mode to help preserve your layout in the case of any stray C-x 0 presses