In this lecture we learn how to create Theorems, Corollaries, Proofs, and all the other standard environments you might need when writing your thesis.

The Basics

Here is a simple example of how to insert a Theorem into your $\mathrm{\LaTeX}$ document.

\documentclass{article}
\newtheorem{theorem}{Theorem}
\begin{document}
Consider the following two statements. One of them is easier than other.
\begin{theorem}
Let $p$ be an even prime. Then $p = 2$.
\end{theorem}
\begin{theorem}
There are infinitely many primes of the form $p = 2^k -1$.
\end{theorem}
\end{document}
• The line \newtheorem{theorem}{Theorem} in the preamble defines the theorem environment for us.
• In the document itself, we use the standard \begin{theorem} ... \end{theorem} to use it. $\mathrm{\LaTeX}$ automatically numbers the theorems.

Let us unpack the command \newtheorem{theorem}{Theorem} a bit. For starters, why does it contain the word “theorem” three times?

• Firstly, \newtheorem is the name of the command. This command is used for defining all such environments (irrespective of whether they are theorems, corollaries, or lemmas etc). For this reason we will adopt the terminology that a theoremesque environment is any environment that is defined via the \newtheorem command[1].
• Secondly, the theorem inside the first set of curly brackets is the “internal” name for the theoremesque environment we are defining. This is the word we use when invoking the environment with \begin{}. You are free to choose whatever you want here—just like with your choice of label in the \label{} command, this is a purely internal tag, and it won't ever get printed.
• Finally, the Theorem in the second set of curly brackets is the “external” name for the theoremesque environment we are defining. This is what $\mathrm{\LaTeX}$ will typeset on the page. Note this Theorem has to be capitalised, otherwise $\mathrm{\LaTeX}$ will print it without a capital letter.

In practice, it usually makes sense to keep the internal and external names the same (apart from not capitalising the internal name)—that way you can't forget what you called them! The exception to this is if you want to choose a shorter version for the internal name, to save on typing. For example, I like to use \newtheorem{prop}{Proposition} when defining Proposition environments, since typing out “proposition” all the time gets tiring.

Here is a variation on the preceding example that illustrates this.

1. I just made this name up. ↩︎

\documentclass{article}
\newtheorem{thm}{Theorem}
\newtheorem{pro}{Prophecy}
\begin{document}
Consider the following two statements. One of them is easier than other.
\begin{thm}
Let $p$ be an even prime. Then $p = 2$.
\end{thm}
\begin{pro}
There are infinitely many primes of the form $p = 2^k -1$.
\end{pro}
\end{document}

Numbering Theorems

There are two additional ways to tweak the \newtheorem command that allow us to fine tune the numbering. They both involve adding an addition [parameter] to the \newtheorem command. They differ only in where you put the additional term.

Note that in the last example, the second statement was printed as Prophecy 1. This is because by default, each environment is numbered separately, each starting at 1.

I personally detest this style of numbering. The reason for this is that if all theoremesque environments are numbered separately then it is very difficult to find things, particularly in long documents. Indeed, suppose you open your 800 page textbook and discover the following abomination on p354:

Now aside from the fact that the mathematics is nonsensical, how on earth are you going to find Lemma 47? Let alone Corollary 239? Should you flip forwards or backwards?

To solve this problem it is useful to allow similar theoremesque environments to “share” a counter. This is achieved by adding a pair of square brackets to the \newtheorem command.

Consider the following pair of commands:

\newtheorem{theorem}{Theorem}
\newtheorem{lemma}[theorem]{Lemma}

The first line defines a Theorem environment. The second line defines a Lemma environment, and the [theorem] that we added in between the internal name {lemma} and the external name {Lemma} tells $\mathrm{\LaTeX}$ to number the Lemma environment using the same counter as the Theorem environment.

Warning: You must use the internal name of a theoremesque environment you have already defined, and it must go between the internal name and the external name of the new theoremesque environment you are defining.

Here is a complete example:

\documentclass{article}
\newtheorem{theorem}{Theorem}
\newtheorem{prop}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\begin{document}
Our main result is the following statement.
\begin{theorem}
\label{p=2}
Let $p$ be an even prime. Then $p = 2$.
\end{theorem}
To prove Theorem \ref{p=2} we will need the following auxiliary proposition.
\begin{prop}
\label{q-not-prime}
If $q$ is an even number which is strictly greater than 2 then $q$ is not prime.
\end{prop}
Our proof of Theorem \ref{p=2} also uses the following technical lemma.
\begin{lemma}
The number 2 is prime.
\end{lemma}
\end{document}

