如何在emacs中调用latexmk,并跳转到下一个错误
我想使用 latexmk 编译我的 LaTeX 文档Emacs。特别是我需要 Emacs 功能 next-error
,它通常用 Cx ` 调用,并跳转到文档中的下一个 LaTeX 错误。
我想使用Cx编译
或AUCTeX Cc Cc
来调用latexmk
。
首先,我将latexmk
设置为使用
$pdflatex = 'pdflatex -interaction=nonstopmode';
选项1:Cx编译
我按Cx编译
并输入latexmk -pdf foo
,它运行 pdflatex
。但是 next-error
不会跳转到错误,即使 *compilation* 缓冲区包含错误:
! Paragraph ended before \author was complete.
<to be read again>
\par
l.48
[...]
Compilation exited abnormally with code 12
如何自动跳转到第 48 行中的此错误?
请注意,解析 Latex 输出的问题与 Latexmk 直接无关。当我刚刚执行 Cxcompile pdflatex -interaction=nonstopmode foo
时,也会出现同样的问题。
选项 2:AUCTeX
如何设置 AUCTeX 在 .tex 文件上调用 latexmk -pdf
而不是 pdflatex
?当然,我也希望 next-error
在这里工作。
更新:我开始了赏金,因为如果这有效的话,它将对很多人来说是一个很好的工具。我认为如果给出一个解决方案,让我可以在 Emacs 中使用 latexmk
轻松编译我的 LaTeX 文档,并使用 next-error
跳转到错误(当然,错误可能位于包含 .tex 文件中,不一定位于主文件或当前缓冲区中)。
更新:感谢 Ivan(和 Chris)使 AUCTeX+Latexmk 工作起来。同时,我发现使用 Rubber 来编译 LaTeX 也是一个不错的选择。它将以 gcc
和其他编译器使用的格式显示错误消息,因此它自然可以与 Emacs Cxcompile
配合使用,例如 Cxcompilerubber --pdf foo< /code>,并且错误消息被正确解析。
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.
I would like to call latexmk
either using C-x compile
or the AUCTeX C-c C-c
.
First, I set latexmk
to use
$pdflatex = 'pdflatex -interaction=nonstopmode';
Option 1: C-x compile
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
How can I automatically jump to this error in line 48?
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
.
Option 2: AUCTeX
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.
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).
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
抱歉,我无法发表评论,否则我只会将其添加为评论。 Chris Conway 的答案有效,只是它应该使用
TeX-run-TeX
而不是TeX-run-command
以便 AucTeX 知道如何处理错误消息。添加类似于
TeX-expand-list
的内容并使用"latexmk %(-PDF) %s"
也可能是明智的,这样它就可以在 pdf 和DVI 模式。就我个人而言,我发现使用自定义更容易,尤其是在尝试时。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 ofTeX-run-command
so that AucTeX knows to process the error messages.It might also be wise to add something like
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.使用
Cc Cc
让 AucTeX 运行 Latexmk 相对容易。下面将在 TeX 命令列表中添加一个Latexmk
选项:技巧是让
next-error
起作用。如果您深入研究 AucTeX 源代码,您可能会找到它在 TeX 输出缓冲区上使用的正则表达式;它不会自动应用于 TeX-run-command 创建的缓冲区。 (您也许还可以说服compile
模式使用此正则表达式。)另一种方法是重新定义变量
LaTeX-command
。这有点不确定,因为我认为很多 AucTeX 函数都假设它们可以将命令行选项附加到该字符串上并执行结果。It's relatively easy to get AucTeX to run latexmk with
C-c C-c
. The following will add aLatexmk
choice to the list of TeX commands:The trick is getting
next-error
to work. If you dig around in the AucTeX sources, you can probably find the regex it uses on TeX output buffers; it's not automatically applied to the buffer created by TeX-run-command. (You might also be able to convincecompile
mode to use this regex.)Another approach is to redefine the variable
LaTeX-command
. This is a bit iffy because I think a lot of AucTeX functions assume they can tack command-line options onto this string and execute the result.添加 %(mode) 可以为 Latexmk 提供更多选项,例如非交互式(如果在 auctex 中如此设置)。
Adding %(mode) gives latexmk some more options like noninteractive if it is set so in auctex.