[texhax] \newif, \csname and \endcsname

Heiko Oberdiek heiko.oberdiek at googlemail.com
Mon Jan 31 12:21:52 CET 2011


On Mon, Jan 31, 2011 at 08:39:06AM +0100, jfbu wrote:

> >\newif\ifok
> >\newif\ifnotok
> >\newcommand{\printtest}{%
> >\csname ifok\endcsname\csname ifnotok\endcsname print test\fi\fi}

> >\printtest

> >Tex complains that there is an "Extra \fi", why?
> 
> I can not say why, but

Already explained by Uwe Lueck.

> 2. the problem seems to be fixed by that version:
> 
> \newcommand{\printtest}{%
> \expandafter\expandafter\csname ifok\endcsname\csname
> ifnotok\endcsname print test\fi\fi}

Or with one \expandafter only:

\newcommand{\printtest}{%
  \csname ifok\expandafter\endcsname
    \csname ifnotok\endcsname
      print test%
    \fi
  \fi
}

The first \csname is not the problem, but the
second hides an internal conditional (\ifnotok),
that is unhided by \expandafter.

Yours sincerely
  Heiko Oberdiek


More information about the texhax mailing list