6

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.

  • @Mico There are cases where the environment form won't work e.g. if the environment is defined with environ. So prooftrees needs to use \forest ... \endforest as \begin{forest} ... \end{forest} won't work. But I agree that in standard cases, it is hard to think of a reason to prefer the macro version. – cfr Aug 21 '16 at 20:54
  • @cfr - Thanks for providing an example of when the embedded macros version works whereas the embedded environment version does not. – Mico Aug 21 '16 at 21:06

1 Answers1

10

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.

egreg
  • 1,121,712
  • Wow, half a million rep, that's really something, thanks for all that you contribute here – Au101 Aug 21 '16 at 22:39
  • In just a few hours (or minutes?!) you'll have passed the 500K reputation threshold on this site. Congratulations in advance, and many thanks for all the good stuff I've learned from you over the past few years!! – Mico Aug 22 '16 at 06:31
  • My best congratulations, Enrico!!! Now you're a myth!!! – karlkoeller Aug 22 '16 at 06:56