[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Detect latexmk is running on currently buffer.

From: Ikumi Keita
Subject: Re: Detect latexmk is running on currently buffer.
Date: Thu, 14 Oct 2021 01:18:27 +0900

>>>>> Hongyi Zhao <> writes:
>> Thank you very much for your improvement, I'll test and feedback.

> I've tested with this project [1]. It seems that the background
> latexmk process failed to compile the master latex file after I made
> some changes and saved it.

> [1]

> But I can't sure this is caused by the above code revision,
> considering that the above LaTeX project is very complicated in
> itself.

After reconsideration, I came to think that it's better to clear process
buffer only when emacs is going to restart latexmf process.  Here is my
second proposal:

(defvar my-AUCTeX-process nil)
(use-package smart-compile
  (declare-function smart-compile-string "smart-compile")
  (defun run-latexmk ()
    (when (string-match ".tex$" (buffer-file-name))
      (unless (and (processp my-AUCTeX-process)
                   (eq (process-status my-AUCTeX-process) 'run))
        (let ((buf (get-buffer-create "*Background TeX proccess*")))
          (erase-buffer buf) ;; flush previous log
          (setq my-AUCTeX-process
                 "Background TeX" buf
                 ;; use an external application as the previewer
                 ;;(smart-compile-string "latexmk -pv %f")

                 ;; use pdf-tools
                 (smart-compile-string "latexmk %f")))))))
  (define-minor-mode AutoTeX-mode
    "Mode for compiling latex sources and creating PDFs after saving."
    :global nil
    :lighter " Auto"
    (if AutoTeX-mode
        (add-hook 'after-save-hook 'run-latexmk t t)
      (remove-hook 'after-save-hook 'run-latexmk t)))

  :hook (LaTeX-mode . (lambda () (AutoTeX-mode 1))))

I hope this works.

Ikumi Keita

reply via email to

[Prev in Thread] Current Thread [Next in Thread]