5

The other day I was typing up a proof containing a list and I accidentally wrote \item inside the proof environment (from the amsthm package) but outside of any list environment. To my surprise, LaTeX typeset the file without complaining! But as soon as I moved \item outside of the proof environment, LaTeX complained of a "lonely \item''.

So this code gives an error

\documentclass{article}
\usepackage{amsthm}
\begin{document}
\begin{proof}
Some text
\end{proof}
\item
\end{document}

while this code does not

\documentclass{article}
\usepackage{amsthm}
\begin{document}
\begin{proof}
\item
Some text
\end{proof}
\end{document}

What's going on here?

  • 1
    Because proofs and theorems are build via simple lists. (Might not have been such a good idea) – daleif Oct 02 '14 at 13:15
  • @daleif There is a very good reason for that. Compare \begin{proof}\begin{enumerate}\item My item\end{enumerate}\end{proof} with \textit{Proof.}\quad \begin{enumerate}\item My item\end{enumerate}. – yo' Oct 02 '14 at 13:19
  • 1
    It's also allowed in center or flushleft; not that it's recommended to use it. – egreg Oct 02 '14 at 13:24
  • 1
    @tohecz : a lot of people does not like that feature – daleif Oct 02 '14 at 13:45
  • @daleif Well, they can just go ahead and ask a question about it, since it can of course be switched off. – yo' Oct 02 '14 at 13:46
  • @tohecz, how would you do that, especially in such a manner that enumerate does not add extra space at above the list – daleif Oct 02 '14 at 14:14
  • @daleif There are many questions on this topic, for example http://tex.stackexchange.com/questions/173158/how-to-reduce-vertical-spacing-between-proof-environment-and-enumerate-environme – yo' Oct 02 '14 at 14:28
  • But doesn't they all give Proof on a line of it own in all cases. I do not particularly like that - waste of space. – daleif Oct 02 '14 at 14:35
  • @daleif Well, ask a new question about it then, I'm sure that once you precisely specify what do you want, people will give a solution quickly ;) – yo' Oct 02 '14 at 14:38

1 Answers1

5

All theorem-like environments, along with center, flushleft, flushright, quote, quotation (and some others) are implemented as lists. For instance, center is defined by

% latex.ltx, line 3965:
\def\center{\trivlist \centering\item\relax}
\def\endcenter{\endtrivlist}

and

\begin{center}
something
\item
\end{center}

would not raise an error, because \item is allowed in trivlist (which is the basic environment which general lists are based on), but the result would be funny.

This is done in order to ensure that lists inside these environments work properly. Also proof is defined with trivlist.

It might be possible to disallow \item in such environments, by making trivlist reinstate the correct meaning for \item. Something like

\def\center{\trivlist \centering\item\relax\let\item\@itemerr}
\def\endcenter{\endtrivlist}

and adding to the code for trivlist code such as

\let\item\@defaultitem

where the \@itemerr and \@defaultitem commands are hypothetical. The kernel presently doesn't do this (and it won't, as this might break existing documents).

egreg
  • 1,121,712