15

In my .emacs I have

'(TeX-PDF-mode t) 

set. So I'm using PDFLaTeX. I'm not sure why this is not the default these days. I had also set

'(LaTeX-command "latex -shell-escape")

In hindsight this was a bad idea, but I didn't realise it till I was trying to get SyncTeX to work, but it wouldn't. I belatedly realized that because I had set LaTeX-command manually, I was overwriting the

--synctex=1

option that would normally have been there.

Which brings to my question.

  1. Is LaTeX-command the right command to modify to add the -shell-escape option, and if so
  2. What is the right way to add an option to LaTeX-command?

@David Carlisle suggested

(setq LaTeX-command (concat LaTeX-command " -shell-escape"))

which seems to be in the right ballpark, but this gives the error:

 Symbol's value as variable is void: LaTeX-command

NOTE: Evaluating LaTeX-command just gives "latex", so this may not be the right thing to append to.

  • The following works for me: '(LaTeX-command "latex -shell-escape -synctex=1"). – Philipp Feb 2 '14 at 23:18
  • @Philipp The idea is to just add -shell-escape to whatever is already in LaTeX-command (if that is the right command to change). – Faheem Mitha Feb 2 '14 at 23:37
  • 3
    When you get an error like 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 variable LaTeX-command is in the library tex.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 use progn when more than one entry. tex.stackexchange.com/a/156617/26911 – lawlist Feb 3 '14 at 20:35
  • @FaheemMitha Are you still looking for an answer? Are you interested in a per-document way to set the LaTeX command? – giordano Feb 18 '14 at 23:21
  • @giordano I suppose I am. I haven't checked lawlist's answer yet, though. Sure, I'd be interested in a per-document way. – Faheem Mitha Feb 19 '14 at 3:58
18

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:

  1. edit LaTeX-command-style (the suggested way if you want to activate shell escape for all documents)
  2. add a new element to TeX-engine-alist
  3. 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

  1. 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
  2. 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.

  • Hi giordano. Sorry about being so slow in responding to this. I guess it fell off my radar. I tried (eval-after-load "tex" '(progn (setq LaTeX-command (concat LaTeX-command " -shell-escape")))), but this seemed to remove synctex as well for some reason. Without it I get Running LaTeX' on corrmodel' with ``pdflatex --synctex=1 -interaction=nonstopmode "\input" corrmodel.tex''. With it I get Running LaTeX' on corrmodel' with ``pdflatex -shell-escape -src-specials -interaction=nonstopmode "\input" corrmodel.tex''. Can you reproduce? – Faheem Mitha Apr 27 '14 at 17:12
  • I thought this might be caused by something in my .emacs file, but I stripped it down to basics, and I still get the same result. – Faheem Mitha Apr 27 '14 at 17:38
  • I'm unclear on the difference between "TeX-engine-alist::The do-it-for-me way" and "Set the default-shell-escape engine as default". I'm particularly fuzzy on why you would uncomment the (setq TeX-engine 'default-shell-escape) in the earlier code. – Faheem Mitha Apr 27 '14 at 18:00
  • @FaheemMitha after adding that code, did you restart Emacs? I always give it for granted, but this is needed to make changes effective. – giordano Apr 27 '14 at 18:10
  • 1
    I haven't gone through the rest of the options, but the latex command style thing works fine. Thanks again. – Faheem Mitha Apr 28 '14 at 21:54
3

To summarize the answer by @giordano for use by an Elisp beginner, you should add this to the bottom of your TeX document:

% Local Variables:
% TeX-command-extra-options: "-shell-escape"
% End:

And you should add this to your init-file:

(with-eval-after-load 'tex
  (add-to-list 'safe-local-variable-values
               '(TeX-command-extra-options . "-shell-escape")))

To make the changes take effect without restarting Emacs, you should run M-: (load user-init-file) RET and then type M-x normal-mode in your TeX buffer.

Note that this change to your init-file means that compiling malicious TeX code using AUCTeX can run arbitrary shell commands, so be careful.

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.