# Exsheets: how do I print the 'solutions' on the same line?

I want to print (dump) the solutions to questions at the end of the book. If I just use \printsolutions I get every solution on a new line (as a new paragraph).

I need to have them on the same line (only numbers, no names), Something like this:

1) Sol one. 2) Sol two. 3) ... etc.

Is there a way/workaround to accomplish this?

If yes, is there a way to automatically include the section/subsection name in the list (on the same line)? Like: ¨

Section 1. Subsection one. 1) Sol one. 2) Sol two. Subsection two. 1) Sol one. 2) Sol two. Section 2. Subsection 1. 1) Sol one ...

Edit:

Following cgnieder Edit I'm trying to find a way to avoid manual labeling and '\nameref'. I came up with something but it's not working as it should - 'printsolutions' gives the same name for sections. Please see the inline text and comments as well. Help!

\documentclass{scrartcl}
\usepackage{exsheets}
\setlength{\parindent}{0pt}

\DeclareQuestionProperty{section-title}
\SetupExSheets{counter-within=section ,
counter-format=qu)}

\newcommand{\lsection}[1]{
\def\secName{#1}
\section{#1}
}
\SetupExSheets{section-hook = \noindent\bfseries
Section \GetQuestionProperty{section-title}{\CurrentQuestionID}
\space}

\begin{document}

\lsection{One}
\begin{question}
\SetQuestionProperties{section-title= \secName }
foo
\end{question}
\begin{solution}
foo
\end{solution}

\begin{question}
\SetQuestionProperties{section-title= \secName }
bar
\end{question}
\begin{solution}
bar
\end{solution}

Solutions for section "\secName" are: \printsolutions[section]\\ % OK
ALL the solutions until here are: \printsolutions % OK

\lsection{Two}

\begin{question}
\SetQuestionProperties{section-title= \secName }
baz
\end{question}
\begin{solution}
baz
\end{solution}

\begin{question}
\SetQuestionProperties{section-title= \secName }
foobar
\end{question}
\begin{solution}
foobar
\end{solution}

Solutions for section "\secName" are: \printsolutions[section]\\ % OK
ALL the solutions at this point are wrong, the 1st section name is "Two" instead of "One": \printsolutions % WRONG!!

\lsection{Answers} %changing '\lsection' to '\section' makes all the section names as "Two"
This is the output of 'printsolutions' wrongly showing the same section name throuhout (the last name used):
\printsolutions

\end{document}

• Instead of editing this question IMHO it would have been better to ask a new question... anyway, this looks like an expansion issue: the section-title property is set to the token \secName (and not to whatever tokenlist it is defined) Oct 15, 2014 at 7:58
• @cgnieder If you can suggest a title & content for the new question so it won't be marked as a duplicate of this Q, I'd happily open a new one. My problem is still the original question (we can skip the 'subsection'). Neither of the proposed answers to the Q do the job as needed. Unfortunately, given my limited knowledge, I don't know how to solve the 'expansion' issue on my MWE. Thanks Oct 15, 2014 at 8:33
• The original question was »how do I print the 'solutions' on the same line?« – I believe that is not your problem any more. As for the content: take the code of your edit and describe the problems your having with it. Oct 15, 2014 at 8:38
• @cgnieder The second part of the Q was "is there a way to automatically include the section/subsection name in the list". There's no automation in manually labelling the questions and the section. But I will do as you suggest when I'll find a meaningful title for my problem :) Oct 15, 2014 at 8:52

The list you want is possible using the inline-nr headings instance and with setting \exsheets_par: equal to \scan_stop:. The second point prevents exsheets from a) inserting a \par after its environments and b) inserting vertical space after the \par. This is an undocumented feature but built-in extra for this purpose. I'll add an official user interface for it.

Unfortunately there is currently no way to get the complete list automatically with section titles inserted at the appropriate places. But you can use exsheets' \exlabel mechanism maybe together with nameref for a semi-automatic solution:

\documentclass{scrartcl}
\SetupExSheets{counter-within=section}

\usepackage{nameref}

% place \label and \exlabel simultaneously:
\newcommand*\mylabel[1]{\label{#1}\exlabel{#1}}

\begin{document}

\section{One}\mylabel{sec:foo}
\begin{question}
foo
\end{question}
\begin{solution}
foo
\end{solution}

\begin{question}
bar
\end{question}
\begin{solution}
bar
\end{solution}

\section{Two}\mylabel{sec:bar}
\begin{question}
baz
\end{question}
\begin{solution}
baz
\end{solution}

\begin{question}
foobar
\end{question}
\begin{solution}
foobar
\end{solution}

\section{Solutions}
\ExplSyntaxOn
\cs_set_eq:NN \exsheets_par: \scan_stop:
\ExplSyntaxOff

\textbf{Section \nameref{sec:foo}} \printsolutions[section={\S{sec:foo}}]
\textbf{Section \nameref{sec:bar}} \printsolutions[section={\S{sec:bar}}]

\end{document}


Edit

With version 0.13 (2014/05/11) exsheets provides the option section-hook. In a combination with nameref and question properties it can be used in the following way to achieve the same layout with only one call of \printsolutions:

\documentclass{scrartcl}
\SetupExSheets{counter-within=section}
\DeclareQuestionProperty{section-title}
\usepackage{nameref}

\begin{document}

\section{One}\label{sec:foo}
\begin{question}
\SetQuestionProperties{section-title=\nameref{sec:foo}}
foo
\end{question}
\begin{solution}
foo
\end{solution}

\begin{question}
\SetQuestionProperties{section-title=\nameref{sec:foo}}
bar
\end{question}
\begin{solution}
bar
\end{solution}

\section{Two}\label{sec:bar}
\begin{question}
\SetQuestionProperties{section-title=\nameref{sec:bar}}
baz
\end{question}
\begin{solution}
baz
\end{solution}

\begin{question}
\SetQuestionProperties{section-title=\nameref{sec:bar}}
foobar
\end{question}
\begin{solution}
foobar
\end{solution}

\section{Solutions}

\SetupExSheets{
headings = inline-nr , % numbered and inline
counter-format = qu) , % numbers 1) 2) ...
section-hook =         % code to be added before solutions of a new section
% are printed
% \par begin a new paragraph for a new section
\noindent\bfseries
Section \GetQuestionProperty{section-title}{\CurrentQuestionID}%
\space
}

\printsolutions

\end{document}

• \exsheets_par: and \scan_stop: work great, thanks. Dec 27, 2013 at 13:41
• As for including the chapters/sections in the "dump", I was looking for a fire-and-forget solution same as a TOC. It's for a book (12 books in a series in fact) that gets updated every year (sections/exercises in and out, lots of modifications) and one of the major annoyances is the errors in the Solutions Chapter at the end. Dec 27, 2013 at 13:48
• @alwaysask Re: »I was looking for a fire-and-forget solution same as a TOC.« -- I understood that but exsheets doesn't provide the means for this... Dec 27, 2013 at 13:50
• Maybe not yet :) A feature request perhaps? I understood I can't have that using exsheets but maybe someone else has a suggestion for another way/package. P.S. The only reason I would use `exsheets' is to be able to write the solutions right under the questions but print them later without worrying too much. Dec 27, 2013 at 14:11
• @ cgnieder Using version 0.16, 'counter-format = qu)' option in the above MWE (after the Edit) doesn't work. L.E. In fact, counter-format has no effect on previous created questions, only on the questions created after a '\SetupExSheets{counter-format = <whatever>}' command. Is this a bug or is it because something changed between V0.13 and V0.16? Oct 13, 2014 at 18:58