I've got an example like that:
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\ab}{a}
\newcommand{\aORb}[1]{%
\ifstrequal{#1}{a}{"a" was given}{not a}, %
\ifstrequal{#1}{b}{"b" was given}{not b}%
}
\begin{document}
begin
\aORb{\ab{}}
end
\end{document}
And the output of that code is:
begin
not a, not b
end
However, if I put simply "a" or "b" as an argument to \aORb
instead of \ab{}
then it works fine.
Is there another command in etoolbox
package that will allow me to do such a comparison correctly?
Best Answer
The
etoolbox
manual states for\ifstrequal
on page 17: (emphasis mine)So you always compare the string “\ab{}” with “a” and “b”. If you want to allow macros as input you need to expand them manual:
This expands the first token of
#1
once before\ifstrequal
is processed.If you want to expand the input completely use:
This expands the input completely using
\edef
and wraps it in braces, so only one\expandafter
is enough.Then you need to use
\aORb{\ab}
not\aORb{\ab{}}
, because\ab
doesn't take an argument the{}
would stay and you would compare here “a{}” with “a” and “b”.