14

I see that both attempts to display a theorem in the following code generates similar output.

\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\begin{document}

\begin{theorem}
\( (a + b)^2 = a^2 + 2ab + b^2 \)
\end{theorem}

{
\theorem
\( (a + b)^2 = a^2 + 2ab + b^2 \)
}
\end{document}

I want to know what the difference between \begin{theorem}...\end{theorem} and {\theorem ...} is.

4
  • Are you familiar with Plain TeX and LaTeX differences?
    – percusse
    Sep 11, 2012 at 20:02
  • 1
    @percusse No, I work only with LaTeX. Is \begin{theorem}...\end{theorem} LaTeX way of writing a theorem while {\theorem ...} TeX way of writing a theorem? Sep 11, 2012 at 20:04
  • In a nutshell yes, but I'm not entitled to give a comprehensive answer. This is also the root of the confusion about \center,\centering and \begin{center}...\end{center}. See for example tex.stackexchange.com/questions/2651/…
    – percusse
    Sep 11, 2012 at 20:06
  • a misguided user just sent a bug report to the latex bugs site saying that the heading font for all theorems after using \remark{...} was changed to italic. (he didn't use braces to isolate the theorem input.) all latex documentation says that theorems are to be input as environments, not commands, so clearly, the instructions weren't being followed. egreg's answer gives good reasons why one should follow the instructions. Sep 18, 2012 at 15:04

2 Answers 2

10

Assume foo is some environment; with

\begin{foo}

LaTeX does some bookkeping, opens a group and expands the macro

\foo

With

\end{foo}

some check are performed, \endfoo is expanded and the group is closed.

In the case of theorem, we can test

\show\theorem
\show\endtheorem

which gives

> \theorem=macro:
->\@thm {\let \thm@swap \@gobble \th@plain }{theorem}{Theorem}.

> \endtheorem=macro:
->\endtrivlist \@endpefalse .

It may seem that \endtheorem is no big deal; but let's see what \endtrivlist means:

> \endtrivlist=macro:
->\if@inlabel \leavevmode \global \@inlabelfalse \fi \if@newlist
\@noitemerr \global \@newlistfalse \fi \ifhmode \unskip \par \else 
\@inmatherr {\end {\@currenvir }}\fi \if@noparlist \else \ifdim
\lastskip >\z@ \@tempskipa \lastskip \vskip -\lastskip \advance
\@tempskipa \parskip \advance \@tempskipa -\@outerparskip \vskip
\@tempskipa \fi \@endparenv \fi .

So you're missing several things if you omit \end{theorem}.

Perhaps, in the case of theorem not much is missed, but only getting "similar" output doesn't guarantee that, maybe some pages later, something goes awry. The most striking aspect in the particular case is that the vertical spacing after the statement will be wrong, even if you leave an empty line after the closing brace.

This practice is definitely not recommendable: some environments do the bulk of their work exactly at \end...; others do almost nothing at that stage. One should know in depth what every environment does.

Finally, the {\theorem ...} syntax is clumsy.

5
  • Nice! Where should I type \show\theorem\show\endtheorem to see that lines?
    – Sigur
    Sep 11, 2012 at 22:08
  • 1
    @Sigur Just add them to your document and compile it from the command line. You can get a "printed" version good for non interactive runs with {\ttfamily\meaning\theorem}.
    – egreg
    Sep 11, 2012 at 22:10
  • It's interesting to note that \theorem survives without \endtheorem. Yes you "missing several things" but there's no compile error. This is because there's no grouping between the two commands; something inherent when using the \begin{theorem}...\end{theorem} pair.
    – Werner
    Sep 11, 2012 at 22:10
  • 1
    @Sigur: Review the .log file after the run, since \show flushes its contents there.
    – Werner
    Sep 11, 2012 at 22:11
  • 2
    @Werner No compile error doesn't mean that the output is correct.
    – egreg
    Sep 11, 2012 at 22:28
12

As soon as you add some material after both constructs you'll see the difference; \end{theorem} uses \endtrivlist which internally uses \par, effectively ending a paragraph; in the second construct there's no paragraph ending:

\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\begin{document}

\begin{theorem}
\( (a + b)^2 = a^2 + 2ab + b^2 \)
\end{theorem}
aaa

{
\theorem
\( (a + b)^2 = a^2 + 2ab + b^2 \)
}
aaa
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .