Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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