[Tex/LaTex] Automatically run Latex command after saving .tex file in Emacs

automationemacs

How can I have Emacs call the Latex command every time after I save my .tex file?

Thanks

A solution: while playing with ELisp and looking around, I added this to .emacs and it seems to work quite well (just don't press C-x C-s too much frequently, say every 5 secs):

(defun run-latex ()
    (interactive)
    (let ((process (TeX-active-process))) (if process (delete-process process)))
    (let ((TeX-save-query nil)) (TeX-save-document ""))
    (TeX-command-menu "LaTeX"))
(add-hook 'LaTeX-mode-hook (lambda () (local-set-key (kbd "C-x C-s") #'run-latex)))

The advantage of this solution over latexmk is that it is quicker to put working because I don't have to customize anything (and risking making mistakes). Also, in case I want to remove it, I only have to comment the last line (add-hook ... in your .emacs.

Anyway, latexmk seems also another interesting path I will try when I have more time.

Thanks for your answers and help.

Best Answer

Please search this forum for latexmk, which does exactly what you ask.


EDIT: See here: Compile using latexmk in emacs

There are more threads in this forum, if you search for 'latexmk' and 'emacs'.