I am using a loop to define keys with the xkeyval package, as well as to actually read out the keys inside some self-defined command. Everything works perfectly - but for some reason, as soon as I include hyperref, everything breaks:
! Incomplete \ifnum; all text was ignored after line 47.
<inserted text>
\fi
Please consider the following MWE:
\documentclass{article}
\usepackage{xkeyval}
\usepackage{hyperref} % <-- comment this line to make it work
\makeatletter
\count@=0
\loop
\advance\count@ 1
\begingroup\edef\x{\endgroup
\noexpand\define@key{mycmd}{KEY\the\count@}[]{%
\noexpand\@namedef{mycmdKEY\the\count@}{####1}%
}% end of \define@key
}% end of \edef
\x % execute \x
\ifnum\count@<6
\repeat
\presetkeys{mycmd}{KEY1=0,KEY2=0,KEY3=0,KEY4=0,KEY5=0,KEY6=0,%
}{}
\newcount\mycount%
\newcounter{mycnt}
\newcommand*\mycmd[2][]{%
\setkeys{mycmd}{#1}{
\begin{enumerate}
\mycount=0%
\loop%
\advance\mycount 1%
\setcounter{mycnt}{\csname mycmdKEY\the\mycount\endcsname}%
\ifnum\value{mycnt}>0%
\item[item \the\mycount] text
\fi%
\ifnum\mycount<6\repeat%
\end{enumerate}
}%
}%
\makeatother
\begin{document}
\mycmd[
KEY1=200,
KEY2=200,
KEY3=500,
KEY4=1000,
]{}
\end{document}
Here are my observations:
- If I remove the dependency on
hyperref, it works. - If I remove the
enumerateenvironment and replace the call to\itemwith its argument, it also works. - If I remove the call to
setkeysand replace the string\csname mycmdKEY\the\mycount\endcsnamewith1, it also works.
All of this seems pretty weird to me. If anybody could tell me what I am doing wrong here and what I can do to fix it, that would be great!
PS: If you are wondering how I came up with this code in the first place: This question is a follow-up issue based on an earlier question of mine: Defining xkeyval keys within a loop