Using \list
(or \trivlist
) for a display enviornment makes it a lot easier to handle things that are trickier to get right (or at least get like the rest of LaTeX) otherwise.
In particular:
the code to handle how space is combined if one display environment immediately follows another;
the code that detects whether the text following the environment is to be set as a new paragraph or a continuation of the previous one;
The code to adjust the left and right margins in a way that flags to any nested list environments which margins to use.
None of the code for these things is impossibly difficult, but....
When you define an environment with
\newenvironment{foo}[1]{start code with #1}{end code}
what happens internally (after some checking for optional arguments, testing if the environment exists, and taking care of a possible star argument to \newenvironment
) essentially boils down to
\newcommand\foo[1]{start code with #1}% actually \new@command
\def\endfoo{end code}
This means if the environment has no optional arguments
\let\myfoo\foo
\let\endmyfoo\endfoo
copies the environment {foo}
as environment {myfoo}
. (If it has an optional argument \LetLtxMacro
should be used instead of \let
, see When to use \LetLtxMacro?.)
In the article
class the {figure}
environment is defined as
\newenvironment{figure}
{\@float{figure}}
{\end@float}
so saying
\let\myfigure\figure
\let\endmyfigure\endfigure
works:
\documentclass{article}
\newenvironment{foo}[1]{start foo with (#1)}{end foo}
\let\myfoo\foo
\let\endmyfoo\endfoo
\let\myfigure\figure
\let\endmyfigure\endfigure
\begin{document}
\begin{myfoo}{arg}
bar
\end{myfoo}
\begin{myfigure}
copied figure
\caption{my figure}
\end{myfigure}
\end{document}
Some environments like {verbatim}
or AMSmath's {align}
cannot be copied this way since they need to find \end{verbatim}
or \end{align}
, respectively, exactly.
Best Answer
You can use any
LaTeX
command defined by\newcommand
and wrap a\begin{}...\end{}
pair around it, however, it's not recommended, since this is not an environment.The interesting thing is, however, that grouping works anyway, but this is consequence of
\begin...\end
.There are no fontsize environments like
\begin{small}
etc, as there aren't\begin{chapter}
etc.See for example:
Edit Some explanations
This code can be found in
latex.ltx
, see lines 4058f.It can be seen, that
@ifundefined{foo}
would be called, which is false, since it\foo
is defined, so theenvironment
namefoo
is set and\csname #1\endcsname
(i.e.\foo
) is called.Now the
\end{foo}
: partEnvironments look for the
\end...
code, here\endfoo
, which isn't defined, but\csname endfoo\endcsname
expands to a\relax
and nothing bad happens.It should be noted, that many of the well-known environments aren't defined with
\newenvironment
. It's sufficient to use a\foo
command and\def\endfoo
, see\endequation
or\endenumerate
etc. for example.