# Pdflatex does not read the TEX root line, how do I solve that?

I have a main.tex file with several chapters in a sub folder included as: \include{chapters/chapter01} Each of the chapters' tex file have the line % !TEX root = ../main.tex at the top of the file. When I run pdflatex on the main.tex file all goes well:

pdflatex --interaction=nonstopmode --shell-escape main.tex


However, if I run the same command on chapter01.tex it stops with an error as it can not find a \begin{document}. The following commands fail to compile:

pdflatex --interaction=nonstopmode --shell-escape chapters/chapter01.tex


.

cd chapters
pdflatex --interaction=nonstopmode --shell-escape chapter01.tex


Apparently pdflatex neglects the TEX root line.

Is there a way to let pdflatex recognize that there is a root file?

-
The % !TEX root line is for your editor, it's nothing to do with TeX itself – Joseph Wright Mar 9 '14 at 15:30
I didn't know that. I use Sublime Text with LatexTools. The built in compile command works fine, but it runs the full latexmk scripts which takes a while. I wanted to just run pdflatex once so I made a build system containing the above command. I'll see if I can somehow edit the LatexTools build system to only use pdflatex once. – Saaru Lindestøkke Mar 9 '14 at 15:34
How about just running pdflatex once on your main file with some terminal application? – Holene Mar 9 '14 at 16:16
@Holene, that is an option that works but for reasons of convenience I hoped the TEX root method would work. – Saaru Lindestøkke Mar 9 '14 at 16:46
@JosephWright If you would make that an answer I will accept it, as that is the most correct answer to the current question. – Saaru Lindestøkke Mar 9 '14 at 16:47

The % !TEX root line is for your editor, it's nothing to do with TeX itself. This particular form of 'magic comment' originates in the editor TeXShop, and while they are now understood by several other editors, TeX itself takes no notice of them. Thus to use this approach you have to using an editor/IDE, and one that understands the type of 'magic comment' you are using.

-

When using Sublime Text with LaTeXing you need a slightly different directive statement:

% -*- root: file_location -*-


When using LaTeXTools, the statement is supposed to be correct. Reading from the LaTeXTools github documentation

Multi-file documents are supported as follows. If the first line in the current file consists of the text %!TEX root = <master file name>, then tex & friends are invoked on the specified master file, instead of the current one. Note: the only file that gets saved automatically is the current one. Also, the master file name must have a .tex extension, or it won't be recognized.

There is also support for project files; this is to be documented.

I would recommend LaTeXing. It is free to try, and are in my opinion being maintained at a better rate compared to LaTeXTools

-
As this no longer is a proper answer, I'm open to deleting it if the OP or community feels it doesn't provide valuable information – Holene Mar 9 '14 at 16:06