What happens if you use a command form of an environment?

Nice question, with an answer that's not going to be short, even if a short answer to the question “can I use the macro form of an environment?” would be possible, quoting Marcel Marceau in Mel Brooks' “Silent Movie”: NON.

First of all, I recall that \newenvironment{foo}[<n>]{<start>}{<end>} defines the macros \foo and \endfoo, but just because it has to, as TeX only knows macros.

Such macros can be used in defining other environments, but should never appear in the body of a document. And when I say never, I mean it.

Therefore code such as

\newenvironment{foo}
  {a}
  {b}
\newenvironment{baz}
  {c\foo}
  {d\endfoo}

is legal and even slightly better than \newenvironment{baz}{c\begin{foo}}{d\end{foo}}, because it saves a level of grouping and will give a better error message in case \end{baz} is misplaced.

As a number of questions on the same subject shows, using \foo or \baz in a document can lead to very unexpected results. For instance,

\abstract{Text...}

will, with most document classes, leads to wrong typesetting of the whole document. See The abstract environment changes the \linewidth for the whole document that has several questions linked to it as duplicate.

Other cases are even more blatantly wrong: if you try

\align{
<eq 1> \\
<eq 2> \\
<eq 3>}

according to your attempt, you'll have a very nasty surprise.

The body of the environment is almost never an argument to a command and, even when it is, it is not an argument to the macro having the environment's name.

Your “lazy” example \thm{stuff} will setup things for a theorem: step the counter, typeset the label and change the font to italics. Such is the job of \thm. In this case { and } don't delimit an argument, but just form a group; not a big deal, because “stuff” will be typeset anyway. However, italics will continue.

The macros \begin and \end are not just placeholders: they do several actions. They open and close a group, so font or line width changes will be local (see the abstract example and the note about the font with \thm). They also set the current environment name, in order to help you in case nesting is improper. The \end part also adds some bookkeeping at the end, which most basic environments such as list hook at.

I'm the last one to say that being lazy is bad, but the above remarks should be enough to stop you trying being that lazy.

The converse, that is, using a macro as an environment, can work. Mostly it does, in some occasions it just seems to work; therefore I don't recommend doing it.


Fundamentally \newenviroment{<env>}[<args>]{<begin>}{<end>} defines two macros: one associated with the start of the environment and one with the end of the environment, simplistically turning

\begin{<env>}[<args>]
...
\end{<env>}

into

\<env>[<args>]
...
\end<env>

However, using the environment form additionally provides a limited scope to any changes made within the environment in the form of a group. For example, consider

enter image description here

\documentclass{article}

\begin{document}

Lorem ipsum.

\begin{itemize}
  \item An item
  \item Another item
\end{itemize}

Lorem ipsum.

\itemize
  \item An item
  \item Another item

Lorem ipsum.

\end{document}

Note how the environment usage of itemize reverses the list style indentation after \end{itemize} while the "lazy" method (without an \end...) doesn't restore the regular layout. Even if you were to use the command-form \<env>[<args>] ... \end<env>, it's best to stick to the environment use.

Essentially it may boil down to the environment you use. For example, theorems tend to set their "QED" during \end<theorem>. Other environments require and \end<env> (like tabularx or listings or even just the verbatim environment).

Tags:

Environments