I have a macro that contains a loop using \@for and it works until I try to write its output to a file. The following document shows the problem.
\documentclass{article}
\makeatletter
\newwrite\my@out
\AtBeginDocument{\immediate\openout\my@out my.tmp}
\AtEndDocument{\immediate\closeout\my@out}
\def\plist#1{%
\@for\tmpkey:=#1\do{blah }
}
\def\mymacro{%
\plist{a,b,c}% this works, appears in document.
\immediate\write\my@out{hello}% make sure our file is okay
\immediate\write\my@out\plist{a,b,c}% does not work!
}
\makeatother
\begin{document}
\mymacro
\end{document}
When I comment out the last line of \mymacro, the code works and the words `blah blah blah' appear in the pdf. So the logic is not too far off.
However, I must be running into an expansion timing problem when I write to the external file. I get the error message:
! Missing number, treated as zero.
<to be read again>
\def
l.21 \mymacro
I can use another package if I have to. I'm using the LaTeX2e standard \@for in an effort to minimize the number of dependencies the package will have.
I've tried a lot of permutations using \expandafters and \edef, but my understanding just doesn't go far enough.
