6

I'm trying to switch from enumitem lists to tasks lists, but the following, which works in an ordinary enumerate environment, generates a "Something's wrong--perhaps a missing \item" error in the tasks environment:

\documentclass{article}
\usepackage{tasks}
\newcommand{\itemexpansion}{\item test \item test \item test \item test}
\newcommand{\taskexpansion}{\task test \task test \task test \task test}

\begin{document}
% OK
\begin{enumerate}
    \itemexpansion
\end{enumerate}
% Error
\begin{tasks}
    \taskexpansion
\end{tasks}
\end{document}

I can tell that there's an expansion problem here, but that's about as far as my comprehension extends. It doesn't seem to match the situations warned about in the manual. Is there a workaround that will allow me to dump the results of a macro (the contents of which are gathered elsewhere) into a tasks environment?

3

tasks needs to explicitly see \task.

You can add a “command” form of tasks:

\documentclass{article}
\usepackage{tasks}

\ExplSyntaxOn
\NewDocumentCommand{\dotasks}{O{}d()m}
 {
  \hagen_tasks:Vnn { #3 } { #1 } { #2 }
 }
\cs_new_protected:Nn \hagen_tasks:nnn
 {
  \tl_if_novalue:nTF { #3 }
   {
    \begin{tasks}[#2]#1\end{tasks}
   }
   {
    \begin{tasks}[#2](#3)#1\end{tasks}
   }
 }
\cs_generate_variant:Nn \hagen_tasks:nnn { V }
\ExplSyntaxOff


\newcommand{\itemexpansion}{\item test \item test \item test \item test}
\newcommand{\taskexpansion}{\task test \task test \task test \task test}

\begin{document}

\begin{enumerate}
    \itemexpansion
\end{enumerate}

\dotasks{\taskexpansion}

\dotasks(2){\taskexpansion}

\dotasks[counter-format=(tsk[r]),label-width=4ex](2){\taskexpansion}

\end{document}

enter image description here

3

I create a new Tasks environment that calls upon tasks, while expanding the first argument (in this case, \taskexpansion).

\documentclass{article}
\usepackage{tasks,environ}
\newcommand{\itemexpansion}{\item test \item test \item test \item test}
\newcommand{\taskexpansion}{\task test \task test \task test \task test}
\NewEnviron{Tasks}{%
  \def\tmp{\begin{tasks}}%
  \expandafter\expandafter\expandafter\tmp\BODY%
  \end{tasks}%
}
\begin{document}
% OK
\begin{enumerate}
    \itemexpansion
\end{enumerate}
% No longer Error
\begin{Tasks}
    \taskexpansion
\end{Tasks}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.