I've written a LuaLaTeX document that, when compiled, automatically generates a list of questions with answers for an upper-secondary class in quadratic equations. The details are messy, but the main relevant fact is that these are generated randomly: every time I compile, I get a new random pdf.
Now I want to compile one of these pdfs for every student, but pressing the compile button in TeXStudio 20 times then manually numbering the files main1.pdf,main2.pdf etc. gets pretty tedious. Is there any way I can automate this process?
For the sake of having a MWE, you can imagine something like
%!TeX program = lualatex
\documentclass{article}
\usepackage{random}
\newcounter{\somenumber}
\begin{document}
\setrannum{\somenumber}{1}{2}
The number is \somenumber.
\end{document}
Ideally a solution would be self-contained in the TeX file, but if it's not possible I'm open to alternatives (e.g. a bash script?).
lualatexdoes understand option-jobnamethat can be used to change the basename of all output files, e.g.,for n in {1..20};do lualatex -jobname student$n main.tex; donewould createstudent1.pdf,student2.pdf…student20.pdffrommain.tex.latexmkalso supports-jobname. So if you need several LaTeX runs + MakeIndex + Biblatex + …, you can also uselatexmkinside the loop. – cabohah Jan 24 '24 at 06:55