# amslatex theorem numbering

I am writing a report that has in-text exercises as well as end-of-chapter exercises. I want all the exercises to be numbered consecutively. I want the in-text exercises begin with theitalized word "Exercise", followed by the numbering. And for the end-of-chapter ones, I do not have the word "Exercise" in front, just the numbering.

I tried to do this using the \theoremstyle in amstext but the numbering do not come out correctly. Here is a minimal (non)-working example:

\begin{document}
\section{First section}
Cite the second exercise  \ref{two}.  Cite the third exercise \ref{three}.

\begin{exer}  \label{one}   First exercise.    \end{exer}

End of Chapter Exercises

\stepcounter{exer}  \theexer.  \label{two}   Second Exercise.

\stepcounter{exer}  \theexer.  \label{three} Third Exercise.
\end{document}


When I run this code, I end up with the output

Cite the second exercise 1.  Cite the third exercise 1.

Exercise 1.  First exercise.

End of Chapter Exercises.

2.  Second Exercise.

3.  Third Exercise.


which is incorrect. If I replace latex code for the second and the third exercises with

\begin{exer}  \label{two} Second exercise.  \end{exer}

\begin{exer}  \label{three}  Third exercise.  \end{exer}


then the numbering come out correctly, but not in the format I need.

I'm really baffled. Your help is most appreciative. THANKS!

• \refstepcounter is what you need. Be careful with spaces. – egreg Jun 2 at 22:35
• Brilliant! Replacing \stepcounter with \refstepcounter solves my problem. THANKS! Follow up question: Could you elaborate on what you mean by "be careful with spaces"? – underflow Jun 2 at 23:30
• It would be useful if you showed the definition of exer. In this particular case, spaces in the input don't really affect the output, but only because you're lucky. – egreg Jun 2 at 23:41
• oops -- I forgot to cut and paste the definition of exer. Here it is: \theoremstyle{remark} \newtheorem{exer}{Exercise}  – underflow Jun 3 at 0:09

Use \refstepcounter instead of \stepcounter, so that a proper value to be referenced is set.

On the other hand, I'd prefer a more abstract approach:

\documentclass{article}
\usepackage{amsmath,amsthm}

\theoremstyle{remark}
\newtheorem{exer}{Exercise}

\newtheoremstyle{endchapterexer}
{0pt}        % ABOVESPACE
{0pt}        % BELOWSPACE
{\upshape}   % BODYFONT
{0pt}        % INDENT (empty value is the same as 0pt)
\theoremstyle{endchapterexer}
\newtheorem{eexer}[exer]{}

\begin{document}

\section{First section}

Cite the second exercise  \ref{two}.  Cite the third exercise \ref{three}.

\begin{exer}\label{one}
First exercise.
\end{exer}

\subsection*{End of Chapter Exercises}

\begin{eexer}\label{two}
Second Exercise.
\end{eexer}

\begin{eexer}\label{three}
Third Exercise.
\end{eexer}

\end{document}