1

As I understand it, equation can also be used without amsmath, but in the user's guide of amsmath I read that equation is integrated in the amsmath package. Would it make a difference if I used equation with or without amsmath?

7
  • 2
    Yes, it would make a difference. Without amsmath, equation is just $$\refstepcounter {equation}, with amsmath you'll get \incr@eqnum \mathdisplay@push \st@rredfalse \global \@eqnswtrue \mathdisplay {equation}
    – Skillmon
    Jun 28, 2021 at 18:17
  • Thanks for your answer @Skillmon Could you please show me an example? Jun 28, 2021 at 18:19
  • 1
    Well, that's not really an answer, as it doesn't highlight the effects of such differences. It's just the two definitions used with and without amsmath.
    – Skillmon
    Jun 28, 2021 at 18:20
  • Would the same also apply to \begin{equation} \end{equation} with and without amsmath? Or does that make no difference here? Jun 28, 2021 at 18:23
  • 1
    \begin{equation} calls \equation (while doing some other stuff and house keeping), so, yes, this applies to the usage as an environment. Btw. the code used in \end{equation} also differs.
    – Skillmon
    Jun 28, 2021 at 18:27

1 Answer 1

4

If we try comparing the output of LaTeX with and without amsmath and with fleqn and leqno (8 possible combinations) on the following document¹:

\begin{document}
And
\begin{equation}
  y=mx+b
\end{equation}

And here's a long line that es at least two-thirds of the width of the page.
\begin{equation}
  y=mx+b
\end{equation}

\end{document}

So what's going on with the differences in the definitions:

Default LaTeX²,³:

\newenvironement{equation}{$$\refstepcounter{equation}} ❶
    {\eqno \hbox{\@eqnnum}$$\@ignoretrue} ❷

amsmath.sty:

\renewenvironment{equation}{%
  \incr@eqnum ❸
  \mathdisplay@push ❹
  \st@rredfalse ❸
  \global\@eqnswtrue ❸
  \mathdisplay{equation}% ❹
}{%
  \endmathdisplay{equation}% ❹
  \mathdisplay@pop ❹
  \ignorespacesafterend ❺
}

The default declaration isn't terribly complicated: It uses the plain TeX convention of $$$$ to mark display math⁴ It uses \refstepcounter{equation} ❶ to increase the counter number and make sure that we'll get the equation number if we put a \label inside the equation environment. In the closing ❸ \eqno is a primitive which indicates that whatever comes afterwards should be treated as an equation number, \hbox{\@eqnum} actually prints the equation number and \@ignoretrue makes sure that we don't need to worry about LaTeX thinking that the space after \end{equation} is significant.

So why does it look so different in amsmath.sty? Well, some of this is around fixing some issues with equation numbering that can occur, particularly given amsmath’s ability to suppress an equation number that might otherwise be printed with \notag.⁵ This is what's happening with the lines marked ❸.⁶

The lines marked ❹ are a more complicated version of the LaTeX kernel's entering and leaving math with $$. In practical terms, the big difference is going to be in an error context. If we run the following with plain LaTeX and with amsmath:

And
\begin{equation}
  y=mx+b
And here's a long line that es at least two-thirds of the width of the page.
\begin{equation}
  y=mx+b \notag
\end{equation}

plain LaTeX will respond with:

! Missing $ inserted.

while amsmath will give

! LaTeX Error: Bad math environment delimiter.

The final line ❺ is identical in functionality to the LaTeX kernel's \@ignoretrue.⁷

The other place where this functionality comes into play is if you have nested displayed math. “What?” You might say. “Impossible!” And you’d be forgetting that LaTeX users eat impossible for breakfast. That said, while the comments talk about this, the formatting that comes out of such a thing is identical in both plain LaTeX and with amsmath and arguably incorrect in both. I'll let you run it yourself to see:

\begin{equation}
  \begin{minipage}{.5\linewidth}
    \begin{equation}
      y=mx+b
    \end{equation}
    \begin{equation}
      y=mx+b
    \end{equation}
  \end{minipage}
\end{equation}

Update Found one more difference on the margins. If you're using the leqno document option to have equation numbers on the left side and LaTeX cannot fit both the equation number and the equation on a single line, then with amsmath the equation number goes above the equation while with plain LaTeX the equation number goes below the equation.


  1. The two equations are there to compare whether, for a centered display math, the spacing will be the same after a short line and after a long line. By default, TeX assumes that less vertical space is needed if the last line of the paragraph before a [centered] displayed equation is shorter than a designated threshold.

  2. If you look at the source code, LaTeX actually defines \equation and \endequation with \def rather than using \newenvironment, but for the sake of making comparisons easier, I've regularized the definitions here.

  3. For the sake of simplicity, I'm going to skip over the flush left equation case, since this is already going to get complicated enough.

  4. The difference between \[\] and $$$$ has been done to death here already. Look it up yourself.

  5. As for why someone would use \notag in an equation environment in the first place, 🤷🏻‍♂️.

  6. For the sake of brevity, I won't get into the weeds of amsmath‘s handling of equation tags.

  7. Ok, I lied again. The kernel does in fact have the definition: \let\ignorespacesafterend\@ignoretrue but if for some reason you're running a LaTeX kernel older than 26 July 1996, it will define its own version which is \global\@ignoretrue which LaTeX will happily parse except that @ignore isn't defined with \newif, but is instead manually defined so that \@ignoretrue is always global and TeX doesn't object to seeing \global\globalassignment⟩ in the input stream.

1

You must log in to answer this question.

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