I haven't seen this asked specifically, though I have seen related questions.

I just installed the minted package and noticed I have to run latex/pdflatex with a command-line option, -shell-escape, for it to run. I can do that manually, of course, but what if I'm using latexmk?


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
  • Are you sure what it does is invoke pdflatex with -shell-escape? – einpoklum Sep 4 '20 at 19:27
  • Yes, I added part of the note that latexmk -showextraoptions starts with. – snwflk Sep 4 '20 at 19:54

If you need to do this just once, run:

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


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';


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

  • 1
    You can also consider creating a Makefile (or a script, be it bash or cmd), if you want to have --shell-escape on a per-project basis. – rubdos Jun 9 '17 at 17:26
  • 1
    What is q/ for? – bers Jun 28 '19 at 9:11
  • The q/ is explained in the documentation as In this example, the q/.../ construct is a Perl idiom equivalent to single quotes. It is about escaping and proper quoting. – Alex Povel Aug 9 '19 at 12:31
  • Is there supposed to be extra spacing around the %O in the .latexmkrc sample? – Mateen Ulhaq May 15 '20 at 15:51
  • Umm... I don't think so. Don't remember why the extra spacing is in there. Try removing it and check to make sure nothing has gotten messed up. – einpoklum May 15 '20 at 16:40

To enable shell-escape for all *latex commands using a latexmkrc file:

set_tex_cmds( '--shell-escape %O %S' );
  • Thank you very much! I had lots of problems with tikz externalize and pgfplots to be externalized and compiled separately (which worked in the past at some point). Now, I know this is not a solid thing to do, but it works! Thanks mate! – mike Feb 4 at 9:25

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.