I have a LaTeX3e
code for creating autokey exercise lists for my students. I need to create a list of exercises with the following structure (it's in Portuguese, but never mind the content):
As it's noticed, the questions are indented via enumerate environment, in which the numbers stay in a distinct "column", in some distance of the actual questions.
Thing is, the command for collecting answer keys, for some reason, doesn't work inside the enumerate environment.
Here's a MWE of my problem:
\documentclass[23pt, oneside]{book}
\usepackage{xparse}
\ExplSyntaxOn
% first define the user interface
\NewDocumentCommand{\adddtolist}{O{general}m}
{
\marinho_lists_add:nn { #1 } { #2 }
}
\NewDocumentCommand{\listoutputformat}{+m}
{
\marinho_lists_output_format:n { #1 }
}
\NewDocumentCommand{\outputlist}{m}
{
\marinho_lists_output:n { #1 }
}
% define the internal functions
\cs_new_protected:Nn \marinho_lists_add:nn
{
% create the sequence if it doesn't exist
\seq_if_exist:cF { l_marinho_lists_#1_seq }
{
\seq_new:c { l_marinho_lists_#1_seq }
}
% add the item in the form {<number>}{<text>}
\seq_put_right:cx { l_marinho_lists_#1_seq }
{% compute the number based on the sequence length
{ \int_to_arabic:n { \seq_count:c { l_marinho_lists_#1_seq } + 1 } }
{ \exp_not:n { #2 } }
}
}
\cs_new_protected:Nn \marinho_lists_output_format:n
{% the private function holds the format
\cs_set:Nn \__marinho_lists_output_current:nn { #1 }
}
\marinho_lists_output_format:n { #1~--~#2 \par } % a default
\cs_new_protected:Nn \marinho_lists_output:n
{% map the sequence using the current format
\seq_map_function:cN { l_marinho_lists_#1_seq } \__marinho_lists_item:n
}
\cs_new:Nn \__marinho_lists_item:n
{% \__marinho_lists_item:n receives an argument in the form {<number>}{<text>}
% which we pass to \__marinho_lists_output_current:nn as two arguments
\__marinho_lists_output_current:nn #1
}
\ExplSyntaxOff
\newcommand{\key}[1]{\adddtolist[keylist]{#1}}
\newcommand{\showkey}{\outputlist{keylist}}
\usepackage{changepage}
\begin{document}
1. Here's my first question.
\key{As you see, it appears on the list by the end.}
2. Here's my second question.
\key{Again, it appears on the list os keys.}
\begin{enumerate}
\item However, if I try to put the command inside this environment
\key{It doesn't appear on the list.}
\end{enumerate}
\listoutputformat{\textbf{Question #1}: #2\par}
\showkey
\end{document}
One solution I tried was to indent the document text with the changepage
package, using the adjustwidth
environment, but it didn't work either.
Any thoughts on some solution, on how could I list my questions with the number as described?