I am trying to use minted package... Here is an example minimal.tex:

int main() {
printf("hello, world");
return 0;

I need to run pdflatex -shell-escape minimal in a terminal to compile it... When I try to compile it within Emacs as a usual tex file by C-c C-c, I got an error: Package minted Error: You must invoke LaTeX with the -shell-escape flag. Could anyone tell me where I could add this -shell-escape flag under Emacs?

Another small question is regarding minted.sty, at the moment I put it in the same folder as the tex files, which is not the best way I guess... Where do you often put .sty files?


4 Answers 4


On a per-file basis, you would add it as a local variable, usually at the end of the document:

%%% Local Variables:
%%% LaTeX-command: "latex -shell-escape"
%%% End:

After you do this, C-x C-s to save and C-c C-n to reparse the document. Once you reparse the document you, C-c C-c will compile with the -shell-escape option automatically.

Every time you open the file after this, Emacs will complain about -shell-escape being a potentially risky variable. You can choose to apply it or not.


I think that it is not exactly what you are asking, but you can compile it in emacs with M-! and then pdflatex -shell-escape source.tex


This adds the -shell-escape flag to the compile-command:

(require 'tex-mode)
(setcar (cdr (cddaar tex-compile-commands)) " -shell-escape ")

  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Commented Jul 1, 2013 at 19:54
  • cddaar requires cl (or cl-lib). You should mention this works with Emacs builtin TeX mode, not AUCTeX.
    – giordano
    Commented Jul 2, 2013 at 7:39

From AUCTeX, the best option to handle the -shell-escape tag is to set the TeX-command-extra-options variable as "-shell-escape"

You can set it from a file variable either at the beginning of the tex file

% -*- TeX-command-extra-options: "-shell-escape" -*-

or at the end, using M-x add-file-local-variable

     % local variables:
     % TeX-command-extra-options: "-shell-escape"
     % End:

You must reload your file for it to be active or evaluate M-: (hack-local-variables)

Instead, you can write a user function in your init file to toggle the shell-escape compilation on the fly:

     (defun toggle-shell-escape()
       "Toggle TeX-command-extra-options variable between ' ' and '-shell-escape'"
       (message "TeX-command-extra-option is now %s"
                (setq TeX-command-extra-options
              (if (string-empty-p TeX-command-extra-options)

and bind it to a key of your choice.

     (bind-key (kbd "C-c x") #'toggle-shell-escape LaTeX-mode-map)

C-c x will toggle the -shell-escape compilation tag.

You must log in to answer this question.

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