# How to number equations within theorem-like environments

I want to enumerate equations within theorem-like environments.

Example:

\documentclass[a4paper,10pt]{article}
\usepackage{amsmath,amsthm}
\newtheorem{theo}{Theorem}[section]
%
\begin{document}
\section{Natural Numbers}
\begin{theo}
$$\label{eq:1} 1+1=2.$$
\begin{proof}
The proof of the equation~\eqref{eq:1} is left as an exercise.
\end{proof}
\end{theo}
\end{document}


And produce something like

-
Your code has some (easy to fix) errors and won't work. Please fix it. On your question, how would you number equations that appear outside a theorem? –  Gonzalo Medina May 20 '12 at 17:23
My purpose is enumerate equations only in the proofs; because outside I use an 'observation' environment or just  –  Paulo H May 20 '12 at 17:26
I've updated my answer providing a simpler solution. –  Gonzalo Medina May 20 '12 at 17:46

Once amsmath has been loaded, you can use

\numberwithin{equation}{theorem}


A complete example:

\documentclass[a4paper,10pt]{article}
\usepackage{amsmath,amsthm}

\newtheorem{theo}{Theorem}[section]
\numberwithin{equation}{theo}

\begin{document}

\section{Natural Numbers}
\begin{theo}
$$\label{eq:1} 1+1=2.$$
\begin{proof}
The proof of the equation~\eqref{eq:1} is left as an exercise.
\end{proof}
\end{theo}

\end{document}


-

If you're sure that you'll be using numbered equations only within theorem environments (and other theorem-like environments) and if you're loading the amsmath package, you could issue the command

\numberwithin{equation}{theorem}


where theorem is the environment set up with a \newtheorem statement.

If you have several theorem-like environments, be sure to have them share the same counter. How to do this depends strongly on the theorem package that's in use. For the amsthm package, you'd force the lemma, corollary, etc environments to use the same counter as theorem environments do by issuing commands such as

\usepackage{amsmath,amsthm}
\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corrolary}[theorem]{Corollary}
\numberwithin{equation}{theorem}


By the way, don't use the deprecated $$...$$ method to create unnumbered display-style equations. Instead, use something like \begin{equation*} ... \end{equation*}. Among other good things, the spacing around displayed equations will become much better.

-