35

So, what is the difference in using \{ and \} to using \lbrace and \rbrace? Which one is preferred, and when one has to take care?

jjdb
  • 2,238

1 Answers1

39

From the LaTeX kernel (latex.ltx):

\DeclareRobustCommand{\{}{\ifmmode\lbrace\else\textbraceleft\fi}
\DeclareRobustCommand{\}}{\ifmmode\rbrace\else\textbraceright\fi}

Thus differences:

  • \{ and \} work in both text and math mode, \lbrace and \rbrace only in math mode. The latter macros trigger an error in text mode.

  • \{ and \} are shorter (two characters instead of seven).

  • \{ and \} are robust commands. For the discussion of the robustness of \lbrace and \rbrace, see below.

  • \{ and \} might be better supported by editors (matching support, see comment of jjdb).

Similarities:

  • In math mode both variants execute \lbrace and \rbrace.

  • The same math spacing.

\lbrace and \rbrace are defined in fontmath.ltx, also part of the LaTeX kernel (see source2e.pdf):

\DeclareMathDelimiter{\lbrace}
   {\mathopen}{symbols}{"66}{largesymbols}{"08}
\DeclareMathDelimiter{\rceil}
   {\mathclose}{symbols}{"65}{largesymbols}{"07}

They are defined as (\show\lbrace/\show\rbrace):

\def\lbrace{\delimiter "4266308 }
\def\rbrace{\delimiter "5267309 }

And \delimiter is a unexpandable TeX primitive. It is followed by " and a number, both with catcodes 12 (other, unexpandable). And the space at the end is not expandable either. If the characters are reread, e.g. in the table of contents, then the quote character " might cause trouble, if it is used as active character. For example, if someone defines a babel shorthand "4 or "5.

Answer to the comment of egreg referring to his answer to an index question. The quote character " has a special meaning for index entries. (With the default meaning "4 or "5 become 4 or 5 in the index, the quote character gets lost.) This can happen if \index is used in an argument of another command. Otherwise \index reads its argument with verbatim catcodes, thus macros are not expanded.

Heiko Oberdiek
  • 271,626