# Is there a reason to use \begin{environment} \end{environment} rather than \environment \endenvironment?

What reason (other than perhaps being easier for my syntax highlighter to parse) is there to write

\begin{center}
Here is centered text
\end{center}


rather than:

\center
Here is centered text
\endcenter


And likewise for other environments. Does the \begin do any extra funky checks or are they effectively synonymous?

-
See the very related question Defining environments based on other ones: What's the right way? –  Martin Scharrer Aug 21 '11 at 21:39

\begin and \end build a group, which can keep settings local. Simply writing \command ... \endcommand doesn't. Such a scope is very important for me, that's why I prefer the \begin ... \end syntax.

Example:

\documentclass[a4paper]{article}
\begin{document}
\begin{center}
\bfseries Text
\end{center}
text % this is normal font, left aligned as default
\center
\bfseries Text
\endcenter

text % this is still bold! and it's even centered
\end{document}

-
If \endcenter doesn't end centering, what does it do? –  doncherry Aug 21 '11 at 21:43
@doncherry: It ends the triv-list used for centering \endcenter: macro:->\endtrivlist. The \trivlist apparently depends on the group added by \begin .. \end to revert the changes made. –  Martin Scharrer Aug 21 '11 at 21:48
Some environments actively support the "plain form", e.g. \pgfpicture .. \endpgfpicture, because they add a group by themselves. –  Martin Scharrer Aug 22 '11 at 8:33

From latex.ltx:

\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}
\def\end#1{%
\csname end#1\endcsname\@checkend{#1}%
\expandafter\endgroup\if@endpe\@doendpe\fi
\if@ignore\@ignorefalse\ignorespaces\fi}


\begin defines (locally) \@currenvir and \@currenvline, starts a group and sets \@endpefalse; \end checks \@currenvir against its argument (throwing an error if they don't agree) and does other management tasks. It's not only the grouping. On the other hand, \environment and \endenvironment can be (almost always) safely used in the definition of another environment. There are a few topics on TeX.sx about this.

-
Regarding using \environment and \endenvironment in the definition of another environment: that's mostly true, though scoping could also be a issue here, producing undesired results in the end code. –  Stefan Kottwitz Aug 21 '11 at 21:37
The \@currenvir macro \begin{env}...\end{env} will give an error when environments are improperly nested. That's worth making more explicit. –  Matthew Leingang Aug 21 '11 at 23:52

In addition to everything else: \endfoo need not be defined in order for the \end{foo} to work, see everybody who uses size commands as environments and gets away with it (to some extent).

-

Further to Stefan's answer, here is the definition of \begin and \end from latex.ltx, clearly showing the grouping (\begingroup and \endgroup):

\def\begin#1{%
\@ifundefined{#1}% Environment begin
{\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}% <- grouping starts
\def\end#1{% Environment end
\csname end#1\endcsname\@checkend{#1}%
\expandafter\endgroup\if@endpe\@doendpe\fi% <- grouping ends
\if@ignore\@ignorefalse\ignorespaces\fi}


In contrast to that, defining a new environment merely executes (in some order, depending on optional parameter specification):

\def\newenvironment{\@star@or@long\new@environment}
\def\new@environment#1{%
\@testopt{\@newenva#1}0}
\def\@newenva#1[#2]{%
\kernel@ifnextchar [{\@newenvb#1[#2]}{\@newenv{#1}{[#2]}}}
\def\@newenvb#1[#2][#3]{\@newenv{#1}{[#2][{#3}]}}
\def\renewenvironment{\@star@or@long\renew@environment}
\def\renew@environment#1{%
\@ifundefined{#1}%
{\@latex@error{Environment #1 undefined}\@ehc
}\relax
\expandafter\let\csname#1\endcsname\relax
\expandafter\let\csname end#1\endcsname\relax
\new@environment{#1}}
\long\def\@newenv#1#2#3#4{%
\@ifundefined{#1}%
{\expandafter\let\csname#1\expandafter\endcsname
\csname end#1\endcsname}%
\relax
\expandafter\new@command
\csname #1\endcsname#2{#3}% <- \<env>
\l@ngrel@x\expandafter\def\csname end#1\endcsname{#4}}% <- \end<env>


From the definition of \@newenv (I've added some comments), \newenvironment{<env>}{<begin-env>}{<end-env>} assigns <begin-env> to \<env> and <end-env> to \end<env> without any sign of grouping.

-