# Starting Environment inside Environment

Basically I want to do something like this

\newenvironment{myenv}
{\begin{enumerate}[\bfseries 1.]}
{\end{enumerate}}


It works if I leave out the argument ([\bfseries 1.]), but with the argument, when I use my environment I get:

! LaTeX Error: Something's wrong--perhaps a missing \item.

How could I achieve this?

Doing the same thing with the package listings (\begin{lstlistings}) doesn't even work without any arguments. This of course has something to do with how TeX works and I really don't understand its internals. Please illuminate me.

• enumerate doesn't have an optional argument by default it looks like you are using enumerate package syntax without loading the package. listings like all verbatim commands can not be used in the argument or definition of another command Jun 5 '21 at 7:40

The first error is unrelated to the \newenvironment definition. enumerate does not have an optional argument so you get the same error from

\documentclass{article}

\begin{document}

\begin{enumerate}[\bfseries 1.]
\item zzz
\end{enumerate}
\end{document}


as it tries to typeset the [ as text with no preceding \item.

\usepackage{enumerate}


or, better,

\usepackage[shortlabels]{enumitem}


to define a version of enumerate using that syntax. (The syntax you are using comes from the enumerate package, but enumitem will emulate it if given the shortlabels option.

The issue with listings is different. Verbatim-like environments can not be used in the arguments or definitions of other commands. See the listings package docuemntation for its custom environment definition mechanism, \lstnewenvironment.

• Thank you very much, that is everything I needed to know to go on! Jun 7 '21 at 4:54