• [LaTeX] How to tell the user that the document wasn't compiled with -sh

    From Annada Behera@21:1/5 to All on Thu Aug 22 18:05:25 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ulrich D i e z@21:1/5 to Annada Behera on Thu Aug 22 17:24:21 2024
    Annada Behera schrieb:

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Annada Behera on Thu Aug 22 20:02:40 2024
    Annada Behera <segfault@tilde.green> wrote or quoted:
    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)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ulrich D i e z@21:1/5 to Stefan Ram on Fri Aug 23 02:35:25 2024
    Stefan Ram wrote:

    Annada Behera <segfault@tilde.green> wrote or quoted:
    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

    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

    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

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Annada Behera@21:1/5 to Stefan Ram on Fri Aug 23 11:15:33 2024
    On Thu, 2024-08-22 at 20:02 +0000, Stefan Ram wrote:
      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.


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)