# Why does equation environment not give an error without the amsmath package?

As far as I understand the equation environment is defined in the amsmath package so one would expect an error while trying to compile the following document with pdflatex:

\documentclass{article}

\begin{document}

$$a=b+c$$

\end{document}


But I don't get any error while running pdflatex on this file an a pdf output with the equation a + b = c is generated. How does that work exactly?

• @DarthPaghius Why's it a problem? The equation environment is part of the kernel. – Joseph Wright Dec 8 '17 at 7:41
• @JosephWright But every resource I looked at says its a part of ams math package. Is the amsmath overriding the kernel one? – DarthPaghius Dec 8 '17 at 7:42
• Btw, +1, it's a very good question and I'm sure some TeXpert will answer soon. amsmath is a package which does many useful in math, but for a simple equation like the one of your MWE, the TeX kernel is enough. – CarLaTeX Dec 8 '17 at 7:42
• @DarthPaghius I'm sure that some of the top users here will give you an exemplary answer! And, of course, most people don't care how things work but only why they don't work. You're very clever :):):) – CarLaTeX Dec 8 '17 at 8:05
• @Mico It's also possible I involuntary removed it, the important thing is you read it :):):) Good morning, TeXnician! – CarLaTeX Dec 9 '17 at 7:34

You wrote:

As far as I understand the equation environment is defined in the amsmath package

That's not quite correct. The equation environment is defined in the LaTeX kernel -- and it is redefined if the amsmath package is loaded in the preamble.

For completeness, here's the relevant code from the file latex.ltx (the "kernel"):

\@definecounter{equation}
\def\equation{$$\refstepcounter{equation}} \def\endequation{\eqno \hbox{\@eqnnum}$$\@ignoretrue}
\def\@eqnnum{{\normalfont \normalcolor (\theequation)}}


where \eqno is a so-called "primitive" instruction that takes \hbox{\@eqnnum} as its argument. Basically, \equation initiates display-math mode and increments a counter called equation, while \endequation typesets the equation number (on the far right, by default) and closes display-math mode.

And here's the code from amsmath.sty; note that due to the \renewenvironment instruction, the code replaces what the kernel provides:

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


This setup is, quite obviously, rather more elaborate than what's performed in the LaTeX kernel. The most important substantive differences arise from the fact that, if amsmath is loaded, it becomes possible to insert split, aligned, and gathered environments inside an equation environment. In addition, amsmath performs some fancy measuring operations, behind the scenes, to figure out if it's necessary to "shove" the equation number down a bit in order to avoid a collision with an overly long equation.

If you're really interested in the details, I would like to encourage you to examine the information contained in the file amsmath.pdf. Open a command window and type texdoc amsmath.pdf to launch the file in a pdf viewer.

• Thanks for the detailed answer. It was never explicitly mention in the places I looked. – DarthPaghius Dec 8 '17 at 8:27
• @DarthPaghius - You're most welcome! – Mico Dec 8 '17 at 8:32
• @Mico -- the preferred (by knuth, among others) term for someone really knowledgeable about using tex is "TeXnician". and regarding amsmath documentation, a better way to study it is from the commented equivalent of amsmath.sty, namely amsmath.pdf. at a command prompt on a tex live system: texdoc amsmath.pdf – barbara beeton Dec 8 '17 at 13:56
• @Mico -- yes, i realize the potential for naming confusion. fortunately, i don't have to worry about that -- i have a certificate prepared and signed by don knuth that declares me to be an "international TeXnocrat". (i'm still not sure whether that's a good or a bad thing ...) – barbara beeton Dec 8 '17 at 14:33
• @barbarabeeton I used TeXpert first in this post, I didn't know that the preferred term is TeXnician! – CarLaTeX Dec 8 '17 at 15:04