I am attempting to construct a new environment which will allow me to format arbitrary list types (itemize, enumerate, description etc.) with the new environment. As such I am passing it as a parameter to the new environment but it complains when I attempt the following:

#Environment definition here

I get the following error:

! Illegal parameter number in definition of \endmylist. 1 l.15 {\end{#1}}

How can I pass my parameters into the end block?


2 Answers 2


One possibility is to use the xparse package:

  % other code
  • 8
    Thank you, very useful package. As a side note for everyone who, like me, doesn't know xparse the {m} parameter is specified just like table columns. The m stands for "mandatory parameter". Commented Oct 29, 2011 at 14:00
  • 2
    As of October 2021, loading xparse is not needed, as the code has been incorporated in the kernel
    – egreg
    Commented Feb 17, 2023 at 20:24

The environ package is an alternative way to achieve this, since it negotiates the environment content like a macro (called \BODY) and lets you place arguments around it as needed. Here's an example:

enter image description here



  \textbullet~Some code #1 \textbullet\par% Use argument before \BODY ~ \begin{myenv}
  \BODY \par
  \textbullet~Some code #1 \textbullet% Use argument after \BODY ~ \end{myenv}





  • 1
    I’d say that environ is obsolete
    – egreg
    Commented Feb 17, 2023 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .