I'm writing up some lecture notes for a math course in LaTeX (using the book class so far, but I may change that), and as I do so possible homework exercises occur to me which I want to include in the notes. I haven't decided whether to put exercises at the end of each section or the end of each chapter, and in either case exercises may need to move along with associated text if I change my mind about the organization of topics.
(I don't want to intersperse the problems throughout the text, which would of course be the technically simplest solution.)
Ideally, it would be nice to be able to handle this in more or less the following way: in the .tex file, immediately after the text about topic A, I write \exercise{Problem about A}, which produces no immediate output. At some later point, I write \exerciseshere, which produces an enumerated list, with a heading like "Exercises", of all the exercises since the previous \exerciseshere. Alternatively, a command in the preamble allows me to set whether a list of exercises is produced automatically at the end of each section or the end of each chapter (keeping in mind that if there are no exercises, nothing should be done).
Added: It would also be good to be able to include a \label in an exercise, which could be used to refer to its counter in the enumerated list.
How can something like this be implemented? Or is there even already a package that does it?
P.S. I couldn't come up with a very informative title or tag for this question. Please feel free to retitle or retag.
