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?

  • Go to the master file, go to options -> current file as master, done :-) – Johannes_B Jan 11 '16 at 9:32
  • Thank you @Johannes_B. I allready found the solution, just posted this question to answer it by myself so that someone else doesn't have to search for so long as is did. – Spen Jan 11 '16 at 9:38
  • is %!TEX root = ../main.tex a Texmaker's feature? I think you mean texworks? – touhami Jan 11 '16 at 16:27

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.

  • is %!TEX root = ../main.tex a Texmaker's feature? I can't find it any were! – touhami Jan 11 '16 at 21:24
  • @Tim Hoffman thank you for your reply. I got it to work. It seems TeXstudio has a bug. If you run subfiles without ever run the mainfile it's impossible to run subfiles. Since i only opened the mainfile, run it and then run a subfile everything works just fine. I found this problem with the solution in your bug tracker but it was closed. sourceforge.net/p/texstudio/feature-requests/474 – Spen Jan 12 '16 at 10:25
  • @besnep: That request was closed it worked for us and there was no additional feedback. You may file a new bug report. Please make sure to describe the issue as precise as possible. – Tim Hoffmann Jan 12 '16 at 22:09
  • @TimHoffmann: In my own document i couldn't reproduce this problem again. But with the original template this is reproduceable: sourceforge.net/p/texstudio/bugs/1629 – Spen Jan 13 '16 at 11:47

I was looking for an answer for quite some time but couldn't find an answer on the internet. Because of that i thought it would be good to post this problem with the solution i found:

The solution for this problem is quite simple. The mentioned root command doesn't work in TexStudio but you can set a root file manually:

  1. Open the you root/main file
  2. TexStudio menu: options
  3. Root document
  4. Define Current Document as 'Master Document'

I hope this does help someone else.

If there is a alternative to the "%!TEX root =..." command for TexStudio then please feel free to write an answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.