# Incorrect reference when combining amsmath, hyperref, and \tag

In the following MWE, I receive a warning and a reference points to the wrong element.

\documentclass{article}
\usepackage{hyperref}
\usepackage{amsmath}
\begin{document}
$$\label{eq1}$$

$$\tag{\ref*{eq1}b} \label{eq1b}$$

$$\label{eq2}$$

This reference is incorrect: \ref{eq2} points to 1b. Also, this warnings appear:
\begin{verbatim}
pdfTeX warning (ext4): destination with the same identifier
(name{equation.0.2}) has been already used, duplicate ignored
\end{verbatim}
\end{document}


In this variant with equation*, the latter problem is fixed, but a new one introduced. A link that was fine before is now wrong:

\documentclass{article}
\usepackage{hyperref}
\usepackage{amsmath}
\begin{document}
$$\label{eq1}$$

\begin{equation*}\tag{\ref*{eq1}b}
\label{eq1b}
\end{equation*}

$$\label{eq2}$$

This reference is incorrect: \ref{eq1b} points to 1. No warning.
\end{document}


How can I get all references correct?

These questions are similar, but don't help:

Hyperlinking problems when using subequations, hyperref and cleveref

Hyperref jumps to the wrong equation if the equation has a \tag and cleveref is used

As stated in the answer to Hyperref jumps to the wrong equation if the equation has a \tag and cleveref is used by CyberSingularity, the starred environment should be used. If you do it and load hyperref after amsmath all links are correct:

\documentclass{article}

\usepackage{amsmath}
\usepackage{hyperref}

\begin{document}
Some text
$$0=0 \label{eq1}$$
other text
\begin{equation*}\tag{\ref*{eq1}b}
1=1 \label{eq1b}
\end{equation*}
other text
$$2=2 \label{eq2}$$

These references are correct: \ref{eq1}, \ref{eq1b} and \ref{eq2}.
\end{document}


Note that this holds only for equation (it might be a feature request to Heiko Oberdiek making \tag work properly in equation). For align and the other multiline environments there's no problem:

\documentclass{article}

\usepackage{amsmath}
\usepackage{hyperref}

\begin{document}

\begin{align}
0&=0 \label{eq1} \\
1&=1 \tag{\ref*{eq1}b} \label{eq1b} \\
2&=2 \label{eq2}
\end{align}

These references are correct: \ref{eq1}, \ref{eq1b} and \ref{eq2}.

\end{document}

• Thanks! I had tried the starred variant as you see from my original question, but "...and load hyperref after amsmath" is key here. – bers Nov 4 '14 at 16:44