4

Is it possible to have amsmath automatically number equations in "subequations" style, when a multiline construct like

\begin{align}
E &= m c^2 \\
c^2 &= a^2 + c^2
\end{align}

is encountered?

Using the subequations environment explicitly is useful, when it is necessary to refer to a group of equations. When the only reason for using it is a style requirement, that successive equations should be numbered as (13a), (13b), etc., it would however be nice to have this automated away.

Additionally, this would be extremely useful in LyX, where using the Subequations module breaks the layout of the live-preview.

2

Not a good idea, in my opinion. If LyX is not able to cope with subequation, then don't use it or ask its developers to fix it.

Anyway, you can do it:

\documentclass{article}
\usepackage{amsmath}
\usepackage{etoolbox}

\makeatletter
\let\endalignnosub\endalign
\renewenvironment{align*}{\start@align\@ne\st@rredtrue\m@ne}{\endalignnosub}
\renewenvironment{alignat*}{\start@align\z@\st@rredtrue}{\endalignnosub}
\renewenvironment{xalignat*}{\start@align\@ne\st@rredtrue}{\endalignnosub}
\renewenvironment{flalign*}{\start@align\tw@\st@rredtrue\m@ne}{\endalignnosub}
\appto\endalign{\endsubequations}
\preto\align{\subequations}
\preto\alignat{\subequations}
\preto\xalignat{\subequations}
\preto\flalign{\subequations}
\let\endgathernosub\endgather
\renewenvironment{gather*}{\start@gather\st@rredtrue}{\endgathernosub}
\preto\gather{\subequations}
\appto\endgather{\endsubequations}
\makeatother

\begin{document}

\begin{align}
a &= b \\
c &= d
\end{align}

\begin{align*}
a &= b \\
c &= d
\end{align*}

\end{document}

It's necessary to change all environments, because they depend on \endalign, so one cannot just change it.

But don't. Really.

enter image description here

  • This solution works pretty well (except that I add a \appto\subequations{\let\subequations\relax} to allow \begin{subequations}\label{eq:equation-group}\begin{align}... without getting labels (1aa), (1ab), (1ac)...). But is there maybe some solution, that still allows using \begin{align} \notag hello \\ & world \end{align} without getting (1a) instead of (1) as the label? – kdb Nov 7 '18 at 15:31
  • 1
    @kdb Aha! Now you know why it's not good to do that. Really. ;-) – egreg Nov 7 '18 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.