4

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 ,
         headings=inline-nr ,
         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}
alwaysask
  • 2,248
  • 13
  • 16
  • 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) – cgnieder Oct 15 '14 at 07: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 – alwaysask Oct 15 '14 at 08: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. – cgnieder Oct 15 '14 at 08: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 :) – alwaysask Oct 15 '14 at 08:52

1 Answers1

4

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}
\usepackage[load-headings]{exsheets}
\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
\SetupExSheets{headings=inline-nr,counter-format=qu)}

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

\end{document}

enter image description here


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}
\usepackage[load-headings]{exsheets}[2014/05/11]
\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}
cgnieder
  • 66,645
  • \exsheets_par: and \scan_stop: work great, thanks. – alwaysask Dec 27 '13 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. – alwaysask Dec 27 '13 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... – cgnieder Dec 27 '13 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. – alwaysask Dec 27 '13 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 = }' command. Is this a bug or is it because something changed between V0.13 and V0.16? – alwaysask Oct 13 '14 at 18:58
  • @alwaysask works nicely for me (using an up to date TL2014) – cgnieder Oct 13 '14 at 19:01
  • @ cgnieder I have a 'last night install' of a vanilla Texlive, so it's up to date. Changing 'counter-format = qu)' to ' counter-format = qu]' or anything you like does absolutely nothing. L.E. - let alone it doesn't do "% numbers 1) 2) ... " – alwaysask Oct 13 '14 at 19:05
  • @alwaysask As I said: I can't reproduce any issues. It works nicely for me – cgnieder Oct 13 '14 at 19:11
  • @alwaysask Ah, I believe I get it: one can't change the format for the \printsolutions call any more... – cgnieder Oct 13 '14 at 19:16
  • @cgdenier The above MWE gives me the solutions like this: "Section One 1. foo 2. bar Section Two 1. baz 2. foobar" instead of "Section One 1) foo 2) bar Section Two 1) baz 2) foobar". If I place a '\SetupExSheets{counter-format = qu)} ,say, between sections or question creation places, the solutions from that point on (and NOT all of them) will be like 1) 2) 3) (the previous remain at 1. 2. 3. L.E. Now I read your answer. Ok, so I can't change the format on the answers after creating the question. Not good ... – alwaysask Oct 13 '14 at 19:19
  • @alwaysask OK, I found out why that is and (I believe I remember why I changed this but) I'll update exsheets again in order to make this example work again. It may take a while, though... – cgnieder Oct 13 '14 at 19:31
  • @cgdenier Thanks! One more Q please. Did the new versions introduced anything that can be used to avoid using labels to accomplish the original task? I have more than 100 sections in a book and more than 3000 exercises (questions) per book so I need to define new commands for environments etc. - I just can't keep {sec:fooooing} all the sections and the questions just to link the answers to a section title). I managed to do label auto-creation using the section title (after changing almost all packages starting with the encoding!) but I still have issues that negatively affect 'printsolutions'. – alwaysask Oct 13 '14 at 19:42
  • I edited my original Q with a MWE based on your Edit (after V0.13) as an attempt to avoid labeling and making things simpler. Unfortunately it has some unexpected results. Any clues please? Thanks. – alwaysask Oct 15 '14 at 02:28
  • There's a problem. When there's no solution to a question I simply skip the solution environment for that Q so the numbering keeps going and it doesn't show [an empty answer] in the \printsolutions list - thats perfect. But when a section starts with a Q without answer, the respective Section Name doesn't get printed with \printsolutions. To test, in any of the above MWEs just delete the 1st 'solution' environment in the second section (section Two) and the result is: Section One 1. foo 2. bar 2. foobar instead of Section One 1. foo 2. bar Section Two 2. foobar – alwaysask Oct 16 '14 at 15:10
  • @alwaysask I might have a solution but I need to test this first... – cgnieder Oct 17 '14 at 00:07
  • There's no hurry. I was thinking, instead of using a workaround, maybe there's a possibility to tweak the exsheets package code to prevent such an issue and I'll be patient for a future version of the package (looking forward anyway for the new version that you said it will correct the counter-format = <> issue on printsolutions anyway). Thanks – alwaysask Oct 17 '14 at 08:00
  • The counter-format issue is already fixed in an updated TeX Live. http://permalink.gmane.org/gmane.comp.tex.ctan.announce/11303 – cgnieder Oct 17 '14 at 13:32
  • I would like to include chapters in the whole deal (original question) and \printsolutions[chapter] outputs the section name before every question (which I don't know how to solve). Should I paste an MWE here or open a new question? – alwaysask Nov 04 '14 at 09:39