# Difference between a space and a “wave” symbol (tilde/“~”)?

As title, what is the difference between a and ~?

I see no differences after the compilation.

MWE:

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}

\author{You}

\date{\today}

\begin{document}
\maketitle

I am cool.

I~am~cool.

\end{document}

-
You will see the difference at end of line. ~ is unbreakable space where as space isn't unbreakable. –  Harish Kumar Mar 28 '14 at 1:54
"I am cool"... That's a rather bold statement :p –  Jubobs Mar 28 '14 at 2:23
It controls space too, it's very often used after a \the.... counter output command. –  Christian Hupfer Jan 13 at 21:27
In text mode ~=\nobreakspace –  karlkoeller Jan 13 at 21:29
@yo' Should I delete this questions, then? –  hkviktor Jan 13 at 21:31

The difference can be seen at the end of line. A space is breakable and a ~ is an un-breakable space.

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorinlistoftodos]{todonotes}

\author{You}

\date{\today}

\begin{document}
\maketitle

\hspace*{0.9\textwidth}I am cool.

\hspace*{0.9\textwidth}I~am~cool.

\end{document}


The three words I am and cool are glued together in the second line.

-

The ~ is an active character, which means it's the same as a macro like \mbox and so on. Its function is described by its definition, which is

\nobreakspace{}


so typing ~ is equivalent to typing \nobreakspace{}.

What does \nobreakspace do? Here it is:

\leavevmode\nobreak\


(a space follows the last backslash). So a paragraph is started or nothing is done if we're already in a paragraph (\leavevmode); then \nobreak is issued, which disallows any line break at the point (\nobreak) and then a normal interword space is inserted.

Thus when typing

no~break


there will be a space between the two words, but the line will not be broken after no.

Why the {} after \nobreakspace? If you have no~break in a caption, in the .aux file the expanded version will appear

no\nobreakspace  {}break


The braces have been introduced to cope with the rare case when a space after ~ is wanted; without them no~ break would write

no\nobreakspace   break


and, upon reading the .aux file, the space would be ignored. With the braces

no\nobreakspace  {} break


will be written and the additional space would not be ignored.

-
Nice explanation. Can I say +1? –  karlkoeller Jan 13 at 21:40

This is the definition of ~ in latex.ltx

\catcode \~=13
\def~{\nobreakspace{}}


while \nobreakspace is defined as

\DeclareRobustCommand{\nobreakspace}{%
\leavevmode\nobreak\ }


So, the active character ~` is equivalent to a space that cannot be broken into lines.

-