如何在emacs中调用latexmk,并跳转到下一个错误

发布于 2024-08-20 02:22:03 字数 1629 浏览 5 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

思念满溢 2024-08-27 02:22:03

抱歉,我无法发表评论,否则我只会将其添加为评论。 Chris Conway 的答案有效,只是它应该使用 TeX-run-TeX 而不是 TeX-run-command 以便 AucTeX 知道如何处理错误消息。

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

添加类似于

'("%(-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 模式。就我个人而言,我发现使用自定义更容易,尤其是在尝试时。

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" "")))

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.

迷荒 2024-08-27 02:22:03

使用 Cc Cc 让 AucTeX 运行 Latexmk 相对容易。下面将在 TeX 命令列表中添加一个 Latexmk 选项:

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

技巧是让 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 a Latexmk choice to the list of TeX commands:

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

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

弱骨蛰伏 2024-08-27 02:22:03

添加 %(mode) 可以为 Latexmk 提供更多选项,例如非交互式(如果在 auctex 中如此设置)。

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

Adding %(mode) gives latexmk some more options like noninteractive if it is set so in auctex.

(add-hook 'LaTeX-mode-hook (lambda ()
  (push 
    '("Latexmk" "latexmk -pdf %(mode) %s" TeX-run-TeX nil t
      :help "Run Latexmk on file")
    TeX-command-list)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文