Search code examples
emacslatexlispauctex

Emacs/AUCTeX: run command on file that is not currently open


I edit my LaTeX files in Emacs using AUCTeX. To compile, I press C-c C-c, which will run pdflatex root, if root.tex is the file displayed in the current buffer.

But what if I want it to run pdflatex on a file that is not displayed in the current buffer?

For example, I am editing an included .tex file, chapter2.tex, and press C-c C-c. The command I want it to run is still pdflatex root, since chapter2.tex is just included in root.tex.

How can I do that?


Solution

  • When you create a new file AUCTeX will ask you about the "master" document for it. If you define a master, C-c C-c will compile the master instead of the currently open file.

    AUCTeX keeps track of this by adding a footer with the information it needs. Assuming you have a master document index.tex, the footer would look like this:

    %%% Local Variables: 
    %%% mode: latex
    %%% TeX-master: "index"
    %%% End: