如何在emacs中调用latexmk,并跳转到next-error [英] How to call latexmk in emacs, and jump to next-error

查看:27
本文介绍了如何在emacs中调用latexmk,并跳转到next-error的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 latexmk 来编译我的Emacs 中的 LaTeX 文档.特别是我需要 Emacs 功能 next-error,它通常用 C-x ` 调用,并跳转到文档中的下一个 LaTeX 错误.

I would like to use latexmk to compile my LaTeX documents in Emacs. Especially I need the Emacs functionality next-error, which is typically called with C-x `, and jumps to the next LaTeX error in the document.

我想使用 C-x compile 或 AUCTeX C-c C-c 来调用 latexmk.

I would like to call latexmk either using C-x compile or the AUCTeX C-c C-c.

首先,我设置 latexmk 使用

$pdflatex = 'pdflatex -interaction=nonstopmode';

选项 1:C-x 编译

我按下 C-x compile 并输入 latexmk -pdf foo,它会运行 pdflatex.但是 next-error 不会跳转到错误,即使 *compilation* 缓冲区包含错误:

I press C-x compile and type latexmk -pdf foo, which runs pdflatex. But next-error will not jump to the errors, even if the *compilation* buffer contains errors:

! Paragraph ended before author was complete.
<to be read again> 
                   par 
l.48 
[...]
Compilation exited abnormally with code 12 

如何自动跳转到第 48 行的这个错误?

How can I automatically jump to this error in line 48?

注意这个解析latex输出的问题与latexmk直接无关.当我只是执行 C-x compile pdflatex -interaction=nonstopmode foo 时也会出现同样的问题.

Note that this question of parsing the latex output has nothing to do with latexmk directly. The same problem occurs when I just do C-x compile pdflatex -interaction=nonstopmode foo.

选项 2:AUCTeX

如何设置 AUCTeX 以在我的 .tex 文件上调用 latexmk -pdf 而不是 pdflatex?当然,我希望 next-error 也能在这里工作.

How can I set AUCTeX to call latexmk -pdf instead of pdflatex on my .tex file? Of course, I want next-error to work here too.

更新:我开始了赏金,因为如果这有效,它将成为许多人的好工具.如果给出的解决方案可以让我在 Emacs 中使用 latexmk 轻松编译我的 LaTeX 文档并使用 next-error 跳转到错误,我认为问题已得到解答(当然,错误可能在包含 .tex 文件中,不一定在主文件或当前缓冲区中).

UPDATE: I started a bounty because if this worked it would be a great tool for many people. I consider the question answered if a solution is given that lets me easily compile my LaTeX document using latexmk in Emacs and jump to the errors using next-error (of course, the errors might be in included .tex files, not necessarily in the master file or the current buffer).

更新:感谢 Ivan(和 Chris)使 AUCTeX+Latexmk 工作.同时,我发现使用 Rubber 编译 LaTeX 也是一个不错的选择.它将以 gcc 和其他编译器使用的格式显示错误消息,因此它自然适用于 Emacs C-x compile,例如C-x compile Rubber --pdf foo,错误信息解析正确.

UPDATE: Thanks to Ivan (and Chris) for making AUCTeX+Latexmk work. In the meantime, I found that using Rubber to compile LaTeX is also an excellent choice. It will display error messages in the format used by gcc and other compilers, so it naturally works with Emacs C-x compile, e.g. C-x compile rubber --pdf foo, and the error messages are parsed correctly.

推荐答案

对不起,我没有能力发表评论,或者我只是将其添加为评论.Chris Conway 的答案有效,除了它应该使用 TeX-run-TeX 而不是 TeX-run-command 以便 AucTeX 知道处理错误消息.

Sorry I don't have the ability to comment, or I would just add this as a comment. Chris Conway's answer works, except that it should use TeX-run-TeX instead of TeX-run-command so that AucTeX knows to process the error messages.

(add-hook 'LaTeX-mode-hook (lambda ()
  (push 
    '("Latexmk" "latexmk -pdf %s" TeX-run-TeX nil t
      :help "Run Latexmk on file")
    TeX-command-list)))

添加类似的东西也可能是明智的

It might also be wise to add something like

'("%(-PDF)"
  (lambda ()
    (if (and (not TeX-Omega-mode)
             (or TeX-PDF-mode TeX-DVI-via-PDFTeX))
        "-pdf" "")))

TeX-expand-list 并使用 "latexmk %(-PDF) %s" 以便它可以在 pdf 和 dvi 模式下工作.就个人而言,我发现使用自定义更容易,尤其是在您进行试验时.

to TeX-expand-list and use "latexmk %(-PDF) %s" so that it will work in both pdf and dvi mode. Personally, I find it easier to use customize especially when you are experimenting.

这篇关于如何在emacs中调用latexmk,并跳转到next-error的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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