# Multiline equation, label once and support page break

I want a multiline equation that labeled once and support page break. If I choose

\begin{align}\begin{split}
balabala\\
balabala
\end{split}\end{align}


then the split makes it unable to support page break. I understand that I can use align together with nonumber but I want a smarter way that I don't have to worry. It doesn't matter where the label appears.

A simplified question would be: is there any way that automatically set label on the first line and at the same time the whole equation allows page break?

• Welcome to TeX.SX! If the multi-line equation is labeled only once, wouldn’t a page break cause confusion? I mean, if the whole thing is split across two pages, then which part of the equation the label is to represent? – Ruixi Zhang Jul 20 '18 at 1:15
• This is called visual formatting and should be deferred to the so-called “final revision” of your document/article/book/… It’s usually a mistake to worry prematurely about such issues, because they are likely to disappear when the document is modified and the page breaks change consequently. If you actually are in the final revision phase, the solution could be an align environment with equation numbers manually suppressed on all lines but one by means of \notag. – GuM Jul 20 '18 at 1:16
• @RuixiZhang I see your point but I said it doesn't matter where the label appears, which means it's perfectly fine to me that the label always shows up in the first line (which would have no confusion at all). – RoderickLee Jul 20 '18 at 1:30
• The post I linked in my comment explicitly answered that “[t]he environment split can't handle page breaks”, so you are to replace your split anyway. It also comes with the suggestion from @DavidCarlisle to minimize your commands change. IMHO, there is no simple code that will allow split to page break. And I find the align*+\tag solution is at least better than the align+\notag one. – Ruixi Zhang Jul 20 '18 at 2:14
• @PhelypeOleinik not duplicate. And this question is already well answered below by nox – RoderickLee Jul 20 '18 at 12:54

If I understand you correctly, this is what you are looking for: Some aligned equations that are numbered once in the very beginning (first line) and allow page-breaks? The following code does that.

It uses the align* environment to suppress automatic equation numbering. I wrote the short macro \numberthis which does number the current line of an align* environment and updates the equation counter. Then I patched the align* environment to use it and number the first line. As others mentioned, you also need \allowdisplaybreaks.

\documentclass[12pt,a4paper]{article}
\usepackage{amsmath}
\usepackage{etoolbox}

\usepackage{lipsum}

\newcommand{\numberthis}{\refstepcounter{equation}\tag{\arabic{equation}}}
\expandafter\appto\csname align*\endcsname{\numberthis}
\allowdisplaybreaks

\begin{document}
\begin{align*}
(a+b)^2&=a^2+2ab+b^2\\
(a-b)^2&=a^2-2ab+b^2\\
a^2-b^2&=(a+b)(a-b)
\end{align*}
\lipsum[1-3]
\begin{align*}
(a+b)^2&=a^2+2ab+b^2\\
(a-b)^2&=a^2-2ab+b^2\\
a^2-b^2&=(a+b)(a-b)\\
a&\\
b&\\
c&
\end{align*}

\end{document}


• I’d prefer \newcommand\numberthis{\addtocounter{equation}{1}\tag{\theequation}} by @IanThompson in this answer since it accommodates a numbering style which is not necessarily arabic. However, this post pointed out the potential problem with the cleveref package. – Ruixi Zhang Jul 20 '18 at 4:54
• @RuixiZhang You can change this to your liking, of course. It's worth mentioning that \refstepcounter is usually the preferred way over \addtocounter. While both increase the counter by one, the former enables you to reference to it later by \labeling . The latter doesn't. \chapter, \section, but also floats, use this in order to label them. This is not needed here (correct), as I used \tag already. You still could use \stepcounter{equation} as equivalent of \addtocounter{equation}{1}. – nox Jul 20 '18 at 11:10
• 1) @RuixiZhang’s suggestion of using \theequation is good, but of course \refstepcounter is much better than \addtocounter. 2) It would be preferable to define a new environment with a different name than to redefine align*. – GuM Jul 20 '18 at 11:12
• In this context \refstepcounter does no different from \stepcounter, because a \label in align* refers to \tag. – egreg Jul 22 '18 at 14:50

Please note: This answer serves more as a LaTeX code-improving suggestion than as an attempt to change amsmath’s subordinated math environments. The latter should be discouraged.

## You shouldn’t use subordinated math environments to write multiple equations

Here are two quotes from amsldoc.pdf, the User’s Guide for the amsmath Package:

Section 3.4, p. 6: … [T]he split environment is for single equations that are too long to fit on one line and hence must be split into multiple lines.

and

Section 3.7, p. 9: … [V]ariants gathered, aligned, and alignedat … can be used as a component in a containing expression.

In summary, you shouldn’t use subordinated math environments to write multiple equations, as the subordinates are merely building blocks within other top-level math environments, and the top-levels — such as align, align*, gather, gather*, etc. — are the intended structures for multiple equations.

## You should put your attention on breaking multiple equations

Again, I present two other quotes from the User’s Guide for the amsmath Package:

Section 3.9, p. 10: … When the amsmath package is in use page breaks between equation lines are normally disallowed; the philosophy is that page breaks in such material should receive individual attention from the author. … If you prefer a strategy of letting page breaks fall where they may, even in the middle of a multiline equation, then you might put \allowdisplaybreaks[1] in the preamble of your document.

and in the same section

