[Tex/LaTex] How to compile from a subchapter or how to set root file

rootsubfilestexstudio

I have a document structure with subfiles/subchapters. Until know i worked with TexMaker and TexLive on Windows and with the following line in every subfile, everything just worked great.

%!TEX root = ../main.tex

Friends recommended TexStudio as a better editor, so i tried it but i can't compile from subfiles.
What ist the problem?

Best Answer

Please use the form % !TeX root = ../main.tex

For details see the TeXstudio user manual.

Background information on % !TeX

These 'magic' comments were first introduced by TeXShop. Afterwards, other editors started to adopt them, including TeXworks, Texmaker and TeXstudio. There's no official standard. So capabilities, and tolerance towards capitalization and spaces may be different among the editors. The above form is the original one and should be accepted by all editors.

Additional hint

TeXstudio has an integrated root detection. If you have main.tex open and sub.tex included in main. It automatically detects that main.tex is the root document and thus compiles that even if the editor has focus on sub.tex.

It's still good practice to set % !TeX root because then everything works even without an open root document. Additionally, your TeX files are more portable since AFAIK other editors do not support automatic root detection.

For further details see the user manual section on multi file documents.

Related Question