lua-implementation of pdf@shellescape should be reconsidered.
Closed this issue · 2 comments
u-fischer commented
Starting from a question on tex.sx
https://tex.stackexchange.com/questions/354830/lualatex-compilation-fails-when-sorting-text-using-luacode
the following minimal example was created. It fails with the error
)...xlive/2016/texmf-dist/tex/luatex/lualibs/lualibs-lua.lua:195: standard outpu
t file is closed
The error is caused by the faulty definition of sort_tdo
which doesn't restore correctly the output handler but also leads to the question if the lua implementation of \pdf@shellescape
in oberdiek.pdftexcmds.lua
should be reconsidered to use a less fragile method.
\documentclass{article}
\directlua{
function sort_tdo (jobname)
file=io.open(jobname.."sorted", "w")
% zz=io.output() %store output
io.output(file)
io.close(file)
% io.output(zz) %restore output
end
}
\directlua{
function shellescape()
if os.execute then
tex.write(os.execute())
end
end}
\directlua{sort_tdo("\jobname.tdo")}
\makeatletter
%\def\pdf@shellescape{\directlua{tex.sprint(status.shell_escape .. " ")}} %works
\def\pdf@shellescape{\directlua{shellescape()}}% breaks
\ifnum\pdf@shellescape>0 %
\show\x
\fi
\begin{document}
\end{document}
davidcarlisle commented
On 21 February 2017 at 10:25, u-fischer ***@***.***> wrote:
Starting from a question on tex.sx
https://tex.stackexchange.com/questions/354830/lualatex-
compilation-fails-when-sorting-text-using-luacode
the following minimal example was created. It fails with the error
)...xlive/2016/texmf-dist/tex/luatex/lualibs/lualibs-lua.lua:195: standard outpu
t file is closed
The error is caused by the faulty definition of sort_tdo which doesn't
restore correctly the output handler but also leads to the question if the
lua implementation of ***@***.*** in oberdiek.pdftexcmds.lua should
be reconsidered to use a less fragile method.
\documentclass{article}
\directlua{
function sort_tdo (jobname)
file=io.open(jobname.."sorted", "w")
% zz=io.output() %store output
io.output(file)
io.close(file)
% io.output(zz) %restore output
end
}
\directlua{
function shellescape()
if os.execute then
tex.write(os.execute())
end
end}
\directlua{sort_tdo("\jobname.tdo")}
\makeatletter
***@***.***{\directlua{tex.sprint(status.shell_escape .. " ")}} %works
***@***.***{\directlua{shellescape()}}% breaks
***@***.***>0 %
\show\x
\fi
\begin{document}
\end{document}
Thanks yes. Also I suspect it could be better as
\protected\edef\pdf@shellescape{\directlua{tex.sprint(status.shell_escape
.. " ")}}
so you only do it once, at a point known to be safe. this is read only
so can't change during
a run anyway
or perhaps
\protected\edef\pdf@shellescape{\numexpr\directlua{tex.sprint(status.shell_escape)}\relax}
To avoid the slightly risky space and so \the\pdf@shellescape works
davidcarlisle commented
the new pdf@shellescape is in the last ctan release, thanks for the comment.