如何将 Latexmk 绑定到 Emacs 中的一个键并让它显示错误(如果有)

发布于 2024-12-07 08:04:42 字数 781 浏览 1 评论 0原文

我正在使用 AUCTeX,我想绑定一个键,例如 C-0,它执行以下操作:

  1. 保存活动文件而不提示我。
  2. 在活动文件上运行 latexmk 而不提示我。
  3. 如果 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:

  1. Saves the active file without prompting me.
  2. Runs latexmk on the active file without prompting me.
  3. 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 技术交流群。

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

发布评论

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

评论(4

美羊羊 2024-12-14 08:04:42

像这样的东西吗?

(require 'tex-buf)

(defun run-latexmk ()
  (interactive)
  (let ((TeX-save-query nil)
        (TeX-process-asynchronous nil)
        (master-file (TeX-master-file)))
    (TeX-save-document "")
    (TeX-run-TeX "latexmk" "latexmk" master-file)
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (minibuffer-message "latexmk done"))))

(add-hook 'LaTeX-mode-hook
          (lambda () (local-set-key (kbd "C-0") #'run-latexmk)))

编辑
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?

(require 'tex-buf)

(defun run-latexmk ()
  (interactive)
  (let ((TeX-save-query nil)
        (TeX-process-asynchronous nil)
        (master-file (TeX-master-file)))
    (TeX-save-document "")
    (TeX-run-TeX "latexmk" "latexmk" master-file)
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (minibuffer-message "latexmk done"))))

(add-hook 'LaTeX-mode-hook
          (lambda () (local-set-key (kbd "C-0") #'run-latexmk)))

Edit:
TeX-save-document saves your master file and any sub-files (if you just have one file, it's your master file), and when TeX-save-query is nil, it doesn't ask you for confirmation. Then TeX-run-TeX runs latexmk using the mechanism usually used for running TeX, which includes error message parsing, but because it usually starts an asynchronous process, we set TeX-process-asynchronous to nil to wait for it to end. The odd-looking plist-get form is the documented way to check for errors from TeX-run-TeX (see comments in tex-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.

走走停停 2024-12-14 08:04:42

这是你想要的吗?

(defun my-tex ()
"Saves the current buffer and runs LaTeX, all with no prompts or further interaction."
  (interactive)
  (save-buffer)
  (TeX-command "LaTeX" 'TeX-master-file -1))

我不使用 Latexmk,但要完成这项工作,您所需要做的就是将字符串“LaTeX”切换为您在 TeX-command-list 中用于 Latexmk 的名称字符串(这可能只是“latexmk”或“Latexmk”)。

我很高兴你问这个问题,因为这对我现在很有用!

Does this do what you want?

(defun my-tex ()
"Saves the current buffer and runs LaTeX, all with no prompts or further interaction."
  (interactive)
  (save-buffer)
  (TeX-command "LaTeX" 'TeX-master-file -1))

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!

回忆凄美了谁 2024-12-14 08:04:42

假设您已经使用了 中的答案要在 emacs 中调用 Latexmk,并跳转到下一个错误latexmk 添加到 AUCTeX 的命令列表中,可以使用以下函数:

(defun run-latexmk ()
  (interactive)
  (save-buffer)
  (TeX-command "Latexmk" 'TeX-master-file 0)
  (if (plist-get TeX-error-report-switches (intern (TeX-master-file)))
      (next-error))) ;; 0 -> suppress confirmation

并使用以下任意一个将其绑定到 C-0 的键绑定技术;这是 TeX 模式的本地功能:

(define-key TeX-mode-map (kbd "C-0") 'run-latexmk)

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:

(defun run-latexmk ()
  (interactive)
  (save-buffer)
  (TeX-command "Latexmk" 'TeX-master-file 0)
  (if (plist-get TeX-error-report-switches (intern (TeX-master-file)))
      (next-error))) ;; 0 -> suppress confirmation

And use any of the key-binding techniques to bind it to C-0; here's one that's local to the TeX mode:

(define-key TeX-mode-map (kbd "C-0") 'run-latexmk)

The run-latexmk function is based on digging through TeX-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

过去的过去 2024-12-14 08:04:42

我使用 自定义次要模式 在后台运行 Latexmk 并报告任何错误/警告通过flymake。它们的编号显示在模式行中,您可以使用(例如)MnMp 来导航它们。特别是,每次保存文件时都会发生您描述的三个步骤。

我仅将其用于单文件项目;它可能无法涵盖您的用例。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文