Sublime Text 2: Working with multiple documents, building master file

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!


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.

%!../main_file.tex
\documentclass[12pt,a4paper]{scrartcl}

\usepackage[czech,english]{babel}

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

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

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

and a simple build file aiming at my custom script:

{
    "cmd": ["/path/to/build/script.sh", "$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 ;)

#!/bin/bash
file="$1"
flag="-halt-on-error"

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

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

exit 0