[Tex/LaTex] Curly brace to insert something into an equation? Like an inverted underbrace

bracketsmath-mode

I have a generic equation, into which I want to "insert" something so that the reader can see what I inserted into the equation and at which point.

E.g.

\documentclass{plain}

\begin{document}
\[ f = < x | R y > \]

Insert $\int d^3 p |p> <p|$ = 1 before y.
\end{document}

What I imagine is a horizontal curly brace, which extends underneath the equation, and which has its tip touching a spot just slightly to the left of the $y$, while in the brace there is written $\int d^3 p |p> <p|$. It would look something like an inverted \underbrace{foo}_{bar}, but I have no idea how to achieve something like that.

In ASCII art this would maybe look like this:

f = <x | R y >            (1)
        __|__
   ____|     |____
  | Insert here! | 

Best Answer

Here's a variant of Gonzalo's code that uses \mathop{}\limits instead of \raisebox. The output is almost the same.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\[
  f = \langle x | R\mathclap{\mathop{}\limits_{\overbrace{
                   \textstyle\int d^3 p |p\rangle \langle p|}}}y
      \rangle 
\]
\end{document}

If you want something more flexible, use the \braceinsert macro from the code below. It takes one optional argument (the amount by which the brace should be lowered, with default 0ex) and one mandatory argument (the stuff you want under the brace). Moreover, it takes care of the case that the \braceinsert is surrounded by \left...\right delimiters, like this:

example for \braceinsert

To be precise, you'll have to use \bileft...\biright instead of \left...\right (like braceinsert left and right). After the outermost \biright, only explicit superscripts will work, so instead of ' you'd have to use ^\prime. (Subscripts won't work properly, but I don't know when one would want one.)

\documentclass{article}
\usepackage{mathtools}
\setlength{\textwidth}{11cm}
\makeatletter
\newcounter{left@right}
\newcommand*\bileft[1]{\left#1\stepcounter{left@right}}
\newcommand*\biright[1]{\right#1%
    \@ifnextchar^{\with@superscript}{\without@superscript}}
\def\with@superscript^#1{^{#1}\without@superscript}
\def\without@superscript{%
    \addtocounter{left@right}{-1}%
    \ifnum\theleft@right=0
      \vphantom{\brace@insert@strut}
      \gdef\brace@insert@strut{}
    \fi
    }
\def\brace@insert@strut{}
\newcommand{\braceinsert}[2][0ex]{%
    \def\insert@material{%
        \mathop{\rule[-#1]{0pt}{0pt}}\limits_{\overbrace{#2}}%
        }%
    \expandafter\g@addto@macro\expandafter\brace@insert@strut
        \expandafter{\insert@material}
    \ifnum\theleft@right>0
      \smash{\mathclap{\insert@material}}
    \else
      \mathclap{\insert@material}
    \fi
    }
\makeatother
\begin{document}
In the formula
\[
  f = 5 \bileft( b^2 + \langle x | R
      \braceinsert[0.2ex]{\textstyle\int d^3 p |p\rangle \langle p|}
      y \rangle \biright)^2,
\]
the depth of the stuff under the brace is added only \emph{after}
\verb|\biright)^2|.
\end{document}

(Maybe this is wayyy too complicated?)