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

问题描述

限时删除!!

谁能告诉我first start-processsecond start-process.显示 pdf 文件的 second start-process 应该运行 only if 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.

我愿意接受关于如何最好地确定 first start-process 是否正确完成的建议.一种方法是查看 output 缓冲区以确定最后一行是否等于Process process finished".制作 *.pdf 文件可能需要几,即使它没有错误,second start-process 如果它也开始了,就会失败早期的.Sit-for 不是最好的选择,因为如果 first start-processsecond start-process 应该被中止代码> 未正确完成.生成 output 缓冲区也需要几秒钟,因此检查缓冲区中的最后一行也需要等到 first start-process 结束.然而,发现一个成功的退出代码(如果存在这样的事情)会比在输出缓冲区中搜索字符串 equals 更好....

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 . . . .

仅供参考:.latexmkrc $pdflatex 代码行将 *.pdf 的副本放回工作目录,而 .latexmkrc $out_dir 代码行将所有辅助文件放入 /tmp 文件夹中.这是必需的,因为 OSX 的 Tex-Live 不支持 $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

推荐答案

这个答案 提供了一种链接异步命令的方法, 使用 sentinels 等待每个命令在运行以下之前终止.

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,否则显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:47