My LaTeX workflow involves frequent recompiles (good ol' C-c C-c in AucTeX). Right now I'm working on a large document that's composed of chapters, each in an individual file. I would like to use the \input{} or \include{} mechanism to compile the final document, however that involves stripping the chapters sources from the preamble.

I could create a "main" file (a chapter-main.tex for every chapter.tex) with the preamble and \include{chapter.tex}, but this means that as I'm editing an individual chapter, I need to switch to a different file for a recompilation, which breaks my workflow.

Are there any ways to use the \include{} mechanism that don't get in the way of editing files individually?..

  • In TeXShop you can set a "project root" embedded in a comment at the top of a file. That way when you use the keycombination for compiling, what's compiles is not the currently edited file but the root file. Is that a feature of AucTeX? Apr 15, 2011 at 23:40

3 Answers 3


There are several solutions for working with multiple files; I prefer subfiles. If you merely want to indicate which file is the "master", insert the following at the top of the file (and replace "rootfile" as appropriate):

% Local Variables: 
% TeX-master: "rootfile"

I ended up using the following solution: \usepackage{standalone} combined with \usepackage{import}. This is probably not the most general solution, but was easiest to implement for my purposes.

The standalone package ignores the preambles for individual files, so any \newcommand or \renewcommand statements need to go inside \begin{document}, and all the packages individual files use need to be declared in the "master" file's preamble. Those were the only changes I needed to make to my chapter files; after that I simply include them into the master file using the import package (this helps takes care of handling relative paths):




TeXnicCenter allows for compiling the "current" document (the file being edited) through a single "build file" button. Additionally, a "build project" button will compile the "master" file. This allows for editing and compiling of (say) chapters without having to switch back to the "master" document for a recompile. Hope this helps, W

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.