Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\newenvironment{mylist}[1]
{
\begin{#1}
#Environment definition here
}
{\end{#1}}

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?

share|improve this question
4  
The reason why you can't use arguments in the "end" part of the definition of a new environment and some possible solutions are given in Why can't the end code of an environment contain an argument?. –  Gonzalo Medina Jun 13 '11 at 2:03
add comment

1 Answer 1

up vote 15 down vote accepted

One possibility is to use the xparse package:

\usepackage{xparse}
\NewDocumentEnvironment{mylist}{m}{%
  \begin{#1}%
  % other code
}{%
  \end{#1}%
}
share|improve this answer
2  
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". –  Riccardo Oct 29 '11 at 14:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.