2

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

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>

Thanks in advance.

cgss
  • 301
  • 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 https://pastebin.com/ or https://gist.github.com/) – moewe Nov 22 '20 at 14:58
  • @moewe No, I don't work with MWE. To be honest, I haven't actually compiled it in my machine. I just extract it from my working tex file. I dug around in the aux files a bit and I think I found the problem. Could you please try again with section* instead of just section? I am actually using section* so both aux file name the equation 0.1 but with section they name them 1.1 and 2.1. – cgss Nov 22 '20 at 15:02
  • @DavidCarlisle I am usually very focused to produced an example as minimal as possible I don't always check it. In this case it kinda helped because with the modification I commented above it reproduces the error so we know exactly the problem. I edited the question accordingly. I also added a pagebreak so to make the error obvious. – cgss Nov 22 '20 at 15:14
  • Use equation* and the problem will disappear. – egreg Nov 22 '20 at 15:28
  • 1
    thanks for the edit (I deleted earlier comment) – David Carlisle Nov 22 '20 at 15:32
  • @egreg It actually worked.! I am gonna guess that since I labeled it manually I don't need latex do to its thing but other than that I have no idea as to why. I also have no idea what campa is talking about but if you agree what is the best practice answer the question so I can accept. Thanks. – cgss Nov 22 '20 at 15:36
  • 1
    @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

1 Answers1

3

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 \end{equation}, 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}
\usepackage[hidelinks]{hyperref}

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

egreg
  • 1,121,712
  • 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 https://tex.stackexchange.com/q/1863/4427 for the other question. – egreg Nov 22 '20 at 15:56