Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?..

share|improve this question
    
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
add comment

3 Answers

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"
share|improve this answer
add comment

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

share|improve this answer
add comment
up vote 2 down vote accepted

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):

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

etc.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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