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.

  • 1
    See my answer for possible gotcha's in setting `tex-start-options`, but that *should* work. – NickD Feb 22 '22 at 23:19

3 Answers3

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

NickD
  • 27,023
  • 3
  • 23
  • 42
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.

NickD
  • 27,023
  • 3
  • 23
  • 42
gigiair
  • 2,124
  • 1
  • 8
  • 14
  • 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? –  May 28 '21 at 14:55
  • Mode should be LaTeX, it is default using AUCTeX. Are you using AUCTeX ? – gigiair May 28 '21 at 15:31
  • No, sorry I am not using AUCTeX - just ordinary tex-mode and company. –  May 28 '21 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 – gigiair May 28 '21 at 15:44
  • I got aware of the misunderstanding as soon I hit the add-comment button. I've edited the original comment. –  May 28 '21 at 15:46
  • Sorry, I cant help, I do not use ordinary tex-mode. – gigiair May 28 '21 at 15:48
  • I've installed AUCTeX. Compilation works just fine now. Thanks for your effort. –  May 28 '21 at 15:58
  • If this solution works for you, you could check it. It might help others. – gigiair Jun 28 '21 at 14:42
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.

gigiair
  • 2,124
  • 1
  • 8
  • 14