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
- Text mode, no math preview
\textbackslashBackslash in running text: C:\textbackslash Users prints C:\Users.
\backslashBackslash symbol in math mode, as an ordinary symbol.
A \setminus BSet difference. A binary operator, so it gets space on both sides.
\verb|\newline|Inline code printed exactly as typed, backslash included.
- Text mode, no math preview
\texttt{\textbackslash section}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.
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
LaTeXA \setminus BQuotient by a group action
LaTeXG \backslash XA left quotient is written with
\backslash; it is spaced as an ordinary symbol.Complement inside a universe
LaTeXU \setminus A = A^{c}A command name inside a formula
LaTeX\text{use } \verb|\frac{a}{b}| \text{ for } \frac{a}{b}Difference of three sets
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
LaTeXSave the file in C:\textbackslash Users\textbackslash Public.Compiled resultSave the file in C:\Users\Public.
Showing a LaTeX command
LaTeXStart a section with \verb|\section{Title}|.Compiled resultStart 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 ofC:\Users\PublicWriteC:\textbackslash Users\textbackslash Public\\is a line break, not a symbol; in math it breaks the line or causes an error.Instead ofA \\ BWriteA \setminus B\textbackslashis a text command; in math mode use\backslash.Instead of$\textbackslash$Write$\backslash$\verbcannot 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,\setminusand\verball work without packages.\smallsetminusneeds amssymb.MathJax and KaTeX
MathJax and KaTeX support
\backslashand\setminusin math. In Markdown with math, a single\may be eaten by the Markdown parser; write\\backslashif it disappears.Microsoft Word
In Word type the backslash key directly. In an equation,
\backslashfollowed by Space inserts it;\setminusdoes 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.
- 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.
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.
Related LaTeX reference
- LaTeX SymbolsThe most-used math symbols in one table: relations, operators, sets, logic, arrows, Greek letters and accents, each with its command.
- Cross Product in LaTeX\times between vectors, the i, j, k determinant with vmatrix, dotless-i unit vectors and the magnitude formula.
- Indicator Function in LaTeXThe double-struck 1: why \mathbb{1} breaks in pdfLaTeX, \mathds{1} and \mathbbm{1} as fixes, and notation that also works on the web.
- 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