25

Why is \underbrace (and similar commands) in the form

\underbrace{my formula}_{some text under my formula}

?

Shouldn't a standard macro be in the form

\underbrace[some text under my formula]{my formula}

since the text to put under is optional?

Why is it treated like a math operator?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\underbrace{a+b=c}
\]
\[
\underbrace{a+b=c}_{\text{something}}
\]
\[
\lim_{x\to a} x= a
\]
\end{document}

enter image description here

  • I don't know, but probably to be consistent with plain TeX. – TeXnician Dec 2 '18 at 9:47
  • @TeXnician I'm curious :) – CarLaTeX Dec 2 '18 at 9:48
  • 1
    And, don't forget the related expression for \overbrace: \overbrace{a+b=c}^{\text{something}}. I'm surmising that the use of _ and ^ in these directives was meant to be, at least in part, somewhat mnemonic. – Mico Dec 2 '18 at 10:01
  • If that plain TeX syntax bother: \let\oldunderbrace\underbrace \def\underbrace#1#2{{\oldunderbrace{#1}_{#2}}} – Fran Dec 2 '18 at 10:58
  • Nice question!! – manooooh Dec 5 '18 at 4:02
18

The \underbrace macro is exactly the same in LaTeX as in plain: it's one of those things which came with the original 'load on top of plain' approach, well before latex.ltx. Moreover, the _ 'argument' isn't an argument at all, it's a TeX core subscript. It looks like an argument, but the construction uses low-level TeX math mode primitives.

Re-implemented today, one would likely set up such that the alignment is done without the primitives, and thus the text part would be an argument. But that's a completely different question!

  • 2
    One might argue that it is more-or-less a subscript anyway, so the interface is consistent with \sum, \int, ... – Joseph Wright Dec 2 '18 at 10:00
  • 1
    And also mnemonic, as Mico said. – CarLaTeX Dec 2 '18 at 10:10
  • 8
    @JosephWright There's the added problem that \underbrace{a}_{b} is treated as an Op atom, with consequences on spacing. It's usually better to brace it: {\underbrace{a}_{b}}. – egreg Dec 2 '18 at 10:26
  • @egreg Sure, but that's not directly related to the syntax ... – Joseph Wright Dec 2 '18 at 10:37
5

When you look at the definition of \underbrace (or \overbrace) you'll see the following:

> \underbrace=macro:
#1->\mathop {\vtop {\m@th \ialign {##\crcr $\hfil \displaystyle {#1}\hfil $\crcr
\noalign {\kern 3\p@ \nointerlineskip }\upbracefill \crcr \noalign {\kern 3\p@ 
}}}}\limits .

It shows that the first (and only) argument to \underbrace is set as a math operator and closes with \limits. And, math operators have their limits (superscripts and subscripts) set on top/below it. It's therefore no surprise that you can do:

enter image description here

$\underbrace{abcd}_{dcba}\ \underbrace{abcd}^{dcba}$

It's treated like a math operator because that's the primitive way of stacking elements below/above something so that it doesn't displace the someting vertically.

1

I think it's much easier to iterate with the underscore syntax. For example

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
  \underbrace{\left(\frac12+\frac13\right)}_{
    >\underbrace{\frac14+\frac14}_{
      \underbrace{2\cdot \frac14}_{
        \frac12
        }
    }
  }
  \quad + \quad
    \underbrace{\left(\frac14+\frac15+\frac16+\frac17\right)}_{
    >\underbrace{\frac18+\frac18+\frac18+\frac18}_{
      \underbrace{4\cdot \frac18}_{
        \frac12
        }
    }
  }
  \quad > \quad \frac12+\frac12
\end{equation*}

\end{document}

Try to do the same with the "option" syntax. The point is that with the "underscore" syntax, you write the code for the iteration sequentially, from left to right, similarly to what the output will look like, while with the option syntax, you'd end up writing from right to left, so the bottom 1/2 in the output will be the leftmost formula after the three \underbrace commands.

iterating underbrace

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.