When I use \equation...\endequation instead of \begin{equation}...\end{equation}, all equations have the same number (I know this isn't best practice for environments; I'm trying to understand the underlying behavior), as in the following example.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
The first equation is
\equation
\label{pyth} a^2 + b^2 = c^2.
\endequation
The second equation is
\equation
\label{quad} x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}.
\endequation
Referenced in order: \eqref{pyth} and \eqref{quad}.
\end{document}
While debugging, I've found three ways to fix it, but I have no idea why they work.
1. If I append \usepackage[colorlinks]{hyperref} to the preamble, on my first compilation I get the error message ! Argument of \Hy@setref@link has an extra }, but when I compile again, there's no error, and the equations are numbered correctly:
2. If I comment out \usepackage{amsmath} (and replace \eqref with \ref), the equations are numbered correctly, even without hyperref.
3. Since \begin{...} and \end{...} build a group, as mentioned in this post, I tried providing my own group:
The first equation is
\begingroup
\equation
\label{pyth} a^2 + b^2 = c^2.
\endequation
\endgroup
The second equation is
% Only the first one needs to be in a group
\equation
\label{quad} x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}.
\endequation
This also numbers the equations correctly, which was interesting, because I don't a priori know how equation numbering is related to groups.
Thus, my question is: what differences between \equation...\endequation and \begin{equation}...\end{equation} cause these to solve this problem? Why do these solutions work?


\equationand\endequationin the body of a document. – egreg Dec 30 '15 at 22:59\equationand\endequationwere part of macros that I had defined in the preamble. But I don't know why includinghyperrefor adding\begingroup...\endgroupchanges anything, and would like to understand that. – Arun Debray Dec 30 '15 at 23:03\equationform produces anything at all it is by accident not design. – David Carlisle Dec 30 '15 at 23:05