2

I'm writing a document which I want to split into several chapters, each chapter in its own .tex file. My main document has the preamble and I use \include commands to include each chapter. My question is, when I'm working on the chapter, say, ch1.tex, is it possible to compile ch1.tex so I can see the output and continue working on it that way until I'm done with it? As I understand it, ch1 should have no preamble, right? Would I have to make a common preamble file so that I can \include it in each chapter when I work on it, compile as necessary, and then comment it out when I'm ready to put the entire document together including all chapters?

My apologies if this question is confusing, or if it has been answered before.

EDIT: Per request of comments below, the editor I'm using is TeXShop on Mac OS X Yosemite

Amit
  • 377
  • 1
  • 2
    Also: \includeonly{ch1} for example, to prevent the inclusion of other chapters, for better/quicker editing –  Mar 04 '15 at 19:07
  • 4
    don't comment out the chapters you are not working on just use \includeonly to work on one chapter while allowing cross references and numbering to be correct for the chapters that you are not using. – David Carlisle Mar 04 '15 at 19:09
  • @DavidCarlisle: If I go with the \include option, then I always have to have two files open. First file is the ch1.tex file, but the file I compile is the overall main file. I imagine that could get kind of annoying. I took a look at the subfiles package @Werner mentioned, and I think that might solve it – Amit Mar 04 '15 at 19:16
  • 2
    Most editors will let you run the main document while editing the chapter, just needs to be told in a comment or configuration which is the master file. Id use \include, it is built in to latex and much much simpler and works well for this use. – David Carlisle Mar 04 '15 at 19:20
  • @DavidCarlisle: Thanks, looking at your profile it certainly seems like you know what you're talking about, so I'm going to go with your advice. Could you describe briefly the work flow if I go with the \include method? I have a main document which has the \includes, and I'm editing the ch1.tex. Now, when I want to visually see the progress I've made, I have to go back to the main file to compile, right? I don't compile ch1.tex. Did I get that right? – Amit Mar 04 '15 at 19:24
  • 1
    you need to run latex on the master file but most editors let you run that from a single keystroke while editing the chapter, eg the editor I use, emacs allows comments like % -*- TeX-master: "../master.tex" -*- that tell it that all the document level commands like latex, bibtex etc should use the file ../master.tex even if the current file is cha1.tex – David Carlisle Mar 04 '15 at 20:30
  • 1
    If you edit your question to mention which editor you are using to write your files, someone who uses that editor can answer your question directly (about how to set the master file and about how to use \include and \includeonly properly). – jon Mar 04 '15 at 20:40
  • @jon: I added the editor I'm using. Would appreciate a quick demonstration how to set up the master file – Amit Mar 04 '15 at 21:17
  • 1
  • @TorbjørnT.: That is exactly the solution I was looking for, perfect. If someone wants to put this in the form of an answer, I can mark it as the correct answer. – Amit Mar 04 '15 at 21:33
  • 1
    If you do want modify open/modify the main file to compile only the chapter you are working, then you are searching for docmute or standalone packages. Here there are a MWE (with beamer and \input instead of your document class with \include, but that should be irrelevant). – Fran Mar 05 '15 at 06:48

0 Answers0