This is not really a practical question, but more of an academic one:

I use emacs to write my LaTeX files and in order to process multifile documents I include at the end of each file a local variable %%% TeX-master: "master" that tells emacs that when I compile this file I actually want to compile the file "master.tex".

Now I was just wondering if there is a way to do this in LaTeX something like \setmaster{master} or \includedin{master} that one can simply put in the begining of the file and it tells directly to the compiler it should start looking at the other file first.

  • I use arara for this: arara: making a rule to compile the main file from a chapter file There are a host of other automation tools, but imho, arara is king
    – cmhughes
    Jul 13, 2013 at 9:42
  • @cmhughes: that looks quite nice, but it depends on an alternative compiler. my question was if LaTeX supports the feature natively. As far as my settings go they work pretty fine and I am not thinking of changing any time soon (hence the "academic question")
    – John C
    Jul 13, 2013 at 9:54

1 Answer 1


This is possible, but with important limitations. Let's assume we have master.tex and secondary.tex.

First of all, how should \setmaster be defined? It's quite easy:

   % Make all later \setmaster commands to be no-ops
   % Start reading the master file
   % When it's finished, don't read from this file any more

But where should \setmaster be defined? Either in the document itself or in a personalized format file. In the first case, surround the definition between \ifdefined\setmaster\else and \fi, because we don't want to read it when secondary.tex is input.

First limitation. Paths will be relative to the location of the secondary file, so all files must all be in the same directory: you can't have \input{../master} and then master.tex call \input{subdir/secondary}.

Second limitation. TeX sets the job name equal to the first input file, if not overridden from the command line with the option -jobname. So, without cooperation from the editor/front-end, you won't get master.log or master.pdf, but secondary.log. This is a built-in behavior of TeX and it can't be modified: as soon as TeX is started and opens a file for input (in this case secondary.tex), it opens the .log file with the name derived from it or from the -jobname command line option.

Thus such an approach is not better than stating what's the main file using the editor's or front-end's features. Many of them have this feature, so this should be the preferred method.

The arara methods outlined in the answers to arara: making a rule to compile the main file from a chapter file are worthy of more than a look, because they are independent from whatever editor/front-end is being used.

You must log in to answer this question.

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