I need to wrap a tasks environment inside a custom \NewEnviron. Apparently, tasks chokes on code besides its \task or \item due to the way it handles its own environment body, presumably causing it to do so on \BODY. Any way to get around this? Exact error given is "Something's wrong--perhaps a missing \item", as per:

\documentclass[a4paper]{book}
\usepackage{environ}

% Misc. stuff to precede the tasks env here
\BODY
% Misc. stuff to follow
}{}

\begin{document}

\item item 1
\item item 2
\item item 3

\end{document}

• @clemens \BODY is provided by environ; it expands to the contents of what's between \begin{mytaskenv} and \end{mytaskenv}. Perhaps I'm misunderstanding your suggestion? – Texman Apr 7 '15 at 7:35
• tasks needs to see the expansion of the macro \BODY in order to do its work – cgnieder Apr 7 '15 at 7:41
• Is there a simple way to accomplish that? – Texman Apr 7 '15 at 22:07

You have to expand \BODY before \begin{mytaskenum} starts its job:

\documentclass[a4paper]{book}
\usepackage{environ}

% Misc. stuff to preceed the tasks env here
\expandafter\tempbegin\BODY
% Misc. stuff to follow
}

\begin{document}

\item item 1
\item item 2
\item item 3

Check:

\item item 1
\item item 2
\item item 3

\end{document}


Cleaner alternative with xparse:

\documentclass[a4paper]{book}
\usepackage{environ}
\usepackage{xparse}

\ExplSyntaxOn
{
}
{
#1
}
\ExplSyntaxOff

% Misc. stuff to preceed the tasks env here
% Misc. stuff to follow
}

\begin{document}

\item item 1
\item item 2
\item item 3

Check:


The \domytaskenum command simply calls \texman_domytaskenum:V \BODY; in turn \texman_domytaskenum:V is a variant of \texman_domytaskenum:n that does the job of processing the argument in the mytaskenum environment. The V variant uses the value of the token list stored in \BODY as if it was the explicit contents. Basically it does the same trick as before, but in a more abstract way, without doing the temporary definition.