When beginners start writing equations in LaTeX, one of the first confusing issues they encounter is that mathematical symbols do not appear correctly in normal text.
This happens because LaTeX treats mathematical expressions differently from regular text. To write formulas, variables, limits, or matrices properly, you must place them inside math mode.
Table of Contents
In this guide, you will learn how math mode in LaTeX works and how to write both inline math (equations inside a sentence) and display math (equations on a separate line) with clear examples.
What Is Math Mode in LaTeX?
Math mode is a special formatting mode in LaTeX designed specifically for mathematical expressions.
For example, writing this in normal text will cause an error:
x^2 + y^2
But inside math mode:
$x^2 + y^2$ \[x^2 + y^2\]
LaTeX correctly interprets the expression as mathematics.
Inline Math Using $…$
The most common way to write mathematical expressions inside a sentence is using dollar signs.
Inline math keeps the equation within the same line as the surrounding text.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Suppose that $g(x) \leq f(x) \leq h(x)$ for all $x$ in some open interval containing $c$,
except possibly at $x = c$ itself. Suppose also that $ \lim_{x \to c}g(x) = \lim_{x \to c}h(x) = L$.
Then $\lim_{x \to c}f(x) = L$. This is called the Sandwish Theorem.
\end{document}
In this example, the expressions are written inside $...$, which tells LaTeX to switch to math mode so that the mathematical symbols are displayed correctly within the line of text.
Inline Math Using \( … \)
Another modern way to write inline mathematical expressions is using parentheses syntax.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Suppose that \(g(x) \leq f(x) \leq h(x)\) for all \(x\) in
some open interval containing \(c\), except possibly at \(x = c\)
itself. Suppose also that \(\lim_{x \to c}g(x) = \lim_{x \to c}h(x) = L\).
Then \(\lim_{x \to c}f(x) = L\). This is called the Sandwish Theorem.
\end{document}
This method produces the same result as $...$, but it helps avoid conflicts that may occur when dollar symbols are used elsewhere in a document.
For this reason, many modern LaTeX style guides recommend using this syntax for writing inline mathematical expressions.
Inline Math Using the math Environment
LaTeX also provides the math environment for writing inline mathematical expressions.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
Suppose that \begin{math}g(x) \leq f(x) \leq h(x)\end{math} for all
\begin{math}x\end{math} in some open interval containing \begin{math}c\end{math},
except possibly at \begin{math}x =c\end{math} itself.
Suppose also that \begin{math}\lim_{x \to c}g(x) =\lim_{x \to c}h(x) = L\end{math}.
Then\begin{math}\lim_{x \to c}f(x) = L\end{math}. This is called the Sandwish Theorem.
\end{document}
Although this method works correctly, it is less commonly used because it requires more typing compared to shorter syntax.
Most LaTeX users prefer $...$ or \( ... \) for inline expressions.
Display Math Using \[ … \] (Recommended)
The most commonly recommended method for display equations is the bracket syntax.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
A set of $ mn $ number (real or imaginary) arranged in the
form of a rectangular array of $ m $ rows and $ n $ columns
is called an $ m \times n $ matrix. An $ m \times n $ matrix
is usually written as
\[ A =\begin{pmatrix}
a_{11} & a_{12} & \cdots & a_{1n}\\
a_{21} & a_{22} & \cdots & a_{2n}\\
\vdots & \vdots & \ddots & \vdots\\
a_{n1} & a_{n2} & \cdots & a_{nn}
\end{pmatrix} \]
\end{document}
This method is widely used because it is short, clean, and part of standard LaTeX.
It also works well with modern packages, which is why \[ ... \] is considered the best choice for writing display equations in most documents.
Display Math Using $…$
Sometimes equations need to stand out clearly from the surrounding text. In such cases, we use display math, which places the equation on a new centered line.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$$ x^2 + y^2 = z^2 $$
$$ E = mc^2 $$
\end{document}
A traditional method uses double dollar symbols.
However, the $$...$$ syntax is not officially recommended in LaTeX because it originates from plain TeX and may cause spacing problems in complex documents.
Display Math Using the displaymath Environment
A more structured way to write display equations is the displaymath environment.
\begin{displaymath}
equation
\end{displaymath}
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{displaymath}
E = mc^2
\end{displaymath}
\end{document}
This environment places the equation on a new centered line without numbering it.
Inline Math vs Display Math
Understanding when to use each type of math formatting is important.
| Type | Usage | Example |
|---|---|---|
| Inline Math | Equations inside a sentence | $x^2 + y^2$ |
| Display Math | Important formulas on a new line | \[ E = mc^2 \] |
Inline math keeps the text flowing naturally, while display math highlights important formulas.
FAQs
What is math mode in LaTeX?
Math mode in LaTeX is a special formatting mode used to write mathematical expressions such as equations, symbols, fractions, and limits. It automatically adjusts spacing, fonts, and formatting so mathematical formulas appear correctly.
What is the difference between inline math and display math in LaTeX?
Inline math appears within a sentence and is typically written using $...$ or \( ... \). Display math places equations on a separate centered line and is usually written using \[ ... \] or equation environments.
How do you write inline equations in LaTeX?
Inline equations in LaTeX are commonly written using dollar signs $...$ or the syntax \( ... \). These methods allow mathematical expressions to appear within a line of text.
How do you write display equations in LaTeX?
Display equations in LaTeX are written using \[ ... \], displaymath, or equation environments. These methods place equations on a new centered line.
Why should you avoid using $$...$$ in LaTeX?
The $$...$$ syntax comes from plain TeX and is not recommended in standard LaTeX documents because it may cause spacing issues and conflicts with some packages.
When should you use inline math in LaTeX?
Inline math should be used for short mathematical expressions, variables, or symbols within a sentence so that the paragraph structure remains natural.
When should you use display math in LaTeX?
Display math is used for longer equations or formulas that need to stand out from the surrounding text and appear on a separate centered line.
Conclusion(Best Practice)
To keep mathematical documents clean and professional in LaTeX, it is recommended to use $...$ or \( ... \) for short inline expressions within a sentence.
For equations that should appear on a separate line, \[ ... \] is generally preferred. In modern LaTeX documents, it is also better to avoid using $$...$$ because it is not part of standard LaTeX syntax and may cause formatting issues.

![This figure represents the matrix and definition. But, this image shows use of \[ . . .\] in display mode.](https://www.physicsread.com/wp-content/uploads/2023/03/matrix_def.png)
Medicine