32

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

35

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.

  • 3
    another pro for me - using VIM - is to jump from { to the corresponding } by pressing % ;) – jjdb Apr 17 '13 at 13:03
  • Thanks. Where can I find out what 'expandable' means? – jjdb Apr 17 '13 at 13:09
  • 2
    It's not really true that \lbrace and \rbrace are "robust": check tex.stackexchange.com/a/41144/4427 for a similar problem with \langle and \rangle – egreg Apr 17 '13 at 14:02
  • 1
    @egrep The index issue is different matter than LaTeX's robustness. Otherwise would you consider characters such as !, @, ... as fragile? But you are right that " might cause trouble, if " is an active character (babel, ...). – Heiko Oberdiek Apr 17 '13 at 18:42
  • 1
    @jjdb Answer updated. – Heiko Oberdiek Apr 17 '13 at 19:03

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.