Why can't I compile the following even though I have enabled -shell-escape?
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{inputfile.tex}
%\def\paramA{standalone}
\def\paramB{Hello World}
\documentclass{\paramA}
\begin{document}
\paramB
\end{document}
\end{filecontents*}
\begin{document}
\immediate\write18{pdflatex "\def\paramA{standalone}\input{inputfile}"}
\immediate\write18{inputfile.pdf}
done!
\end{document}
Log File
This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/W32TeX)
\write18 enabled.
<< the unnecessary texts are intentionally removed by me for the sake of simplicity >>
No file executor.aux.
! Undefined control sequence.
<write> pdflatex "\def \paramA
{standalone}\input {inputfile}"
l.13 ...\def\paramA{standalone}\input{inputfile}"}
?
\paramAis not defined.\write18tries to expand it before sending it to the shell (which it shouldn’t in this example). It needs therefore to be protected by\noexpandor\stringor\unexpanded:\immediate\write18{pdflatex "\def\noexpand\paramA{standalone}\noexpand\input{inputfile}"}or\immediate\write18{\unexpanded{pdflatex "\def\paramA{standalone}\input{inputfile}"}}– Qrrbrbirlbel Feb 13 '13 at 01:50\immediate\write18{pdflatex "\def\string\paramA{standalone}\string\input{inputfile}"}or\immediate\write18{\detokenize{pdflatex "\def\paramA{standalone}\input{inputfile}"}}. The error is caused by the expansion of\immediate\write. – Heiko Oberdiek Feb 13 '13 at 01:56