Just when I think I starting to understand \expandafter
I run into this problem where I am trying to test if \ConditionG
, \ConditionH
, etc are defined in a loop. I tried all the combinations I could think of and am not able to get this to work:
\documentclass{article}
\usepackage{pgffor}
\usepackage{etoolbox}
\begin{document}
%\def\ConditionG{}% This should show up as undefined
\def\ConditionH{}
\foreach \i in {G, H}{
\expandafter\ifdefined\csname Condition\i\endcsname% Incorrect Results: everything defined
\textbackslash Condition\i\ is defined\par
\else
\textbackslash Condition\i\ is not defined\par
\fi
}
\hrule
\foreach \i in {G, H}{% Using etoolbox
\ifdef{\expandafter\csname Condition\i\endcsname}{% Incorrect Results: everything defined
\textbackslash Condition\i\ is defined\par
}{
\textbackslash Condition\i\ is not defined\par
}
}
\end{document}
Joseph's detailed explanation regarding When to use \edef, \noexpand, and \expandafter? makes sense to me, but can't seem to apply that to my problem.