GCD in LaTeX (\gcd(a, b))

gcd⁡(a,b)\gcd(a, b)
LaTeX command
\gcd(a, b)
Package
No package needed: built into LaTeX
Mode
Math mode only

Where it is used

Greatest common divisor of a and b, the largest integer dividing both.

\gcd is a predefined operator, so it prints upright, and like \lim it accepts limits under it in display style. Bezout's identity says \gcd(a, b) = ax + by for some integers x and y, and a and b are coprime when \gcd(a, b) = 1. Many number theory papers drop the name and write (a, b), which is compact but clashes with ordered pairs and open intervals. The Euclidean algorithm rests on \gcd(a, b) = \gcd(b, a \bmod b), where \bmod gives binary-operator spacing. There is no matching built-in command for the least common multiple.

Minimal compilable example

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

gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a, b) = \gcd(b, a \bmod b)
\documentclass{article}
\begin{document}
GCD: $\gcd(a, b)$

\[ \gcd(a, b) = \gcd(b, a \bmod b) \]
\end{document}

Related symbols

All نظرية الأعداد →

Frequently asked questions

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

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

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

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