Nesting subequations within align
The subequations
environment & the parentequation
counter
The original subequations
environment redefines \theparentequation
in a way that it is independent from the counter parentequation
:
\protected@edef\theparentequation{\theequation}%
But we can redefine the subequations
environment so that only the value of equation
is saved and \theparentequation
uses the counter parentequation
again:
\def\theparentequation{\arabic{parentequation}}%
But that way we would loose the setting of \theequation
that might involve \thechapter
in classes like book
. For this, we could change it again manually to
\def\theparentequation{\thechapter.\arabic{parentequation}}%
etoolbox
and \patchcmd
Another approach uses etoolbox
and its \patchcmd
macro.
First we let \theparentequation
be the same as \theequation
:
\let\theparentequation\theequation
After that we look for every ocurrence of equation
and change it to parentequation
:
\patchcmd{\theparentequation}{equation}{parentequation}{}{}
At this point we don't need the \def
inition of \theparentequation
inside the subequations
environment anymore:
\usepackage{etoolbox}
% let \theparentequation use the same definition as equation
\let\theparentequation\theequation
% change every occurence of "equation" to "parentequation"
\patchcmd{\theparentequation}{equation}{parentequation}{}{}
\renewenvironment{subequations}{%
\refstepcounter{equation}%
% \def\theparentequation{\arabic{parentequation}}% we patched it already :)
\setcounter{parentequation}{\value{equation}}%
\setcounter{equation}{0}%
\def\theequation{\theparentequation\alph{equation}}%
\ignorespaces
}{%
\setcounter{equation}{\value{parentequation}}%
\ignorespacesafterend
}
\nextParentEquation
Let me also define the command \nextParentEquation
that increments parentequation
and resets equation
so that we don't have to do this manually.
\newcommand*{\nextParentEquation}{%
\stepcounter{parentequation}\setcounter{equation}{0}%
}
Workaround for parentequation
labels (by OP Mobius Pizza)
While \label
directly after \begin{subequations}
works for referencing the first parent equation, to enable it to work after \nextParentEquation
it is necessary to define a alias command \parentlabel
for example, to evade sanitation performed by amsmath
:
\let\parentlabel\label
Addition by Qrrbrbirlbel
I didn't think of labeling the parentequations, but with OP's addition (see above), I would even go a step further and redefine the subequations
environment and the \nextParentEquation
so that they take on optional argment, the label's name.
Code
This MWE uses report
with one \chapter
to demonstrate that \thechapter.
doesn't get lost while redefining the subequations
environment, this also works with article
, of course.
\documentclass{report}
\usepackage{amsmath}
\usepackage{etoolbox}
% let \theparentequation use the same definition as equation
\let\theparentequation\theequation
% change every occurence of "equation" to "parentequation"
\patchcmd{\theparentequation}{equation}{parentequation}{}{}
\renewenvironment{subequations}[1][]{% optional argument: label-name for (first) parent equation
\refstepcounter{equation}%
% \def\theparentequation{\arabic{parentequation}}% we patched it already :)
\setcounter{parentequation}{\value{equation}}% parentequation = equation
\setcounter{equation}{0}% (sub)equation = 0
\def\theequation{\theparentequation\alph{equation}}%
\let\parentlabel\label% Evade sanitation performed by amsmath
\ifx\\#1\\\relax\else\label{#1}\fi% #1 given: \label{#1}, otherwise: nothing
\ignorespaces
}{%
\setcounter{equation}{\value{parentequation}}% equation = subequation
\ignorespacesafterend
}
\newcommand*{\nextParentEquation}[1][]{% optional argument: label-name for (first) parent equation
\refstepcounter{parentequation}% parentequation++
\setcounter{equation}{0}% equation = 0
\ifx\\#1\\\relax\else\parentlabel{#1}\fi% #1 given: \label{#1}, otherwise: nothing
}
\begin{document}
\chapter{Test}
\begin{equation}
0 \neq 1
\end{equation}
\begin{subequations}[eq:2]% or: \label{eq:2}
\begin{align}% or: \parentlabel{eq:2}
A & = B+1 \label{eq:2a} \\
B+1 & = C \label{eq:2b}
\intertext{therefore}\nextParentEquation[eq:3]% or: \nextParentEquation\parentlabel{eq:3}
A & = C \label{eq:3a} \\
B & = C-1 \label{eq:3b}
\end{align}
\end{subequations}
\eqref{eq:2}: \eqref{eq:2a}, \eqref{eq:2b} \\ \eqref{eq:3}: \eqref{eq:3a}, \eqref{eq:3b}
\begin{equation}
1 \neq 2
\end{equation}
\end{document}
Output
As you mentioned, use subequations
outside the align
environment and use some box manipulation to align the equations horizontally:
\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{subequations}
\begin{align}
A &= B+1 \\
B+1 &= C
\end{align}
\end{subequations}
\vspace*{-\belowdisplayshortskip}
\noindent therefore
\vspace*{-\abovedisplayshortskip}
\begin{subequations}
\begin{align}
\phantom{B+1}\llap{$A$} &= C \\
B &= C-1
\end{align}
\end{subequations}
\end{document}
The maximum length of the LHS of the top set of sub-equations is longer/wider than that of the bottom. So, we insert a \phantom{<longest LHS>}\llap{$<LHS>$}
into the second set of sub-equations to make up for this horizontal difference in length.
The additional vertical adjustments make the representation more compact with the break of the short therefore
text.