# File I/O to create exercise set with tasks package: missing \item

by Scott H.   Last Updated September 24, 2019 22:23 PM - source

Background: I'm attempting to use some exercises from an open text that are distributed across many files. I've rewritten the input mechanism and have it working fine. I can use multicols and enumerate to print exercise sets vertically across two columns, but would like to print them horizontally, thus the tasks package. The problem is as follows:

Problem: When changing from enumerate to tasks, I'm getting a missing \item. error. I assume that this is due to a \par introduced somewhere in the I/O operations being included in a \task (the tasks package documentation lists this as one way that the environment differs from enumerate, no \par's allowed). If this is the case, then I can't find where it's introduced. If not, then I have no idea what's going on.

MWE:

\documentclass{article}
\usepackage{xparse}
\usepackage{filecontents}

\begin{filecontents*}{numbers_20.tex}
{$5 - (2+3)$}
{$0$}
\end{filecontents*}

\begin{filecontents*}{numbers_21.tex}
{$5 - (2-3)$}
{$6$}
\end{filecontents*}

\exinput{numbers_20.tex}
\exinput{numbers_21.tex}
\end{filecontents*}

\ExplSyntaxOn

%Relevant code below
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NewDocumentCommand{\exinput}{m}{
\ior_open:Nn \l__exread_ior {#1} % open exercise file
\ior_get:NN \l__exread_ior \l_tmpb_tl % get line
}

\NewDocumentCommand{\exsetinput}{m}{
\ior_open:Nn \l__exsetread_ior {#1} % open set file
\ior_map_inline:Nn \l__exsetread_ior {\seq_put_right:Nn \l_tmpb_seq {##1}} % put exercises in a sequence
% if following changed to enumerate, and line 31 to item then works as expected.
% seq items are "exinput" (above) and should print \task\blah
\seq_use:Nn \l_tmpb_seq {}

\seq_clear:N \l_tmpb_seq
}

\ExplSyntaxOff
\begin{document}