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 b
    a ∣ b

    a divides b. A relation, with space on both sides.

  • a \nmid b
    a ∤ b

    a does not divide b (amssymb).

  • a \not\mid b
    a ∤ b

    Fallback without amssymb; the slash may sit a little off.

  • p^k \parallel n
    p k ∥ n

    p^k exactly divides n (some authors use ∥ for this).

  • \{\, x \mid x > 0 \,\}
    { x ∣ x > 0 }

    \mid is 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.

Templates

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.

\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 of
    a | b
    Write
    a \mid b
  • Without amssymb \nmid is undefined; load it or use \not\mid.

    Instead of
    a \nmid b  (no amssymb)
    Write
    \usepackage{amssymb}
  • Divisibility is a vertical bar, not a slash.

    Instead of
    a \backslash b
    Write
    a \mid b

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    \mid works everywhere; \nmid needs amssymb (loaded by most templates).

  • MathJax and KaTeX

    MathJax and KaTeX support \mid, \nmid and \not\mid without configuration.

  • Microsoft Word

    In a Word equation \mid followed by Space inserts ∣; \nmid gives ∤.

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.

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 b with amssymb, or a \not\mid b without it.
Why not just type a | b?
The keyboard bar has no spacing; \mid is 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.

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