How can I specify inside a latex file (for example as a local variable) that compiling with latexmk should use a latexmkrc file with a specific path say /path/to/latexmkrc and not the default one and not that in the current directory.

Here is what I tried:

%%% Local Variables:
%%% TeX-command-extra-options: "-r /path/to/latexmkrc"
%%% End:

However this doesn't work. If I look at the log window, it starts with

Running `Latexmk' on `myfile' with ``latexmk -shell-escape myfile''
Subroutine pythontex redefined at (eval 10) line 6.
Rc files read:

(And /path/to/latexmkrc is neither /home/myuser/.latexmkrc nor .latexmkrc).


The problem seems to be related to latexmk if I choose latex as compiler, it seems to add the option. Here is how latexmk is setup in my init.el

(eval-after-load "tex"
     (push '("Latexmk" "latexmk %(-PDF) %s" TeX-run-TeX nil t
             :help "Run Latexmk on file")

1 Answer 1


I solved the problem by adding an %(extraopts) to the definition of Latexmk in my init.el file. This causes emacs to append the TeX-command-extra-options to the Latexmk command:

(eval-after-load "tex"
     (push '("Latexmk" "latexmk %(-PDF) %(extraopts) %s" TeX-run-TeX nil t
             :help "Run Latexmk on file")

Compare M-x describe-variable RET TeX-expand-list-builtin:

 (lambda nil TeX-command-extra-options))

Nevertheless by looking on the definition of the LaTeX command in TeX-command-list I noticed that LaTeX doesn't include the %(extraopts) expand string whereas plain TeX does.

("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %(output-dir) %t" TeX-run-TeX nil
  (plain-tex-mode ams-tex-mode texinfo-mode)
  :help "Run plain TeX")
 ("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil
  (latex-mode doctex-mode)
  :help "Run LaTeX")

Maybe someone could comment, why LaTeX parses the TeX-command-extra-options variable even without %(extraopts) in its definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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