0

I want to run Latexmk automatically with the correct TeX-engine as set in the local file variable at the end of the file, for example:

%% Local Variables:
%% TeX-engine: luatex
%% End:

In my .emacs file I tried something like:

(add-hook 'LaTeX-mode-hook (lambda ()
  (push 
    '("Latexmk" "latexmk %(-PDF) %s" TeX-run-TeX nil t
      :help "Run Latexmk on file")
    TeX-command-list)

'("%(-PDF)"
  (lambda ()
    (if (equal TeX-engine 'luatex)
        "-lualatex" "-pdf"))))

but it doesn't work.

So how can I get the desired result?

  • I don't know, but could you clean up the code you posted, so it at least has balancing parentheses and is properly indented? As you posted it, your intention is quite unclear. (Hint: Edit the code in an elisp buffer, perhaps *scratch*. Place the cursor at the start and hit M-C-q to indent the code. Select the whole block and indent it four spaces with C-u C-x TAB. Then paste it into your question.) – Harald Hanche-Olsen Jan 30 '16 at 21:37
  • Oh, addendum: After indenting the code in emacs and before copying it, select it again and run M-x untabify. – Harald Hanche-Olsen Jan 30 '16 at 22:02
1

I am going out on a limb and guessing that what you want is more along these lines (totally untested):

(eval-after-load "tex"
  '(progn
     (push '("Latexmk" "latexmk %(-PDF) %s" TeX-run-TeX nil t
             :help "Run Latexmk on file")
           TeX-command-list)
     (push '("%(-PDF)"
             (lambda ()
               (if (equal TeX-engine 'luatex)
                   "-lualatex" "-pdf")))
           TeX-expand-list)))

By using eval-after-load instead of a hook variable, I avoid having the same value pushed over and over again each time the mode is run. (You could achieve the same by using pushnew, since we are trying to push literally the same object on each run. Or by arraning for a hook function to remove itself after running.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.