My objective is to automatically compile parameterized template from within a main input file. For each compilation, a unique jobname and parameter are passed to the compiler. The problem is, passing parameter requires me to manage both expansion and unexpansion in the proper order.
Consider the important part of MWE,
\immediate\write18{pdflatex -jobname=\outputfilename\space "\def\name{\target} \input{template}"}
The \target
must be expanded while \def\name
must be unexpanded.
\documentclass[preview,border=12pt]{standalone}
\usepackage{filecontents}
\begin{filecontents*}{template.tex}
\documentclass[preview,border=12pt]{standalone}
\begin{document}
Hello \name
\end{document}
\end{filecontents*}
\usepackage{pgffor,graphicx}
\foreach \outputfilename/\target in {a/Andy,b/Bill,c/Charlie}{\immediate\write18{pdflatex -jobname=\outputfilename\space "\def\name{\target} \input{template}"}}
\begin{document}
The files we created automatically are:
\foreach \outputfilename in {a,b,c}{\fbox{\includegraphics[scale=2]{\outputfilename}}\endgraf}
\end{document}
I have not learnt the token expansion so this case seems very disturbing in my daily usage of TeX. How to manage these expansions?