# Standalone compilation of sources intended for \input{} or \include{}

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? –  Matthew Leingang Apr 15 '11 at 23:40

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.


\chapter{Introduction}
\import{chapters/introduction/}{introduction}


etc.

-

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

-