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\csnameenvironment again:)– Didii Jul 20 '12 at 13:23\c@countis the latex counter defined as in your question with\newcounter{count}just accessed differently. It's the same as\roman{count}except that it saves an expansion and 7 tokens (which probably mattered more in 1990 than it does now:-) – David Carlisle Jul 20 '12 at 13:25:)I do have a problem now with the\def, for some reason I can't expand what I write assome data. I'll edit the question. – Didii Jul 20 '12 at 13:32\edefinstead of\defafter\expandafter. – egreg Jul 20 '12 at 13:49:)– Didii Jul 20 '12 at 13:51