# Cross-referencing an equation reset using setcounter

I have to reset equation counter at some point and then reference equations using the new labels but the cross-referencing is not taking the reference to the right location. Here is what I am talking about.

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\newcommand{\cotwo}{CO\textsubscript{2}}
\usepackage{hyperref}
\hypersetup{
}
\begin{document}
$$\label{eq:xas} \boxed{x_\text{A}^\text{s} = x_\text{A}^\ell \text{e}^{C_1}}$$
$1 - x_\text{A}^\text{s} = (1 - x_\text{A}^\ell) \text{e}^{C_2}$
Substituting for $x_\text{A}^\text{s}$ from Equation \ref{eq:xas}.
$1 - x_\text{A}^\ell \text{e}^{C_1} = (1 - x_\text{A}^\ell) \text{e}^{C_2}$
\setcounter{equation}{0}
$$\label{eq:dlnsdT} \cfrac{\partial \ln \text{s}}{\partial T} = \cfrac{\partial}{\partial T}\left[\cfrac{\mu_\text{\cotwo}^\text{v} - \mu_\text{\cotwo}^\ast}{RT}\right]$$
Substituting in Equation \ref{eq:dlnsdT}, we get
\end{document}


In the second reference, I want to refer to the equation right above, not the top equation. Does someone know what's wrong with the cross-referencing here or am I missing something obvious?

• You get an error from the duplicate equation destination with the same identifier (name{equation.0.1}) has been already used, duplicate ignored If you really want two equation (1) then you will need to give different unique labels for hyperref to use as anchors see hypperref package doc – David Carlisle Nov 21 '16 at 7:51

David Carlisle already provided some explanation, here is a way to manipulate the hyperanchor which is basically generated from the corresponding macro \theHequation by counting the total numbers of equations and appending the current total number of equations to the expansion of \theHequation.

The counting is done with my xassoccnt package and associating the totalequations counter to the real equations counter.

This way unique anchor names are used, as long as no one changes the value of totalequations directly.

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\usepackage[version=4]{mhchem}
\usepackage{xassoccnt}
\newcommand{\cotwo}{\ce{CO2}}

%%CO\textsubscript{2}}

\newcounter{totalequations}
\DeclareAssociatedCounters{equation}{totalequations}%

\usepackage{hyperref}
\hypersetup{
}

\let\theOldHequation\theHequation
\renewcommand{\theHequation}{\theOldHequation::\number\value{totalequations}}

\begin{document}

$$\label{eq:xas} \boxed{x_\text{A}^\text{s} = x_\text{A}^\ell \text{e}^{C_1}}$$
$1 - x_\text{A}^\text{s} = (1 - x_\text{A}^\ell) \text{e}^{C_2}$
Substituting for $x_\text{A}^\text{s}$ from Equation \ref{eq:xas}.
$1 - x_\text{A}^\ell \text{e}^{C_1} = (1 - x_\text{A}^\ell) \text{e}^{C_2}$
\clearpage
\setcounter{equation}{0}
$$\label{eq:dlnsdT} \cfrac{\partial \ln \text{s}}{\partial T} = \cfrac{\partial}{\partial T}\left[\cfrac{\mu_\text{\cotwo}^\text{v} - \mu_\text{\cotwo}^\ast}{RT}\right]$$
Substituting in Equation \ref{eq:dlnsdT}, we get \dots however in \ref{eq:xas} there is an equation with the same number!
\end{document}