# How does one insert a backslash or a tilde (~) into LaTeX?

• How does one insert a "\" (backslash) into the text of a LaTeX document?
• And how does one insert a "~" (tilde)? (If you insert \~, it will give you a tilde as an accent over the following letter.)

I believe \backslash may be used in math formulae, but not into text itself. Lamport's, Kopka's, and Mittelbach's texts have said as much (but no more), and so left me hanging on how to get a backslash into regular text.

• For the special case where a backslash or tilde must be written to an auxiliary file or shell escape see: How can I provide a verbatim (unescaped) commandline for executing with \write18? Apr 13, 2012 at 10:28
• For future reference, this is a great resource for finding out what to do to accomplish a given character. Feb 12, 2015 at 21:42
• For MathJax use simply \sim. Feb 15, 2019 at 12:57
• One of the bad ideas of mine, before I started using ˝\sim˝, was (don't use it): $\text{~}$ Jan 5, 2020 at 12:28

### TL;DR

\textbackslash produces a backslash in text-mode. The math-mode $\sim$ and \texttildelow (from textcomp package) are options for a lower tilde (while \~{} and \textasciitilde produce a raised tilde in text-mode)

The Comprehensive LaTeX Symbol List is your friend. The correct link seems to keep changing, but if you have a complete TeX Live installation, the command texdoc symbols-a4 will display your local copy.

\textbackslash and \textasciitilde are found in several places in the document, but the LaTeX 2e ASCII Table (Table 529 as of this writing) and the following discussion are a convenient resource for all ASCII characters. In particular, the discussion notes that \~{} and \textasciitilde produce a raised tilde, whilst the math-mode $\sim$ and \texttildelow are options for a lower tilde; the latter is in the textcomp package, and looks best in fonts other than Computer Modern. If you are typesetting file names or urls, the document recommends the url package.

Remember to delimit TeX macros from surrounding text, e.g. bar\textasciitilde{}foo.

• This is pretty awesome and helped me a lot. I just want to add that in case you use these in a text, do like so: bar\textasciitilde{}foo.
– Till
May 14, 2011 at 20:53

\usepackage{url}


near the beginning of the document, and enclose any web and email addresses in the document in \url{...}:

\url{http://www.math.drofnats.edu/~gauss}
\url{gauss@math.drofnats.edu}


..."

I hope this could help you in typewriting a regular tilde character.

Personally, I learned more actually changing the catcodes myself :)

\begingroup
\catcode ~=11
\gdef\mytilde{~}
\catcode \|=0
\catcode \\=11
|gdef|mybs{\}
|endgroup


and then something like

This is a tilde: \mytilde
This is a backslash: \mybs

• \def\mybs{\char092} does the same for the backslash
– user2478
Aug 29, 2012 at 15:03
• @Herbert: True, but more cryptic ... Aug 29, 2012 at 15:23
• ok, then we use \string\  for non cryptic ...
– user2478
Aug 29, 2012 at 15:38