Starting from version 11.88 of AUCTeX, you can add an option to the TeX processor with the file-local variable TeX-command-extra-options
:
%%% TeX-command-extra-options: "-shell-escape"
As explained in the manual, you have to manually make this variable safe as a local variable because of the security holes it can open.
Note: this question inspired me to add this feature.
Until version 11.87, AUCTeX hadn't a facility to add easily an option to the compiler (at least I always missed to find it). I see at least three strategies you can follow:
- edit
LaTeX-command-style
(the suggested way if you want to activate shell escape for all documents)
- add a new element to
TeX-engine-alist
- add a new element to
TeX-command-list
I'll try to outline 1 and 2. 3 is similar to 2 in spirit.
Note: in a previous version of the answer I suggested to edit LaTeX-command
, but that variable should be reserved to the actual latex
binary name. Setting it to latex -shell-escape
doesn't play well with forward/inverse search (for the curious person: TeX-source-correlate-determine-method
would fail because there is no latex -shell-escape
binary and so forward/inverse search would fall back on source specials, even if SyncTeX is actually available).
LaTeX-command-style
This variable allows to change the options passed to the compiler, its syntax is a bit cumbersome, though. In addition, this isn't a file local variable so you can't set (by default) it on a per-document basis.
The customize way
Issue M-x customize-variable
RET LaTeX-command-style
RET. In the String
field of the variable add -shell-escape
after %(latex)
. E.g., if the value of the field is
%(PDF)%(latex) %S%(PDFout)"
change it into
%(PDF)%(latex) -shell-escape %S%(PDFout)"
The do-it-for-me way
Add the following code to your .emacs
.
(setq LaTeX-command-style '(("" "%(PDF)%(latex) -shell-escape %S%(PDFout)")))
TeX-engine-alist
Insert a new element, called for example default-shell-escape
, similar to the default
element of TeX-engine-alist-builtin
. You can do it by using the customization interface or adding an Elisp code to your .emacs
.
After creating this new engine, you'll be able to activate it by using the menu Command > TeXing Options > Use Default with shell escape
. If you want to set it by default for all documents or on a per-document basis see below.
The customize way
Issue M-x customize-variable
RET TeX-engine-alist
RET. Press the INS
button and fill the fields in the following way:
- Symbol:
default-shell-escape
- Name:
Default with shell escape
- Plain TeX command:
tex -shell-escape
- LaTeX command:
latex -shell-escape
- ConTeXt command: leave empty
The do-it-for-me way
Add the following code to your .emacs
(eval-after-load "tex"
'(progn
(add-to-list
'TeX-engine-alist
'(default-shell-escape "Default with shell escape"
"pdftex -shell-escape"
"pdflatex -shell-escape"
ConTeXt-engine))
;; (setq-default TeX-engine 'default-shell-escape)
))
Set the default-shell-escape
engine as default
Now you can set the new fictitious engine as default for all documents
- by customizing
TeX-engine
(M-x customize-varaiable
RET TeX-engine
RET) and selecting Default with shell escape
in the drop-down Value Menu
, or
- by uncommenting (ie, removing
;;
at the beginning of) the
(setq TeX-engine 'default-shell-escape)
line in the previous Elisp code.
Use the default-shell-escape
engine on a per-document basis
Alternatively, you can leave the default engine as it is and pick up the default-shell-escape
engine only in the documents in which you actually need it. In those documents, issue M-x add-file-local-variable
RET TeX-engine
default-shell-escape
RET.
'(LaTeX-command "latex -shell-escape -synctex=1")
.-shell-escape
to whatever is already inLaTeX-command
(if that is the right command to change).Symbol's value as variable is void: something-or-other
, it usually means the library containing the definition of that particular variable hasn't been loaded yet. In this case, the variableLaTeX-command
is in the librarytex.el
. So whenever you want to redefine a variable in a particular library and avoid an error message like the one you got, you can do something like:(eval-after-load "tex" '(progn (setq LaTeX-command (concat LaTeX-command " -shell-escape")) ))
You would useprogn
when more than one entry. tex.stackexchange.com/a/156617/26911