如何将 latexmk 绑定到 Emacs 中的一个键并让它显示错误(如果有的话) [英] How do I bind latexmk to one key in Emacs and have it show errors if there are any

查看:20
本文介绍了如何将 latexmk 绑定到 Emacs 中的一个键并让它显示错误(如果有的话)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using AUCTeX and I would like to bind a key, e.g. C-0, that does the following:

  1. 在不提示我的情况下保存活动文件.
  2. 在活动文件上运行 latexmk 而不提示我.
  3. 如果 latexmk 遇到任何 by ,则显示错误.
  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 .

我的问题是不是如何绑定一个键(Tyler 在下面的评论中发布了一个链接)但是如何想出一个函数来完成第 1 项–3.

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.

我打电话给 Latexmk

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

这是我的 .latexmkrc

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 Emacs 23.3 and AUCTeX 11.86.

推荐答案

类似的事情?

(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 是零,它不会要求您确认.然后TeX-run-TeX使用通常用于运行TeX的机制运行latexmk,其中包括错误信息解析,但因为它通常启动一个异步过程,我们设置TeX-process-asynchronous 为 nil 以等待它结束.看起来很奇怪的 plist-get 表单是从 TeX-run-TeX 中检查错误的文档化方法(请参阅 tex-buf.el 中的注释)code>),如果有错误,我们跳到第一个;如果没有错误,我们会在迷你缓冲区中显示一条消息,只是为了好玩.

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.

最后,local-set-key 是将键绑定到函数的一种方式.

Finally, the local-set-key is one way to bind a key to the function.

这篇关于如何将 latexmk 绑定到 Emacs 中的一个键并让它显示错误(如果有的话)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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