Math Mode Brackets – How to Overlap Under-Braces and Over-Braces

bracketsmath-mode

I am trying to typeset an equation that has overlapping over and under braces as per the image below:

enter image description here

I have managed to typeset it using a sort of a hack, by typing the equation twice, once using \phantom commands and then raising it. Is there an easier way, perhaps a macro? MWE for the image above is shown below.

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\[a+b+\overbrace{c+d+e+f+g}^{x}+h+i+k+l=e^2\]
\vspace{-35pt}
\[\phantom{+b+c+d+}\underbrace{\phantom{e+f+g+h+i}}_{y}\phantom{+k+=e^2}\]
\end{document}

Best Answer

\documentclass[12pt]{article}
\usepackage{amsmath}
\begin{document}
\[
  a+b+\rlap{$\overbrace{\phantom{c+d+e+f+g}}^x$}c+d
     +\underbrace{e+f+g+h+i}_y +k+l=e^2
\]
\end{document}

enter image description here