Working with Large LaTeX Documents (in Emacs)

September 8, 2014

Eivind Uggedal in Working Effectively with Large LaTeX Documents:

First off, you are digging your own grave if you’re not seperating your document into separate files. I tend to use a separate file for each chapter. Long chapters could also be separated into a file for each section. For chapters you should use the \include{} command for including you separate files into you main document. The \input{} command is best suited for including several sections from multiple files as it does not automatically start a new page for every included file.

I agree with essentially everything here and in the rest of the article except perhaps the part about digging your own grave. I am less quick to split documents into separate files; I usually don’t do so for anything under 40–50 pages unless I am working with coauthors (in which case putting sections in separate files can help minimize conflicts arising from simultaneous edits). I find that Emacs handles large, single-file documents quite easily and I enjoy being able to move between sections as needed without opening separate files. Another benefit of keeping everything in one file is that all words and symbols in the entire document are always available for automatic completion (dynamic expansion) with M-/ (e.g., for tab completion of theorem or equation labels). On the other hand, I always use separate files for book-length projects by default.

For fast navigation between sections and subsections in single-file projects, you can use RefTeX. To load it, add this to your .emacs file:

;;; RefTeX
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)

Then, M-x reftex-toc will display the table of contents in a new split window. Alternatively, M-x imenu is another way to jump to specific sections but lacks the more LaTeX-specific features of RefTeX.

For multi-file projects in Emacs, you can minimize compilation problems by adding a comment like the following to the end of the file so that AUCTeX knows which file is the main file:

%%% Local Variables:
%%% TeX-master: "main"
%%% End: