This question led to a new package:
underoverlap
Introduction
Based on this question and then this question, I'm trying to perfect the \overunderbrace macro. Right now, I'm trying to get the spacing right.
Minimal Working Example
\documentclass[varwidth=20cm,margin=3mm]{standalone}
\usepackage{mathtools}
\usepackage{xcolor}
\makeatletter
\def\overunderbrace#1#2#3{%
\begingroup%
\let\overunderbrace@sup\empty%
\let\overunderbrace@sub\empty%
\ignorespaces%
\@ifnextchar^{%
\@overunderbracesup{#1}{#2}{#3}%
}{%
\ignorespaces%
\@ifnextchar_%
{\@overunderbracesub{#1}{#2}{#3}}%
{\@overunderbrace {#1}{#2}{#3}}%
}%
}
\def\@overunderbracesup#1#2#3^#4{%
\def\overunderbrace@sup{#4}%
\ignorespaces%
\@ifnextchar_%
{\@overunderbracesub{#1}{#2}{#3}}%
{\@overunderbrace {#1}{#2}{#3}}%
}
\def\@overunderbracesub#1#2#3_#4{%
\def\overunderbrace@sub{#4}%
\ignorespaces%
\@ifnextchar^%
{\@overunderbracesup{#1}{#2}{#3}}%
{\@overunderbrace {#1}{#2}{#3}}%
}
\def\@overunderbrace#1#2#3{%
\mathrlap{\overbrace{\textcolor{red}{#1#2}}^{\mathclap{\overunderbrace@sup}}}%
#1%
\mathrlap{\underbrace{\textcolor{green}{#2#3}}_{\mathclap{\overunderbrace@sub}}}%
#2%
#3%
\endgroup%
}
\makeatother
\newcommand{\config}[2]{\left\langle\,#1, #2\,\right\rangle}
\begin{document}
$$
\config{F\vphantom{F'}}{p}
\longrightarrow
\config{F'}{p}
\longrightarrow
\config{F'}{p'}
\longrightarrow
\cdots
$$
$$
\overbrace
{\config{F\vphantom{F'}}{p}\longrightarrow\config{F'}{p}}^{test}
\longrightarrow
\config{F'}{p'}
\longrightarrow
\cdots
$$
$$
\overunderbrace
{\config{F\vphantom{F'}}{p}\longrightarrow}
{\config{F'}{p}}
{\longrightarrow\config{F'}{p'}}
^{\text{environmental}}
_{\text{local}}
\longrightarrow
\cdots
$$
\end{document}

As you can see, the braces are horizontally misaligned to the content.
Note
The \@overunderbrace code here may seem (unnecessarily) more complicated than the code from the answer I based it on, but that's because I'm trying to set up a repeating pattern, so we can get more than just two overlapping braces. The way to do that seems to be to:
- set [brace 1] with [phantom+rlap arguments 1+2]
- set [argument 1]
- set [brace 2 with [phantom+rlap arguments 2+3]
- set [argument 2]
- etc...
Diagnosis
To diagnose the problem, I replaced \phantom with \textcolor in the following code:
\def\@overunderbrace#1#2#3{%
\mathrlap{\overbrace{\textcolor{red}{#1#2}}^{\mathclap{\overunderbrace@sup}}}%
#1%
\mathrlap{\underbrace{\textcolor{green}{#2#3}}_{\mathclap{\overunderbrace@sub}}}%
#2%
#3%
\endgroup%
}

The black output is identical to the previous image. The red (green) content is the placement that the over(under)brace is based on.
It occurred to me that TeX determines spacing between math 'atoms' based on their respective types (ord, bin, rel, etc.). And I'm messing with this process by reordering the segments, \phantoming and \mathrlaping them.
Attempted Solution
So I augmented the formal parameters, making sure they always encounter the same 'environment' (to the best of my ability):
\def\@overunderbrace#1#2#3{%
\@@overunderbrace%
{\mathord{}#1\vphantom{#2}}%
{\vphantom{\mathord{}#1}#2\vphantom{#3\mathord{}}}%
{\vphantom{#2}#3\mathord{}}%
}
\def\@@overunderbrace#1#2#3{%
... the old \@overunderbrace ...
}

For comparison, I added the same formula without any braces, and then with only the overbrace (from the TeX command). As you see, no color is visible anymore (except for the rulers I added manually), so the printed content is aligned with its phantom images.
This solution is usable, but as you can see by the comparison, the spacing is still not right. Possibly because it's now using some 'inter-atom' glue twice in a row.
This is the point where I give up and ask for help.
Question: How can I get perfect spacing in a setup like this?

\[…\]preferable to$$? – Werner Jan 29 '13 at 18:30\newcommand{\config}[2]{{}\left\langle\,#1, #2\,\right\rangle{}}, it works. Somewhere on the way, your math-lapping gets in the way of TeX’s math-spacing algorithm. Meaning: The left and right angles do not see the appropriate math classes and assume something else (or nothing?). – Qrrbrbirlbel Jan 29 '13 at 18:54{}. Building on that, I've actually made the following sensible change:\newcommand{\config}[2]{\mathord{\left\langle\,#1, #2\,\right\rangle}}, and it works. This doesn't fix the general problem, of course, but it is another diagnostic result. – mhelvens Jan 29 '13 at 19:04{}to the the first and the second argument of\overunderbrace:\overunderbrace {{}\config{F\vphantom{F'}}{p}\longrightarrow} {{}\config{F'}{p}} …or directly:\def\@overunderbrace#1#2#3{% \mathrlap{\overbrace{\textcolor{red}{{}#1{}#2}}^{\mathclap{\overunderbrace@sup}}}% #1% \mathrlap{\underbrace{\textcolor{green}{{}#2#3}}_{\mathclap{\overunderbrace@sub}}}% #2% #3% \endgroup% }– Qrrbrbirlbel Jan 29 '13 at 19:08\UOLunaugmentand not\UOLaugmentin the left margin. – Hendrik Vogt Feb 02 '13 at 16:27