You are here: Home / Przedsięwzięcia/Projects / TeX Pearls / 2008 Pearls / javier-mugica / src / ifhacking.txt

ifhacking.txt

Suppose we have the common construction

\iffound
%found code
\else
%not found code
\fi

where \iffound has been \let to \iftrue or \iffalse, and suppose that in "%found code" there is another "if" test, without else part,
but the control sequence \if... has to be built from a \csname. For example, \csname if@inner@test\endcsname.
If \iffound is false it will be skipped, so we had better skip also its matching \fi. So one may think that the solution
is to also build the \fi from a \csname, i.e., \csname fi\endcsname:

\iffound
\csname if@inner@test
%Code for this true case
\csname fi\endcsname
\else
%not found code
\fi

Wrong!!! If the inner "if" is false, the fi will not be built, and we are missing an \if.
The solution I found is the following trickery:

\iffound
\iftrue
\csname if@inner@test
%Code for this true case
\fi
\csname fi\endcsname
\else
%not found code
\fi

The actual example is in the code of my package fenixtok, file fenixtok.sty in CTAN.

Document Actions