I sometimes use Makefiles with LaTeX documents, and so I'd like to define a command that does something similar to AUCTeX's C-c C-a (TeX-command-run-all) but using make.

I tried creating a function that calls both "Make" and "View", as suggested for Arara in this answer, but the "View" command never seems to be executed. I see a message that says "Compilation finished", but then the viewer does not open. Here's what I have in my init.el file:

(use-package tex
  :ensure auctex
  :mode ("\\.tex\\'" . TeX-latex-mode)
  (setq TeX-view-program-list '(("PDF Tools" TeX-pdf-tools-sync-view)))
  (setq TeX-view-program-selection '((output-pdf "PDF Tools")))
  (add-hook 'TeX-after-compilation-finished-functions
     :help "Run make"))
  (defun adamliter-TeX-make ()
    "Interactive function for running GNU Make on a (La)TeX file."
    (TeX-command-sequence '("Make" "View") t))
  (:map TeX-mode-map
        ("C-c C-m" . adamliter-TeX-make)))

Moreover, how do I ensure that the document buffer is reverted? I have basically the same setup for Arara based on the linked answer, but when I run adamliter-TeX-arara, the document buffer does not seem to revert, despite having added TeX-revert-document-buffer to the hook TeX-after-compilation-finished-functions. Is this hook not run when commands are invoked via TeX-command-sequence?

1 Answer 1


TeX-run-compile runs the make process not in the current buffer but in the *compilation* buffer.

That is the reason why TeX-command-sequence does not find the running make process. It cannot set its sentinel for the make process. That sentinel would start the next command in the command sequence.

Use TeX-run-TeX instead of TeX-run-compile. With TeX-run-TeX the make process becomes the buffer process of the TeX buffer. That buffer is current in TeX-command-sequence.

That should also solve your problem with TeX-after-compilation-finished-functions.

Note, that I did not find a simple way to use TeX-run-compile. You cannot shift the buffer process to another buffer. One could advise get-buffer-process to return the process of TeX-command-buffer if the process of the current buffer is nil. But, then we get the problem that the sentinel also uses the process-buffer. So tweaking TeX-command-sequence for TeX-run-compile is a dead end.

  • +1, thanks, this solves the first part of the question. Do you have any idea why TeX-revert-document-buffer is not run after a successful execution of adamliter-TeX-make, however? If I run adamliter-TeX-make with the PDF already open in a buffer, the changes will not show up unless I manually revert the buffer, despite having set TeX-after-compilation-finished-functions to include TeX-revert-document-buffer.
    – Adam Liter
    Jun 28, 2019 at 18:08
  • @AdamLiter Do you have time for a debug session?: chat.stackexchange.com/rooms/95504/…
    – Tobias
    Jun 28, 2019 at 18:37
  • Result of the debug session so far for others who want to investigate the issue: pdf-view-revert-buffer is always run after error-free compilation of the LaTeX file. But, it is ineffective if the LaTeX output is requested by C-c C-l during the compilation process. (a really strange effect)
    – Tobias
    Jun 28, 2019 at 19:47
  • Thanks again for all you did to help. I figured out one further piece of information, which is that this only happens with pdf-tools. If I switch to using DocView, then this does not happen. I've opened a bug report in the pdf-tools repository. Also, since this seems like a bug, and you've answered the main part of the question, I've accepted your answer. Thanks again!
    – Adam Liter
    Jun 30, 2019 at 14:22
  • 1
    @AdamLiter Superb! Thank you for improving Emacs through persistency;-).
    – Tobias
    Jul 1, 2019 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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