0

When editing multiple files, AucTeX keeps track of the master file by appending the following to each file:

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../document"
%%% End:

I'm editing a document with multiple colleagues and I don't want to add this to their files when editing them.

Is there a way to set an AucTeX variable pointing to the path of the master file, and whenever I hit C-c C-c, it will look for that file?

One option is to hit M-: and type (setq-default TeX-master "../document"). Is there a better way than that?

1

Not sure what AUCTeX does when TeX-master is not set, nowadays, but if you use the default latex-mode that comes with Emacs, the corresponding tex-master is guessed by looking for a nearby buffer with the usual \documentclass thingy. If you keep one document per directory, this is usually all it takes to DTRT and you don't need to set any file-local variable: just make sure you have that main .tex file opened in a buffer in that same Emacs session.

AUCTeX being usually fancier than this builtin latex-mode, I expect it also has some way to guess the right TeX-master. If it doesn't, then I suggest you file a feature-request.

But there are other options:

  • Set the TeX-master from a .dir-locals.el file. To set up a .dir-locals.el file, the best way is through Emacs using M-x add-dir-local-variable.

  • Set the TeX-master via dir-locals-set-class-variables and dir-locals-set-directory-class.

  • Do you all by hand, old-school style:

    (add-hook 'LaTeX-mode-hook
              (lambda ()
                (when (string-prefix-p "/thing/with/colleagues"
                                       default-directory)
                  (setq TeX-master "../document"))))
    
| improve this answer | |
  • I didn't know about this latex-mode feature. Unfortunately, it seems that AUCTeX doesn't have it. Thanks for the first two suggestions with .dir-local.s.el and dir-locals-set-{class-variables,directory-class}, I haven't use them yet, but I'll look them up. – Yamaneko Sep 12 '18 at 14:33
  • 1
    To set up a .dir-locals.el file, the best way is through Emacs using M-x add-dir-local-variable. I tried to add the absolute path ((latex-mode (TeX-master (concat default-directory "document")))), but I still haven't managed to get it working. When I eval, it outputs t, which is the AUCTeX output when the open file is the master file. By the way, is there a difference between .dir-local.s.el and .dir-locals.el? – Yamaneko Sep 19 '18 at 12:46
  • @Yamaneko: w.r.t to .dir-local.s.el and .dir-locals.el, yes there's a big difference: the first doesn't work (was a typo, thanks!). – Stefan Sep 19 '18 at 13:23
  • Thanks! I wasn't sure. This answer is exactly what I need. As soon as I get it working, I'll accept it. Let me try a couple times more and I'll report later. – Yamaneko Sep 19 '18 at 17:20
  • 1
    @Yamaneko: Also, feel free to improve the answer with a description of how to use add-dir-local-variable. – Stefan Sep 19 '18 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.