20

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?

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
Frank
  • 64,140
  • 93
  • 237
  • 324

2 Answers2

20

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: 
itsjeyd
  • 5,070
  • 2
  • 30
  • 49
Benjamin Bannier
  • 55,163
  • 11
  • 60
  • 80
  • 2
    The local variable route has the disadvantage of requiring you to kill the buffer and reopen it before the variable is set (maybe there's a smarter way to do it?). The first time you open the file, you can also do `M-x TeX-master-file-ask`. – Chris Conway Feb 04 '10 at 13:24
  • @ChrisConway The smarter way is `M-x normal-mode`. – Resigned June 2023 Apr 07 '17 at 17:03
8

C-c _ creates this footer automatically