LaTeX is a high-quality typesetting software used to create professional documents like research papers, thesis, reports, and more. It is extensively used in academia for its ability to beautifully typeset math equations.
One of the most common elements in LaTeX is the curly bracket – {
and }
. They are utilized for a variety of purposes, from grouping text and equations to denoting sets in math. However, LaTeX does not display the curly brackets directly. So how does one properly write and display curly brackets in LaTeX? This comprehensive guide will walk you through it.
Escaping the Curly Brackets
To print the curly bracket characters {
and }
in LaTeX, you need to escape them using the backslash \
as below:
\{ and \}
Let‘s take a basic example:
\documentclass{article}
\begin{document}
This is an example with escaped brackets \{ and \}.
\end{document}
This will produce the output:
This is an example with escaped brackets { and }.
The backslash tells LaTeX to print the next character as regular text instead of interpreting it as a command.
You need to escape every curly bracket that you want to display in the output. Unescaped brackets will cause errors or disappear entirely.
Curly Brackets for Grouping
In LaTeX, curly brackets are commonly used to group text and commands to limit the scope or apply specific formatting. This is helpful when:
- You want to apply formatting like
\textit
,\textbf
etc. to a section of text without affecting the rest. - Use math mode
$
delimiters in running text. - Creating custom commands/environments.
Here is an example:
\documentclass{article}
\begin{document}
This is some \textbf{bold text \textit{with italicized section} in bold}.
Whereas this \{\textbf{bold text \textit{with italicized section}} in bold\} keeps the scope limited.
\end{document}
Output:
This is some bold text with italicized section in bold.
Whereas this {bold text with italicized section} in bold keeps the scope limited.
As you can see, the curly brackets nicely limit the scope of the inner formatting commands.
Curly Brackets in Math Mode
Curly brackets {}
are ubiquitously used in LaTeX math environments to denote sets, intervals, boundary conditions and other common mathematical concepts.
For example:
f: \{1, 2, ..., n\} → \{1, 2, ..., m\}
To make the curly brackets visible in math mode, again they need to be escaped as below:
$f: \{\} → \{\}$
Here is a complete document showing escaped curly brackets denoting sets in a math equation:
\documentclass{article}
\begin{document}
$f: \{1, 2, ..., n\} \rightarrow \{1, 2, ..., m\}$
\end{document}
This produces the math equation with curly brackets:
$f: {1, 2, …, n} \rightarrow {1, 2, …, m}$
Note that only the displayed curly brackets are escaped i.e. the ones inside $ $
. The brackets grouping the math mode $
don‘t need to be escaped.
Let‘s see a more complex example:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
A &= \{x ∈ R : x^2 < 1\} \\
B &= \{x, y, z\}
\end{align*}
\end{document}
Output:
A = \{x ∈ R : x^2 < 1\}
B = \{x, y, z\}
This showcases:
- Escaped curly brackets denoting real number sets and intervals
- Curly brackets grouping math mode without escaping
amsmath
package for multi-line equations
Curly Brackets in Equation Environments
There are dedicated LaTeX environments like cases
and matrix
to showcase special structures including curly brackets in equations.
For example, the cases
environment from amsmath
package:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
x=
\begin{cases}
-b/2a & \quad \text { if } \Delta = 0 \\
(-b-\sqrt{\Delta})/2a & \quad \text { if } \Delta > 0
\end{cases}
\end{equation*}
\end{document}
This generates the equation:
/ -b/2a if Δ = 0
x =
| (-b−√Δ)/2a if Δ > 0
With automatic sizing, spacing and rows of equations denoted by curly brackets.
Similarly, environments like bmatrix
and Bmatrix
from amsmath
can generate brackets of varying sizes:
A =
\begin{Bmatrix}
a & b \\
c & d
\end{Bmatrix}
You can build matrices, piecewise functions, cases diagrams and more with these handy environments.
Common Issues with Curly Brackets
When starting out with LaTeX math, users often face issues in getting the curly brackets to appear correctly. Here are some common problems and solutions:
1. Brackets simply disappear in output
This happens when you forget to escape the curly brackets with \
. Just add the slash and it will work.
2. Mismatched bracket errors
This points to unescaped left {
or right }
brackets which LaTeX tries to parse as a grouping. Fix all bracket escapes.
3. Brackets rendered as single brace
Use { }
for braces. For curly brackets, use the correct \{\}
escape sequence.
4. Text outside math environment rendered inside brackets
The bracket escapes \{\}
will trigger inline math mode. Simply remove to prevent.
In essence, most issues boil down to the cardinal rule – "Escape every curly bracket that you want displayed in LaTeX output". This takes care of most use cases.
Setting Brackets Delimiters Globally
Instead of manually escaping every curly bracket, you can set LaTeX to automatically render them in math expressions using \left
and \right
commands:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
%% Set curly brackets as default math delimiters
\renewcommand*{\leftdelimiter}{\{}
\renewcommand*{\rightdelimiter}{\}}
$$
f: {1, 2, ..., n} \to {1, 2, ..., m}
$$
\end{document}
Now you don‘t need to escape every {
and }
! They will appear as curly brackets by default. Useful in case you have many bracketed math expressions.
The \left
and \right
commands adjust the size, spacing and type of delimiters on-the-fly. You can customize braces, brackets, bars and more.
Code Examples Using Curly Brackets
Let‘s consolidate what we have learned through some annotated code examples demonstrating common applications of curly brackets in LaTeX:
1. Sets in Math Expressions
\documentclass{article}
\usepackage{amsmath}
\begin{document}
% Curly brackets denote sets
$ A = \{\mathbf{x} \in \mathbb{R}^n | \mathbf{x} \cdot \mathbf{x} \leq 1\} $
% Escape the displayed brackets
$ B = \{1, 2, 3, ..., n\} $
% No need to escape bracket groups
$\{1 + 2 + 3 + ... + n\}$
% amsmath environments
\begin{equation*}
S = \{\{1\}, \{1, 2\}, \{1, 2, 3\}\}
\end{equation*}
\end{document}
This showcases bracketed sets in inline and display math styles.
2. Number Intervals
\documentclass{article}
\usepackage{amsmath}
\begin{document}
% Inline intervals
$ x \in \{\!-\!1, 1\} $
% Multi-line interval notation
\begin{align*}
I &= \{\} \\
J &= \{1, 2, 3\} \\
K &= \{x ∈ R : |x - 3| < 2\}
\end{align*}
% Interval notation with cases
\begin{equation*}
f(x) =
\begin{cases}
x^2, & x ∈ \{−1,1\} \\
0, & \text{otherwise}
\end{cases}
\end{equation*}
\end{document}
Intervals notation like set builder forms , inequality and cases environments are demonstrated.
3. Matrix Bracketing
\documentclass{article}
\usepackage{amsmath}
\begin{document}
% Inline matrix
$ A = \{\{\mathbf{a}\}, \{\mathbf{b}, \mathbf{c}\}\} $
% Small matrix
\[
B = \begin{bsmallmatrix}
1 & 0 \\
0 & 1
\end{bsmallmatrix}
\]
% Large matrix delimiters
\[
C = \begin{Bmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \cdots & a_{mn}
\end{Bmatrix}
\]
\end{document}
Here, different bracket sizes for matrices are demonstrated using amsmath
environments.
As you can see, curly brackets have a wide range of usage in LaTeX math typesetting. The key things to remember are:
- Use backslash
\
escape sequence to print{}
characters - Escape only the displayed brackets, not bracket groups
- Utilize delimiters globally instead manual escapes when convenient
- Leverage
amsmath
environments for complex notation
With this knowledge, you should be able to adeptly make use of curly brackets for quality math typesetting in LaTeX!