This post explains how to typeset multi-part definitions in LaTeX.
The absolute value function is a simple example of a two-part definition.
![]()
The Möbius function is a more complicated example of a three-part definition.

Here’s how you could write LaTeX for the absolute value definition.
|x| =
\left\{
\begin{array}{ll}
x & \mbox{if } x \geq 0 \\
-x & \mbox{if } x < 0
\end{array}
\right.
The right-hand side of the equation is an array with an opening brace sized to fit on the left. Braces are special characters and so the opening brace needs to be escaped with a backslash. LaTeX requires a \right for every \left but the dot in \right. says to make the matching container on the right side empty.
Since this pattern comes up fairly often, it’s handy to have a command to encapsulate it. We define \twopartdef as follows.
\newcommand{\twopartdef}[4]
{
\left\{
\begin{array}{ll}
#1 & \mbox{if } #2 \\
#3 & \mbox{if } #4
\end{array}
\right.
}
Then we could call it as follows:
|x| = \twopartdef { x } {x \geq 0} {-x} {x < 0}
The command \threepartdef is very similar to \twopartdef.
\newcommand{\threepartdef}[6]
{
\left\{
\begin{array}{lll}
#1 & \mbox{if } #2 \\
#3 & \mbox{if } #4 \\
#5 & \mbox{if } #6
\end{array}
\right.
}
You could call \threepartdef for the Möbius function as follows.
\mu(n) = \threepartdef
{1} {n=1}
{0} {a^2 \,|\, n \mbox{ for some } a > 1}
{(-1)^r} {n \mbox{ has } r \mbox{ distinct prime factors}}
Related posts:
Typesetting music in LaTeX
How to display side-by-side figures in LaTeX
Including images in LaTeX
LaTeX and PowerPoint presentations
How to put PDF properties in a LaTeX file

{ 5 comments… read them below or add one }
gappy 09.14.09 at 15:46
John,
This functionality is provided natively by LaTeX in the “cases” environment. It’s described in the LaTeX Companion (sec. 8.4.1).
Example:
|x| =
\begin{cases}
x & \text{if } x \geq 0 \\
-x & \text{if } x < 0
\end{cases}
(Editors note: To use the “cases” environment, add
\usepackage{amsmath}to the preamble. — JC)John 09.14.09 at 15:53
Thanks. I didn’t know that.
The “cases” environment wasn’t part of LaTeX when I learned it, back before version 2e. Back in my day …
Daniel Lemire 09.14.09 at 17:04
I also hacked something similar for a recent paper of mine. I also did not know about the cases environment, though I’m a long time LaTeX user.
Alasdair 09.15.09 at 01:06
If you’re using LaTeX for maths (which you are!) then you should automatically also use the amsmath package, which contains many many commands for different sorts of displayed equations, of which cases is one. Not all of amsmath is part of standard LaTeX.
Stefan 10.07.09 at 18:42
The cases environment will be a bit higher than the array environment, you could see if you would compare the examples above, because there’s a fixed \arraystretch of 1.2 internally. It may be ok, but if you want to stretch it less or more according to the content here’s a possibility, amsmath: cases and \arraystretch.