17

I have a main LaTeX file that has multiple chapter files included using \input command. For compiling them in emacs/auctex, I have to open main LaTeX and ^C^C.

How can I compile the main LaTeX from a chapter file?

ADDED

I don't know exactly what happened, but I had to use ^C _ to specify the master file.

https://stackoverflow.com/questions/2199463/emacs-auctex-run-command-on-file-that-is-not-currently-open

1
  • 1
    The reason it didn't work when you did it manually is that the variable only takes effect when you reopen the buffer. You could save the file and then do revert-buffer to reload it.
    – sturgman
    Commented Mar 27, 2020 at 18:10

1 Answer 1

19

Add at the end of each chapter file

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

to point AUCTeX to the main file. Furthermore, (quoting the AUCTeX manual)

if you often use \include or \input, you should make AUCTeX aware of the multi-file document structure. You can do this by inserting (setq-default TeX-master nil) into your init file. Each time you open a new file, AUCTeX will then ask you for a master file.

Or, if you usually use the same master filename

You should always set this variable to the name of the top level document. If you always use the same name for your top level documents, you can set TeX-master in your .emacs file.

(setq-default TeX-master "master") ; All master files called "master".

2
  • Could it be applied for the if the chapter linked as \subfile{cost}?
    – alper
    Commented Jun 2, 2022 at 10:56
  • On my system I had to save the file and reopen it before this worked. Took me an embarrassing amount of time to figure that out! Commented Oct 13, 2023 at 14:05

You must log in to answer this question.

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