Please consider the following, non-working, example:
\documentclass{standalone}
\makeatletter
\parindent\z@
\@namedef{blafasel}{foo}
\def\foo{foo}
\def\bar{bar}
\makeatother
\begin{document}
1:
\expandafter\ifx\@nameuse{blafasel}\foo
\message{true}
\else
\message{false}
\fi
2:
\expandafter\ifx\@nameuse{blafasel}\bar
\message{true}
\else
\message{false}
\fi
\end{document}
How must I alter this code so that the output is "correct" (1: true\n2: false
)? So far, I tried up to 9 \expandafter
before \ifx
, but none gave me the desired output. Why is that?
EDIT
Okay, my mistake was that @ wasn't a letter anymore... Using three \expandafters
did the trick. Nonetheless i'd like to know what happens here. How does LaTeX expand @namedef and @nameuse resp.? Extending the example by the following code also gives weired results:
3:
\expandafter\ifx\csname blafasel\endcsname\bar
true
\else
false
\fi
4:
\expandafter\ifx\csname blafasel\endcsname\bar
true
\else
false
\fi
etoolbox
's\ifcsequal{<csname one>}{<csname two>}{<true>}{<false>}
\(end)csname
gave me twice "false" for some reason...\foo
in 3, then you'll gettrue
. You're gettingfalse
twice because you're doing the same test.