3

When I save a LaTeX file, I want to compile it as well on the background. In order to achieve it I have done following module:

(defun my-run-latex ()
  (interactive)
  (save-all)
  (setq TeX-command-force "LaTeX")
  (setq TeX-clean-confirm t)
  (TeX-command-master))

(add-hook 'LaTeX-mode-hook (lambda ()
                 (local-set-key (kbd "C-x C-s") 'my-run-latex)))

But when I do that I keep having following message:

Please answer y or n.  Process `LaTeX' for document `program' running, kill it? (y or n)

What may be the reason for this message? Is it possible to ignore it or automatically confirm it via y?

1 Answer 1

4

The reason for the message is exactly what it says. A LaTeX process is still running for the master file.
AucTeX is running LaTeX asynchronously. If the LaTeX sources are long the compilation may still be running when you save twice in quick succession.

The right way avoiding that message automatically is killing the still running LaTeX process before TeX-command-master.
I suggest the following version of your function my-run-latex that does kill the running process if it exists.
Saving files is also done as it is supposed by the AucTeX package. You can change it back to your version with the (for me non-existing) function save-all if you want.

(defun my-run-latex ()
  "Save all buffers and run LaTeX on the current master."
  (interactive)
  (let* ((TeX-command-force "LaTeX")
     (TeX-clean-confirm t)
     (TeX-save-query nil)
     (master (TeX-master-file))
     (process (and (stringp master) (TeX-process master))))
    (TeX-save-document master)
    (when (and (processp process)
           (eq (process-status process) 'run))
      (delete-process process))
    (TeX-command-master)))
1
  • Sorry for late comment. When I first run ` my-run-latex; 70 Master file:` selection line shows up in the minibuffer. When I enter, it does not show up again and compiles right away. Is it a normal behavior?
    – alper
    Mar 24, 2022 at 8:32

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.