The MWE bellow uses exsheets
package to print the solutions to questions at the end of a book. The code doesn't work as it should as it seems to be an expansion issue.
When, instead of \SetQuestionProperties{section-title= \secName }
, I put what \secName variable it's supposed to hold at that point, One
in the 1st section and Two
in the 2nd, then all is well (i.e. replace "\secName" with "One" for the 1st couple of occurrences and with "Two" for the next couple).
Does anyone know how to make this code work, to properly pass the string values of the \secName variable to \SetQuestionProperties?
The current result is "Section Answers 1). foo 2). bar Section Answers 1). baz 2). foobar" and it should be Section One 1). foo 2). bar Section Two 1). baz 2). foobar
.
\documentclass{scrartcl}
\usepackage{exsheets}
\setlength{\parindent}{0pt}
\SetupExSheets{counter-within=section}
\DeclareQuestionProperty{section-title}
\SetupExSheets{counter-within=section ,
headings=inline-nr ,
counter-format=qu).}
\SetupExSheets{section-hook = \noindent\bfseries
Section \GetQuestionProperty{section-title}{\CurrentQuestionID}
\space}
\newcommand{\secName}{}
\newcommand{\lsection}[1]
{
\renewcommand{\secName}{#1}
\section{#1}
}
\begin{document}
\lsection{One}
\begin{question}
\SetQuestionProperties{section-title= \secName }
say foo
\end{question}
\begin{solution}
foo
\end{solution}
\begin{question}
\SetQuestionProperties{section-title= \secName }
say bar
\end{question}
\begin{solution}
bar
\end{solution}
\lsection{Two}
\begin{question}
\SetQuestionProperties{section-title= \secName }
say baz
\end{question}
\begin{solution}
baz
\end{solution}
\begin{question}
\SetQuestionProperties{section-title= \secName }
say foobar
\end{question}
\begin{solution}
foobar
\end{solution}
\lsection{Answers}
\printsolutions
\end{document}