I'm using toggle switches to create different outputs with a single tex-file. However my output PDF is always named after the producing tex-file e.g. luaexample.tex
produces luaexample.pdf
.
Along with the toggles I now want to create a variable
\def\fileID{Z}
which should be appended to the filename, to get e.g. luaexampleZ.pdf
.
I thought using lua would be a create option to do so, and indeed the following almost works:
\documentclass{article}
\usepackage{luacode}
\def\fileID{Z}
\begin{document}
A random number:
\begin{luacode}
tex.print(math.random())
\end{luacode}
\begin{luacode}
os.remove("\jobname\fileID.pdf")
os.rename("\jobname.pdf", "\jobname\fileID.pdf")
\end{luacode}
\end{document}
But the PDF due to rename is created after \end{document}
but the lua code section appears before. If I compile the document twice, it works, but the firstly compiled PDF is renamed. I'd like to avoid this double compilation.
If I put the lua code after \end{document}
it is not executed.
So, how can I execute lua code or in general latex code after \end{document}
?
\renewcommand
? That does not produce an output, just an aux file. But I think it would kind of crash quite a lot depending on the job name, wouldn't it? I just want to rename the final pdf, not all intermediate files. And I wouldn't know how to append a string to the\jobname