I need to enable shell escape for a package that I want to use. What is shell escape exactly, and how do I enable it in my editor or compiling toolchain?

Links to answers for different editors/toolchains, in alphabetical order:

Note: this is a FAQ post. Related Meta question: Canonical question on enabling shell-escape in different editors. Please add an answer for your own editor/toolchain if it is missing. Thank you!

When adding an answer, please indicate if the setting is permanent or per-document, and/or describe how you can add a button, shortcut, menu item, etc. to make it easy to switch between shell-escape and regular compilation.

  • 1
    +1 Great effort! May 27, 2021 at 13:22
  • can you add Texworks in the list
    – rpapa
    May 28, 2021 at 7:06
  • @rpapa I don't have Texworks installed, so I don't know how it works there - maybe you can add an answer for Texworks?
    – Marijn
    May 28, 2021 at 7:07
  • 1
    can someone add Texpad?
    – Michelle
    Dec 12, 2021 at 22:11
  • 1
    vscode would be good
    – mathtick
    Mar 1 at 11:36

11 Answers 11


General information: what is shell escape?

A number of LaTeX packages need to use external tools to function. Such a tool is called from the LaTeX source code using a system command. However, by default the unrestricted use of external system calls is not permitted by LaTeX. This is a security measure to prevent malicious LaTeX code to delete files, change system settings, allow remote access, et cetera. Therefore, when you try to compile a document using default settings, you will get an error message and/or wrong output if you use a package that needs an external tool.

To be able to use such packages you can change the security settings for the current document. This is done by using a compiler flag called shell-escape. Note that this introduces the risks outlined above, so you should only use this flag if you trust the source code that you are trying to compile.

Some example packages that use shell escape:

  • minted
  • svg
  • asypictureB
  • imakeidx
  • gnuplottex
  • graphviz
  • tikz (externalize)
  • standalone (convert option)
  • pgfplots (gnuplot)

The default setting is usually "Restricted Shell escape" this allows a small number of programs to be called by default (in a restricted form that does not allow shell redirection) these are (in a default TeX Live 2021 configuration)

  • bibtex
  • bibtex8
  • extractbb
  • gregorio
  • kpsewhich
  • makeindex
  • repstopdf
  • r-mpost
  • texosquery-jre8

If you do not want to allow even these programs to run, then you can use the option
in all the ways described for --shell-escape below.

To check if the shell-escape mechanism is active, you can use this small document (taken from here), but slightly changed so that it produces output --- log messages are often hidden in some editor/integrated environments):


    No shell escape\or
    Unrestricted shell escape\or
    Restricted shell escape%


It will create a document with the current shell escape setting displayed.



To enable shell escape in Latexmk you need to add the -shell-escape option to the Latexmk call, as follows:

latexmk -shell-escape yourfile.tex


Arara uses 'magic comments' at the top of the .tex file to determine the options. For shell escape you need to add the option shell: true or equivalently shell: yes. The options are specified between curly braces and separated by commas. Examples:

% arara: pdflatex: { shell: true }
% arara: xelatex: { synctex: 1, shell: yes }
% arara: lualatex: { shell: true, interaction: nonstopmode }

AUCTeX (Emacs)

Custmize variable TeX-command-extra-options to have value " -shell-escape ":

  1. Enter customization typing (in Emacs jargon) M-x customize-option RET TeX-command-extra-options RET (that is, Alt+X, then customize-option, ENTER, TeX-command-extra-options, ENTER)

  2. In the edit box, type -shell-escape , ensuring spaces before and after -shell-escape.

  3. Then click on Apply and Save to make change permanent.

Emacs screenshot

  • Thanks for the answer. I'm not familiar with AUCTeX, is this per document or a general setting? Is it possible to use different shortcuts to compile with and without shell escape?
    – Marijn
    May 27, 2021 at 13:53
  • This is a general setting. I will search for a per document solution and edit post to include that. May 27, 2021 at 14:02

Terminal/Command Prompt

To enable shell escape when you use the terminal (Linux/Mac) or Command Prompt (Windows) to compile, you should add the -shell-escape flag to the command, in between the compiler name and the filename. Examples:

pdflatex -shell-escape yourfile.tex
xelatex -shell-escape yourfile.tex
lualatex -shell-escape yourfile.tex

You generally need to add the flag every time you run the compiler. Do not add the flag to other programs such as bibtex, biber, makeglossaries etc.


Vim + vimtex

The vimtex plugin is highly configurable in terms of which command it uses under the hood to compile LaTeX sources. So the steps needed to add -shell-escape will depend on the specific one you are using.

