1

I'm writing a book which includes exercises spreaded through its chapters. To typeset the exercises I'm using the exsheets package. I want to make an appendix with all the solutions listed per chapter (and I've been aware this wasn't possible, according to Exsheets: how do I print the 'solutions' on the same line?).

I've seen that the newest version of exsheets has a chapter-hook option that, according to the manual (found at http://ctan.mirrors.hoobly.com/macros/latex/contrib/exsheets/exsheets_en.pdf.):

[chapter-hook = {code}] Adds "code" to the list of solutions every time solutions from a new chapter are printed (before the solutions of the corresponding chapter are printed).

The problem is that it's the only mention of chapter-hook the author makes, with no particular examples, so I don't even know where to put the option.

I've tried with the following:

\chapter{Grouped Exercises I}
\begin{question}
    Integrate $\int \cos{x}\ \mathrm{d}x$
\end{question}
\begin{solution}
    $\sin{x} + C$
\end{solution}
% ...
% more code here
% ...
\appendix
\chapter{Solutions to exercises}
\printsolutions[all,chapter-hook={Chapter}]

but when compiling with pdfLaTeX, it throws the error:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! LaTeX error: "kernel/key-choice-unknown"
! 
! Key 'exsheets/exsheets_print_solutions/chapter-hook' accepts only a fixed
! set of choices.
! 
! See the LaTeX3 documentation for further information.
! 
! For immediate help type H <return>.
!...............................................  

l.6 \printsolutions[all,chapter-hook={Chapter}]

What to do? How's the correct way of using chapter-hook option under these circumstances?

Thanks in advance!

  • Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Jun 01 '14 at 08:33
  • There is no exercise environment in exsheets, as far as I know and understood the manual, it should rather read \begin{question}...\end{question}. Furthermore you do not use any mathematical mode for your math question –  Jun 01 '14 at 09:02
  • exsheets uses LaTeX3 syntax, I am not familiar with that, but looking into the code and using the error message, there is possibly a bug, where chapter-hook is treated as a choice-key whereas it is intended to be a command-key. –  Jun 01 '14 at 09:04
  • @cgnieder: Perhaps you can provide some help? –  Jun 01 '14 at 09:17
  • I updated the linked question with an example for section-hook @ChristianHupfer users only get notified in comments if they already have commented on a question/answer. It's easier to ping me in chat. – cgnieder Jun 01 '14 at 10:39
  • @cgnieder: Sorry about the "missing" notification. You already provided a solution, I obtained the version 0.13 (2014/05/11) from CTAN. –  Jun 01 '14 at 17:08
  • @ChristianHupfer, sorry about the mistakes on the example! I wrote it "on the fly", and couldn't checked it for mistakes. I've just edited the question to correct these changes. Thanks for noticing! – logo_writer Jun 01 '14 at 18:11

1 Answers1

2

Are you using TeX Live? The new options were introduced in version 0.13 (2014/05/11) which is not part of TL2013 (it was published after the freeze I believe). You either have to update exsheets manually or wait for TL2014 (or use the pretest version).

Either way: below is an example how the option could be used.

enter image description here

\documentclass{scrbook}
\usepackage{exsheets}[2014/05/11]
\SetupExSheets{
  counter-within = chapter
}
\DeclareQuestionProperty{chapter-number}

\newcommand*\diff[1]{\mathop{}\!\mathrm{d}#1}

\begin{document}

\chapter{Some Chapter}\label{ch:foo}
\section{foo}
\section{Grouped Exercises I}
\begin{question}
  \SetQuestionProperties{chapter-number=\ref{ch:foo}}
  Integrate $\int \cos x \diff{x}$.
\end{question}
\begin{solution}
    $\sin x + C$
\end{solution}

\chapter{Some Other Chapter}\label{ch:bar}
\section{bar}
\section{Grouped Exercises II}
\begin{question}
  \SetQuestionProperties{chapter-number=\ref{ch:bar}}
  Integrate $\int \sin x \diff{x}$.
\end{question}
\begin{solution}
    $-\cos x + C$
\end{solution}

\appendix
\SetupExSheets{
  chapter-hook =
    \section*{Exercises from chapter~\GetQuestionProperty{chapter-number}{\CurrentQuestionID}}
}

\chapter{Solutions to exercises}
\printsolutions

\end{document}
cgnieder
  • 66,645