As this example shows, any theoremesque environment can be labelled and then cross-referenced via the \label{} and \ref{} commands, just as we did in Lecture 2 for sections.

Suppose you'd rather that the theorems were numbered according to sections, so that the first theorem in Section 1 is called Theorem 1.1 and the first theorem in Section 2 is called Theorem 2.1. This is achieved by adding [section] at the end of the \newtheorem{} command, like this:  \newtheorem{theorem}{Theorem}[section].

Here is a complete example:

\documentclass{article}
\newtheorem{theorem}{Theorem}[section]
\begin{document}
\section{Introduction}
In this section we will prove the following two statements. One of them is easier than other.
\begin{theorem}
Let $p$ be an even prime. Then $p = 2$.
\end{theorem}
\begin{theorem}
There are infinitely many primes of the form $p = 2^k -1$.
\end{theorem}
\section{Conclusion}
Meanwhile in this section we will prove the following interesting result.
\begin{theorem}
Every day of the week ends with a y''.
\end{theorem}
\end{document}

Similarly if you'd rather theorems reset their counters with every subsection, you can use \newtheorem{theorem}{Theorem}[subsection]. Any of the numbered hierarchical environments from this table in Lecture 2 can be used.

If you have defined multiple theoremesque environments (say, Theorems and Corollaries), you might want the Corollaries to be numbered according to the Theorem they follow from. For this you, just as with sections, you add the internal name [theorem] onto the end of the newtheorem command that defines the Corollary environment:

\newtheorem{theorem}{Theorem}
\newtheorem{corollary}{Corollary}[theorem]

Warning: Pay attention to where the [theorem] goes! The two commands  \newtheorem{corollary}[theorem]{Corollary} and \newtheorem{corollary}{Corollary}[theorem] are not the same!

Here is a complete example:

\documentclass{article}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}{Corollary}[theorem]
\begin{document}
\begin{theorem}
\label{p=2}
Let $p$ be an even prime. Then $p = 2$.
\end{theorem}
Theorem \ref{p=2} has two important corollaries.
\begin{corollary}
The number 4 is not prime.
\end{corollary}
\begin{corollary}
The number 6 is not prime.
\end{corollary}
Our second main result goes as follows:
\begin{theorem}
$\pi$ is not an integer.
\end{theorem}
As a corollary we obtain:
\begin{corollary}
$\pi$ is not a prime number.
\end{corollary}
\end{document}

Let us summarise what we have covered so far:

1. \newtheorem{internal-name}{External Name}[blah] defines a new theoremesque environment External Name which is internally called internal-name, and which is numbered according to blah. Here blah can either be section (or any other hierarchical numbered level), or it can be the internal name of a theoremesque environment that has already been defined.
2. \newtheorem{internal-name}[blah]{External Name} defines a new theoremesque environment External Name which is internally called internal-name, and which shares its numbering with blah. Here blah must be the internal name of a theoremesque environment that has already been defined.

Warning: You cannot use both parameters at the same time. Thus \newtheorem{internal-name}[blah]{External Name}[blah2] will throw an error.

The amsthm Package

There are more ways to tweak our theoremesque environments. We will now describe some of the more common ones.

These all require the amsthm package (recall this is the third of the three “key” packages mentioned in Lecture 1).

Sometimes you might want to define a theoremesque environment that is not numbered at all. Just as with the \align command we discussed last time, this is done by replacing \newtheorem with \newtheorem*.

Here is a variation on the last example showing this in action:

\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\newtheorem*{corollary}{Corollary}
\begin{document}
\begin{theorem}
\label{p=2}
Let $p$ be an even prime. Then $p = 2$.
\end{theorem}
Theorem \ref{p=2} has two important corollaries.
\begin{corollary}
The number 4 is not prime.
\end{corollary}
\begin{corollary}
The number 6 is not prime.
\end{corollary}
Our second main result goes as follows:
\begin{theorem}
$\pi$ is not an integer.
\end{theorem}
As a corollary we obtain:
\begin{corollary}
$\pi$ is not a prime number.
\end{corollary}
\end{document}

Note that the amsthm package also improves the readability by indenting the first line after a theorem. (Compare to the previous picture.)

So far, all of our theoremesque environments have been typeset in the same way: the External Name is rendered in bold, and the content of the theoremesque environment (i.e. what appears between the \begin{internal-name} and \end{internal-name} commands) are typeset in italics.

This is a common way to display actual theorems, but for some theoremesque environments it is not always appropriate. For example, definitions are usually not typeset in italics. The amsthm package provides three styles that can be invoked using the command \theoremstyle.  They are:

