0

I have the following two questions:

1) Is it still recommended these days to use the guess-TeX-master snippet from AUCTeX wiki?

2) If yes, could someone provide some hints on why it doesn't work in the following config of mine?

(use-package tex
  :ensure auctex
  :defer t
  :mode ("\\.tex\\'" . latex-mode)
  :init
  (declare-function my-guess-TeX-master "init.el")
  (declare-function my-latex-mode-hook "init.el")
  :custom
  (TeX-auto-save t)
  (TeX-parse-self t)
  (reftex-plug-into-AUCTeX t)
  (latex-run-command "pdflatex")
  (TeX-source-correlate-method 'synctex)
  :config
  (setq TeX-outline-extra '(("[ \t]*\\\\\\(bib\\)?item\\b" 7)
                            ("\\\\bibliography\\b" 2))) ; adding own headings to outline minor mode
  (defun my-guess-TeX-master (filename)
    "Guess the master file for FILENAME from currently open .tex files."
    (let ((candidate nil)
          (filename (file-name-nondirectory filename)))
      (save-excursion
        (dolist (buffer (buffer-list))
          (with-current-buffer buffer
            (let ((name (buffer-name))
                  (file buffer-file-name))
              (if (and file (string-match "\\.tex$" file))
                  (progn
                    (goto-char (point-min))
                    (if (re-search-forward (concat "\\\\input{" filename "}") nil t)
                        (setq candidate file))
                    (if (re-search-forward (concat "\\\\include{" (file-name-sans-extension filename) "}") nil t)
                        (setq candidate file))))))))
      (if candidate
          (message "TeX master document: %s" (file-name-nondirectory candidate)))
      candidate))
  (defun my-latex-mode-hook ()
    (turn-on-auto-fill)
    (abbrev-mode)
    (LaTeX-math-mode)
    (outline-minor-mode)
    (setq TeX-master (my-guess-TeX-master (buffer-file-name))))

  (add-hook 'LaTeX-mode-hook #'my-latex-mode-hook)
  (add-hook 'LaTeX-mode-hook #'reftex-mode)
  (add-hook 'LaTeX-mode-hook #'turn-on-reftex))

For instance, I have a file named main.tex and has local variables indicating it's the master file, then I create a new file dummy.tex and upon creation I'm prompted to indicate which is the master file. It seems that guess-TeX-master is either not working or not guessing properly the master file.

  • 1
    this function only looks through open buffers, and it searches for a sting \include("yourfile") or \input("yourfile.tex") to decide if a file is a master file. This function does not care for local vars. – jue Oct 28 '19 at 11:05
  • Thank you for clarifying this. If I understand this correctly, this means that I don't need to have local vars in the main.tex if I'm using \input{"yourfile.tex"} because it's being guessed by guess-TeX-master. But, if I have yourfile.tex open in a buffer does that file still need local vars if I want to be able to compile that file using C-c C-c? – Kirk Walla Oct 28 '19 at 12:52
  • You did understand correctly. No local vars are necessary (about master file) for that. – jue Oct 28 '19 at 17:14

Your Answer

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

Browse other questions tagged or ask your own question.