According to the TeXbook's* description of the


construct on p. 209 (the emphasis is mine)

TeX will expand macros following \if until two unexpandable tokens are found. If either token is a control sequence, TeX considers it to have character code 256 and category code 16, unless the current equivalent of that control sequence has been \let equal to a non-active character token. In this way, each token specifies a (character code, category code) pair.

What if one, or both, of the unexpandable tokens is an active character, e.g.

\if\noexpand @ ...

What is an active character's effective character code in the "eyes" of an \if construct?

* 20th printing, Addison-Wesley 1991


If you suppress expansion with \noexpand then it acts like a command name so is a character code if it is let to a character,

If you suppress expansion with \string then \if sees a non-active token of catcode 12, with the character code of the original character.


\if\noexpand @X yes \else no\fi

\if\noexpand @ \string@ yes \else no\fi



yes no

as \noexpand tests equal to X here as it is \let to X note however that if the character is \let to a character as here, then it isn't expandable so the \noexpand isn't needed.

  • What if the active character isn't \let to anything? – Evan Aad Aug 15 '17 at 11:34
  • @EvanAad it acts like a csname all non-character control sequences are equal to each other but not equal to any character – David Carlisle Aug 15 '17 at 11:35
  • Then why does the following manuscript outputs 'no'? \catcode`@=13\if @\relax yes\else no\fi\bye – Evan Aad Aug 15 '17 at 11:38
  • @EvanAad you expanded the if before assigning the catcode – David Carlisle Aug 15 '17 at 11:40
  • 4
    put a space after the 13, it is expanding \if while trying to finish the number to assign the catcode \count0=13\ifx ab 2\else 4\fi assigns count0 to be 134 – David Carlisle Aug 15 '17 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.