# autoref to dmath (from breqn package) generates wrong link text

In the following minimal example, what is wrong with my dmath equation? Why does hyperref call it a Figure, while autoref gets the link text correct for an equation defined with

\documentclass{amsart}

\usepackage{breqn}

\begin{document}
$$\label{multiplication} 2 * 1 = 2$$

\begin{figure}
\caption{Something strange}
\label{fig}
\end{figure}

1 + 1 = 2
\end{dmath}

I want to talk about \autoref{addition}, not \autoref{fig}.

$$\label{subtraction} 2 - 1 = 1$$

And \autoref{multiplication} is not very interesting.  Let me speak of \autoref{addition}.
\end{document}


The document has three hyperlinks to equations and one to the figure. But the output says "Figure" three times and "Equation" only once. All the links to breqn environments are wrong.

It is using the correct number, but the wrong text, combined to form "Figure 2" that doesn't actually exist in the document.

Swapping the order of \usepackage lines makes no difference.

What's the right way to use \label on \begin{dmath} and \begin{dgroup} environments?

Environment dmath of package breqn does not use \refstepcounter for the incrementation of the counter equation. Package hyperref hooks into \refstepcounter to add a hyper anchor as link target. Therefore your example uses the anchor before (figure.1) and you get the previous figure as link target.

Workaround: The following example patches \eq@setnumber to use \refstepcounter instead of \stepcounter:

\documentclass{amsart}

\usepackage{breqn}
\usepackage{etoolbox}

\makeatletter
\patchcmd\eq@setnumber{\stepcounter}{\refstepcounter}{}{%
\errmessage{Patching \noexpand\eq@setnumber failed}%
}
\makeatother

\begin{document}
\begin{figure}
\caption{Something strange}
\label{fig}
\end{figure}

\begin{figure}
\caption{Something strange}
\label{fig2}
\end{figure}

1 + 1 = 2
\end{dmath}

I want to talk about \autoref{addition}, not \autoref{fig}.

$$\label{subtraction} 2 - 1 = 1$$

And \autoref{subtraction} is not very interesting.  Let me speak of

• dmaht sets \@currrentlabel manually instead of using \refstepcounter. Thus it ignores hyperref completely. \autoref uses the anchor name to get the counter, the last anchor name was figure.1, thus \autoref sets the prefix for figures. Apr 29, 2015 at 9:54
• On further investigation, it looks like you're right that the hyperlink actually was going to the figure prior to the equation (usually they were on the same page making it hard to detect). Your patchcmd fixes both the text and the behavior. Thanks. Apr 29, 2015 at 15:53