Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}%
share
    
Do you want the "stuff in between" without a label? If not, what label do you want for it? –  Steven B. Segletes Mar 5 '13 at 14:08
    
@StevenB.Segletes As in the MWE: it should be labeled (2). –  mafp Mar 5 '13 at 14:32
add comment

3 Answers

up vote 3 down vote accepted

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

share
add comment

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

enter image description here

share
1  
Good solution, but I find it very confusing to the reader. –  egreg Mar 5 '13 at 14:35
    
I agree on both counts that solution is excellent but that presentation is confusing to reader. It would be less so if the stuff in between were unlabeled, but then it could not be referenced. –  Steven B. Segletes Mar 5 '13 at 18:00
    
@egreg But consider the possibility that the subequations carry a special main tag, and it won't be confusing. –  mafp Mar 6 '13 at 16:15
add comment

I found a practical solution for resume some subequations between some stuff. I use the \tag{} option but I include into the tag the \ref{} option like this:

\begin{subequations}
\begin{align}
\rm\displaystyle \tan\upgamma&=\frac{\upeta_r}{1-(\upomega/\upomega_r)^2} \\
\rm\displaystyle \tan(90^{\circ}-\upgamma)&=\tan\left(\frac{\uptheta}{2}\right)=\frac{1-(\upomega/\rm \upomega_r)^2}{\upeta_r}
\end{align}
\label{eq:1}

some text or whatever you want

begin{equation}
\rm\displaystyle \upomega^2=\upomega_r^2\left(1-\upeta_r\tan\left(\frac{\uptheta}{2}\right)\right)\tag{\ref{eq:1}c}
\label{eq:ewins_4_6_c}
\end{equation}

I know this is not the \LaTeX{} way but is very practical

share
add comment

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .