From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Detect latexmk is running on currently buffer.
Date: Tue, 12 Oct 2021 15:54:49 +0800 [thread overview]
Message-ID: <CAGP6PO+juWdVEQJjf2jTjRBoeFSHGdSn_JXcrg_c1XjXtm2Cig@mail.gmail.com> (raw)
Currently, I'm using the following configuration to automate the LaTeX
workflow in Emacs with AUCTeX:
```emacs-lisp
;; Automatically revert a buffer when the corresponding file on disk is updated.
(global-auto-revert-mode 1)
(setq auto-revert-use-notify nil)
;; Automatically save the buffer to disk periodically.
(use-package real-auto-save
:hook ((TeX-mode python-mode) . real-auto-save-mode)
:config
(setq real-auto-save-interval 5) ;; in seconds
)
;; After the buffer is changed and saved to disk, run latexmk on the
;; corresponding file immediately.
;;See ~/.latexmkrc for correspoding configuration
(use-package smart-compile
:init
(declare-function smart-compile-string "smart-compile")
(defun run-latexmk ()
(when (string-match ".tex$" (buffer-file-name))
(let ((buf (get-buffer "*Background TeX proccess*")))
(if (bufferp buf) (kill-buffer buf))) ;; flush previous log
(start-process-shell-command
"Background TeX" "*Background TeX proccess*"
;; 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)))
)
```
Though the above method works, I meet a problem when the project LaTeX
files are large to some extent. To be more specific, when the project
is large to a certain extent, the compilation time of latexmk will be
relatively long, which may lead to the following race condition: When
the previous latexmk process has not ended, the subsequent latexmk
process is launched again.
Any hints for fixing this problem?
Regards
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province
next reply other threads:[~2021-10-12 7:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 7:54 Hongyi Zhao [this message]
2021-10-12 9:32 ` Detect latexmk is running on currently buffer Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-12 12:08 ` Hongyi Zhao
2021-10-12 12:58 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-12 12:15 ` Hongyi Zhao
2021-10-12 12:59 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-12 13:10 ` Hongyi Zhao
2021-10-12 13:23 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-12 17:33 ` Emanuel Berg via Users list for the GNU Emacs text editor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGP6PO+juWdVEQJjf2jTjRBoeFSHGdSn_JXcrg_c1XjXtm2Cig@mail.gmail.com \
--to=hongyi.zhao@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).