# show solution after each subquestion using exsheets package

I have a scrbook document with chapters and sections and each section contains a set of questions + solutions (using the exsheets package, with numbering reset in every section; see MWE below). Each question has a set of subquestions, and since the number of subquestions is sometimes quite large, I would like to print the solutions right after the subquestion (instead of printing them all after each question). How can I do that? The MWE below prints the solutions after each question.

P.S. I use enumerate instead of tasks to create the subquestions because the tasks package gives me lost floats errors.

\documentclass{scrbook}
\usepackage[counter-within = section, counter-format=ch.se.qu]{exsheets}
\usepackage{enumitem}
\SetupExSheets{solution/print=true}

\begin{document}
\chapter{first chapter}
first chapter
\section{first section}
first section of first chapter\\

\begin{question}
first question
\begin{enumerate}[label=\alph*)]
\item first subquestion
\item second subquestion
\end{enumerate}
\end{question}

\begin{solution}
\begin{enumerate}[label=\alph*)]
\item solution to first subquestion
\item solution to second subquestion
\end{enumerate}
\end{solution}

\begin{question}
second question
\begin{enumerate}[label=\alph*)]
\item first subquestion
\item second subquestion
\end{enumerate}
\end{question}

\begin{solution}
\begin{enumerate}[label=\alph*)]
\item solution to first subquestion
\item solution to second subquestion
\end{enumerate}
\end{solution}
\end{document}

• One way to do it is to write the solutions to the subquestions right in the question body and forget about the solution environment for that particular question (or for all questions if needed). Of course, you loose some of the exsheets power. So an \item of your enumerate list looks about like this: \item first subquestion \hfill\itshape{solution to first subquestion} %instead of \hfill\... you can use whichever formatting suits your application. I can post an MWE if you want. – alwaysask Nov 4 '14 at 11:05
• Indeed, I can include a \solution environment after each subquestion \item (because I want to retain the option to toggle between yes/no print answers). However, then each solution shows as a solution to the main question (instead of the subquestion). – Sander Nov 4 '14 at 11:17
• @Sander you can only have one solution environment per question environment. Otherwise I cannot guarantee exsheets to work as described... – clemens Nov 5 '14 at 8:20

One possibility – the only one I can think of right now – is using \PrintSolutionT (mentioned in section 11 of the manual, the explanation there is wrong, though...).

\PrintSolutionT{<true code>} and its siblings \PrintSolutionTF{<true code>}{<false code>} and \PrintSolutionF{<false code>} check if the option solution/print has been set to true or false and leave the corresponding code in the input stream. The corresponding code will not be saved (obviously) and cannot be recalled with \printsolutions but if I understood the question correctly that is not what you're after anyway.

\documentclass{scrbook}
\usepackage[counter-within = section, counter-format=ch.se.qu]{exsheets}
\usepackage{enumitem}
\SetupExSheets{solution/print=true}
% or \SetupExSheets{solution/print=false} to hide the answers

\begin{document}
\chapter{first chapter}
first chapter

\section{first section}
first section of first chapter

\begin{question}
first question
\begin{enumerate}[label=\alph*)]
\item first subquestion
\PrintSolutionsT{\par\emph{solution to first subquestion}}
\item second subquestion
\PrintSolutionsT{\par\emph{solution to second subquestion}}
\end{enumerate}
\end{question}

\begin{question}
second question
\begin{enumerate}[label=\alph*)]
\item first subquestion
\PrintSolutionsT{\par\emph{solution to first subquestion}}
\item second subquestion
\PrintSolutionsT{\par\emph{solution to second subquestion}}
\end{enumerate}
\end{question}

\end{document}


Regarding your PS: you cannot use floats in a tasks environment. The reason is the same as explained in Footnotes doesn't work inside tasks. But tasks is (and never was) intended to replace enumerate. IMHO a tasks list only makes sense if you want a list with two ore more columns.

• I slightly modified the printSolutionsT command to meet my desired layout (red and boxed answers), and this works well! One drawback however (not important to me at the moment though) is that I cannot simply collect all solutions in a separate section; the solution numbering is absent. – Sander Nov 5 '14 at 19:41
• @Sander Yes, I mentioned that in my answer. You'd hav to use the solution environment additionally (and type the answers twice...) – clemens Nov 7 '14 at 12:24