如何在AUCTeX中向TeX-command-list添加一个函数(latexmk变体)?

时间:2012-02-26 16:32:06

标签: emacs auctex

我使用Latex, Emacs: automatically open *TeX Help* buffer on error and close it after correction of the error?中的以下函数通过latexmk编译.tex文档:

(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"
                 (TeX-command-expand "latexmk -pdf %s" 'TeX-master-file); adjusted
                 master-file)
    (if (plist-get TeX-error-report-switches (intern master-file))
        (TeX-next-error t)
      (progn
    (demolish-tex-help)
    (minibuffer-message "latexmk: Done")))))

如何将此函数“添加”到TeX-command-list,以便.tex文件中的C-c C-c执行此功能? [。C-c C-c在.tex文件上执行时应使用run-latexmk作为默认值]

我试过

(add-hook 'LaTeX-mode-hook
      (lambda ()
        (add-to-list 'TeX-command-list
             '("latexmk" #'run-latexmk
               TeX-run-command nil t :help "Run latexmk") t)
        (setq TeX-command-default "latexmk")))

但它失败并显示消息:TeX-command-expand: Wrong type argument: stringp, (function run-latexmk)(取自* Messages *)

1 个答案:

答案 0 :(得分:4)

您不想使用TeX-run-command,因为这是用于运行shell命令。您将需要运行TeX-run-function,但它仍然将“函数”作为字符串,因此您应该说(未经测试):

(add-hook 'LaTeX-mode-hook
   (lambda ()
     (add-to-list 'TeX-command-list
          '("latexmk" "(run-latexmk)"
            TeX-run-function nil t :help "Run latexmk") t)
     (setq TeX-command-default "latexmk")))