# A Question in Compiling book Class

I am writing my thesis using book class. And I use include function so that I can have separate files for each chapter. One problem with this is that I must click run button in the main file. If I click run button in chapter files, error occurs. I learned that this is not a problem in TeX Studio so long as all the files is open. But I am using TeXWork and TeXMaker. So I always to find the right button to click, which is annoying. Is there an easy fix for this problem, please? Thanks.

I'm using TeXMaker to write my thesis, and after trying with include and input, that had the problem you mentioned, I ended up using the subfiles package, in this way:

Main document

\documentclass{report}

\usepackage{subfiles}

\begin{document}

\subfile{./Chapter} % Chapter file's name (and position)

\end{document}


Chapter document

\documentclass[./MainDocument.tex]{subfiles} % Main document file's name (and position)

\begin{document}
...
\end{document}


In this way I can compile a single chapter. I saw that not all the properties (such as line spacing or headers/footers) of the main document are passed to the subfile; however, I compile the subfile only to check the content of the chapter, while I check the style and so on when I run the main document.

• How did you find that out, please? Only curious. – LaTeXFan Aug 13 '15 at 6:56
• @LaTeXfan Actually I don't remember, since it was when I started organizing my thesis files and learning LaTeX at the same time, so I was googling like a thousand problems a day! :-) – MarcoG Aug 13 '15 at 6:59

Both Texmaker and TeXworks are able to do this.

• Texmaker: With the main file open, select Options --> Define Current Document as master document (How to best use and compile multiple .tex files as part of same final document?)

• TeXworks: At the top of the chapter file, write

%!TeX root = /path/to/main/file


For example, if main.tex is in the same folder as chapter1.tex, write %!TeX root = main.tex. If main.tex is in the folder above, you can write %!TeX root = ../main.tex.

• Is there a similar way to achieve this for TeXShop, please? – LaTeXFan Sep 30 '15 at 3:22
• – Torbjørn T. Sep 30 '15 at 6:16