My target is to have an output Solved Exam.pdf when \ifSolution is true, and The Exam.pdf when \ifSolution is false.
However, I don't know if this answer is relevant here to change the \jobname and thus all the output files since it only affects the name of the aux file.
P.S. I am using lualatex to compile.
\newif\ifSolution
\ifSolution
% https://tex.stackexchange.com/a/252346/2288
\edef\TeXjobname{\jobname}
\edef\jobname{\detokenize{Solved Exam}}% <<< the output file is not "Solved Exam.pdf"
\documentclass[answers]{exam}
\else
% https://tex.stackexchange.com/a/252346/2288
\edef\TeXjobname{\jobname}
\edef\jobname{\detokenize{Exam}}% <<< the output file is not "Exam.pdf"
\documentclass{exam}
\fi
\begin{document}
\begin{questions}
\question a question
\begin{solution}
the solution
\end{solution}
\end{questions}
\end{document}
\documentclass. – campa Dec 07 '20 at 15:19finish_pdffilecallback. Maybe you can rename the output with Lua callback. It could be as simple asos.rename(tex.jobname..".pdf", "new_name.pdf"). – Alan Xiang Dec 07 '20 at 15:59\jobnameis possible, or try to wraplualatexcall around with other tools. One way I can think of is that you can write the value of\ifSolutionto an external file and have another program inspect it and rename (copy) the output of LuaTeX. – Alan Xiang Dec 07 '20 at 16:38CMDfile by texstudio that hastexfot lualatex -jobname="[Exam] <file name>" -synctex=1 -interaction=nonstopmode "\AtBeginDocument{\printanswersfalse}\input{<file name>}". However, I am not sure about if possible by the document itself without external help. – Diaa Dec 07 '20 at 16:49