I am trying to test an if-condition, where the name of the condition depends on a macro argument. To do this, I use \csname ifcondition#1 \endcsname
. This works fine in a simple macro like this:
\newif\ifconditionA
\conditionAtrue
\def\test#1{
\csname ifcondition#1\endcsname
A: True
\fi
}
\test{A}
However, in my real use case, this test is part of an \ifcase
branch, like so:
\documentclass{article}
\begin{document}
\newif\ifconditionA
\conditionAtrue
\def\test#1#2{
\ifcase#2
Case 0
\or
%\ifconditionA % This works
\csname ifcondition#1\endcsname
Case 1, A: true
\fi
\fi
}
\test{A}{0}
%\test{A}{1} % This works
\end{document}
This fails with the error message ! Extra \fi. \test ...tion#1\endcsname Case 1, A: true \fi \fi
.
If I use the name of the condition directly, without \csname
, it works fine, and it also works if the branch containing the condition is executed.
What's going on, and how do I fix this?