2
\documentclass[a4paper,11pt]{book}
\usepackage{hyperref}
\usepackage[lastexercise,answerdelayed,exercisedelayed]{exercise}
\renewcommand{\AnswerName}{Exercise}


\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}
\begin{Answer}
aggsg f
\end{Answer}


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


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


\part{Exercises}
\shipoutExercise

\part{Solutions}
\shipoutAnswer


\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

Trump
  • 23

1 Answers1

1

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}
\usepackage[lastexercise,answerdelayed,exercisedelayed]{exercise}
\renewcommand{\ExerciseName}{Exercice}
\renewcommand{\AnswerName}{Exercice}
\usepackage{totcount}
\regtotcounter{Exercise} % register the counter for getting the total
\usepackage{chngcntr}
\counterwithin{Exercise}{chapter}
\counterwithin{Answer}{chapter}
\usepackage{xassoccnt}
\NewTotalDocumentCounter{totalex}
\usepackage{titleref}
\usepackage{etoolbox}
\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}
\renewcommand{\AnswerHeader}{\ifnumcomp{\value{Exercise}}{=}{1}{\ifnumcomp{\thechapter}{=}{1}{}{\vspace{10pt}}\noindent\Large\textbf{Chapter\ \thechapter\ \currenttitle}\par\vspace{10pt}}{}\noindent\normalsize\bfseries\AnswerName\ \ExerciseHeaderNB\ \ExerciseHeaderDifficulty\par\medskip}

\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}
\begin{Answer}
aggsg f
\end{Answer}
\begin{Exercise}[difficulty={2}]
another exercise
\end{Exercise}
\begin{Answer}
another answer
\end{Answer}
\begin{Exercise}[difficulty={1}]
one more exercise
\end{Exercise}
\begin{Answer}
one more answer
\end{Answer}
\chapter{Modern physics}
\section*{Departure from classical physics}
There exists a $\delta>0$
\begin{Exercise}[label={dghd}, difficulty={2}]
b7dyfas789
\end{Exercise}
\begin{Answer}
hjsdgfkihsk 
\end{Answer}

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

\part{Exercises}
\shipoutExercise

\part{Solutions}
\shipoutAnswer

\end{document}

enter image description here

enter image description here

CarLaTeX
  • 62,716
  • Thank you. Just one more thing. The exercises are numbered continuously without the chap number. So in this example chap 3 begins with exercise 5. – Trump Dec 30 '18 at 19:08
  • @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
  • If I add them the exercises are numbered with chapter number. If I remove them the exercises are numbered continuously but only the name of the first chapter appears in the exercises part. – Trump Jan 01 '19 at 17:45
  • @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 01 '19 at 17:48
  • Yes I get this. – Trump Jan 01 '19 at 17:50
  • @Trump But what I see is the output without the numbering within the chapter, if you want a continuous numbering all along the document, my code has to be changed, I test the number 1 to understand if it is the first exercise of the chapter. If you want the continuos numering you have to use a boolean like \newboolean{firstanswerofthechapter} here: https://tex.stackexchange.com/a/371320/101651. – CarLaTeX Jan 01 '19 at 18:00