I have a project for which I make extensive use of the great xkeyval package. However, I'm still struggling with some more extravagant things. For example, I want to use enumerated keys (key1 to keyN, where N is some arbitrary integer).
To avoid copy&paste work, I have come up with the idea of using a loop to make all the calls to \define@key - however, this doesn't quite work as I would have expected it to do.
Please consider the following MWE. You will observe that the document contains the string "test", but not the following string "something", which I would have expected to appear. Whether this works or not seems to depend on the exact definition of the \index command.
\documentclass{article}
\usepackage{xkeyval}
\makeatletter
\count@=0
\loop
\advance\count@ 1
%\edef\index{1}% <-- uncomment this line
\edef\index{\@arabic\count@}% <-- and comment this one to make it work
\expandafter\def\csname KV@family@key\index\endcsname ##1{\expandafter\def\csname familykey\index\endcsname{##1}}
%\define@key{family}{key\index}{\expandafter\def \csname familykey\index\endcsname{#1}}% <- using this line instead of the above doesn't make a difference
\ifnum\count@<6
\repeat
\makeatother
\begin{document}
test
\setkeys{family}{key1=something}{
\csname familykey1\endcsname
}
\end{document}
The fact that exchanging the line with the definition of \index makes a difference leads me to the conclusion that something's wrong with the argument expansion, but I can't seem to figure out how to make it work.
Any suggestions?