[texhax] \newif, \csname and \endcsname

Uwe Lueck uwe.lueck at web.de
Mon Jan 31 08:47:31 CET 2011


"Vafa Khalighi" <vafakhlgh at gmail.com>, 31.01.2011 08:14:15:
> \documentclass{article}
> \newif\ifok
> \newif\ifnotok
> \newcommand{\printtest}{%
> \csname ifok\endcsname\csname ifnotok\endcsname print test\fi\fi}
> \begin{document}
> This is a test
> \printtest
> \end{document}
>
> Tex complains that there is an "Extra \fi", why?

Nice little study. \newif\ifok performs \let\ifok\iffalse. Therefore. \csname ifok\endcsname expands to an alias of \iffalse, therefore \csname ifnotok\endcsname is not expanded, so TeX is not aware of another \if..., TeX just tries to find an \else or a \fi matching \ifok. The first matching \fi is the first \fi. Then TeX finds the second \fi, and TeX cannot remember any \if... matching the second \fi -- this is what it is telling you.

Cheers, 

    Uwe.


More information about the texhax mailing list