1

I made a function, compiling the current latex file:

;close the *async pdflatex* window, when pdflatex finishes
(defun latex-sentinel (process event)
      (message event)
      (cond ((string-match-p "finished" event)
                  (progn
                        (kill-buffer "*async pdflatex*")
                        (message "pdflatex done")
                        (delete-other-windows)))))

(defun latex-compile ()
      "Runs pdflatex on current file"
      (interactive)
      (let* ((file-name (shell-quote-argument (buffer-file-name)))
            (process (start-process-shell-command
                           "pdflatex"
                           "*async pdflatex*"
                           (concat "pdflatex " file-name))))
            (set-process-sentinel process 'latex-sentinel)
            (setq new-window (split-window-below 40))
            (set-window-buffer new-window "*async pdflatex*")
            (other-window 1)))

(add-hook 'LaTeX-mode-hook (lambda () 
    (define-key LaTeX-mode-map (kbd "<f2>") 'latex-compile)))

When there is an error, while compiling, pdflatex freezes, and I see this:

enter image description here

My current workflow:

  1. Scroll up to see the error
  2. kill-this-buffer - to kill pdflatex process
  3. delete-window - to close *async pdflatex* window and get back to editing.

Is it possible to track, that the process has stopped and is waiting for user input? My current sentinel activates only on "finished" event. So I could automate my current workflow.

4

2 回答 2

3

[@Thomas:你不需要 AUCTeX。内置函数latex-mode还为该任务提供了C-c C-c绑定。]

一般来说,检测到一个进程正在“等待我”是困难的/不可能的(充其量你可以监控进程的 CPU 使用率,如果它有一段时间是 0%,你可以确定它可能在等你,但即使这样做很棘手,因为您需要找到合适的操作系统进程来监控,然后使用系统相关的操作来获取 CPU 使用率)。\nonstopmode\inputlatex-modes 通常通过传递pdflatex 的命令行来“解决”这个问题。

于 2013-06-03T14:05:34.700 回答
0

我有同样的困难。以下似乎没问题。

(defun latex-compile()
  (interactive)
  (save-buffer)
  (set 'tex-to-pdf   "pdflatex -interaction=nonstopmode")
  (set 'file-name (shell-quote-argument (buffer-file-name)))
  (set 'comm1 (concat tex-to-pdf " " file-name ))
  (set-process-sentinel
   (start-process-shell-command "latex-compile"
                "*async latex-compile*"
                comm1)
   'tex-to-pdf-sentinel))
;;;
(defun tex-to-pdf-sentinel (process event)
    (cond
     ( (string-match-p "finished" event)
     (message "latex-compile complete"))
     ( (string-match-p "\\(exited\\|dumped\\)" event)
     (message "error in latex-compile"))
     ))

set我意识到不建议使用全局变量;这只是一个最小的例子。

您可以在第一个完成时设置第二个sentilel,例如,以便查看器打开以显示.pdf输出,或者您希望确保bibtex每次都运行。这可以节省对 C-c C-c in的重复调用latex mode

于 2015-02-22T14:18:32.890 回答