I have a macro \Content wich contains several occurence of a macro \comm. The latter increases a counter a displays the value of the counter. Calling \Content gives the correct output. But i want to write this \Content into a file, and i encounter a problem. I guess, this is because \write does not like \stepcounter. I would like to understand why, and to find a workaround.
\documentclass{article}
\begin{document}
\newcounter{myCounter}
\newcommand{\comm}{%
\stepcounter{myCounter}%
var\arabic{myCounter} %
}
\def\Content{text \comm text \comm text \comm}
\Content %%%% This works
\newwrite\tempfile
\immediate\openout\tempfile=counter.txt
\immediate\write\tempfile{\Content}
\immediate\closeout\tempfile
\end{document}
PS : by the way, the error message is Missing \endcsname inserted. which i don'T really understand...
EDIT1 I formulate more precisely my question : the macro \Content is given, and i dont' want to modify it. I just know that it contains many occurences of \comm. And i want to write the content of \COntent into a file, but replacing each \comm by something like var1, var2 which increases with some counter.
\Content( and therefore let the counter increase), and then write the result of this expansion into a file... On the other hand, i was always convinced of "with LaTeX, nothing is impossible" ... – Loic Rosnay Jun 11 '12 at 08:09\ContentYou have to evaluate the assignments which happens "in the stomach" in the terminology of the TeXBook. So you have to do the assignments first save the tokens of each of the three values, and then build the content from that. In other words, do what @egreg says. – David Carlisle Jun 11 '12 at 08:31\Contentis given to me in a tex file. I can only implement something in a documentclass and compile the tex-file with this class, but not modify\Contentper hand. :( – Loic Rosnay Jun 11 '12 at 08:45