Modulo in LaTeX (\bmod)

 mod \bmod
LaTeX command
\bmod
Package
No package needed: built into LaTeX
Mode
Math mode only

Where it is used

Binary modulo operator: typesets 'mod' between two operands, as in a mod n, with operator spacing.

Use \bmod for the remainder operation inside an expression, such as 17 \bmod 5 = 2 or the hash function h(k) = k \bmod m. It produces upright mod with medium spacing on both sides, just like a binary operator. For congruences, use \pmod instead: a \equiv b \pmod{n} prints the parenthesized form with extra space before it. amsmath also defines \mod{n}, which gives a wider unparenthesized gap, and \pod{n}, which keeps the parentheses but drops the word. Typing the bare letters mod would italicize them as a product of variables, so always use one of these commands.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

h(k)=k mod m,17 mod 5=2h(k) = k \bmod m, \quad 17 \bmod 5 = 2
\documentclass{article}
\begin{document}
Modulo: $\bmod$

\[ h(k) = k \bmod m, \quad 17 \bmod 5 = 2 \]
\end{document}

Related symbols

All علوم الحاسوب →

Frequently asked questions

How do I write Modulo in LaTeX?
Type \bmod in math mode, for example $h(k) = k \bmod m, \quad 17 \bmod 5 = 2$. It works in plain LaTeX without loading any package.
Which package do I need for \bmod?
None. \bmod is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use \bmod in text mode, or only in math mode?
Only in math mode. Outside $...$ LaTeX stops with "Missing $ inserted", so write $\bmod$ in running text.
Math poweredاكتب LaTeX باستخدام الذكاء الاصطناعي

أفضل محرر LaTeX بالذكاء الاصطناعي، بديل Overleaf

يساعد Octree الباحثين من أكثر من 15 جامعة على كتابة أوراق البحث بشكل أسرع باستخدام الذكاء الاصطناعي

  • أنشئ رسوم TikZ جميلة باستخدام الذكاء الاصطناعي
  • ارفع صورة وحولها إلى LaTeX بسلاسة
  • احصل على مساعدة فورية في كتابة وتنسيق أوراق البحث