[Tex/LaTex] Theorem packages: which to use, which conflict

best practicespackagestheorems

As far as I know, one can create theorem environments using any of amsthm, ntheorem, thmtools and probably more.

How should I define my theorem environments? Is one package clearly superior? Which packages conflict? Is there one package that does everything? (For some reason I am using ntheorem but I cannot remember why).

For example, thmtools looks like it has some nice features, but I'm afraid of breaking my ntheorem-defined custom environments…

Best Answer

To answer your question of whether ntheorem is clearly superior to amsthm (or the other way round), the answer is unfortunately no as both have advantages and shortcomings.

Feature-wise, ntheorem is clearly ahead of amsthm, but amsthm is more robustly designed, and has, as such, less bugs (of course, depending on how you use the ntheorem package, you may never encounter these bugs, but it's better to be aware of them).

Comparison of features of ntheorem and amsthm

The following table is inspired from the one given in the French FAQ entry about theorem and shows a list of features of each packages, clearly showing that ntheorem can do more things than amsthm.

alt text

Examples of ntheorem bugs

Here are a few chosen bugs which can occur in ntheorem and of which you should be aware before deciding whether to use ntheorem or amsthm. All these bugs are specific to ntheorem and do not occur in amsthm.

Break style clash with high material

When using the break style, if you put something a little too high at the start of the theorem, it will overlap with the theorem title:

alt text

\documentclass{article}
\usepackage{ntheorem}
\theoremstyle{break}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}
$\displaystyle \sum_{n=1}^{+\infty}{\frac{1}{n^2}} = \frac{\pi^2}{6}$
\end{theorem}
\end{document}

Footnote in theorem note

While it may not be a very good pratice to put footnotes in theorem optional arguments, it can be needed some times, but doesn't work with ntheorem (the footnote text will be lost; you must use the \footnotemark/\footnotetext trick):

\begin{theorem}[Fermat's little theorem\footnote{First stated in a letter dated October 18, 1640.}]
...
\end{theorem}

Long theorem note

If the theorem's optional argument is too long (either because the document is in two column mode or because the note is indeed very long), it will hang out of the margin. Here's an example in two column mode:

alt text

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{ntheorem}
\newtheorem{theorem}{Theorem}
\begin{document}
\lipsum[1]
\begin{theorem}[A very very very very long optional argument]
\lipsum[2]
\end{theorem}
\lipsum[3-5]
\end{document}

Examples of amsthm bugs

Although it has less bugs, amsthm is not completely bug-free. Here's a variant of the "too long theorem optional argument" ntheorem bug, but which only occurs with amsthm if a list is immediately following the theorem head:

alt text

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\begin{document}
\lipsum[1]
\begin{theorem}[A very very very very long optional argument]
\begin{enumerate}
\item Bla bla bla.
\item Bla bla bla.
\item Bla bla bla.
\end{enumerate}
\end{theorem}
\lipsum[3-6]
\end{document}