LaTeX by Example: Math Mode
LaTeX is famous for its mathematical typesetting. This example introduces inline math and display math modes.
Code
\documentclass{article}
\usepackage{amsmath} % Recommended for better math support
\begin{document}
% Inline math: embedded in text using $ ... $
Einstein's famous equation is $E = mc^2$.
The roots of the quadratic equation are given by $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$.
% Display math: centered on its own line using \[ ... \]
The integral of a function $f(x)$ is denoted as:
\[
\int_{a}^{b} f(x) \, dx = F(b) - F(a)
\]
% Superscripts and Subscripts
Summation: $\sum_{i=1}^{n} i^2 = \frac{n(n+1)(2n+1)}{6}$
\end{document}Explanation
LaTeX has two primary modes for typesetting mathematics: inline mode and display mode. Inline math is written between dollar signs $ ... $ and is designed to flow with the surrounding text. LaTeX automatically adjusts the size of symbols like summation limits to prevent disrupting the line spacing.
Display math is written between \[ ... \] (or inside the equation environment). This places the equation on its own line, centered, with extra vertical space. Symbols in display mode are typically larger and more elaborate; for example, limits on integrals and sums are placed above and below the operator rather than to the side.
The syntax for math symbols is intuitive. Superscripts are created with the caret ^ and subscripts with the underscore _. If the script contains more than one character, you must group them in curly braces, e.g., x^{10}. Commands like \frac{numerator}{denominator} and \sqrt{expression} handle complex structures effortlessly.
Code Breakdown
$E = mc^2$ renders the equation inline. The spaces inside the math mode are ignored by LaTeX.\[ ... \] is the standard LaTeX command for unnumbered display equations. Avoid using $$ ... $$ as it is deprecated TeX syntax.
