[Tex/LaTex] Do fontsize environments exist

environmentslatex-basemacros

Without any doubt there are fontsize switches in the form of control sequences (described here for instance.) But, from time to time I ran into code examples where environment versions of those were used, e.g. \begin{small}...\end{small}. After testing those successfully I began to incorporate them into my TeX vocabulary.

A few days ago @GonzaloMedina commented on one of my answers that those environments do not exists and constructions relying on them work by pure coincidence. Then I tried to find out more about those ominous environments. Ominous because they don't seem to be somehow documentated. (The only thing I found that tried to explain them in a somehow systematical manner was some Wikibooks resource.)

Are these environments real or not?

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:

\documentclass{article}


\newcommand{\foo}{This does nothing}

\begin{document}
\begin{foo}

\end{foo}
\end{document}

Edit Some explanations

This code can be found in latex.ltx, see lines 4058f.

\def\begin#1{%
  \@ifundefined{#1}%
    {\def\reserved@a{\@latex@error{Environment #1 undefined}\@eha}}%
    {\def\reserved@a{\def\@currenvir{#1}%
     \edef\@currenvline{\on@line}%
     \csname #1\endcsname}}%
  \@ignorefalse
  \begingroup\@endpefalse\reserved@a}

It can be seen, that @ifundefined{foo} would be called, which is false, since it \foo is defined, so the environment name foo is set and \csname #1\endcsname (i.e. \foo) is called.

Now the \end{foo}: part

\def\end#1{%
  \csname end#1\endcsname\@checkend{#1}%
  \expandafter\endgroup\if@endpe\@doendpe\fi
  \if@ignore\@ignorefalse\ignorespaces\fi}

Environments 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.

Related Question