Typevia
Mathematical Typesetting

Introduction to Mathematical Environments

In mathematical, scientific, and technical writing, it is essential to distinguish between different types of statements. A Definition clarifies the meaning of a term, while a Lemma is a "helping proposition" used as a stepping stone toward a larger theorem.

LaTeX does not include these environments by default. Instead, it provides a powerful system for creating them using the amsthm (American Mathematical Society Theorem) package. This guide will teach you how to define, style, and use these environments to create professional academic documents.

Setting Up the amsthm Package

To begin creating definitions and lemmas, you must first include the amsthm package in your document's preamble. The core command used to create these structures is \newtheorem.

Basic Syntax

The \newtheorem command requires two main arguments:

  1. The internal name: This is what you use in your LaTeX code (e.g., defn).
  2. The printed label: This is what the reader sees in the PDF (e.g., Definition).
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsthm} % Required package

% Defining the environments in the preamble
\newtheorem{definition}{Definition}
\newtheorem{lemma}{Lemma}

\begin{document}

\begin{definition}
A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself.
\end{definition}

\begin{lemma}
Every integer greater than 1 has at least one prime divisor.
\end{lemma}

\end{document}

Note: The definitions of these environments must go in the preamble (the area before \begin{document}). If you place them inside the document body, LaTeX will return an error.

Customizing Styles

The amsthm package provides three predefined styles that change the font and spacing of your environments. You can toggle these using the \theoremstyle{style_name} command.

  1. plain: Bold title, italicized body text. (Default for theorems, lemmas, and corollaries).
  2. definition: Bold title, roman (upright) body text. (Standard for definitions, examples, and exercises).
  3. remark: Italicized title, roman body text. (Used for notes and remarks).

Example: Mixing Styles

\usepackage{amsthm}

\theoremstyle{definition}
\newtheorem{defn}{Definition}

\theoremstyle{plain}
\newtheorem{lem}{Lemma}

\begin{document}

\begin{defn}[Square]
A square is a regular quadrilateral, which means it has four equal sides and four equal angles.
\end{defn}

\begin{lem}
The diagonals of a square are equal and bisect each other at right angles.
\end{lem}

\end{document}

In the example above, the definition text will appear in normal upright font, while the lemma text will be automatically italicized to signify its mathematical importance.

Controlling Numbering

By default, LaTeX numbers each environment independently and sequentially (Definition 1, Definition 2, Lemma 1, etc.). However, most authors prefer to link numbering to sections or share a single counter across all environments.

Numbering by Section

To reset the counter at the start of every section (e.g., Definition 1.1, Definition 1.2), add the section name in square brackets at the end: \newtheorem{defn}{Definition}[section]

Shared Counters

To make lemmas and definitions share the same numbering sequence (e.g., Definition 1 followed by Lemma 2), place the name of the first environment in square brackets in the middle of the second definition:

\newtheorem{defn}{Definition} [section]
\newtheorem{lem}[defn]{Lemma} % Lemma now shares the 'defn' counter

Unnumbered Environments

If you want a definition that doesn't have a number, use the "starred" version of the command. This requires the amsthm package.

\newtheorem*{definition}{Definition}

\begin{definition}
This statement will not have a number assigned to it.
\end{definition}

Practical Application: The Lemma and Proof

Lemmas are almost always followed by a proof. The amsthm package automatically provides a proof environment that handles spacing and adds a "Q.E.D." symbol (a square) at the end.

Example: A Complete Mathematical Block

\documentclass{article}
\usepackage{amsthm, amsmath, amssymb}

\theoremstyle{plain}
\newtheorem{lemma}{Lemma}

\begin{document}

\section{Introduction to Number Theory}

\begin{lemma}
If $n$ is an even integer, then $n^2$ is a multiple of 4.
\end{lemma}

\begin{proof}
Since $n$ is even, there exists an integer $k$ such that $n = 2k$. 
Squaring both sides of the equation, we get:
\[ n^2 = (2k)^2 = 4k^2 \]
Since $k^2$ is an integer, $n^2$ is divisible by 4.
\end{proof}

\end{document}

Best Practices and Common Pitfalls

Best Practices

  • Use Labels for Cross-Referencing: Always add a \label{name} inside your environment. You can then use \ref{name} to refer to "Definition 1" elsewhere in your text. This ensures that if your numbering changes later, your references update automatically.
  • Keep Names Consistent: Use short, logical internal names for your environments, such as defn for Definition and lem for Lemma.
  • Optional Arguments: Use the optional square brackets after \begin{defn}[Title] to give your definition or lemma a specific name or attribution.

Common Pitfalls

  • Forgetting the Package: Beginners often try to use \newtheorem without loading amsthm. While standard LaTeX has a very basic version of this command, amsthm is required for styles and the proof environment.
  • Over-Italicizing: Avoid using the plain style for definitions. Long definitions in italics are difficult to read; use \theoremstyle{definition} instead.
  • Nested Environments: Do not try to place a Lemma inside a Definition environment. These should be kept separate for clarity and proper document structure.

Warning: Be careful with the order of arguments in \newtheorem. Putting the section counter in the wrong place is one of the most common causes of "Missing number" errors in LaTeX. Remember: \newtheorem{env_name}[shared_counter]{Label} OR \newtheorem{env_name}{Label}[section_reset]. You cannot do both!