# Equation numbering within each theorem

I want the equations numbered within each theorem. So the first equation in each theorem is numbered (1), continued to its proof. For example,

Theorem: The equation

(1) x+y=z

is ...

Proof: We have

(2) x=z-y

so ...

But in the next theorem, the numbering restarts to (1) again. How to produce such numbering?

-

You could load the `etoolbox` package and provide the following commands in the preamble -- best after any theorem-related packages, such as `amsthm` or `ntheorem`, are loaded and a theorem-like environment is set up.

``````\usepackage{etoolbox}
\AtBeginEnvironment{theorem}{\setcounter{equation}{0}}
``````

I can't help but observe that such a setup is quite likely to create quite a bit of confusion among your readership, because there will likely be multiple equations (1), (2), etc., right? How are you going to cross-reference multiple equations (2), say, that occur in Theorems 3, 4, and 5?

Assuming that in your document equations occur only in the statements of theorems and their proofs, and assuming further that you also load the `amsmath` package, you may instead wish to issue the command

``````\numberwithin{equation}{theorem}
``````

This will number the equations as (1.1), (1.2), ... for Theorem 1, as (2.1), (2.2), ... for Theorem 2, etc.

Addendum prompted in part by @egreg's comment: The first approach, in addition to likely causing some confusion among your readers, might cause some oddities if you happen to load the `hyperref` package as well. Hyperref's mechanisms by default will try to link all cross-references to `equation (1)` to the first such equation in the document, even if the labels used in the cross-referencing commands actually refer to other equations which happen to be also numbered "1". One can solve this immediate problem via the method recommended by @egreg, i.e., with

``````\renewcommand{\theHequation}{\thetheorem.\arabic{equation}}
``````

But you'll still be stuck risking massive confusion among your readers when they encounter a statement such as "As was established by equations (1), (1), and (1) of the preceding theorems, ...".

-