# Number exercises according to chapter

I'm using the exercise package together with memoir class. How do I number my exercises according to chapter number, in the same way that display equations are numbered? Here's a minimal example

\documentclass{memoir}

\usepackage{mathtools}
\usepackage{exercise}

\begin{document}
\chapter{Foo}
Lorem ipsum dolor sit amet
\begin{Exercise}
This should come out as Exercise 1.1
\end{Exercise}

\begin{Exercise}
This should be Exercise 1.2
\end{Exercise}

\chapter{Bar}
\begin{Exercise}
And this should be Exercise 2.1
\end{Exercise}

\begin{Exercise}
Certainly this should be Exercise 2.2
\end{Exercise}
\end{document}


I'm thinking of tapping into a counter variable in memoir or somewhere else. How do I go about it? I would like the numbering to also affect the Answer environment.

-

I guess that

\usepackage{exercise,chngcntr}
\counterwithin{Exercise}{chapter}


should do what you need. The chngcntr package is used for binding a counter to another or to free one from another (with \counterwithout).

-

The exercise package provides the Exercise counter. Therefore, if you want the exercises numbered according to the chapter counter, you need:

\renewcounter{Exercise}[chapter]% Reset counter every chapter
\renewcommand{\theExercise}{\thechapter.\arabic{Exercise}}%


For any future reference on counters (how to reset them, so-called "master and slave" countering), consider reading the following UK TeX FAQ entries:

-
To help with future applications, what reference manual can I look up usage of \thechapter? (I found \arabic in vim-LaTeX Suite :help arabic) – Kit Sep 4 '11 at 14:48
@Kit: I've added 2 references to my answer. – Werner Sep 4 '11 at 14:54

If you're willing or happy to use the amsmath package, you could also set

\usepackage{amsmath,exercise}