# Does --no-shell-escape break \pdf@shellescape?

Edit: since posting the question I've fixed a few mistakes. I don't think they affect the answer given below, but I wanted to correct the record for completeness.

# Background

I have a Python script which calls lualatex to generate lots of short standalone documents. Being paranoid and trying to learn good habits, I use subprocess.check_call() and --no-shell-escape to make sure my call to lualatex doesn't do anything out of the ordinary. The script runs fine at work, but at home lualatex encounters an error and returns a nonzero return code. This error doesn't occur if I omit --no-shell-escape from the options list.

It would be nice to understand why this is the case! Can any TeX.SE residents shed some light?

# MWE

Here's a test snippet written by egreg in this answer.

%From https://tex.stackexchange.com/a/96718/82389
\documentclass{article}
\usepackage{pdftexcmds}
\makeatletter
\count@=\pdf@shellescape
\showthe\count@
\makeatother

\begin{document}
Ciao
\end{document}


If I save the above as test.tex and run lualatex --no-shell-escape test at work, it reports

work $lualatex --no-shell-escape test.tex This is LuaTeX, Version beta-0.76.0-2013121407 (rev 4627) [...output trimmed...] > 0. l.6 \showthe\count@  If I run the same command at home, however, the following happens. home$ lualatex --no-shell-escape test.tex
This is LuaTeX, Version 0.95.0 (TeX Live 2016)
[...output trimmed...]
! Missing number, treated as zero.
<to be read again>
\relax
l.5 \count@=\pdf@shellescape

?
> 0.
l.6 \showthe\count@


In particular, I get an error where there was none before.

I'm not sure what's going on, and would be interested to find out more.

# Other information

## Version numbers

At work:

• LuaTeX, Version beta-0.76.0-2013121407 (TeX Live 2013/dev/Debian) (rev 4627)
• pdftexcmds Version: 2011/11/29 v0.20
work $luatex --version | head -n 1 This is LuaTeX, Version beta-0.76.0-2013121407 (TeX Live 2013/dev/Debian) (rev 4627) work$ locate pdftexcmds.sty
/usr/share/texlive/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
work $kpsewhich pdftexcmds.sty /usr/share/texlive/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty work$ grep 'Version:' < kpsewhich pdftexcmds.sty
%% Version: 2011/11/29 v0.20


At home:

• LuaTeX, Version 0.95.0 (TeX Live 2016)
• pdftexcmds Version: 2017/03/19 v0.25.
• NB. In the original post, I mistakenly thought that the version was v0.20 at home as well. This is incorrect. It seems I have more than one installation of texlive, and thankfully luatex is using the more recent version of the style file.
home $luatex --version | head -n 1 This is LuaTeX, Version 0.95.0 (TeX Live 2016) home$ locate pdftexcmds.sty
/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
/usr/share/texlive/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
home $kpsewhich pdftexcmds.sty /usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty home$ grep 'Version:' < \$(kpsewhich pdftexcmds.sty)
%% Version: 2017/03/19 v0.25


## The definition of \pdf@shellescape

At work (pdftexcmds v0.20) the definition of \pdf@shellescape is

\ifnum\luatexversion<68 %
\else
\def\pdf@shellescape{%
\directlua0{%
oberdiek.pdftexcmds.shellescape()%
}%
}%
\fi


At home (pdftexcmds v0.25) of pdftexcmds, it's defined as

\ifnum\luatexversion<68 %
\else
\protected\edef\pdf@shellescape{%
\numexpr\directlua{tex.sprint(status.shell_escape)}\relax}
\fi


At the time of writing, the latter definition is also present in the current version of pdftexcmds. The implementation seems to be discussed in this GitHub issue.

## Misc

If I run lualatex --shell-escape test.tex, \count@ is printed as 1. If I run lualatex test.tex, \count@ is printed as 2. In both scenarios I don't get any TeX errors. The two commands behave the same at both work and home.

• The lualatex versions are quite different. You can only compare the same package and engine versions. Aug 27 '18 at 14:46
• I'm not sure I follow. The package versions are already the same. If the engine versions were the same, wouldn't I expect identical results on both machines? Aug 27 '18 at 15:29
• both of those luatex versions are very old beta versions, there have been multiple changes in luatex (which is already at 1.07 in texlive and 1.09 in development releases) (although that may not affect this issue) Aug 27 '18 at 18:54
• @daleif I've just noticed I was wrong about the home version of pdftexcmds and have corrected the original post. So my previous comment was incorrect: both the luatex and package versions are different. Aug 28 '18 at 20:27

## 1 Answer

Apparently it does...

I think this is a bug in the newer version of pdftexcmds that wasn't in the older version (either way, you should update your distribution :).

pdftexcmds defines \pdf@shellescape with:

\ifnum\luatexversion<68 %
\else
\protected\edef\pdf@shellescape{%
\numexpr\directlua{tex.sprint(status.shell_escape)}\relax}
\fi


which will make something like \numexpr 0\relax.

But if, after you load pdftexcmds, you say \show\pdf@shellescape, you'll see (running with the --no-shell-escape flag):

> \pdf@shellescape=\protected macro:
->\numexpr \relax .


which raises the ! Missing number, treated as zero. error.

This happens because earlier in the code, pdftexcmds has:

\ifnum\luatexversion<36 %
\else
\catcode\0=9 %
\fi


which makes 0 be an ignored character. With this catcode regime, the 0 returned disappears, and invalidates the \pdf@shellescape macro.

The older version of pdftexcmds didn't have this issue because \pdf@shellescape wasn't created with \edef, but with \def, so when the macro was used, the \catcode of 0 was correct:

\ifnum\luatexversion<68 %
\else
\def\pdf@shellescape{%
\directlua0{%
oberdiek.pdftexcmds.shellescape()%
}%
}%
\fi


To fix this you can simply re-define the \pdf@shellescape in the same way after pdftexcmds is loaded, except that now 0 won't be ignored:

\documentclass{article}
\usepackage{pdftexcmds}
\makeatletter
\ifnum\luatexversion<68 %
\else
\protected\edef\pdf@shellescape{%
\numexpr\directlua{tex.sprint(status.shell_escape)}\relax}
\fi
\count@=\pdf@shellescape
\showthe\count@
\makeatother

\begin{document}
Ciao
\end{document}

• thanks for the analysis, I'm travelling so can't look at this straight away, but if you could drop an issue at github.com/ho-tex/oberdiek/issues I'd be grateful! Aug 27 '18 at 18:57
• @DavidCarlisle Done. You're welcome :) Aug 27 '18 at 19:35
• @Phelype Oleinik @DavidCarlisle I just wanted to point out that I was mistaken about the version of pdftexcmds` I was using at home. I've updated the original post; I don't think this affects what Phelype wrote at all, but I wanted to mention it for completeness. Aug 28 '18 at 20:28
• @DavidR No problem :) I thought so, because I could reproduce the issue (with both the working older version and the newer one, with this feature) here, and the error message you showed was pointing towards that conclusion, I wrote my answer based on that :) Aug 28 '18 at 23:15