Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a function (latexmk variant) to TeX-command-list in AUCTeX?

Tags:

emacs

auctex

I use the following function from Latex, Emacs: automatically open *TeX Help* buffer on error and close it after correction of the error? to compile .tex documents via latexmk:

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

How can I "add" this function to TeX-command-list so that C-c C-c in .tex files executes this function? [C-c C-c should use run-latexmk as default when executed on .tex files]

I tried

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

but it fails with message: TeX-command-expand: Wrong type argument: stringp, (function run-latexmk) (taken from *Messages*)

like image 516
Marius Hofert Avatar asked Feb 26 '12 16:02

Marius Hofert


1 Answers

You don't want to use TeX-run-command since that is for running a shell command. You will want to run TeX-run-function, but it still takes the "function" as a string so you should say (untested):

(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")))
like image 138
Ivan Andrus Avatar answered Oct 14 '22 01:10

Ivan Andrus