Introduction to Mathematical Operators
In LaTeX, typesetting mathematics involves more than just typing numbers and letters. One of the most important distinctions you must make is between variables and operators.
By default, LaTeX treats letters in math mode as variables and typesets them in italics (e.g., $x, y, z$). However, mathematical functions and operators—such as "sin," "log," or "lim"—should be typeset in upright (roman) font to distinguish them from variables. If you simply type sin(x) in math mode, LaTeX interprets it as the product of $s$, $i$, and $n$, resulting in $sin(x)$.
To fix this, LaTeX provides specific commands for operators that handle both the font style and the correct spacing around the operator automatically.
Basic Binary Operators
Binary operators are symbols that act on two elements. While your keyboard has keys for plus (+) and minus (-), other common mathematical symbols require specific LaTeX commands.
Common Symbols
Here are the most frequently used binary operators:
- Multiplication: Use
\times($\times$) or\cdot($\cdot$). Never use the letter 'x'. - Division: Use
\div($\div$) for the division symbol or\frac{num}{den}for fractions. - Plus-Minus: Use
\pm($\pm$) or\mp($\mp$).
Code Example: Basic Arithmetic
\documentclass{article}
\begin{document}
The area of a circle is calculated using:
\[ A = \pi \cdot r^2 \]
Solving for quadratic roots:
\[ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \]
Standard operations:
\[ 10 \div 2 \times 5 = 25 \]
\end{document}Note: LaTeX automatically adds appropriate spacing around binary operators. For example, it knows that the space around the
+in $a + b$ should be larger than the space in a subscript like $x_{a+b}$.
Standard Mathematical Functions
LaTeX includes built-in commands for almost all standard trigonometric, logarithmic, and hyperbolic functions. Using these commands ensures that the operator is upright and spaced correctly.
Frequently Used Commands
| Category | Commands |
|---|---|
| Trigonometric | \sin, \cos, \tan, \sec, \csc, \cot |
| Inverse Trig | \arcsin, \arccos, \arctan |
| Logarithmic | \log, \ln, \lg |
| Limits/Others | \lim, \max, \min, \sup, \inf, \det |
Code Example: Using Built-in Functions
\documentclass{article}
\begin{document}
Using standard functions:
\[ \sin^2 \theta + \cos^2 \theta = 1 \]
The definition of a natural logarithm:
\[ \ln(e^x) = x \]
A limit example:
\[ \lim_{x \to \infty} \frac{1}{x} = 0 \]
\end{document}Large Operators and Limits
"Large" operators are symbols like summations ($\sum$), integrals ($\int$), and products ($\prod$). These operators often behave differently depending on whether they are "inline" (inside a sentence) or "displayed" (on their own line).
Placement of Limits
By default:
- Inline Mode (
$...$): Limits are placed to the right of the symbol to save vertical space: $\sum_{i=1}^{n}$. - Display Mode (
\[...\]): Limits are placed directly above and below the symbol: [\sum_{i=1}^{n}]
Code Example: Summations and Integrals
\documentclass{article}
\begin{document}
Inline summation: $\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$
Display mode summation:
\[ \sum_{i=1}^{n} i = \frac{n(n+1)}{2} \]
An integral with limits:
\[ \int_{a}^{b} f(x) \, dx \]
\end{document}Best Practice: When writing integrals, it is common practice to add a small space before the "dx" using the
\,command. This improves readability significantly.
Defining Custom Operators with amsmath
Sometimes you need an operator that LaTeX doesn't provide by default, such as "rank," "tr" (trace), or "erf" (error function). While you could use \mathrm{rank}, this won't handle mathematical spacing correctly.
The professional way to handle this is by using the amsmath package and the \DeclareMathOperator command.
Syntax
\DeclareMathOperator{\command}{operator name}
This command must be placed in your preamble (the area before \begin{document}).
Code Example: Custom Operators
\documentclass{article}
\usepackage{amsmath}
% Define custom operators in the preamble
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\rank}{rank}
% Use the starred version for operators that need limits
\DeclareMathOperator*{\argmax}{arg\,max}
\begin{document}
The trace of the matrix is:
\[ \tr(A) = \sum_{i=1}^{n} a_{ii} \]
We can also find the rank:
\[ \rank(M) = k \]
Finding the maximum value's argument:
\[ \argmax_{x \in D} f(x) \]
\end{document}Common Pitfalls and Best Practices
To create professional-looking documents, keep these tips in mind:
1. Never use text mode inside math mode
If you need to put a word in an equation that isn't an operator, use \text{...} from the amsmath package.
- Wrong:
$x = 5 for y > 0$(The "for" will be italicized and poorly spaced if not wrapped in\text). - Right:
x = 5 \text{ for } y > 0
2. Don't use \limits manually unless necessary
You can force limits to appear above/below an operator in inline mode using \sum\limits_{i=1}^n. However, this is usually discouraged because it messes up the line spacing of your paragraph. Stick to the defaults unless you have a specific design reason to change them.
3. Modulo Operators
For modular arithmetic, LaTeX provides three different commands depending on the context:
a \bmod n: Used as a binary operator ($a \bmod n$).a \pmod n: Used for congruences, adds parentheses and a large space ($a \equiv b \pmod n$).a \pod n: Same as\pmodbut omits the "mod" text.
4. Comparison Operators
Always use the dedicated commands for inequalities:
- Greater/Less than or equal:
\ge($\ge$) and\le($\le$). - Not equal:
\neq($\neq$). - Approximately equal:
\approx($\approx$) or\sim($\sim$).
By using the correct operator commands instead of plain text or basic symbols, you ensure your mathematical documents meet the high typesetting standards expected in scientific and academic publishing.
