70

I stumbled upon an example, which needed to be compiled with the additional option --shell-escape. Using this option it worked just fine, but I'm curious:

Why or when is this option needed and what does it actually do?

4
  • If I'm not wrong I believe that this option enables TeX to execute other commands during the process. See tex.stackexchange.com/q/76105/14757
    – Sigur
    Commented Dec 31, 2012 at 10:38
  • 10
    Have you checked What are \immediate & \write18 and how does one use them?? In short: “No \write18 without --shell-escape (minus a few safe exceptions).” Commented Dec 31, 2012 at 10:42
  • 4
    Additional note: -shell-escape or --shell-escape for TeXLive or -enable-write18 or --enable-write18 for MikTeX does the same thing. Commented Jan 4, 2013 at 1:10
  • 2
    I disagree with the suggested closure. None of the linked threads mentions --shell-escape is such way that it would be obvious to non-experienced users.
    – yo'
    Commented Jan 4, 2013 at 11:46

1 Answer 1

59

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.

2
  • 1
    Can you please provide a working example where we can see how is this command written inside a LaTeX document? I would really appreciate it. Commented Jun 29, 2016 at 15:21
  • 1
    You can for example see the end of the last snippet in this answer where they use \write18 to compile a .tex into .dvi and convert the .dvi to .ps to .pdf.
    – T. Verron
    Commented Jun 29, 2016 at 19:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .