I try to expand a string using a counter. I will use a very simple example:
\def\st{}
\setcounter{i}{1}
\expandafter\def\expandafter\st\expandafter{\st{ } \the\numexpr\value{i}}
\addtocounter{i}{1}
\texttt{\st}
One would expect the result to be '1'. Yet, the result is '2' because the counter increased after the expansion. So, I undestand that 'st' is always "interpreted" using the final value of 'i'. So, in an iteration of the counter 'i' one would get n n n n ... (where 'n' is the final value of 'i'). But I would like to get 1 2 ... n. How can this be done?
(I spent a lot of time trying to achieve this reault, alas, in vain!)
\edef
rather than\def
. But just use etoolbox macros. This would be done\def\st{} \setcounter{tmpi}{1} \eappto\st{\the\numexpr\value{tmpi}} \addtocounter{tmpi}{1} \texttt{\st}
.