This took me hours to track down, partially because I am fairly new to TeX. I want to understand why the custom counter eqpart in the following code fails to increment properly when using mathclap. The counter jumps from a to d. The first equation only has the right counter because it is not wrapped in mathclap. Removing mathclap from ubrace gives the correct count which is b.
\documentclass[10pt]{article}
\usepackage{unicode-math}
\usepackage{mathtools}
\usepackage{xcolor}
\newcounter{eqpart}[section]
\setcounter{eqpart}{0}
\renewcommand{\theeqpart}{\alph{eqpart}}
\newcommand*{\ubrace}[3][black]{
\colorlet{current}{.}
\color{#1}
\underbrace{#2}_{ \mathclap{ #3 } }
\color{current}
}
\makeatletter
\newcommand{\tageqpart}[1]{%
\ifmeasuring@\else
\refstepcounter{eqpart}
\displaystyle(\theeqpart)
\fi
\@bsphack
\protected@write\@auxout{}
{\string\newlabel{#1}{{(\theeqpart)}{\thepage}}}
\@esphack
}
\makeatother
\begin{document}
\begin{align*}
\underbrace{x + y}_{ \tageqpart{test1} } = 0
\end{align*}
\begin{align*}
\ubrace{x + z}{\tageqpart{test2}} = 0
\end{align*}
\end{document}
EDIT:
Heeding the advice of David Carlisle I have refined the \ubrace command as:
\newcommand*{\ubrace}[3][black]{
\begingroup
\color{#1}
\overbrace{#2}^{#3}
\endgroup
}

\mathclaplike any command using\mathchoicetypesets its arguments 4 times display,text,script and scriptscript with the final version only being chosen later when the math list is finished. In classic TeX you can not detect this. Also why do you use\colorletand explicitly save/restore the colour rather than simply using a group? – David Carlisle Jan 14 '15 at 10:58\mathchoiceand its implications, see http://tex.stackexchange.com/questions/43978/proper-use-of-mathchoice – Steven B. Segletes Jan 14 '15 at 11:25\mathcoice. To answer your question I am not familiar with TeX. After learning more about a group I can see why it is a better choice. Thank you for the tip. – arynhard Jan 14 '15 at 14:57\mathclap? – arynhard Jan 14 '15 at 15:04