Interrupting and resuming subequations
My solution provides a second environment subequations*
that picks up the values from the last subequations
or subequations*
environment.
The \end{subequations}
part is redefined to save the values of the counters (in this case 1
and 2
= b
) in auxiliary counters. These are used in the subequations*
environment.
Note: It is the possible to label the subequations*
environments which means that there will be more than one “Master” equation. This is gets interesting when you use a \pageref
.
The reason for etoolbox
’ \patchcmd
macor can be read in another answer of mine. Short version: The \theparentequation
macro is defined independently from the parentequation
counter.
Code
\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
\usepackage{etoolbox}
\makeatletter
\newcounter{qrr@oldeq}
\newcounter{qrr@oldsubeq}
\newcounter{qrr@realeq}
\renewenvironment{subequations}{%
\refstepcounter{equation}%
\protected@edef\theparentequation{\theequation}%
\setcounter{parentequation}{\value{equation}}%
\setcounter{equation}{0}%
\def\theequation{\theparentequation\alph{equation}}%
\ignorespaces
}{%
\setcounter{qrr@oldeq}{\value{parentequation}}%
\setcounter{qrr@oldsubeq}{\value{equation}}%
\setcounter{equation}{\value{parentequation}}%
\ignorespacesafterend
}
\newenvironment{subequations*}{%
\setcounter{qrr@realeq}{\value{equation}}%
\let\theparentequation\theequation%
\patchcmd{\theparentequation}{equation}{parentequation}{}{}%
\setcounter{parentequation}{\numexpr\value{qrr@oldeq}-1}%
\setcounter{equation}{\value{qrr@oldsubeq}}%
\def\theequation{\theparentequation\alph{equation}}%
\refstepcounter{parentequation}%
\ignorespaces
}{%
\setcounter{qrr@oldeq}{\value{parentequation}}%
\setcounter{qrr@oldsubeq}{\value{equation}}%
\setcounter{equation}{\value{qrr@realeq}}%
\ignorespacesafterend
}
\makeatother
\begin{document}
\begin{subequations}\label{eq:master}%
\begin{align}%
a & = b \label{eq:master:ab}\\
c & = d \label{eq:master:cd}
\end{align}%
\end{subequations}%
%
Some stuff in between
\begin{equation}%
A = B\label{eq:helper}
\end{equation}
%
Resume here the subequations, i.e., continue with 1c:
\begin{subequations*}\label{eq:Master}
\begin{align}%
e & = f \label{eq:master:ef}\\
g & = h \label{eq:master:gh}
\end{align}%
\end{subequations*}%
Master~\eqref{eq:master}, consisting of~\eqref{eq:master:ab}, \eqref{eq:master:cd} and \eqref{eq:master:ef}, \eqref{eq:master:gh} from Master \eqref{eq:Master},
and helper~\eqref{eq:helper} and final~\eqref{eq:final}.
Some stuff at the end:
\begin{equation}%
A = B\label{eq:final}
\end{equation}
\end{document}
Output
Here is another method.
I explain: the subequations
now admit an optional argument. The expected values are resume
, intermezzo
, or nothing. As soon as neither resume
nor intermezzo
is encountered, a new potential thread is initialized: continuation goes with resume
, putting stuff in-between can be anything and if it is again a subequations
block it has to be flagged intermezzo
.
The code takes into account that hyperref
patches subequations
.
One caveat: subequations
block playing in the rôle of intermezzi can not be globally labeled: only the actual sub-equations may be.
\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}
% original amsmath definition
% \subequations:
% \long macro:->\refstepcounter {equation}\protected@edef \theparentequation {\theequation }\setcounter {parentequation}{\value {equation}}\setcounter {equation}{0}\def \theequation {\theparentequation \alph {equation}}\ignorespaces
% saved by hyperref in
% > \HyOrg@subequations=\long macro:
% hyperref-patched \subequations: (\endsubequations not modified)
% > \subequations=macro:
% ->\stepcounter {equation}\protected@edef \theHparentequation {\@ifundefined {th
% eHequation}\theequation \theHequation }\addtocounter {equation}{-1}\HyOrg@subeq
% uations \def \theHequation {\theHparentequation \alph {equation}}\ignorespaces
% .
% extending the environment
% 1. with optional parameter: expected values resume or intermezzo or none.
% 2. while keeping the hyperref customization.
\makeatletter
\def\user@resume{resume}
\def\user@intermezzo{intermezzo}
%
\newcounter{previousequation}
\newcounter{lastsubequation}
\newcounter{savedparentequation}
\setcounter{savedparentequation}{1}
%
\renewenvironment{subequations}[1][]{%
\def\user@decides{#1}%
\setcounter{previousequation}{\value{equation}}%
\ifx\user@decides\user@resume
\setcounter{equation}{\value{savedparentequation}}%
\else
\ifx\user@decides\user@intermezzo
\refstepcounter{equation}%
\else
\setcounter{lastsubequation}{0}%
\refstepcounter{equation}%
\fi\fi
\protected@edef\theHparentequation{%
\@ifundefined {theHequation}\theequation \theHequation}%
\protected@edef\theparentequation{\theequation}%
\setcounter{parentequation}{\value{equation}}%
\ifx\user@decides\user@resume
\setcounter{equation}{\value{lastsubequation}}%
\else
\setcounter{equation}{0}%
\fi
\def\theequation {\theparentequation \alph{equation}}%
\def\theHequation {\theHparentequation \alph{equation}}%
\ignorespaces
}{%
% \arabic{equation};\arabic{savedparentequation};\arabic{lastsubequation}
\ifx\user@decides\user@resume
\setcounter{lastsubequation}{\value{equation}}%
\setcounter{equation}{\value{previousequation}}%
\else
\ifx\user@decides\user@intermezzo
\setcounter{equation}{\value{parentequation}}%
\else
\setcounter{lastsubequation}{\value{equation}}%
\setcounter{savedparentequation}{\value{parentequation}}%
\setcounter{equation}{\value{parentequation}}%
\fi\fi
% \arabic{equation};\arabic{savedparentequation};\arabic{lastsubequation}
\ignorespacesafterend
}
\makeatother
\begin{document}\thispagestyle{empty}
\begin{subequations}\label{eq:master}
\begin{align}
a & = b \label{eq:master:ab}\\
c & = d \label{eq:master:cd}
\end{align}
\end{subequations}
%
Some intermezzo stuff in between
\begin{equation}
A = B\label{eq:helper}
\end{equation}
%
\begin{subequations}[intermezzo]
\begin{align}
C &= D\label{eq:inter1}\\
E &= F\label{eq:inter2}
\end{align}
\end{subequations}
Resume here the subequations, i.e., continue with 1c:
\begin{subequations}[resume]
% \label{eq:Master} % NO! impossible here
\begin{align}
e & = f \label{eq:master:ef}\\
g & = h \label{eq:master:gh}\\
g & = h \label{eq:master:gh2}
\end{align}
\end{subequations}
Master~\eqref{eq:master}, consisting of~\eqref{eq:master:ab},
\eqref{eq:master:cd} and \eqref{eq:master:ef}, \eqref{eq:master:gh},
\eqref{eq:master:gh2}
and helpers \eqref{eq:helper}, \eqref{eq:inter1} and \eqref{eq:inter2}. But one
can not label the intermezzo block, only its subequations.
Some more continued stuff:
\begin{subequations}[resume]
\begin{align}
i & = j \label{eq:master:ij}\\
k & = l \label{eq:master:kl}\\
i & = j \label{eq:master:ij2}
\end{align}
\end{subequations}
and we re-initialize again (resuming will continue from here):
\begin{subequations}
\begin{align}
A &= B\label{eq:final1}\\
B &= A\label{eq:final2}
\end{align}
\end{subequations}
Two intermezzi (my head starts spinning!):
\begin{subequations}[intermezzo]
\label{eq:Intermediate}
\begin{align}
A &= B\label{eq:final3}\\
B &= A\label{eq:final4}
\end{align}
\end{subequations}
\begin{align}
A &= B\label{eq:final5}\\
B &= A\label{eq:final6}
\end{align}
And we resume again (some aspirin please!)
\begin{subequations}[resume]
\begin{align}
A &= B\label{eq:final7}\\
B &= A\label{eq:final8}
\end{align}
\end{subequations}
So we had a new block of subequations \eqref{eq:final1}, \eqref{eq:final2},
\eqref{eq:final7}, and \eqref{eq:final8}; and in-between there were
\eqref{eq:final3}, \eqref{eq:final4}, \eqref{eq:final5}, and \eqref{eq:final6}.
\end{document}