1

Background story:

I have to compile my LaTeX document with the -shell-escape command line option because the pgfplots library I am using calls gnuplot. This was necessary to get a plot of a recursive function requiring double precision fpu.

Problem:

When I hit C-c C-C or C-c C-f in emacs (GNU Emacs 26.3) the document is compiled using pdflatex \\nonstopmode\\input mydoc.tex but the plot in the PDF output document stays empty, because of some restrictions. When I compile manually using pdflatex -shell-escape \\nonstopmode\\input mydoc.tex everything works just fine.

Failed attempts:

I have set tex-start-options variable in the 'tex run group' to "-shell-escape", but it did not appear in the tex-shell.

Update:

Meanwhile I have installed AUCTeX as suggested. I am still curious to find out how the issue can be solved without it.

2
  • 1
    See my answer for possible gotcha's in setting tex-start-options, but that should work. Commented Feb 22, 2022 at 23:19
  • By any chance have you set latex-run-command? I think I've found a bug. Commented Nov 9, 2023 at 22:50

3 Answers 3

2

For the built-in TeX mode (i.e. not AucTeX), you can customize the variable tex-start-options: do C-h v tex-start-options and hit the Customize link. Enter --shell-escape as the value string, hit Apply or Apply and Save and try C-c C-c in your TeX file again.

EDIT: I see you said you tried this. I did too and it works fine. Maybe you didn't apply the customization? BTW, you can only tell by looking at the command at the top of the resulting *tex-shell* buffer: the prompt still says pdflatex (or whatever).

5
  • Shouldn't it be -shell-escape? Commented Sep 7, 2022 at 22:24
  • The AucTeX equivalent is TeX-command-extra-options. Commented Sep 7, 2022 at 23:04
  • @young_souvlaki: both versions work AFAIK with every processor (pdflatex, xelatex, lualatex). The usual convention is a double dash for long options and a single dash for short options, so I try to encourage the universal adoption of that convention :-) Commented Jun 8, 2023 at 20:30
  • Yea I like that thinking, -shell-escape does look odd. Commented Jun 19, 2023 at 21:14
  • I haven't had any luck with tex-start-options in latex-mode. It seems to ignore the setting. Commented Nov 7, 2023 at 6:16
0

My favourite solution :

I have composed this small function in my init file that I find convenient.

 (defun TeX-command-toggle-shell-escape () "toggles the option --shell-escape from the tex command" (interactive) (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)) 

You can bind it to "C-c C-t C-x" (for instance).' Using the package bind-key syntax :

 (bind-key "C-c C-t C-X" #'TeX-command-toggle-shell-escape LaTeX-mode-map) 

So, the key sequence "C-c C-t C-x" activates or deactivates the shell-escape option.

Other solution :

You can add a local variable to your source file

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

But the file has to be reloaded to activate the variable - or you can do M-x normal-mode instead.

8
  • Thanks for your instant reply. I've copied your local variable solution to the end of my document adding % mode: tex. When I reloaded it, there was a warning about possibly dangerous options and I had to confirm, what I did. But still -shell-escape is not added to to the command appearing in the tex-shell buffer. I can't find TeX-command-extra-options in the variable documentation. Could it be that it does not exist an my system? Commented May 28, 2021 at 14:55
  • Mode should be LaTeX, it is default using AUCTeX. Are you using AUCTeX ? Commented May 28, 2021 at 15:31
  • No, sorry I am not using AUCTeX - just ordinary tex-mode and company. Commented May 28, 2021 at 15:42
  • Thats not incompatible. AUCTeX is for Emacs, pdftex is for TeXLive. To install AUCTeX on Emacs : M-x package-install RET auctex RET. Or check C-h v AUCTeX-version if installed Commented May 28, 2021 at 15:44
  • I got aware of the misunderstanding as soon I hit the add-comment button. I've edited the original comment. Commented May 28, 2021 at 15:46
0

|I use this minor mode:

(define-minor-mode tex-command-shell-escape-mode "Enable compilation with -shell-escape" :init 1 :lighter " -shell-escape" (setq TeX-command-extra-options (if (string-empty-p TeX-command-extra-options) "-shell-escape" ""))) 

You can bind it to C-c C-t C-x for instance to toggle the shell-escape mode.

(bind-key "C-c C-t C-X" #'tex-command-shell-escape-mode LaTeX-mode-map) 

This probably shouldn't work properly if you're using TeX-command-extra-option for some other purpose elsewhere. It's not my case.