# Different equations with the same tag cause wrong reference

I would like to achieve something quite similar to this question, except that I would also like to reference said equations. Here's a minimal example:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}

\begin{document}
\section*{Chapter A}
$$\label{star1}\tag{\star} a^2 + b^2 = c^2$$
The main equation of this chapter is the Pythagorean theorem, \eqref{star1}.

\pagebreak

\section*{Chapter B}
$$\label{star2}\tag{\star} i^2 = -1$$
The main equation of this chapter is the definition of the imaginary unit, \eqref{star2}.
\end{document}


The problem is that \eqref{star2} points to the Pythagorean. I also get this warning which I am pretty sure is relevant: destination with the same identifier (name{equation.0.1}) has been already used, duplicate ignored <to be read again>

• Mhh, the MWE as posted works fine for me: The resulting PDF contains two each linking to a different equation. I also get no warning about destinations with the same label. Delete the .aux file and compile again. – moewe Nov 22 '20 at 14:39
• @moewe I did. I actually deleted all the aux files just in case. The problem remains. – cgss Nov 22 '20 at 14:54
• With the exact MWE you posted? Can you please show us the complete .log file of the (second) LaTeX run. (If it is too long to fit into the question, you can upload it to a text-sharing website such as pastebin.com or gist.github.com) – moewe Nov 22 '20 at 14:58
• thanks for the edit (I deleted earlier comment) – David Carlisle Nov 22 '20 at 15:32
• @campa that probably should be the answer (and looking in the aux file that does cause unique names (AMS.2 and AMS.4 rather than duplicated equation.0.1 but I still get the internal duplicate id error for some reason. – David Carlisle Nov 22 '20 at 15:38

The package hyperref should be loaded last: only a few packages have to be loaded after it and none of those in the MWE.

However, this doesn't solve the issue. The problem is a race condition: with equation the associated counter is stepped and then reset at its previous value if \tag is scanned before , but it's too late and hyperref has already provided an anchor.

The tag being the same is not the problem, although I'd be wary of doing it, because it's probably confusing the reader.

Using equation* solves the issue.

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathtools}

\begin{document}

\section*{Chapter A}
\begin{equation*}\label{star1}\tag{$\star$}
a^2 + b^2 = c^2
\end{equation*}
The main equation of this chapter is the Pythagorean theorem, \eqref{star1}.

\pagebreak

\section*{Chapter B}
\begin{equation*}\label{star2}\tag{$\star$}
i^2 = -1
\end{equation*}
The main equation of this chapter is the definition of the imaginary unit, \eqref{star2}.
\end{document}

• Thanks for the explanation. Which packages should be loaded after hyperref? Also, no need to worry about the reader. Sections are small(5-10 pages) and quite independent. – cgss Nov 22 '20 at 15:48
• @cgss OK, you know your audience. See tex.stackexchange.com/q/1863/4427 for the other question. – egreg Nov 22 '20 at 15:56