Style Used for Appearance
plain Theorems, Propositions, etc. Theorem 1. Blah blah...
definition Definitions, Examples Definition 1. Blah blah...
remark Remarks, Notes Remark 1. Blah blah...

To use one of these for a theoremesque environment, put \theoremstyle{style-name} on the line immediately before the relevant \newtheorem command. This style will apply to all following theoremesque environments until another \theoremstyle{} command is encountered.

The style plain is just the default style. Thus the only point of the \theoremstyle{plain} command is to reset the theorem style to default.

Here is an example of this in action:

\documentclass{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{defn}{Definition}
\theoremstyle{remark}
\newtheorem{rem}[defn]{Remark}
\theoremstyle{plain}
\newtheorem{thm}[defn]{Theorem}
\newtheorem{cor}[defn]{Corollary}
\begin{document}
\begin{defn}
A prime number $p$ is a positive integer that cannot be formed by multiplying two smaller natural numbers.
\end{defn}
\begin{thm}
Let $p$ be an even prime. Then $p = 2$.
\end{thm}
\begin{cor}
The number 4 is not prime.
\end{cor}
\begin{rem}
A similar argument shows that 6 is also not a prime number.
\end{rem}
\end{document}

Some much for theorems. How about proofs?

The amsthm package comes with a special Proof environment. This environment is built into the package, and thus there is no need to use a \newtheorem{} command to define it first. To invoke a Proof environment you simply type \begin{proof}, and to finish it add \end{proof}.

The Proof environment is not numbered (since it customary to place the proof after the statement of the result). Moreover the Proof environment adds a square □ at the end, flushed to the right.

\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\begin{document}
\begin{defn}
A prime number $p$ is a positive integer that cannot be formed by multiplying two smaller natural numbers.
\end{defn}
\begin{thm}
Let $p$ be an even prime. Then $p = 2$.
\end{thm}
\begin{proof}
If $p \ne 2$ then $p = 2k$ for some integer $k \ge 2$. This contradicts the definition of a prime number.
\end{proof}
\begin{thm}
There are infinitely many primes $p$ of the form $2^k -1$.
\end{thm}
\begin{proof}
Exercise.
\end{proof}
\end{document}

We conclude today's lecture by discussing two other minor tweaks that are often useful.

Naming a Theorem

Sometimes you want to give a particular Theorem a name. You can append a name of your choice to any theoremesque environment by appending [Theorem Name] to the \begin{} command.

The name you specify will appear in brackets after the name and number the theoremesque environment would have had. The exception to this is the Proof environment, where the name will replace the word “Proof”.

Here is an example.

\documentclass{article}
\usepackage{amsthm}
\newtheorem{thm}{Theorem}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\begin{document}
\begin{defn}[Mersenne Prime]
A \textbf{Mersenne prime} $p$ is a prime number of the form $p = 2^k - 1$ for some positive integer $k$.
\end{defn}
\begin{thm}[The Mersenne Prime Conjecture]
There are infinitely many primes $p$ of the form $2^k -1$.
\end{thm}
\begin{proof}[Proof of the Mersenne Prime Conjecture]
Exercise.
\end{proof}
\end{document}
Changing the proof symbol

Perhaps you don't like a white square as your end-of-proof marker. Fear not! This can be customised by adding \renewcommand\qedsymbol{blah} to your preamble, where blah is what you'd like to change it to. For example, I prefer a black filled-in square, so I use

\renewcommand\qedsymbol{$\blacksquare$}

Another popular option is simply the letters Q.E.D.

\renewcommand\qedsymbol{\textbf{Q.E.D}}


Here is an example:

\documentclass{article}
\usepackage{amsthm}
\usepackage{amssymb}
\newtheorem{thm}{Theorem}
\theoremstyle{definition}
\newtheorem{defn}[thm]{Definition}
\renewcommand\qedsymbol{$\blacksquare$}
\begin{document}
\begin{defn}[Mersenne Prime]
A \textbf{Mersenne prime} $p$ is a prime number of the form $p = 2^k - 1$ for some positive integer $k$.
\end{defn}
\begin{thm}[The Mersenne Prime Conjecture]
There are infinitely many primes $p$ of the form $2^k -1$.
\end{thm}
\begin{proof}[Proof of the Mersenne Prime Conjecture]
Exercise.
\end{proof}
\end{document}

Note we had to use the amssymb package, since the \blacksquare symbol is part of that package.

That's it for today. Now it's time for you to go out and prove those theorems!