Divides and Does Not Divide in LaTeX
Write "a divides b" as a \mid b and "a does not divide b" as a \nmid b (from amssymb, which most templates load). Do not use the keyboard |: it is an ordinary symbol, so a | b has no space around the bar.
Divisibility symbols
a \mid ba divides b. A relation, with space on both sides.
a \nmid ba does not divide b (amssymb).
a \not\mid bFallback without amssymb; the slash may sit a little off.
p^k \parallel np^k exactly divides n (some authors use ∥ for this).
\{\, x \mid x > 0 \,\}\midis also the "such that" bar in set-builder notation.
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.
Divides and does not divide 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.
Divides
LaTeX3 \mid 12Does not divide
LaTeX5 \nmid 12Common divisor
LaTeXd \mid a \;\text{and}\; d \mid b \implies d \mid \gcd(a, b)Prime divisor
LaTeXp \mid ab \implies p \mid a \;\text{or}\; p \mid bDivisibility by a power
LaTeX2^k \mid n \quad\text{but}\quad 2^{k+1} \nmid n
\mid, | and \vert
All three draw a vertical bar, but with different spacing. \mid is a relation, like =, so it gets a thick space on each side. | and \vert are ordinary symbols with no added space, right for absolute values |x| and norms, wrong for divisibility.
In set-builder notation \{ x \mid x > 0 \} the relation spacing of \mid is also what you want. For a bar that grows with tall content, use \middle| between \left\{ and \right\}.
Negating the symbol
\nmid is a single, well-designed glyph from amssymb. \not\mid overlays a slash on \mid and works without packages, but the slash can look misplaced in some fonts.
Common mistakes
The keyboard bar is an ordinary symbol, so the letters touch it.
Instead ofa | bWritea \mid bWithout amssymb
\nmidis undefined; load it or use\not\mid.Instead ofa \nmid b (no amssymb)Write\usepackage{amssymb}Divisibility is a vertical bar, not a slash.
Instead ofa \backslash bWritea \mid b
In Overleaf, MathJax and Word
Overleaf and pdfLaTeX
\midworks everywhere;\nmidneeds amssymb (loaded by most templates).MathJax and KaTeX
MathJax and KaTeX support
\mid,\nmidand\not\midwithout configuration.Microsoft Word
In a Word equation
\midfollowed by Space inserts ∣;\nmidgives ∤.
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.
Divides and does not divide in LaTeX: questions
- How do I write "does not divide" in LaTeX?
a \nmid bwith amssymb, ora \not\mid bwithout it.- Why not just type a | b?
- The keyboard bar has no spacing;
\midis spaced as a relation, which is correct for divisibility. - Is \mid the same symbol as in set-builder notation?
- Yes.
\{ x \mid x > 0 \}uses the same command and spacing.
Related LaTeX reference
- Absolute Value in LaTeX|x|, \lvert x \rvert, bars that stretch with \left| \right|, double bars for norms, and an \abs macro with mathtools.
- And Symbol and Logic Symbols in LaTeXLogical and (\land), or, not, implies, iff, for all and there exists, and how to print a literal & instead.
- Angstrom Symbol in LaTeXÅ in text (\AA), in formulas (\mathring{A} or \text{\AA}) and as a unit with siunitx (\qty{1.5}{\angstrom}).
- How to Type a Backslash in LaTeXThe \ character in text (\textbackslash), in math (\backslash), in code (\verb) and as set minus (\setminus).
- 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