In general, vimtex admits a magic comment in the form of

 %! TEX program = my-program

but in this case, my-program is a key to an internal table where the real commands or options for the commands are kept. Notice that if you change this directive you have to reload the plugin (\lx by default) to make it active.

vim + vimtex + latexmk

By default, there are no keys that enable the usage of -shell-escape directly from the source file. The recommended way is to add a latexmkrc file in the root directory of your project with the content:

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

(or lualatex or xelatex or...).

If somebody uses vimtex with latexrun or other configurations, please add/edit this entry!



Overleaf has shell escape enabled by default. However, it only works when your document is in the root folder of your Overleaf project.



To enable shell escape globally (for all documents), you can go under menu OptionsConfigure TeXstudioCommands and then add -shell-escape after appropriate commands.

For example, to enable shell escape for LuaLaTeX, the command in its row should be:

lualatex.exe -synctex=1 -interaction=nonstopmode -shell-escape %.tex

TeXstudio LuaLaTeX compiler dispatch setting

To enable shell escape on a per-document basis, a "magic comment" can be added to the root document. For PDFLaTeX, the comment is:

% !TeX TXS-program:compile = txs:///pdflatex/[-shell-escape]

For LuaLaTeX:

% !TeX TXS-program:compile = txs:///lualatex/[-shell-escape]

Et cetera.

Note that the first time the document is compiled with the comment inserted, TeXstudio will ask for user permission to execute the command. It may also add a !TeX document-id = ... line to the document preamble, allowing it to remember the setting. The software will re-request permission to run the command any time the command is modified in any way.

  • Is nonstopmode necessary for TeXstudio, or can you also use other modes? If other modes are possible, maybe this setting can be removed from the example (because nonstopmode hides errors, which is bad)?
    – Marijn
    May 28, 2021 at 10:58
  • And more in general (see also the updated note on the question): could you indicate if the setting is permanent or per-document, and/or describe how you can add a button/shortcut/menu item/etc. to make it easy to switch between shell-escape and regular compilation? Thanks!
    – Marijn
    May 28, 2021 at 11:04
  • 1
    @Marijn: -synctex=1 -interaction=nonstopmode are the TeXstudio default compiler flags. If these flags are omitted from the example, I suspect a lot of less-technically-inclined users will inadvertently wipe them out by copy-pasting and then wonder why their compiler and viewer work differently.
    – COTO
    May 28, 2021 at 15:10


To enable shell escape in Texmaker, open the menu OptionsConfigure Temaker (or press Ctrl+,), add -shell-escape to the commands of interest, and then click OK. For example:

Configure Texmaker panel

The configuration changes apply to all documents and are restored at the next execution.

Alternatively, to define a separate compilation command with shell escape enabled, open the menu UserUser CommandsEdit User Commands, select an empty command, and add the compilation command of your choice with the option -shell-escape. For example:

Edit user commands panel

You can then run the command either from the menu UserUser Commands or by pressing Alt+Shift+Fn, where n is the number of the defined user command.



I am an AUCTeX User. I use this user function

  (defun TeX-command-toggle-shell-escape ()
        (setq TeX-command-extra-options
              (cond ((string-match-p "\\_<--shell-escape\\_>" TeX-command-extra-options )
                     (replace-regexp-in-string "\\_<--shell-escape\\_>" "" TeX-command-extra-options))
                    ((string-empty-p TeX-command-extra-options)"--shell-escape")
                    (t(format "--shell-escape %s" TeX-command-extra-options))))
        (message "TeX-command-extra-options : `%s'" TeX-command-extra-options))

and I have bound this function to "C-c C-t C-x". I find it very convenient.


Visual Studio Code + LaTeX Workshop

In Visual Studio Code you can create a shortcut, a so called "recipe", with the LaTeX Workshop extension which lets you compile the document with a single click in the extension's interface.

Go to the file settings.json by opening your Command Palette (Ctrl+Shift+P) and choosing "Preferences: Open Settings (JSON)". You will need to add a recipe and a "tool" which can be used by the recipe as many times as needed. Since there will already be a few recipes and other settings in there, don't forget to separate them with commas. For xelatex and lualatex just replace "command": "pdflatex" with the appropriate one.

    "latex-workshop.latex.recipes": [
            "name": "pdflatex-shell-escape-recipe",
            "tools": [
    "latex-workshop.latex.tools": [
            "name": "pdflatex-shell-escape",
            "command": "pdflatex",
            "args": [

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.