On this page
For a backslash in text, use \textbackslash; in math mode use $\backslash$. For a tilde in text, use \textasciitilde; in math mode use $\sim$. Do not type a bare ~ - in LaTeX it is a non-breaking space, not a printable character. For literal snippets like file paths, use \verb so every character prints exactly as typed.
The quick answer
| You want | Text mode | Math mode |
|---|---|---|
| Backslash \ | \textbackslash | $\backslash$ |
| Tilde ~ | \textasciitilde | $\sim$ |
| Literal string (paths, code) | \verb with delimiters | not applicable |
Add \usepackage[T1]{fontenc} to your preamble so these glyphs render correctly in the PDF. That is the setup used in the compiled example below.
Why typing a bare ~ or \ breaks your document
LaTeX reserves ten characters for its own syntax: # $ % ^ & _ { } ~ and the backslash. Seven of them - #, $, %, &, _, {, and } - print when prefixed with a backslash. The other three (^, ~, and the backslash) need special handling:
~is a non-breaking space. WritingFigure~\ref{f:demo}keeps the word and number on one line. It never prints a tilde glyph, which is why a bare~seems to "disappear" in the PDF.^starts a superscript in math mode and is an error in ordinary text.\is the command escape character; a single backslash starts a command name, and\\is a line break.
Two more traps: \~{n} is an accent command that places a tilde over its letter (producing n-tilde), so use \textasciitilde when you want the standalone text tilde. For a literal caret in text, use \textasciicircum. And in math mode $\sim$ is a relation symbol ("similar to"), so use it for math, not for the text character.
How do I type literal text like file paths or code?
For short inline snippets, \verb prints everything between two identical delimiter characters exactly as typed, with no LaTeX interpretation: \verb|C:\Users\me\file_1.tex| comes out literally, backslashes and underscores included. For longer blocks, use the verbatim environment. If the snippet is a URL, the url package and its \url{...} command handle special characters and line breaking for you.
A complete example you can compile
This document puts all of the above together:
\documentclass{article}
\usepackage[T1]{fontenc}
\title{Typing a Backslash or Tilde in LaTeX}
\date{October 2026}
\begin{document}
\maketitle
LaTeX reserves ten characters. Seven of them print with a backslash
prefix: \# \$ \% \& \_ \{ \}. The other three are the caret (type
\verb|\textasciicircum| in text), the tilde, and the backslash.
For a visible backslash in text use \verb|\textbackslash| (or
$\backslash$ in math mode). For a visible tilde in text use
\verb|\textasciitilde| (or $\sim$ in math mode). A bare tilde is not a
character at all: it is a non-breaking space, as in Figure~\ref{f:demo}.
The accent command \verb|\~{n}| places a tilde over its letter,
producing \~{n}; use \verb|\textasciitilde| for the text character.
For literal snippets such as file paths, \verb|C:\Users\me\file_1.tex|
prints every character exactly as typed.
\begin{figure}[h]
\caption{A bare tilde keeps the word Figure and the number together.}
\label{f:demo}
\end{figure}
\end{document}
We verified this file compiles as-is with a local Tectonic 0.17.0 compile on October 29, 2026.
FAQ
How do I type a tilde in LaTeX text mode?
Use \textasciitilde for a standalone text tilde. A bare ~ produces a non-breaking space, and the accent command \~ (for example \~{n}) places a tilde over a letter instead.
Why does my tilde not show up in the PDF?
Because ~ is LaTeX syntax for a non-breaking space. The character is working as designed: it glues two words together and prints nothing. Use \textasciitilde when you want the visible glyph.
How do I write a Windows path with backslashes in LaTeX?
Wrap it in \verb with a delimiter pair, for example \verb|C:\Users\me\file_1.tex|. Everything between the delimiters prints literally, so you do not have to escape each backslash by hand.
What are the ten special characters in LaTeX?
#, $, %, ^, &, _, {, }, ~, and the backslash. Seven of them - #, $, %, &, _, {, and } - print when prefixed with a backslash; ^, ~, and the backslash itself need the commands covered above.
What is the difference between \textasciitilde and $\sim$?
\textasciitilde is the tilde as a text character, for prose and literal text. $\sim$ is the math relation symbol, sized and spaced for formulas. Pick the one that matches where you are writing.
Further reading
Our guide on controlling figure and table placement in LaTeX is a related how-to. A companion piece on inserting figures is coming to this series. More how-tos are on the Bibby AI blog. Source question: How does one insert a backslash or a tilde (~) into LaTeX? on TeX Stack Exchange.
Write your next paper in Bibby AI. LaTeX-native editing in the browser, free to start. Compare plans on the pricing page.
Last updated: October 29, 2026. By the Bibby AI editorial team.