如何将 Latexmk 绑定到 Emacs 中的一个键并让它显示错误(如果有)
我正在使用 AUCTeX,我想绑定一个键,例如 C-0
,它执行以下操作:
- 保存活动文件而不提示我。
- 在活动文件上运行
latexmk
而不提示我。 - 如果
latexmk
遇到任何由 .
我的问题不是如何绑定一个键(泰勒在下面的评论中发布了一个链接)而是如何提出一个完成第 1-3 项的函数。
调用 Latexmk
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("Latexmk" "latexmk %s" TeX-run-TeX nil t
:help "Run Latexmk on file")
TeX-command-list)))
我通过This is my .latexmkrc
$pdf_mode = 1;
$recorder = 1;
$latex = 'latex -recorder -halt-on-error -interaction=nonstopmode -shell-escape';
$pdflatex = 'pdflatex -recorder -halt-on-error -interaction=nonstopmode -shell-escape';
我正在使用 Emacs 23.3 和 AUCTeX 11.86。
I'm using AUCTeX and I would like to bind a key, e.g. C-0
, that does the following:
- Saves the active file without prompting me.
- Runs
latexmk
on the active file without prompting me. - Shows me errors if
latexmk
encounters any by .
My problem is not how to bind a key (for which Tyler posted a link in a comment below) but how to come up with a function that accomplishes item 1–3.
I call Latexmk by
(add-hook 'LaTeX-mode-hook (lambda ()
(push
'("Latexmk" "latexmk %s" TeX-run-TeX nil t
:help "Run Latexmk on file")
TeX-command-list)))
This is my .latexmkrc
$pdf_mode = 1;
$recorder = 1;
$latex = 'latex -recorder -halt-on-error -interaction=nonstopmode -shell-escape';
$pdflatex = 'pdflatex -recorder -halt-on-error -interaction=nonstopmode -shell-escape';
I'm using Emacs 23.3 and AUCTeX 11.86.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
像这样的东西吗?
编辑:
TeX-save-document
保存您的主文件和任何子文件(如果您只有一个文件,则它是您的主文件),并且当TeX-save-query
为nil,它不要求您确认。然后TeX-run-TeX
使用通常用于运行TeX
的机制来运行 Latexmk,其中包括错误消息解析,但因为它通常会启动一个异步进程,所以我们设置TeX-process-asynchronous
为 nil 以等待它结束。看起来奇怪的plist-get
形式是检查TeX-run-TeX
错误的记录方法(请参阅tex-buf.el
中的注释) code>),如果有错误,我们跳转到第一个;如果没有错误,我们会在迷你缓冲区中显示一条消息,只是为了好玩。最后,
local-set-key
是将键绑定到函数的一种方法。Something like this?
Edit:
TeX-save-document
saves your master file and any sub-files (if you just have one file, it's your master file), and whenTeX-save-query
is nil, it doesn't ask you for confirmation. ThenTeX-run-TeX
runs latexmk using the mechanism usually used for runningTeX
, which includes error message parsing, but because it usually starts an asynchronous process, we setTeX-process-asynchronous
to nil to wait for it to end. The odd-lookingplist-get
form is the documented way to check for errors fromTeX-run-TeX
(see comments intex-buf.el
), and if there are errors, we jump to the first one; if there are no errors, we show a message in the minibuffer just for fun.Finally, the
local-set-key
is one way to bind a key to the function.这是你想要的吗?
我不使用 Latexmk,但要完成这项工作,您所需要做的就是将字符串“LaTeX”切换为您在
TeX-command-list
中用于 Latexmk 的名称字符串(这可能只是“latexmk”或“Latexmk”)。我很高兴你问这个问题,因为这对我现在很有用!
Does this do what you want?
I don't use latexmk, but to make that work all you need to do is switch the string "LaTeX" for the name string you use for latexmk in
TeX-command-list
(which is probably just "latexmk" or "Latexmk").I'm glad you asked, as this will be useful for me now!
假设您已经使用了 中的答案要在 emacs 中调用 Latexmk,并跳转到下一个错误 将
latexmk
添加到 AUCTeX 的命令列表中,可以使用以下函数:并使用以下任意一个将其绑定到 C-0 的键绑定技术;这是 TeX 模式的本地功能:
run-latexmk
函数基于对TeX-command-master
的深入挖掘,并根据您的需要进行了简化。请注意,对(next-error)
的调用可能并不总是发生,因为 LaTeX 可能会对您的错误感到困惑并暂停等待输入Assuming you've already used the answer in How to call latexmk in emacs, and jump to next-error to add
latexmk
to the command list for AUCTeX, you can use the following function:And use any of the key-binding techniques to bind it to
C-0
; here's one that's local to the TeX mode:The
run-latexmk
function is based on digging throughTeX-command-master
, and simplifying it to your needs. Note that the call to(next-error)
may not always happen, because LaTeX may get confused by your error and pause waiting for input我使用 自定义次要模式 在后台运行 Latexmk 并报告任何错误/警告通过flymake。它们的编号显示在模式行中,您可以使用(例如)
Mn
和Mp
来导航它们。特别是,每次保存文件时都会发生您描述的三个步骤。我仅将其用于单文件项目;它可能无法涵盖您的用例。
I use a custom minor mode that runs latexmk in the background and reports any errors/warnings via flymake. Their number is displayed in the mode line, and you can navigate them using (e.g.)
M-n
andM-p
. In particular, the three steps you describe happen every time you save the file.I use this only for single-file projects; it may not cover your use cases.