Is there a way to add an index to a command? For example:
\newcounter{count}
\loop<condition>
\def\var\Roman{count}{some data}
\repeat
The \var\Roman{count}
should become the variable \varI
, \varII
, \varIII
and so on.
Background: I need to get some data from external files and store it into variables (which I will later use to create a document). Normally every \varI
should be the same as every \varII
, but I need to check whether it really is the case or not. If not I should return a warning or error.
Solution for the first problem is in the comments, but I have a second problem.
Suppose I wrote this:
\newcommand\addindex[3]{ % #1 as name of var, #2 as index and #3 as content
\expandafter\def\csname #1\Roman{#2}\endcsname{#3} % thanks to egreg
}
\newcounter{count}
\loop\unless\ifnum\value{count}=5
\stepcounter{count}
\addindex{var}{count}{\arabic{count}}
\repeat
All \var<index>
have now as value 5, because they are defined as \arabic{count}
, and not their value at the moment. Adding \expandafter
before \arabic{count}
does not seem to work for some reason...
\@namedef{var\romannumeral\c@count}{some data}
– David Carlisle Jul 20 '12 at 11:59\expandafter\def\csname var\Roman{count}\endcsname{...}
– egreg Jul 20 '12 at 12:50:p
@DavidCarlisle: thanks, but in that way I have to use TeX counters instead of LaTeX counters. I prefer the LaTeX way:)
– Didii Jul 20 '12 at 13:12\csname
environment again:)
– Didii Jul 20 '12 at 13:23