# weird ifnum with compact syntax [duplicate]

In some packages like tabularx, I find the following syntax in many places

{\ifnum0=}\fi


or even

\ifnum0={\fi}


But I can't figure out why this can be useful for? Is  a register of some kind? Or is it a TeX-hack to generate error on specific occasion ?

## marked as duplicate by Manuel, Andrew Swann, user31729, Werner, zerothJul 9 '14 at 14:41

Ah the \ifnum funky brace groups beloved of TeX\halign programmers:-)




is part of the syntax for a number in TeX.

125


is a decimal

"7D


is hex and

}


is the character code of the specified character (which is also 125 as it happens).

So....

{\ifnum0=}\fi


the inner \ifnum is testing if 0=125 which is false so when expanded this is equivalent to { so starts a brace group. However if the tokens are not being expanded and TeX is just looking for matching {} pairs then it sees that as a matching pair so you can go

\def\foo{  {\ifnum0=}\fi }


but

\def\foo{  {  }


is an error (or at least does not stop at that }.

Usually you can use implicit brace groups \bgroup and \egroup to use an unmatched { but some constructs demand an explicit { token and so this trick (explained by Knuth in the TeXBook comes in useful).

Usually if you find that an environment that uses & to separate alignment cells does not work in a nested alignment it is because the author forgot to use these groups in the definition.

• I suppose than the second version I provided is for getting the }`. "Funky brace groups" you said? :) – M'vy Jul 9 '14 at 13:23
• @M'vy Yes, the second one is the 'matching pair' here – Joseph Wright Jul 9 '14 at 13:26