… Certain equation environments wrap their contents in an unbreakable box[.] … These include split, aligned, gathered, and alignedat.

So I strongly recommend to

1. avoid large chunks of multiple equations;

## Are you putting multiple equations inside subordinated environments which are already inside some multiline top-level environments?

Well, don’t do this. Just use one layer of the top-level environment, whatever that is.

If you write your equations this way, a simple combination of the align* environment and \tag suffices. See, for instance, this answer.

Please note that the answer by @nox is almost identical to that of @IanThompson in the linked post, but the one by @nox will cause all align* to be altered. Are you sure you want to do this?

Added: By combining the comments under @nox’s answer, you may want to use \theequation instead of \arabic{equation}, and to define your own environment for this particular use as suggested by @GuM.

• +1. You may want to think, though, about not using the keyword inner to describe subordinated math environments such as split and aligned. As you probably know (but other readers may be unaware of), inner has a very special meaning in TeX's math-mode world. Maybe use subordinated instead of inner (and top-level instead of outer)? – Mico Jul 20 '18 at 6:16
• @Mico You’re right! I wasn’t thinking about \mathinner when I wrote my answer. Thank you for the suggestions. – Ruixi Zhang Jul 20 '18 at 15:11

I think that @nox’s good answer could be further improved if one defined a new environment, rather than redefining (and hence abusing) align*; I expressed this opinion in a comment, but more than two days have elapsed without the suggestion being accepted, so I dare to submit this additional answer that shows how this can be done. Allow me to stress that this is just an improvement over the solution devised by @nox, whose main credit I’m glad to acknowledge.

Actually, implementing @nox’s solution by means of a new environment may not be entirely straightforward, since deriving new environments from those of amsmath is notoriously tricky. But the trick boils down to a simple hack: just avoid to change the value of \@currenvir inside the code you write. This can be achieved by replacing \begin{FOOENV} and \end{FOOENV} with \FOOENV and \endFOOENV, respectively. In our case, however, the environment we want to use contains a non-letter (an asterisk) in its name, so we must resort to \csanme align*\endcsname, or, which is the same, to \@nameuse{align*}.

Here’s a complete compilable example; further comments can be found in the code itself. I must also withdraw my previous, erroneous remark about the use of \refstepconter: indeed \stepcounter is enough (I had already realized this before @egreg posted his comment!).

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{amsmath}
\usepackage{lipsum} % only for this example (of course!)

\makeatletter

\newenvironment{oddalign}{%
\@nameuse{align*}% or directly "\csname align*\endcsname"
\stepcounter{equation}\tag{\theequation}%
}{\@nameuse{endalign*}} % as above

\makeatother

\allowdisplaybreaks[1] % see amsmath manual, section 3.9

\begin{document}

A normal \texttt{align*} environment (which you might \emph{still} want to use,
of course!):
\begin{align*}
(a+b)^2 &= a^2+2ab+b^2\\
(a-b)^2 &= a^2-2ab+b^2\\
a^2-b^2 &= (a+b)(a-b)
\end{align*}
An example of our new \texttt{oddalign} environment where a page break isn't
needed:
\begin{oddalign}
\label{eq:example1}
(a+b)^0 &= 1 \\
(a+b)^1 &= a+b \\
\begin{split}
(a+b)^2 &= (a+b)(a+b) = a^2+ab+ab+b^2 \\
&= a^2+2ab+b^2
\end{split} \\
\begin{split}
(a+b)^3 &= (a+b)(a+b)^2 = (a+b)(a^2+2ab+b^2) \\
&= a^3+2a^2b+2ab^2+a^2b+2ab^2+b^3 \\
&= a^3+3a^2b+3ab^2+b^3
\end{split} \\
\intertext{and in general}
(a+b)^{n} &= \sum_{k=0}^{n}\binom{n}{k} a^{n-k}b^{k}
\end{oddalign}
Note that our new environment behaves correctly with nested environments (and
with \verb|\intertext|, too).

% Try different alternatives:
% no "\lipsum" at all
% \lipsum[1]
\lipsum[2-3]
% \lipsum[1-3]

We'll now repeat the same code as above in a place where, on the contrary, a
page break \emph{is} needed:
\begin{oddalign}
\label{eq:example2}
(a+b)^0 &= 1 \\
(a+b)^1 &= a+b \\
\begin{split}
(a+b)^2 &= (a+b)(a+b) = a^2+ab+ab+b^2 \\
&= a^2+2ab+b^2
\end{split} \\
\begin{split}
(a+b)^3 &= (a+b)(a+b)^2 = (a+b)(a^2+2ab+b^2) \\
&= a^3+2a^2b+2ab^2+a^2b+2ab^2+b^3 \\
&= a^3+3a^2b+3ab^2+b^3
\end{split} \\
\intertext{and in general}
(a+b)^{n} &= \sum_{k=0}^{n}\binom{n}{k} a^{n-k}b^{k}
\end{oddalign}
Will the next equation be numbered correctly?
$$x=y \label{eq:xy}$$
Yes.

The references are to equations \eqref{eq:example1} and~\eqref{eq:example2},
(and to equation~\eqref{eq:xy}): this is OK\@.  Note, however, that in order for
the references to work correctly, the \verb|\label| commands must be placed at
the very beginning of the \texttt{oddalign} environment.

On second thought, why the name \texttt{oddalign}?  It isn't that odd, after
all!

\end{document}