Expansion issue in tasks package

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


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