# Passing commands as environment-arguments

I'm trying to realize two versions of an environment numberedlist:

• if no argument is passed to it, it should begin the environment enumerate and pass default values as its argument,
• if one argument (or a list of) is passed to it, it should begin the environment enumerate and pass default values + the passed argument as its argument.

My MWE doesn't work properly. It prints out the arguments instead of using them.

\documentclass{article}
\usepackage{ifthen}
\usepackage{enumitem}

\newenvironment{numberedlist}[1][]{%
\let\tempstring{topsep=0.3cm,noitemsep,itemindent=0.5cm,labelsep=0.5cm}%default value
\ifthenelse{\equal{#1}{}}{}{%
}%
\begin{enumerate}[\tempstring]%
}{\end{enumerate}}

\begin{document}

\begin{numberedlist}
\item item 1
\item item 2
\item item 3
\end{numberedlist}

\begin{numberedlist}[resume]
\item continue the list with 4th item!
\item item 5
\item item 6
\end {numberedlist}

\end{document}


You have to expand the list of default options before \begin{enumerate} sees it:

\documentclass{article}
\usepackage{enumitem}

\newcommand\numberedlistdefault{%
topsep=0.3cm,noitemsep,itemindent=0.5cm,labelsep=0.5cm% default value
}

\newenvironment{numberedlist}[1][]
{\expandafter\enumerate\expandafter[\numberedlistdefault,#1]}
{\endenumerate}

\begin{document}

\begin{numberedlist}
\item item 1
\item item 2
\item item 3
\end{numberedlist}

\begin{numberedlist}[resume]
\item continue the list with 4th item!
\item item 5
\item item 6
\end {numberedlist}

\end{document}


But it's perhaps simpler not having a macro:

\newenvironment{numberedlist}[1][]
{\enumerate[
topsep=0.3cm,
noitemsep,
itemindent=0.5cm,
labelsep=0.5cm,
#1
]}
{\endenumerate}


You don't need a conditional, because enumitem happily accepts empty options.

• Thx egreg, you're soo fast :) Solution 1 works and is the explanation I was looking for. The simpler solution 2 doesn't work. It starts counting from 1 again. – musicman May 13 '14 at 18:16
• @musicman Fixed. – egreg May 13 '14 at 18:20