How to have latexmk always use -shell-escape?

If you need to do this just once, run:

latexmk -e '$latex=q/latex %O -shell-escape %S/'

or

latexmk -e '$pdflatex=q/pdflatex %O -shell-escape %S/' -pdf

for PDF output.

If you want latexmk to always run with this option enabled, you should put the following in your .latexmkrc file (yes, that's a thing):

$latex = 'latex  %O  --shell-escape %S';
$pdflatex = 'pdflatex  %O  --shell-escape %S';

Caveat!

Enabling --shell-escape by default is dangerous, since it makes the latex binary execute arbitrary shell commands in latex files.**


You can pass the parameter directly to latexmk as such:

latexmk -shell-escape

This option is not mentioned in the manpage. The manpage suggests the -e option which is also used in the first answer. This option amongst many others can be found using

latexmk -showextraoptions

The command output starts with the following note:

List of extra latex and pdflatex options recognized by latexmk. These are passed as is to (pdf)latex. They may not be recognized by particular versions of (pdf)latex. [..]

Tested with latexmk versions

  • 1 January 2015. Version 4.41
  • 26 Dec. 2019, version: 4.67