0

I'm trying to reformat a separate tex file without having to change the source file. What I want to do here is convert a tasks environment to a simpler enumerate environment. It should be simple -- replace "tasks" with "enumerate" and replace "\task" with "\item."

I've tried many variations on the MWE theme below, but to no avail. I'm sure it's some really simple syntax that I'm just not getting. Thanks in advance for your help!

\documentclass[openany]{book}
\usepackage[most]{tcolorbox}

\newcommand{\task}{\item}
\newenvironment{tasks}[2]{\begin{enumerate} #2}{\end{enumerate}}

\begin{document}

\begin{tasks}(3)
    \task $\pi$
    \task $e^{\pi}$
    \task etc
\end{tasks}

\end{document}
1
  • Do you want to keep the layout of tasks, but just use an enumerate environment? That is, skip (3) supplied to the tasks environment? Also, tcolorbox seems unnecessary in this example.
    – Werner
    Feb 1 at 19:52
3

Like this?

\documentclass{book}

\newcommand{\task}{\item}
\NewDocumentEnvironment{tasks}{od()}{\enumerate}{\endenumerate}

\begin{document}

\begin{tasks}(3)
  \task $\pi$
  \task $e^{\pi}$
  \task etc
\end{tasks}

\end{document}

enter image description here

It is not (or only with some tricks) possible to define an optional argument with parentheses with \newenvironment. But it is rather easy with \NewDocumentEnvironment. The details of said command are explained in the xparse manual: https://ctan.org/pkg/l3packages It is part of an up to date LaTeX kernel, though.

1

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.