Modulus and mod in LaTeX come in a few forms: \bmod for a remainder, \pmod{n} after a congruence, and \lvert z \rvert for the modulus (absolute value) of a number. The table lists the eight commands people use most, with the package each one needs; the full list of number theory symbols follows below.
| Symbol | Command | Use | Package | Copy |
|---|---|---|---|---|
a \bmod n | Modulo as a binary operation | built in | ||
a \equiv b \pmod{n} | Congruence with (mod n) | built in | ||
a \equiv b \mod{n} | Congruence without parentheses | amsmath | ||
\lvert z \rvert | Modulus / absolute value | amsmath | ||
a \mid b | a divides b | built in | ||
a \nmid b | a does not divide b | amssymb | ||
\gcd(a, b) | Greatest common divisor | built in | ||
\operatorname{lcm}(a, b) | Least common multiple | amsmath |
Divisibility is the symbol people search for most: a \mid b means a divides b, and \nmid (from amssymb) negates it. Use \mid rather than a plain bar so LaTeX treats it as a relation with the right spacing. Congruences use \equiv together with \pmod{n}, which adds the parentheses and spacing for you: a \equiv b \pmod{n}. Inline remainders use \bmod, as in a \bmod n.
The greatest common divisor has its own operator, \gcd(a, b); the least common multiple does not, so write \operatorname{lcm}(a, b) with amsmath. Euler’s totient is \varphi(n) (or \phi(n)), the Möbius function is \mu(n), the divisor function is \sigma(n), and the prime-counting function is \pi(x). Floor and ceiling are \lfloor x \rfloor and \lceil x \rceil, and the Legendre symbol is a fraction in parentheses: \left(\frac{a}{p}\right). Sums over divisors read naturally as \sum_{d \mid n} f(d).
The number sets \mathbb{N}, \mathbb{Z}, \mathbb{Q} and \mathbb{Z}/n\mathbb{Z} need \usepackage{amssymb} (or amsfonts). Read more about blackboard bold in our guide to the real numbers symbol and the overview of mathematical expressions in LaTeX.
\mid\nmid\gcd(a, b)\text{lcm}(a, b)\equiv\pmod{n}\varphi(n)\phi(n)\perp\left(\frac{a}{p}\right)\lfloor x \rfloor\lceil x \rceil[x]\{x\}\sigma(n)\mu(n)