Discussion:
[LaTeX] How to tell the user that the document wasn't compiled with -shell-escape flag?
(too old to reply)
Annada Behera
2024-08-22 12:35:25 UTC
Permalink
Hi,

I am writing a LaTeX package and it invokes external Python code to do
some heavy preprocessing. I have not learned TeX programming language
enough yet to do everything in TeX. So, when the user of my package
doesn't invoke pdflatex with the -shell-escape flag, I would like print
a helpful error message telling them so.

Anybody has any idea how that can be done. Thank you.

Annada
Ulrich D i e z
2024-08-22 15:24:21 UTC
Permalink
Post by Annada Behera
Hi,
I am writing a LaTeX package and it invokes external Python code to do
some heavy preprocessing. I have not learned TeX programming language
enough yet to do everything in TeX. So, when the user of my package
doesn't invoke pdflatex with the -shell-escape flag, I would like print
a helpful error message telling them so.
Anybody has any idea how that can be done. Thank you.
Annada
I recommend using the package shellesc (https://ctan.org/pkg/shellesc)
as it provides a unified shell escape interface which works out both
with traditional TeX engines where \write18 is available and with TeX
engines based on LuaTeX which don't have \write18 and instead provide
the function os.execute .

With that package you can query the \write18-status via \ShellEscapeStatus.

The package manual plus implementation, where you can learn how
\ShellEscapeStatus is defined, is at
http://mirrors.ctan.org/macros/latex/required/tools/shellesc.pdf .

Sincerely

Ulrich
Stefan Ram
2024-08-22 20:02:40 UTC
Permalink
Post by Annada Behera
Anybody has any idea how that can be done. Thank you.
Lately, the newer versions of "shellesc" (like since 2020?)
are said to define "ShellEscapeStatus." So, you could totally
do something like this:

\usepackage{shellesc}

\ifnum\ShellEscapeStatus=1 \else
\PackageError{mypackage}{use shell escape}{or else}
\fi

But since I'm rocking an older version, I can't check this out
myself!

|The shell escape status may be queried by checking the
|integer (chardef) command \ShellEscapeStatus, 0 (disabled) 1
|(enabled) 2 (restricted).
probably from the docs (2023)
Ulrich D i e z
2024-08-23 00:35:25 UTC
Permalink
Post by Stefan Ram
Post by Annada Behera
Anybody has any idea how that can be done. Thank you.
Lately, the newer versions of "shellesc" (like since 2020?)
shellesc.dtx says the command \ShellEscapeStatus is a TeX <number>
quantity of the kind \chardef-token and was introduced in
version v1.0a of the shellesc package, released 2019/10/13 .

\ShellEscapeStatus is defined by the following lines:

\chardef\ShellEscapeStatus
\ifx\pdfshellescape\@undefined
\ifx\shellescape\@undefined
\ifx\directlua\@undefined
\z@
\else
\directlua{%
tex.sprint((status.shell_escape or os.execute()) .. " ")}
\fi
\else
\shellescape
\fi
\else
\pdfshellescape
\fi

You also find an example for querying which does with \ifcase:

\ifcase\ShellEscapeStatus
\PackageWarning{shellesc}{Shell escape disabled}
\or
\PackageInfo {shellesc}{Unrestricted shell escape enabled}
\else
\PackageInfo {shellesc}{Restricted shell escape enabled}
\fi
Post by Stefan Ram
are said to define "ShellEscapeStatus." So, you could totally
\usepackage{shellesc}
\ifnum\ShellEscapeStatus=1 \else
\PackageError{mypackage}{use shell escape}{or else}
\fi
If you neither want to load the package nor want to define the
chardef-token you can do s.th. like

\makeatletter
\ifcase
\ifx\pdfshellescape\@undefined
\ifx\shellescape\@undefined
\ifx\directlua\@undefined
\z@
\else
\directlua{%
tex.sprint((status.shell_escape or os.execute()) .. " ")}
\fi
\else
\shellescape
\fi
\else
\pdfshellescape
\fi
\PackageWarning{shellesc}{Shell escape disabled}
\or
\PackageInfo {shellesc}{Unrestricted shell escape enabled}
\else
\PackageInfo {shellesc}{Restricted shell escape enabled}
\fi
\makeatother
Post by Stefan Ram
But since I'm rocking an older version, I can't check this out
myself!
For checking out you can
- look at the documentation of most recent releases of packages at CTAN.
- test with a rathher recent TeX Live release via Overleaf -
https://de.overleaf.com/
- try the test page (https://texlive.net/run) of the
The TeXLive.net Server, https://texlive.net/ .

Ulrich
Annada Behera
2024-08-23 05:45:33 UTC
Permalink
  But since I'm rocking an older version, I can't check this out
  myself!
I wonder how many people are still using the older version of texlive. I
don't know why texlive can't have rolling or LTS version. Need to
downloading a 5 GiB iso file and install it every year. Gets old very
fast.

Loading...