Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

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 ?

share|improve this question

marked as duplicate by Manuel, Andrew Swann, Christian Hupfer, Werner, zeroth Jul 9 at 14:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
    
Perhaps take a look at tex.stackexchange.com/questions/9897/… –  Joseph Wright Jul 9 at 12:52

1 Answer 1

up vote 12 down vote accepted

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.

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

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