views:

299

answers:

2

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 in the current buffer.

But what if I want it to run pdflatex on a file that is not 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?

+10  A: 

When you create a new file auctex will ask you about the "master" document for it. If you define a master CTRL-c CTRL-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: 
honk
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
+1  A: 

C-c _ creates this footer automatically

João Paulo
ON my system `C-C _` is bound to `TeX-master-file-ask`, but it doesn't create the local variable footer.
Chris Conway
It should create after you define the master file.But it doesn't work if the footer is already defined
João Paulo