I wish to write a LaTeX code snippet in a document and hence I loaded the minted package. But upon compiling, the following error popped up :

! Package minted Error: You must invoke LaTeX with the -shell-escape flag. See the minted package documentation for explanation.

Kindly help me out with this issue!

Thanks in advance!

  • as the error message says you have to use --shell-escape option to pdflatex to allow it to run pygmentize Dec 24, 2019 at 11:42
  • I do not know how to use --shell-escape. Can you help me out with that as well !? Thanks for the swift response! Dec 24, 2019 at 11:45
  • Welcome TeX.SE... run the TeX file through the option latex -shell-escape filename.tex
    – MadyYuvi
    Dec 24, 2019 at 11:51
  • your configuration? windows or mac -- sublime text or texmaker etc--let us know
    – js bibra
    Dec 24, 2019 at 11:53
  • I use TeX works on Windows. Dec 24, 2019 at 11:56

1 Answer 1


Since minted package requires access to the shell, this should be permitted within your editor. To do so, you have to add -shell-escape to your command list for LaTex, PdfLaTex, XeLaTex, and LuaLaTex in your editor. In “TexWorks” modify those commands by going into “Options > Configure TexWorks > Commands” change the following commands by adding -shell-escape:

latex.exe -shell-escape -src -interaction=nonstopmode %.tex
pdflatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex
xelatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex
lualatex.exe -shell-escape -synctex=1 -interaction=nonstopmode %.tex

TeXworks with pdflatex and shellescape enabled

enter image description here

The console will show \write18 enabled once the above is run on a file


You can also save the code in a tex file (let’s say you named it testMinted.tex), and compile it from command line by going in to the folder where the file resides (let’s say it is in C:\Users\uqapourm\Desktop\testMinted) and running pdflatex.exe -shell-escape -synctex=1 -interaction=nonstopmode testMinted.tex in the command line.


Sometimes, it is useful to be able to run external commands from inside the tex file : it allows for example to externalize some typesetting, or to use external tools like bibtex. This is available via the \write18 tex primitive.

The problem is that it allows for almost everything.

A tex file is meant to be portable, and one shouldn't have to fear any security issue when compiling a third-party file. So by default, this primitive is disabled.

If an user needs to use it, he needs to explicitely tell the compiler that he trusts the author of the file with shell interaction, and that's exactly the point of the optional --shell-escape argument.

For years \write18 has been used as a back door to the operating system. Syntactically TeX treats it as writing to a file, but register 18 is treated as a pre-opened file that in fact executes commands.

"unrestricted" write18 means that you can execute any command so if you allow this and run a TeX file that someone sent you it may execute arbitrary code, email your password file to a spam bot or whatever.

That is obviously a security risk but there are some commands that are naturally part of the Tex distribution that you might want to always allow (such as image and font conversion) so web2c allows you (or the texlive maintainers by default) to set up a set of "allowed, safe" commands and these are allowed to run in restricted mode.

The third alternative is never to execute commands at all from \write18.

What does "restricted \write18 enabled" mean and why does TexLive keep reporting it?

How to enable shell-escape in TeXworks?


Sometimes, you need to clear the cache in order to get the package to work. This will slow down the operation, but it will avoid errors. To do so, add option to \usepackage[cache=false]{minted}.

  • 2
    it would be much better to set up specific configurations for pdflatex shell-escape, not edit the default configurations to use shell-escape all the time. --shell-escape is disabled by default with good reason. Dec 24, 2019 at 12:21
  • How do I set up specific configurations?? I couldn't follow the steps you stated earlier. Can it be clarified?? Can I follow the method followed in this link: tex.stackexchange.com/questions/187276/… ? Is it really safe to do this? Dec 24, 2019 at 12:49
  • please refer to the comment above by @DavidCarlisle
    – js bibra
    Dec 24, 2019 at 14:13
  • @jsbibra it would be better if you edited your answer not to suggest disabling security by default. (I don't have this editor so I can't provide details of how to set up shell escape in its menus) Dec 24, 2019 at 14:37
  • Thank you very much js bibra sir and David Carlisle sir !! You all helped me solve my issue!! I am grateful to you. Dec 25, 2019 at 1:33

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