I need to write to a file the unexpanded LaTeX. The macro \OuputToFile is bascially an \immediate\write18 and works fine with the following:
\OuputToFile{\detokenize{$\OuterMacro{\cXXX{X}}$}}%
\OuputToFile{\detokenize{$\OuterMacro{\dXXX{X}}$}}%
where the inner macros begin with c and d. BUT, has problems if they being with e or f. That is, the following does not yield the desired results:
\OuputToFile{\detokenize{$\OuterMacro{\eXXX{X}}$}}%
\OuputToFile{\detokenize{$\OuterMacro{\fXXX{X}}$}}%
Why is this, but more importantly how do I remedy this situation?
The output of the MWE below is
but the desired result is
Code:
\documentclass{article}
\usepackage{xparse}
\immediate\write18{printf "\n" > foo.tex }% Initialize File
\NewDocumentCommand{\OuputToFile}{%
m% string to output
}{%
\immediate\write18{printf 'string = "#1"' >> foo.tex }%
\immediate\write18{printf "\n" >> foo.tex }%
}
\def\MyString{$\OuterMacro{\InnerMacro{X}}$}
\begin{document}
Output to file:
\OuputToFile{\detokenize{$\OuterMacro{\cXXX{X}}$}}%
\OuputToFile{\detokenize{$\OuterMacro{\dXXX{X}}$}}%
\OuputToFile{\detokenize{$\OuterMacro{\eXXX{X}}$}}%
\OuputToFile{\detokenize{$\OuterMacro{\fXXX{X}}$}}%
\OuputToFile{\detokenize{$\OuterMacro{\gXXX{X}}$}}%
\end{document}


printf "\cXXX"on the commandline and compare withprintf "\eXXX"why use printf rather than just writing the file directly? – David Carlisle Nov 30 '21 at 00:31printf "%s" "\eXXX"etc which prints\eXXXor use echo instead of printf – David Carlisle Nov 30 '21 at 00:36\OuputToFileinstruction generates a write to the log file of the formrunsystem(printf 'string = "$\OuterMacro {\cXXX {X}}$"' >> foo.tex )...disabled (restricted).Do I need to enable something? – Mico Nov 30 '21 at 00:40-shell-escape. – Peter Grill Nov 30 '21 at 00:51