When you type a function name like \sin or \log in a formula, it is set upright (roman) with the correct space around it. This is not decoration. In math mode every letter is treated as a variable, so typing sin(x) literally collapses into the product of three variables s, i, n — which is why LaTeX predefines the common function names as commands. This page covers the trigonometric, logarithmic, and exponential family; the relatives like \lim and \max that set their subscript directly below; the modular-arithmetic forms \bmod and \pmod; and how to define your own operator when the one you need is not on the list.
Why named operators exist
Inside math mode each letter is taken to be the name of a variable and set in math italic. So typing sin x yields not “sine” but the product of four quantities s, i, n, x, slanted and spaced as a run of variables. That violates the mathematical convention that function names and constants are set upright.
The right way is a dedicated command such as \sin. LaTeX predefines the names of common functions and operators; each is set upright and automatically gets the correct operator spacing around it. For instance \sin x produces the textbook result: an upright “sin” followed by a thin space and the variable x. All of these commands are part of standard LaTeX and need no extra package (only defining your own requires amsmath — see below).
Trig, log & exponential
The most frequently used are the trigonometric, hyperbolic, logarithmic, and exponential family. These are ordinary operators: when they take a script it sits at their right side, not below (the below-type comes in the next section).
- Trigonometric:
\sin\cos\tan\cot\sec\csc, plus the inverses\arcsin\arccos\arctan. - Hyperbolic:
\sinh\cosh\tanh\coth. - Logarithms:
\log(logarithm in general),\ln(natural log),\lg(base-2 log). - Exponential & others:
\exp(exponential),\deg(degree),\dim(dimension),\ker(kernel),\hom,\arg(argument).
Bases and exponents attach through the ordinary script mechanism. \log_2 x gives a base-2 logarithm with a small 2 at the lower right of “log,” and \sin^2\theta puts an exponent 2 at the upper right of “sin” — the customary sin²θ. Choose among \log, \ln, and \lg by meaning: \ln for the natural logarithm, and \lg for the base-2 logarithm (common in information theory).
\[
\sin^2\theta + \cos^2\theta = 1, \qquad
\log_2 8 = 3, \qquad
\ln e = 1.
\]In this display, “sin,” “cos,” “log,” and “ln” are all upright; \sin^2\theta puts the 2 at the upper right of sin, and \log_2 8 puts the 2 at its lower right. The three formulas sit on one line separated by the wide \qquad gap. For contrast, dropping the \ as in sin^2\theta would set s, i, n as slanted variables with the wrong spacing.
Operators that set limits below
Distinct from the functions above is a group of operators that place their subscript directly below the symbol. Limits, suprema and infima, maxima and minima belong here, because the convention is to show “over what range or condition” prominently beneath the symbol.
\lim(limit),\limsup(limit superior),\liminf(limit inferior).\sup(supremum),\inf(infimum),\max(maximum),\min(minimum).\det(determinant),\gcd(greatest common divisor),\Pr(probability).
These set their subscript directly below in display style and at the lower right in text style (inline). The behavior is identical to big operators such as \sum and \int and is governed by the style (to force the below position inline, use \displaystyle; see “Sums, integrals & big operators”). For example \lim_{x \to 0} sets x→0 right under “lim” in a display, and small at the lower right within running text.
\[
\lim_{x \to 0} \frac{\sin x}{x} = 1, \qquad
\max_{1 \le i \le n} a_i .
\]In this display, x→0 sits directly under “lim” and 1≤i≤n under “max,” with the body of each expression following to the right; \sin x is also set correctly in upright type. Written inline as $\lim_{x\to0}\frac{\sin x}{x}$, the range instead appears small at the lower right of “lim.”
Modular arithmetic (mod)
The “mod” of modular arithmetic comes in several forms depending on context, each differing in spacing and parentheses. Standard LaTeX provides \bmod and \pmod; amsmath adds \mod and \pod.
\bmod is mod as a binary operator (the b is for binary). Writing 5 \bmod 3 puts binary-operator spacing around “mod” between 5 and 3, setting it as “5 mod 3.” Use it when you mean the value (the remainder) itself. \pmod{n}, by contrast, is the parenthesized modulus appended to a congruence. Writing a \equiv b \pmod{n} sets “(mod n)” a little apart at the right of the formula, giving “a ≡ b (mod n)” (the argument n is passed in braces). With amsmath loaded, the space before \pmod is automatically tightened in inline (text-style) formulas.
\[
5 \bmod 3 = 2, \qquad
17 \equiv 5 \pmod{12}.
\]In this display, the left expression is set with binary-operator spacing as “5 mod 3 = 2,” and the right one as “17 ≡ 5 (mod 12),” with the congruence sign \equiv and a parenthesized “(mod 12)” appended at the end.
The two that amsmath adds are variants of \pmod. \mod{n} sets just “mod n” without parentheses (a form some authors prefer, with space before it), while \pod{n} drops “mod” but keeps the parentheses, setting “(n).” The table sorts out the four.
| Command | Output (e.g. n=3) | Use / notes |
|---|---|---|
\bmod | a mod b | Binary operator; the remainder value. Standard LaTeX |
\pmod | (mod 3) | Appended to a congruence; parenthesized. Standard LaTeX |
\mod | mod 3 | Variant without parentheses; needs amsmath |
\pod | (3) | “mod” omitted, parentheses kept; needs amsmath |
Defining your own operator
You will sometimes want a function name that is not on the list — the sign function sgn, the trace tr, the rank rank, the image Im — set correctly in upright type. For a one-off, use \operatorname{…} from amsmath. Writing \operatorname{sgn} x sets “sgn” upright with proper spacing, matching the quality of \sin and friends.
If you use the same operator repeatedly, declare it once in the preamble with \DeclareMathOperator{\sgn}{sgn}. Then you write just \sgn in the body, with the definition kept in one place. For an operator whose subscript should sit directly below (like \lim), use the starred form \DeclareMathOperator*{\argmax}{arg\,max} (for a one-off, the starred \operatorname*{…} does the same). Unstarred puts scripts at the right; starred puts them below in displays. All of these come from amsmath (internally the amsopn package, loaded automatically by amsmath), so you need \usepackage{amsmath}.
\usepackage{amsmath}
\DeclareMathOperator{\sgn}{sgn}
\DeclareMathOperator*{\argmax}{arg\,max}
% 本文中 / in the body:
% \[ \sgn x, \qquad \argmax_{x \in S} f(x) \]After these declarations, in a display \sgn x gives an upright “sgn” and the variable x, while \argmax_{x \in S} sets “arg max” (with a thin \, space between the words) and places x∈S directly beneath it. The \, in the name keeps the proper gap between “arg” and “max.” Declared once, a later change of notation is a single edit in the preamble that propagates through the whole document.