ho-tex/oberdiek

lua-implementation of pdf@shellescape should be reconsidered.

Closed this issue · 2 comments

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}

the new pdf@shellescape is in the last ctan release, thanks for the comment.