I am trying to modify a question-solution capability that was answered brilliantly a while back here. After each question text, one can freely use \solution to keep the solution directly with the question text. The solutions are stored in a .sol file through the command \collectSolutions and can be accessed in the document through \printSolutions. The code below is thanks to David Carlisle and works a charm (perhaps it should be a package). This question is about the fine tuning.
The code below will return the numbering of the solutions as: 1: 2a: b: c: 3ai: ii: 3b: 4:
I would like it to return: 1: 2a: b: c: 3ai: ii: b: 4:
\documentclass{article} \makeatletter \newwrite\solutions@file \newcommand{\collectSolutions}{\immediate\openout\solutions@file=\jobname.sol} \newcommand{\sol@enumi}{{\theenumi}} \newcommand{\sol@enumii}{{\theenumi.}\theenumii} \newcommand{\sol@enumiii}{{\theenumi.\theenumii.}\theenumiii} \newcommand{\solution}[1]{% \immediate\write\solutions@file{% \noexpand\solsep\csname sol@\@enumctr\endcsname: \unexpanded{#1\ignorespaces}% }% } \def\solsep{\afterassignment\@solsep\def\@tempa} \def\@solsep{% \ifx\@tempa\sol@lastsec, \else \global\let\sol@lastsec\@tempa \sol@stop\gdef\sol@stop{. }% \textbf{\@tempa} \fi } \newcommand{\printSolutions}{% \let\sol@stop\@empty \gdef\sol@lastsec{0.}% \immediate\closeout\solutions@file \noindent\input{\jobname.sol}\sol@stop } \makeatother %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{document} \collectSolutions \begin{enumerate} \item Question text \solution{Ans} \item Question text \begin{enumerate} \item Part Q \solution{Ans} \item Part Q \solution{Ans} \item Part Q \solution{Ans} \end{enumerate} \item Another Q \begin{enumerate} \item Part Q \begin{enumerate} \item Part Q \solution{Ans} \item Part Q \solution{Ans} \end{enumerate} \item Part Q \solution{Ans} \end{enumerate} \item Question text \solution{Ans} \end{enumerate} \printSolutions \end{document} 
exsheetsI wasn't able to find out how to keep solutions directly embedded next to the question text.embedded next to the question textexactly?\solution{answer text}. Personally I find it very elegant.probsolnpackage? Or you can use a combination ofdatatoolanddatatooltk