4

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 \begin{equation}

\documentclass{amsart}

\usepackage{breqn}
\usepackage[colorlinks]{hyperref}

\begin{document}
\begin{equation}
\label{multiplication}
2 * 1 = 2
\end{equation}

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

\begin{dmath}\label{addition}
1 + 1 = 2
\end{dmath}

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

\begin{equation}
\label{subtraction}
2 - 1 = 1
\end{equation}

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.

Strange output, contains "Figure" in three links and "Equation" in one, exactly opposite the source material

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

4

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}
\usepackage[colorlinks]{hyperref}

\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}

\begin{dmath}\label{addition}
1 + 1 = 2
\end{dmath}

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

\begin{equation}
\label{subtraction}
2 - 1 = 1
\end{equation}

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

Result

3
  • Funny thing was, it does get the counter from dmath, just the text in front is wrong. And chngctr does affect dmath numbering. – Ben Voigt Apr 29 '15 at 5:29
  • 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. – Heiko Oberdiek Apr 29 '15 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. – Ben Voigt Apr 29 '15 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.