Mod and modulo in LaTeX
LaTeX has four mod commands: \bmod for mod as an operation, , and \pmod, \mod and \pod for the modulus written after a congruence, as in \pmod{n}.
LaTeX command
a \bmod bNot the symbol you meant? Draw it to find the command →
Typing up handwritten notes? Convert a whole page of handwriting to LaTeX →
Use \bmod when mod is an operation that gives a value, like the remainder in . It is spaced like a binary operator, a medium gap on each side, the same as +.
Use \pmod{n} at the end of a congruence. It prints the modulus in brackets, (mod n), with a wider gap before it, as number theory texts set it: . amsmath adds two variants: \mod{n} prints mod n with no brackets, and \pod{n} prints only (n).
Typing mod as plain letters gives three italic variables. If \pmod leaves too wide a gap in running text, write (\operatorname{mod} n) by hand for a tighter version, or keep \bmod, which has the smallest gaps of the four.
Other forms
a \equiv b \pmod{n}(mod n) at the end of a congruencea \equiv b \mod{n}mod n without brackets, amsmatha \equiv b \pod{n}only (n), amsmath\operatorname{mod}mod as a plain operatorExamples
$17 \bmod 5 = 2$the remainder, mod as an operation
$17 \equiv 2 \pmod{5}$a congruence with (mod 5)
$a^{p-1} \equiv 1 \pmod{p}$Fermat's little theorem
$x \equiv 3 \mod{7}$mod without brackets, amsmath
$2^{10} \bmod 7 = 2$a power taken mod 7
$h(k) = k \bmod m$a hash function
Tips and common mistakes
- Use
\bmodfor an operation that gives a number,\pmod{n}after a congruence. - Put the modulus in the braces of
\pmod,\modand\pod:\pmod{n}, not\pmodn when n is more than one character. \bmodand\pmodare built in;\modand\podcome from amsmath.- Congruence uses
\equiv(≡), not = or\cong. - Do not type mod as plain letters: they come out italic and spaced as variables.
Working from handwritten notes?
LatexNotes turns a photo or PDF of handwritten mathematics into LaTeX, graphs and all. It is built with real pdflatex before you see it, and the .tex file is yours to edit or take to Overleaf. Free to try, no sign-up.
See how handwriting to LaTeX works, step by step, or go from GoodNotes to LaTeX if you write on an iPad (Notability works the same way).
Convert your maths to LaTeX →FAQ
How do I write mod in LaTeX?
Use for mod as an operation, or \pmod{n} for a congruence.
What is the difference between \bmod and \pmod?
\bmod is a binary operator, a mod b. \pmod{n} writes (mod n) after a congruence, with a wider gap before it.
How do I write mod without the brackets?
Use \mod{n} from amsmath, which prints mod n after a congruence.
How do I get less space before mod?
\bmod has the smallest gaps. For a bracketed form with less space than \pmod, write (\operatorname{mod} n).