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

## migrated from stackoverflow.comJan 20 '11 at 17:54

This question came from our site for professional and enthusiast programmers.

The Comprehensive LaTeX Symbol List is your friend.

\textbackslash and \textasciitilde are found in Table 2 of the list, and page 101 has some other options for the tilde:

$\sim$ and \texttildelow from the textcomp package, possibly using some font other than Computer Modern to get a nice vertically centered tilde

It also suggests using the url package if you are typesetting URL's or Unix file names.

In case you use these in a text, do like so: 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 '11 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 '12 at 15:03
• @Herbert: True, but more cryptic ... – Jonathan Aug 29 '12 at 15:23
• ok, then we use \string\  for non cryptic ... – user2478 Aug 29 '12 at 15:38