subequations
seems to only work outside environments such as align
and equation
. What if I want to preserve the alignment of the equal signs using align
while also would like subequations
numbering within, such as:
\begin{align}
\begin{subequations}
A &= B+1 \\
B+1 &= C
\end{subequations}
\intertext{therefore}
\begin{subequations}
A &= C \\
B &= C-1
\end{subequations}
\end{align}
Which generates multitude of errors 🙁
Best Answer
The
subequations
environment & theparentequation
counterThe original
subequations
environment redefines\theparentequation
in a way that it is independent from the counterparentequation
:But we can redefine the
subequations
environment so that only the value ofequation
is saved and\theparentequation
uses the counterparentequation
again:But that way we would loose the setting of
\theequation
that might involve\thechapter
in classes likebook
. For this, we could change it again manually toetoolbox
and\patchcmd
Another approach uses
etoolbox
and its\patchcmd
macro.First we let
\theparentequation
be the same as\theequation
:After that we look for every ocurrence of
equation
and change it toparentequation
:At this point we don't need the
\def
inition of\theparentequation
inside thesubequations
environment anymore:\nextParentEquation
Let me also define the command
\nextParentEquation
that incrementsparentequation
and resetsequation
so that we don't have to do this manually.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 byamsmath
: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 thesubequations
environment, this also works witharticle
, of course.Output