How to Write Mod in LaTeX
Use \bmod between two numbers: a \bmod b. After a congruence use \pmod{n}, which adds space and parentheses: a \equiv b \pmod{n}. Never type the letters m-o-d directly in math; they come out as an italic product.
The four mod commands
a \bmod bBinary operator: "a mod b" with operator spacing.
a \equiv b \pmod{n}Parenthesised: "(mod n)" with extra space before it.
a \equiv b \mod{n}amsmath: "mod n" without parentheses.
a \equiv b \pod{n}amsmath: "(n)", parentheses without the word.
\operatorname{mod}Upright "mod" with operator spacing you control.
Try it live
Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.
Modulo (mod) examples
Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.
Remainder
LaTeX17 \bmod 5 = 2Congruence
LaTeX17 \equiv 2 \pmod{5}Euler's theorem
LaTeXa^{\varphi(n)} \equiv 1 \pmod{n}Hash function
LaTeXh(k) = k \bmod mChinese remainder theorem
LaTeX\begin{aligned} x &\equiv 2 \pmod{3} \\ x &\equiv 3 \pmod{5} \end{aligned}Inline-friendly form
LaTeXa \equiv b \;(\operatorname{mod} n)
Which one to use
\bmod is for the operation that returns a remainder, as in programming. \pmod is for the relation "congruent modulo n" and is what most number theory texts use. \mod and \pod come from amsmath for authors who prefer "mod n" without parentheses or parentheses without "mod".
Too much space before (mod n)?
\pmod adds a quad of space in display math and less inline. If it looks too wide in running text, write \;(\operatorname{mod} n) yourself, as in the last example.
Common mistakes
Typed letters become italic variables m·o·d.
Instead ofa \equiv b (mod n)Writea \equiv b \pmod{n}\pmodputs parentheses around b; for "a mod b" use\bmod.Instead ofa \pmod bWritea \bmod b%starts a comment in LaTeX; the rest of the line disappears.Instead ofa % bWritea \bmod b
In Overleaf, MathJax and Word
Overleaf and pdfLaTeX
\bmodand\pmodwork without packages;\modand\podneed amsmath.MathJax and KaTeX
MathJax and KaTeX support
\bmod,\pmod,\modand\pod.Microsoft Word
In a Word equation type "mod" and Word sets it upright as a function name, or use
\pmod-style text:(mod n).
Have this math on paper, in a PDF or a photo?
Retyping formulas is slow. These converters read whole pages and handwriting and give you LaTeX or Word with every equation editable.
- Handwritten math to LaTeXPhotograph notes or a whiteboard and get LaTeX for every line.1 credit per image
- PDF to LaTeXTurn a paper or textbook PDF into a .tex project with every equation.10 credits per page
- Image to WordA screenshot or photo of a page becomes Word with editable equations.10 credits per image
Single printed formulas are free: 3 a day without an account, 6 with a free account. New accounts get 30 credits to try handwriting, pages and documents; failed conversions return their credits. See plans and credit prices.
Modulo (mod) in LaTeX: questions
- How do I write mod in LaTeX?
a \bmod bfor the operation,a \equiv b \pmod{n}for a congruence.- What is the difference between \bmod and \pmod?
\bmodis a binary operator;\pmod{n}writes "(mod n)" after a congruence.- Why is my mod italic?
- You typed the letters. Use one of the mod commands or
\operatorname{mod}.
Related LaTeX reference
- Congruent Symbol in LaTeX≅ with \cong for geometry and isomorphism, ≡ with \equiv and \pmod for modular arithmetic, and \ncong / \not\equiv.
- Divides and Does Not Divide in LaTeXa ∣ b with \mid, a ∤ b with \nmid (amssymb), and why | from the keyboard is spaced wrongly.
- How to Write Percent in LaTeXWhy % hides the rest of the line, how to print it with \%, and how to format percentages with siunitx.
- Perpendicular Symbol in LaTeX⊥ with \perp, ∥ with \parallel, \not\perp and \nparallel, and the orthogonal complement W^\perp.
- Checkmark in LaTeX✓ with \checkmark, ✓ and ✗ from pifont (\ding{51}, \ding{55}), and checklists in tables and lists.
- LaTeX equation editorSymbol panel, live preview, and PNG, SVG, MathML or Word export.
- All LaTeX reference pagesSymbols, math structures and text formatting in one list.
Have the formula as a picture?
Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.
Convert an image to LaTeX