使用 setcounter 交叉引用方程重置

使用 setcounter 交叉引用方程重置

我必须在某个时候重置方程计数器,然后使用新标签引用方程,但交叉引用不会将引用带到正确的位置。这就是我要说的。

\documentclass{article}
\usepackage{amsmath}
\usepackage{siunitx}
\newcommand{\cotwo}{CO\textsubscript{2}}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
}
\begin{document}
\begin{equation}\label{eq:xas}
\boxed{x_\text{A}^\text{s} = x_\text{A}^\ell \text{e}^{C_1}}
\end{equation}
\[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}
\begin{equation}\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]
\end{equation}
Substituting in Equation \ref{eq:dlnsdT}, we get
\end{document}

在第二个引用中,我想引用上面的方程,而不是最上面的方程。有人知道这里的交叉引用有什么问题吗?还是我遗漏了一些显而易见的东西?

提前致谢!

答案1

David Carlisle 已经给出了一些解释,这里是一种操纵超锚点的方法,它基本上是\theHequation通过计算方程的总数并将当前的方程总数附加到的展开式中来从相应的宏生成的\theHequation

计数是用我的xassoccnt包完成的,并将totalequations计数器与真实equations计数器关联起来。

这样,只要没有人totalequations直接更改值,就会使用唯一的锚点名称。

\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{
colorlinks=true,
linkcolor=blue,
}


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

\begin{document}

\begin{equation}\label{eq:xas}
\boxed{x_\text{A}^\text{s} = x_\text{A}^\ell \text{e}^{C_1}}
\end{equation}
\[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}
\begin{equation}\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]
\end{equation}
Substituting in Equation \ref{eq:dlnsdT}, we get \dots however in \ref{eq:xas} there is an equation with the same number!
\end{document}

相关内容