6

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

Community
  • 1
  • 1
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102

1 Answers1

4

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")))
Ivan Andrus
  • 5,221
  • 24
  • 31
  • I set multiple options in `Tex-command-list` in `LaTeX-mode-hook`, so I can shoose any one in `C-c C-c`, and I set one of them as `TeX-command-default` in `LaTeX-mode-hook`, but I use another function to run the whole compiling process so I don't have to choose one from `C-c C-c`, how can I use the `Tex-command-default` value in that function? – CodyChan Aug 23 '17 at 07:19
  • Try let-binding TeX-command-default in your other function e.g. (defun xxx () (let ((TeX-command-default "my command")) ...)) – Ivan Andrus Aug 24 '17 at 02:49