Multi-file Editing for LaTeX in Emacs

1 minute read

When I edit large research papers in LaTeX it tends to become a quite large file with lots of distractions. Things like package statements, settings and other document oriented stuff. When I start writing I like to be focussed on the text and not all the stuff that is around it. For this reason I split up my documents into multiple files.

I use a main.tex to tie everything together. Then I split up things like settings, packages and commands in their own files that I include in the main file by using the \input{filename} command.

One of the powers of Emacs' LaTeX (AUCTeX) editing facility is that I can build the document right from within Emacs, but when you split the text over multiple files this no longer works. Luckily there is an option called master file that can be used to tell the LaTeX that when I want to build the current file it should actually build it using the master file.

By adding a small section at the bottom of each file I can tell Emacs to use the file main.tex as the master file. The following snippit assumes that there is a file called main.tex one directory up from the current file. It also tells the TeX-engine to use the xetex compiler instead of the latex default compiler and to always generate a PDF file.

%%% Local Variables: 
%%% mode: latex
%%% TeX-master: "../main"
%%% TeX-engine: xetex
%%% TeX-PDF-mode: t
%%% End: