Basically I want to do something like this

{\begin{enumerate}[\bfseries 1.]}

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.

  • 3
    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



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

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

You can add


or, better,


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!
    – John Smith
    Jun 7 '21 at 4:54

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.