Emacs:如果latexmk完成,可以显示pdf,否则显示错误 [英] Emacs: if latexmk finishes okay, then show pdf, else display errors

查看:643
本文介绍了Emacs:如果latexmk完成,可以显示pdf,否则显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以请我先在第一个 start-process 第二个 启动过程。只有在的 c c c c c c first start-process 没有错误地完成 。可能有一些类型的成功的退出代码可以被发现,但是在这方面我需要一些帮助。

Could anyone please give me hand with the step between the first start-process and the second start-process. The second start-process that displays the pdf-file should run only if the first start-process finishes without errors. There is probably some type of successful exit code that can be spotted, but I would need some help please in that regard.

确定第一个 开始进程是否完成没有错误。一种方法是查看输出缓冲区,以确定最后一行是否等于进程进程完成 。即使没有错误,使* .pdf文件可以采取几个,而第二个 开始进程如果开始太早就失败。 sit-for不是最好的选择,因为如果第一个 <$ 开始进程应该中止c $ c> start-process 未正确完成。生成输出缓冲区也需要几秒钟,因此检查缓冲区中的最后一行还需要等到第一个 start-process 完成。但是,发现一个成功的退出代码(如果这样的事情存在)将比搜索输出缓冲区的字符串等于更好。 。 。 。

I'm open to suggestions regarding how best to determine whether the first start-process finished without errors. One method would be to look at the output buffer to determine whether the last line is equal to "Process process finished". Making the *.pdf file can take a few seconds even if it is without errors, and the second start-process fails if it begins too early. Sit-for is not the best option, since the second start-process should be aborted if the first start-process did not complete correctly. Generating the output buffer also takes a couple of seconds, so checking the last line in the buffer would also need to wait until the first start-process finishes. However, spotting a successful exit code (if such a thing exists) would be better than searching an output buffer for a string equals . . . .

FYI:.latexmkrc $ pdflatex 代码行将* .pdf的副本放回工作目录和.latexmkrc $ out_dir 代码行将所有辅助文件放入 / tmp 文件夹中。这是需要的,因为Tex-Live for OSX不支持 $ aux_dir 。结果是一个干净的工作目录,只包含* .tex和* .pdf文件。

FYI: The .latexmkrc $pdflatex line of code puts a copy of the *.pdf back into the working directory, and the .latexmkrc $out_dir line of code puts all of the auxiliary files into the /tmp folder. This is needed because Tex-Live for OSX does not support $aux_dir. The result is a clean working directory containing just *.tex and *.pdf files.

(defun latexmk ()
  ".latexmkrc should contain the following entries -- without the backslashes:
  $pdflatex .= ' && (cp \"%D\" \"%R.pdf\")';
  $force_mode = 1;
  $pdf_mode = 1;
  $out_dir = '/tmp';"
(interactive)
  (let* (
    (process (file-name-nondirectory buffer-file-name))
    (output (concat "*" (file-name-nondirectory buffer-file-name) "*") )
    (latexmk "/usr/local/texlive/2012/texmf-dist/scripts/latexmk/latexmk.pl")
    (arg-1 "-interaction=nonstopmode")
    (arg-2 "-file-line-error")
    (arg-3 "-synctex=1")
    (arg-4 "-r")
    (arg-5 "/Users/HOME/.0.data/.0.emacs/.latexmkrc")
    (pdf-file (concat "/tmp/" (car (split-string
      (file-name-nondirectory buffer-file-name) "\\.")) ".pdf"))
    (line (format "%d" (line-number-at-pos)))
    (skim "/Applications/Skim.app/Contents/SharedSupport/displayline") )
  (if (buffer-modified-p)
    (save-buffer))
  (start-process process output latexmk arg-1 arg-2 arg-3 arg-4 arg-5 buffer-file-name)
  ;;  (if (last line of output buffer is "Process 'process' finished")
      (start-process "displayline" nil skim "-b" line pdf-file buffer-file-name)
    (switch-to-buffer output)
  ;;  )
    ))






编辑:根据Francesco在下面的答案中概述的概念的工作解决方案可以在相关的线程中获得: https://tex.stackexchange.com/a/156617/26911


EDIT: A working solution based upon the concept outlined by Francesco in the answer below is available in a related thread: https://tex.stackexchange.com/a/156617/26911

推荐答案

此答案提供了一种链接异步命令的方法,使用

This answer provides a way to chain asynchronous commands, using sentinels to wait for each command to terminate before running the following.

您需要调整哨兵才能使用 process-exit-status 。一个最小的工作示例应该是:

You need to adapt the sentinel in order to check the process exit status using process-exit-status. A minimal working example for you should be along the lines of:

(defun run-latexmk ()
  "Asynchronously run `latexmk' and attach a sentinel to it"
  (let ((process (start-process "latexmk" "*output*"
                                "/bin/sh" "-c" "echo KO; false")))
    (set-process-sentinel process 'latexmk-sentinel)))

(defun latexmk-sentinel (p e)
  "Display the pdf if `latexmk' was successful"
  (when (= 0 (process-exit-status p))
    (start-process "displaypdf" "*output*"
                   "/bin/echo" "DISPLAY PDF")))

;; Example use
(with-current-buffer (get-buffer-create "*output*") (erase-buffer))
(run-latexmk)

这篇关于Emacs:如果latexmk完成,可以显示pdf,否则显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