[Tex/LaTex] Interrupting and resuming subequations

math-modenumberingsubequations

As the title states I would like to interrupt and resume a block of equations that is inside a subequations regime. My problem arises when the interrupting stuff shall contain equations on its own:

\documentclass{article}
\usepackage{amsmath}
\usepackage[colorlinks]{hyperref}

\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}%
  \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}, \eqref{eq:master:ef}, \eqref{eq:master:gh},
and helper~\eqref{eq:helper}.
\end{document}

I know how to manually fiddle with the counters, but that is not The LaTeX Way. I have seen something like that for enumerations utilizing the enumitem package. How would an elegant solution look like, that let me write

\begin{subequations}[resume]%
  \begin{align}%
    e & = f \label{eq:master:ef}\\
    g & = h \label{eq:master:gh}
  \end{align}%
\end{subequations}%

Best Answer

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}

intermezzi and resumed enumaration