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.
- 206,688
- 1,573
2 Answers
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/fileFor example, if
main.texis in the same folder aschapter1.tex, write%!TeX root = main.tex. Ifmain.texis in the folder above, you can write%!TeX root = ../main.tex.See http://www.texdev.net/2011/03/24/texworks-magic-comments/
- 206,688
-
Is there a similar way to achieve this for TeXShop, please? – LaTeXFan Sep 30 '15 at 03:22
-
@LaTeXfan How can I compile different .tex file on click on typeset in TeXShop? (MacTeX 2011) – Torbjørn T. Sep 30 '15 at 06:16
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.
- 1,437
-
-
@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 06:59