I want to redirect tex.print
output to a file to collect and reuse the produced LaTeX
material :
the mwe
:
\documentclass{article}
\begin{document}
essai
\directlua{require("essai.lua")}
\directlua{ a = "Hello word \\dots" }
\directlua{ to_file ( a ) }
\end{document}
and the lua script called essai.lua
:
function to_file ( x )
local file_name = "Foo"
out = io.open( file_name .. ".tex", 'w' )
tex.print = out:write
out:write ( "\\documentclass{article}" )
out:write ( "\\begin{document}")
tex.print ( x )
out:write ( "\\end{document}" )
io.close( out )
end
The error message is :
(/usr/local/texlive/2022/texmf-dist/tex/latex/base/ts1cmr.fd)...2/texmf-dist/te x/luatex/lualibs/lualibs-basic-merged.lua:391: error loading module essai.lua f rom file ./essai.lua: ./essai.lua:9: function arguments expected near 'out'
tex.print
. I have some complex document mostly produced using lua output, and I want to preserve the latex output to reuse it. It is why I want to save it to a file.