[Tex/LaTex] Understanding differences between newtheorem and newenvironment

environmentstheorems

The difficulty that I am having is that I make a newtheorem:

\newtheorem{definition}[theorem]{Definition}

It however seems to act nearly the same as with newenvironment:

\newenvironment{definition}[1][Definition]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}]}{\end{trivlist}}

so why would I use one over the other?

as far as the manipulating them goes, I find resources for newtheorem with all sorts of combinations of arguments i.e.:

\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollary}

which looks similar to the newenvironment setup except that we have an [1] in front of [Definition] in newenvironment which I am guessing is taking in an argument and thus could be expanded to several. Also there seems to be a bunch of stuff defined in the 3'rd item of newenvironment where – \begin{trivlist}\item[\hskip \labelsep {\bfseries #1}]{\end{trivlist}
is defined. Are newtheorems arguments already defined in the system or something and not expandable to multiple arguments – is that one of the differences?

Anyways I am just trying to figure out when to use newtheorem and when to use newenvironment

Best Answer

Although \newtheorem is, in fact, similar to \newenvironment, they are different: \newtheorem is specifically designed to define a particular kind of environment: theorem-like structures whereas \newenvironment allows you to define arbitrary environments.

A theorem-like structure is one that typically has a head (formed by a name and a number) and a body (the actual contents of the structure). Of course, you could define your theorem-like structures "from scratch" using \newenvironment, but \newtheorem makes a series of provisions so as to easily account for the different formatting elements which characterize such structures. For example, just by using

\newtheorem{theo}{Theorem}

and then

\begin{theo}
Theorem text.
\end{theo}

you'll get a head with automatic numbering in bold-faced font and the body will be typeset using italics. Additionally, the environments defined using \newtheorem have an optional argument which allows you to specify a name (or an annotation) for your theorem. Take a look at the following example:

\documentclass{article}

\newtheorem{theo}{Theorem}

\begin{document}

\begin{theo}
Theorem text.
\end{theo}

\begin{theo}[Fundamental theorem of algebra]
Theorem text.
\end{theo}

\end{document}

enter image description here

There's a number of packages extending the functionality of the kernel's \newthereom command; the most popular ones are:

The answers to Theorem packages: which to use, which conflict? show a nice comparison between those packages.

Regarding the syntactical aspects, in this answer to Understanding the arguments in newtheorem e.g. \newtheorem{theorem}{Theorem}[section], barbara beeton has explained the syntax for \newtheorem; a similar explanation can be found in this other answer to Using \newtheorem; an explanation for the syntax for \newenvironment can be found in this answer to What is the purpose of putting \newenvironment, \newcounter in a document class?.

Related Question