2

I want to write the name of a equation next to it instead of a number. I followed the structure of the first answer given in Add equation name underneath equation number . But it seems that links turn wrong.

Changing a bit the answer given, here you have MWE:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\eqname}[1]{\tag*{#1}}% Tag equation with name
\usepackage{hyperref}
\begin{document}

\begin{equation} \label{f}
f(x) = a   \eqname{(Constant)} 
\end{equation}

\begin{equation} \label{g} 
g(x) = ax  
\end{equation}


See \eqref{f} and \eqref{g}.
\end{document}

Now, \eqref{f} appears as (Constant) and \eqref{g} as (1), but by clicking in both links the document goes to the first equation, the one named Constant. I cannot go to the second equation clicking in its reference, (1) .

What should I do to fix this? Thanks in advance.

Minkowski
  • 365

2 Answers2

2

I suggest to tap in \theHequation:

\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}

\newcounter{eqname}
\renewcommand{\theHequation}{%
  \theHsection.\arabic{equation}-\arabic{eqname}%
}

\newcommand{\eqname}[1]{% Tag equation with name
  \stepcounter{eqname}%
  \tag{#1}%
}

\begin{document}

\begin{equation} \label{f}
f(x) = a   \eqname{Constant}
\end{equation}

\begin{equation} \label{g}
g(x) = ax
\end{equation}

\begin{equation} \label{gg}
g(x) = ax
\end{equation}

\begin{equation} \label{ff}
f(x) = a   \eqname{Test}
\end{equation}

See \eqref{f} and \eqref{g}.
See \eqref{ff} and \eqref{gg}.
\end{document}
egreg
  • 1,121,712
2

The environments of amsmath are better supported by hyperref. The example can be fixed by using gather instead of equation for the equation that is tagged with a name:

\documentclass{article}
\usepackage{amsmath}
\newcommand{\eqname}[1]{\tag*{#1}}% Tag equation with name
\usepackage{hyperref}
\begin{document}

\begin{gather} \label{f}
f(x) = a   \eqname{(Constant)}
\end{gather}

\begin{equation} \label{g}
g(x) = ax
\end{equation}


See \eqref{f} and \eqref{g}.
\end{document}
Heiko Oberdiek
  • 271,626