Recently, in choose from a list with xstring, Geoff was asking about defining the command \variation
that does the following:
\variation{1}{aaa;bbb;ccc} ----> aaa
\variation{2}{aaa;bbb;ccc} ----> bbb
\variation{3}{aaa;bbb;ccc} ----> ccc
There are a number of nice answers on this question. However, I have found that all of them have the same disadvantage: when I am trying to use the result of \variation
in \ref
or \getrefnumber
from the package refcount, I get an error message.
To be more specific, consider the not-working example based on Heiko Oberdiek solution,
\documentclass{article}
\usepackage{xstring}
\newcommand*{\variation}[2]{%
\edef\variationNext{%
\noexpand\StrBetween[%
\the\numexpr(#1)\relax,%
\the\numexpr(#1)+1\relax
]%
}%
\variationNext{;#2;}{;}{;}\relax
}
\begin{document}
\begin{equation}
2+2=4 \label{aaa}
\end{equation}
\begin{equation}
3+3=6 \label{bbb}
\end{equation}
I can refer to these equations as equation~\ref{aaa} and
equation~\ref{bbb}.
Now I have the string ``aaa;bbb''. If I refer to these equations as
equation~\ref{\variation{1}{aaa;bbb}} and
equation~\ref{\variation{2}{aaa;bbb}}, I get an error message.
\end{document}
I have the same error message with all other proposed solutions. Is it possible to redefine the command \variation
in such a way to it works correctly with \ref
and with \getrefnumber
?