1

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!

1 Answers1

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

OR

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.

SECURITY

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?

PS

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}.

js bibra
  • 21,280
  • 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. – David Carlisle Dec 24 '19 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: https://tex.stackexchange.com/questions/187276/how-to-do-shell-escape-in-texworks#comment433613_187276 ? Is it really safe to do this? – Rajath Kashyap Dec 24 '19 at 12:49
  • please refer to the comment above by @DavidCarlisle – js bibra Dec 24 '19 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) – David Carlisle Dec 24 '19 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. – Rajath Kashyap Dec 25 '19 at 01:33
  • Sorry as I did not look up the community for a similar question and repeated it. – Rajath Kashyap Dec 25 '19 at 01:34
  • @RajathKashyap Always welcome--please upvote the answers/comments you found helpful by clicking on the triangle pointing upwards on the left side of the comment – js bibra Dec 25 '19 at 01:35
  • I fear I cannot do that as I just have a few reputation points. Once I reach fifteen, I will definitely upvote your answer sir!! ( It was yesterday that I joined the community ) – Rajath Kashyap Dec 25 '19 at 01:37
  • Oh, that cache. – Mihai Oct 20 '23 at 07:27