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

CarLaTeX
  • 62,716

3 Answers3

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!

CarLaTeX
  • 62,716
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
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.

Werner
  • 603,163
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