Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently working with LaTeX. I have a big document split up in several sub documents. When I am workin in a sub document, I'd love to compile the master file when pressing ctrl+b, not the file I am currently in. How do I do that?

share|improve this question

I just found the answer myself! As mentioned here, one just has to put %!TEX root = protokoll.tex as the first line of the sub documents!

share|improve this answer
I really appreciate it!!! This problem has confused me for a while. – Zhigong Li May 8 '15 at 5:48

If you have 3 different files you need, you can use first-line (or second if you need utf8 stuff) comments. I use it to compile the main TeX file from one of the children.



I have a script, which looks at the first line:

match=`head -n1 $1 | grep %!`

if [[ $match ]]
        # do stuff with the parent's name, which is ${match:2:100}
        # no match :/

and a simple build file aiming at my custom script:

    "cmd": ["/path/to/build/", "$file"],
    "selector": "whatever"

This way, you can have as many "references" in your files as you want. Just switch the value of head -n1.

To end with, I present to you my XeLaTeX build script ;)


match=`head -n1 $file | grep %!`

if [[ $match ]]
        if [ ${match:2:3} = ../ ]
                cd .. &&
rubber -c 'set arguments -shell-escape' -f -m xelatex -W all $target

exit 0
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .