# The problem

Hi. I'm currently writing my thesis and have my equations numbered within sections. I also use subequations from amsmath. When I use amsmath, hyperref and cleveref together, however, I get 2 warnings about destinations with the same identifier. The result is that \cref{eq:2a} gets the correct number in the pdf but the hyperlink points to eq:1a.

# A MWE

\documentclass{book}

\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{cleveref}

\numberwithin{equation}{section}

\begin{document}
This is a test.

\section{Section 1}

\begin{subequations}\label{eq:1}
\begin{align}
x=y\label{eq:1a}
\end{align}
\end{subequations}

\section{An error}

\begin{subequations}\label{eq:2}
\begin{align}
1=2\label{eq:2a}
\end{align}
\end{subequations}

\end{document}


# The aux

Sure enough,

\newlabel{eq:1}{{0.1.1}{1}{Section 1\relax }{equation.0.0.1.1}{}}
\newlabel{eq:1@cref}{{[equation][1][0,1]0.1.1}{1}}
\newlabel{eq:1a}{{0.1.1a}{1}{Section 1\relax }{equation.0.0.1a}{}}
\newlabel{eq:1a@cref}{{[equation][1][0,1]0.1.1a}{1}}
\@writefile{toc}{\contentsline {section}{\numberline {0.2}An error}{1}{section.0.2}}
\newlabel{eq:2}{{0.2.1}{1}{An error\relax }{equation.0.0.1.1}{}}
\newlabel{eq:2@cref}{{[equation][1][0,2]0.2.1}{1}}
\newlabel{eq:2a}{{0.2.1a}{1}{An error\relax }{equation.0.0.1a}{}}
\newlabel{eq:2a@cref}{{[equation][1][0,1]0.2.1a}{1}}


# Warnings

pdfTeX warning (ext4): destination with the same identifier (name{equation.0.0.1a}) has been already used, duplicate ignored
pdfTeX warning (ext4): destination with the same identifier (name{equation.0.0.1.1}) has been already used, duplicate ignored


# What to do?

All packages have been updated too. So I've tried a few things that can get this to work without any warnings but none is an ideal solution from my point of view.

1. Remove all subequations
2. Remove line \numberwithin{equation}{section}
3. Remove package cleveref
4. Remove package hyperref

This in no doubt related to Hyperref jumps to the wrong equation if the equation has a \tag and cleveref is used and also Cross-references linking to wrong equations using hyperref but I can't manage to use those Q&As to help me here.

I'd really appreciate it if anybody could shed some light on this issue or suggest a workaround.

-
Welcome to TeX.SE, and many thanks for posting such a clear and simple MWE. I can reproduce the warning messages you've come across. Do note that they are warning rather than error messages. AFAICT, all cross-references one can generate with \ref, \autoref, and \cref are correct. Thus, the warning messages may be of no importance. I suspect they have something to do with what the subequations environment has to set up in order to get its job done; note that the label(s) set up by the subequations environment don't seem to be used directly by either hyperref or cleveref. –  Mico Aug 5 '12 at 12:39
Thanks very much for the prompt reply. You are right that the \cref command works, correctly referencing the equations. However, I have noticed that the hyperlinks in the pdf point to the wrong equation. In this example, a link generated by \cref{eq:2a} points to eq:1a even though it is correctly labelled in the pdf. It seems as though the labels are used by hyperref but not cleveref. I'm quite keen to know if anybody has any ideas on getting the hyperlinks working correctly. –  J-P Aug 5 '12 at 15:02
The parent equation is the same. –  Marco Daniel Aug 5 '12 at 15:13
OK, I see what you mean now -- and I can reproduce the problem, i.e., a cross-reference to equation 2.1a gets the correct number but is hyperlinked to equation 1.1a. I've never encountered this problem before. Maybe it has something to do with a couple of recent updates applied to the hyperref package. –  Mico Aug 5 '12 at 16:02

So I found the following solution by playing around with when packages and lines are called and it turns out that if the \numberwithin{}{} line is called before \cleveref, there are no warnings and hyperlinks work as expected, i.e.

\documentclass{book}

\usepackage{amsmath}
\usepackage{hyperref}
\numberwithin{equation}{section}
\usepackage{cleveref}

\begin{document}
...
\end{document}


I have no idea what's going on beneath the hood of these packages so I'd be curious to know why this works. It seems (to me at least) that this is quite strange behaviour between hyperref and cleveref but perhaps this is to be expected.

In the mean time, thanks to all those who had a look at this problem for me!

-