This was interesting. I believe I have a working solution making use of the appto
command from the etoolbox
package. Note that it is recommended to load the hyperref
package with hypertexnames=false
when using autonum
(I have also chosen to use the hidelinks
option).
The autonum
package will only generate an equation number when that equation is actually referenced, so we need a way of referencing all of the equations in a subequations environment when that environment is referenced in a silent manner. We can do this by defining our own reference command that takes a label and does nothing, but then tell the autonum package that it is reference command with the \autonum@generatePatchedReference
macro provided by the package.
\documentclass[11pt,a4paper]{article}
\usepackage{amsmath}
\usepackage[hypertexnames=false, hidelinks]{hyperref} % hypertexnames=false for autonum compatibility (autonum.pdf 3.2 Hyperref)
\usepackage{cleveref}
\usepackage{autonum}
\usepackage{etoolbox} % \appto (etoolbox.pdf 3.3 Hook management)
\newcommand\toplabel[2]{% Args: macro and label for subequations environment
\appto{#1}{(\ref{#2})}%
}
\newcommand\sublabel[2]{% Args: macro and label for a subequation
\appto{#1}{\hoaxref{#2}}% Pretend to reference this equation when #1 is called, to fool autonum
}
\newcommand\hoaxref[1]{%
% Do nothing!
}
\makeatletter
\autonum@generatePatchedReference{hoaxref} % Tell autonum about our reference command (autonum.pdf 3.3 Reference commands)
\makeatother
\begin{document}
\begin{subequations}
\label{eq:1}
\begin{align}
1 + 1 &= 2 \label{eq:1a}\\
2 + 2 &= 4\label{eq:1b}
\end{align}
\end{subequations}
\toplabel{\referone}{eq:1}%
\sublabel{\referone}{eq:1a}%
\sublabel{\referone}{eq:1b}%
Let us examine system \referone.
\begin{subequations}
\label{eq:2}
\begin{align}
3 + 3 &= 8 \label{eq:2a}\\
4 + 4 &= 8\label{eq:2b}
\end{align}
\end{subequations}
For comparison, an ordinary reference to system \ref{eq:2}.
\end{document}
Output:

Usage note: Label the subequations environment equations in the usual way. Then, below this environment, setup a macro to reference the environment with \toplabel{\myMacroName}{subeq:label}
and then \sublabel{\myMacroName}{a:sub:equation}
for each subequation you wish to have numbered (this doesn't have to be all of them!). Here \myMacroName
is what you will use to reference the subequation environment, as shown in the example.