# How to customize the exercise package?

\documentclass[a4paper,11pt]{book}
\usepackage{hyperref}

\begin{document}
{

\tableofcontents
\mainmatter

\chapter{Classical physics}
\section*{The good old days}
For every $\epsilon>0$
\begin{Exercise}[label={afaff}, name={Exercice}, difficulty={1}]
sfsf
\end{Exercise}
aggsg f

\chapter{Modern physics}
\section*{Departure from classical physics}
There exists a $\delta>0$
\begin{Exercise}[label={dghd}, name={Exercice}, difficulty={2}]
b7dyfas789
\end{Exercise}
hjsdgfkihsk

\chapter{Neoclassical physics}
\section{Guess who's back}
\begin{Exercise}[label={NQCD}, name={Exercice}, difficulty={3}]
skjhfkshf
\end{Exercise}
b78asghfkighkia

\part{Exercises}
\shipoutExercise

\part{Solutions}

\end{document}


In the last two parts, the exercises are shown without any reference to the chapters. How can I make them like this:

Chaptername

its exercises

chaptername

its exercises

etc

• Welcome to TeX.SX. Another package you could try out is xsim. – Johannes_B Dec 22 '18 at 12:51
• @Johannes_B It seems good I never used it but I already wrote hundreds of exercises using the exercise package. – Trump Dec 22 '18 at 12:56
• Do you mean "customize"? I hope you mean "costumize". – Benjamin McKay Dec 22 '18 at 13:41
• You can use this answer to get the number of exercises. – Paracosmiste Dec 25 '18 at 12:41

Maybe you would like to number to exercises within chapters.

I've used xassoccnt to print the total number of exercises.

I've modified \ExerciseHeader and \AnswerHeader to print the Chapter number and name before its exercises when you ship out them.

\documentclass[a4paper,11pt]{book}
\renewcommand{\ExerciseName}{Exercice}
\usepackage{totcount}
\regtotcounter{Exercise} % register the counter for getting the total
\usepackage{chngcntr}
\counterwithin{Exercise}{chapter}
\usepackage{xassoccnt}
\NewTotalDocumentCounter{totalex}
\usepackage{titleref}
\usepackage{etoolbox}

\usepackage{hyperref}

\begin{document}
This document contains \TotalValue{totalex} solved exercises.

\tableofcontents
\mainmatter

\chapter{Classical physics}
\makeatletter

\makeatother
\section*{The good old days}
For every $\epsilon>0$
\begin{Exercise}[label={afaff}, difficulty={1}]
sfsf
\end{Exercise}
aggsg f
\begin{Exercise}[difficulty={2}]
another exercise
\end{Exercise}
\begin{Exercise}[difficulty={1}]
one more exercise
\end{Exercise}
\chapter{Modern physics}
\section*{Departure from classical physics}
There exists a $\delta>0$
\begin{Exercise}[label={dghd}, difficulty={2}]
b7dyfas789
\end{Exercise}
hjsdgfkihsk

\chapter{Neoclassical physics}
\section{Guess who's back}
\begin{Exercise}[label={NQCD}, difficulty={3}]
skjhfkshf
\end{Exercise}
b78asghfkighkia

\part{Exercises}
\shipoutExercise

\part{Solutions}

• @Trump Have you copied in your doc also these lines usepackage{chngcntr} \counterwithin{Exercise}{chapter} \counterwithin{Answer}{chapter}? – CarLaTeX Dec 30 '18 at 19:13
• @Trump Have you got this line \renewcommand{\ExerciseHeader}{ \stepcounter{totalex}\ifnumcomp{\value{Exercise}}{=}{1}{\ifnumcomp{\thechapter}{=}{1}{}{\vspace{10pt}}\noindent\Large\textbf{Chapter\ \thechapter\ \currenttitle}\par\vspace{10pt}}{}\noindent\normalsize\bfseries\ExerciseName\ \ExerciseHeaderNB\ \ExerciseHeaderDifficulty\par\medskip}  in your actual document? – CarLaTeX Jan 1 at 17:48