In a book with chapters and sections, I would like to number (and \label for possible reference elsewhere) the exercises at the end of each section as, for example, Exercise 1.2.3, for the third exercise at the end of the second section in the first chapter. It needs to be "dynamic" so that everything is automatically adjusted in the event that I add other exercises, move sections or chapters, etc. (I've already \labeled each chapter and each section.)
Assuming the sections are already numbered as chapter.section, you should be able to declare
\counterwithin{exercise}{section}
in the document preamble after whatever package you use to set up exercises. Check that package documentation to see if it offers an option to do this by itself.
You can separately control the display of the number and whether the counter gets reset every section by using two separate declarations
\renewcommand\theexercise{\thechapter.\thesection.\arabic{exercise}}
for the formatting and
\makeatletter
\@addtoreset{exercise}{section}
\makeatother
for the resetting.
-
1
-
Ha! Thanks from an oldie, to whom 2018 is like yesterday. I'll add it to answer, if you don't mind. – Donald Arseneau Jul 2 '20 at 9:37
-
\label
in the definition ofexercise
environment. A complete example is welcome. – muzimuzhi Z Jul 2 '20 at 2:14\label
-\ref
system is fully dynamic, in the sense that a couple of recompile rounds will full update the cross-reference call-outs. If I understand your query correctly, though, you seem to be asking for a rather different type of "dynamic" -- viz., making the argument of a\label
instruction (and off all related\ref
instructions too!) associated with an exercise environment adjust so that it incorporates the current number of the exercise. If this interpretation is correct, the only sane piece of advice that can be given is, "Don't Even Think About Doing This." – Mico Jul 2 '20 at 4:51exercise
environment is defined. – Mico Jul 2 '20 at 4:54\label
command or do you refer to the exercise number? – leandriis Jul 2 '20 at 5:45