[Tex/LaTex] Using an environment inside an environment

environments

I am often declaring environments which use other environment:

\newenvironment{foo}%
{\begin{itemize}}%
{\end{itemize}}

Somebody told me it is better to use the internal macros for the inner environment.

\newenvironment{foo}%
{\itemize}%
{\enditemize}

Is it true? If so, why is it better?

Best regards,

Luc.

Best Answer

Using the internal forms allows for better error checking. Suppose you have

\newenvironment{fooA}
  {\begin{itemize}}
  {\end{itemize}}

\newenvironment{fooB}
  {\itemize}
  {\enditemize}

If you forget \end{fooA} you'll receive a message about

! LaTeX Error: \begin{itemize} on input line 13 ended by \end{document}.

but if you forget \end{fooB} the message will be

! LaTeX Error: \begin{fooB} on input line 13 ended by \end{document}.

In some cases, the internal form is mandatory, for instance when defining new verbatim environments with the verbatim package or when using environments defined with \NewEnviron from the environ package. Another important case is when you define new environments on top of the amsmath display ones.

In some cases, however, the internal form is to be avoided, the main one being lrbox: using \lrbox and \endlrbox is always wrong.