How to Type a Backslash in LaTeX

A backslash starts every LaTeX command, so it cannot be typed on its own. In text write \textbackslash, in math mode write \backslash, and for code use \verb|\command| or \texttt{\textbackslash command}. Do not write \\: two backslashes are a line break.

Backslash commands

  • \textbackslash
    Text mode, no math preview

    Backslash in running text: C:\textbackslash Users prints C:\Users.

  • \backslash
    ∖

    Backslash symbol in math mode, as an ordinary symbol.

  • A \setminus B
    A ∖ B

    Set difference. A binary operator, so it gets space on both sides.

  • \verb|\newline|
    \newline

    Inline code printed exactly as typed, backslash included.

  • \texttt{\textbackslash section}
    Text mode, no math preview

    Command names in monospace inside normal text.

  • \\
    Text mode, no math preview

    Not a backslash: two backslashes end the line (see new lines).

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

Backslash 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.

  • Set difference

    A ∖ B
    LaTeX
    A \setminus B
  • Quotient by a group action

    G ∖ X
    LaTeX
    G \backslash X

    A left quotient is written with \backslash; it is spaced as an ordinary symbol.

  • Complement inside a universe

    U ∖ A = A c
    LaTeX
    U \setminus A = A^{c}
  • A command name inside a formula

    use  \frac{a}{b}  for  a b
    LaTeX
    \text{use } \verb|\frac{a}{b}| \text{ for } \frac{a}{b}
  • Difference of three sets

    ( A ∖ B ) ∖ C = A ∖ ( B ∪ C )
    LaTeX
    (A \setminus B) \setminus C = A \setminus (B \cup C)

In a LaTeX document

These commands work in the text of a .tex document (Overleaf, TeX Live, MiKTeX), not inside math. The box on the right shows what the compiled PDF looks like.

  • A Windows path in text

    LaTeX
    Save the file in C:\textbackslash Users\textbackslash Public.
    Compiled result

    Save the file in C:\Users\Public.

  • Showing a LaTeX command

    LaTeX
    Start a section with \verb|\section{Title}|.
    Compiled result

    Start a section with \section{Title}.

Why you cannot just type \

LaTeX reads \ as the start of a command name, so a lone backslash swallows the letters after it: C:\Users asks for a command called \Users. \textbackslash and \backslash print the character instead.

The same applies to the other reserved characters: # $ % & _ { } ~ ^. Most are escaped with a backslash (\%, \&, \_), but the backslash itself is not, because \\ already means "new line".

\backslash or \setminus

Both print the same shape. \setminus is a binary operator with space around it, right for set difference A \setminus B. \backslash is an ordinary symbol, used for quotients like G \backslash X or as a delimiter. Some fonts draw \setminus slightly smaller; amssymb also offers \smallsetminus.

Common mistakes

  • Each backslash starts a command, so LaTeX reports "Undefined control sequence".

    Instead of
    C:\Users\Public
    Write
    C:\textbackslash Users\textbackslash Public
  • \\ is a line break, not a symbol; in math it breaks the line or causes an error.

    Instead of
    A \\ B
    Write
    A \setminus B
  • \textbackslash is a text command; in math mode use \backslash.

    Instead of
    $\textbackslash$
    Write
    $\backslash$
  • \verb cannot be used inside the argument of another command.

    Instead of
    \footnote{\verb|\x|}
    Write
    \footnote{\texttt{\textbackslash x}}

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    \textbackslash, \backslash, \setminus and \verb all work without packages. \smallsetminus needs amssymb.

  • MathJax and KaTeX

    MathJax and KaTeX support \backslash and \setminus in math. In Markdown with math, a single \ may be eaten by the Markdown parser; write \\backslash if it disappears.

  • Microsoft Word

    In Word type the backslash key directly. In an equation, \backslash followed by Space inserts it; \setminus does the same for the operator.

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.

Backslash in LaTeX: questions

How do I type a backslash in LaTeX text?
Use \textbackslash. In math mode use \backslash.
What does \\ do in LaTeX?
It ends the current line (a line break), in text, tables and multi-line equations. It does not print a backslash.
How do I write set difference?
Use A \setminus B. It looks like a backslash but is spaced as an operator.
How do I show a LaTeX command in my document?
Use \verb|\command| inline, or a verbatim or listings block for longer code.

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