TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Both MiKTeX and TeX Live are shipped with a package manager that allows for easy install of packages to the appropriate location (this includes updating the FNDB). For adding the -shell-escape Emacs, does Customizing pdfLaTeX for a particular file with AUCTeX? or Using minted (source code LaTeX package) with emacs/auctex help? – Werner Dec 13 '11 at 7:13
You could instead compile with latexmk (which is better in other ways too) in emacs and set it to use shell-escape in it's configuration file, see e.g. stackoverflow.com/questions/7587287/… – N.N. Dec 13 '11 at 7:31
About where to put the .sty files. Ideally, this package would be included in your distribution. If not, you would normally include in your local texmf tree. What distribution are you using? – Ricardo Jul 2 '13 at 5:21

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

share|improve this answer

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

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

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

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

share|improve this answer
See here how to make LaTeX-command safe as a local variable. You should mention this works with AUCTeX. – giordano Jul 2 '13 at 7:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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