2

I have a formulation that consists of several subequations that I would like to refer to as a formulation and as individual equation in my article. Right now I have this:

\usepackage{hyperref}  
\begin{subequations}
MySubequation
\begin{align}
    a = b \label{eq:1a}\\
    a = c \label{eq:2b}\\
\end{align}
\end{subequations}

I would like to refer to this formulation in text as "MySubequation" and hyperlink it to the formulation. However, if I use \ref{MySubequation} it only shows the counter number for the formulation. Is there any way I can reference to a set of subequations as a name?

Werner
  • 603,163

1 Answers1

1

Here are some options that you could use:

\documentclass{article}

\usepackage{amsmath,hyperref}
\newcommand{\fourthoffive}[5]{#4}

\newcommand{\hyperlinktoeqn}[2]{%
  \ifcsname r@#1\endcsname
    \expandafter\expandafter\expandafter
    \hyperlink\expandafter\expandafter
    \expandafter{\expandafter\expandafter\expandafter
      \fourthoffive\csname r@#1\endcsname}{#2}%
  \else
    #2%
  \fi
}

\begin{document}

\section{A section}

\begin{subequations}

\hyperlinktoeqn{eq:1a}{MySubequation1}
\hyperlink{myeqn}{MySubequation2}
\begin{align}
  a &= b \label{eq:1a}\raisebox{\HyperRaiseLinkDefault}[0pt][0pt]{\hypertarget{myeqn}} \\
  a &= c \label{eq:2b}
\end{align}
\end{subequations}

\end{document}

While both MySubequation1 and MySubequation2 point to the first sub-equation, they approach it differently.

  1. The first extracts the regular hyperlink inserted by hyperref as being a combination of elements. Specific to equations within article, the reference is comprised on 5 elements:

    1. the reference (\@currentlabel during \label-making)

    2. the page (\thepage at the time of page shipout)

    3. the title (used by nameref as \@currentlabelname)

    4. the hyperlink name (\@currentHref, as constructed by hyperref)

    5. blank - {}

    What we're interested in is extracting "4. the hyperlink name". For this we use \fourthoffive after extracting the appropriate reference details (each label <label> is stored in the .aux as \r@<label>; see Understanding how references and labels work). Some testing is performed in order to make sure the label exists, together with a whole lot of \expandafters in order to ensure we retrieve the correct low-level components.

  2. For the second MySubequation2 link, we set a \hypertarget within the first sub-equation, raised (by \HyperRaiseLinkDefault or \baselineskip, the typical default) in order to land with the entire equation still visible.

    A straight-forward \hyperlink{<link>}{<text>} to the appropriate target suffices in this case.

Werner
  • 603,163