25

In my answer to Two-column layout with left column just as wide as its content I've used non-breaking spaces ~ (ties) to align monospaced text. Actually I rather meant control spaces \ , but they're less convenient to type (and read), and line breaks were not of interest anyway. Some experiments concerning line breaking are documented in the code below.

Question: Besides their line-breaking behaviour, is there any difference between \ and ~? In particular, do (or may) they by nature have a different width?

 

\documentclass{article}
\usepackage{lipsum}
\usepackage{parskip}

\begin{document}

\lipsum[75]

%non-breaking space
lorem lorem lorem lorem lorem lorem lorem lorem lorem 
lorem lorem lo~lo~lo~lo~lo~lo~lo~lo~ip~ip~ip~sum sum sum sum sum sum sum sum sum

lorem lorem lorem lorem lorem lorem lorem lorem lorem 
lorem lorem lo~lo~lo~lo~lo~ %input line break doesn't affect non-breaking space
lo~lo~lo~ip~ip~ip~sum sum sum sum sum sum sum sum sum

lorem lorem lorem lorem lorem lorem lorem lorem lorem 
lorem lorem lo~lo~lo~lo~lo  %breaks at input line break
lo~lo~lo~ip~ip~ip~sum sum sum sum sum sum sum sum sum

%breaks at protected space
lorem lorem lorem lorem lorem lorem lorem lorem lorem 
lorem lorem lo~lo~lo~lo~lo\ lo~lo~lo~ip~ip~ip~sum sum sum sum sum sum sum sum sum

\end{document}

enter image description here

0

1 Answer 1

30

Control space \ and a tie ~ have the same width and only differ in their line-breaking behaviour. The definition of the latter, taken from latex.ltx is:

\DeclareRobustCommand{\nobreakspace}{%
   \leavevmode\nobreak\ }
\catcode `\~=13
\def~{\nobreakspace{}}
6
  • 1
    I'm wondering why it's LaTeX that defines the tie. Is it not a TeX primitive?
    – dgs
    Jun 9, 2012 at 23:34
  • @dgs: Yes, TeX actually defines it as \penalty\@M\ , but LaTeX redefines it.
    – Werner
    Jun 9, 2012 at 23:40
  • 8
    @Werner ~ is not a primitive in plain TeX, it is an active character with a macro definition (\penalty\@M\ , as you say).
    – Joseph Wright
    Jun 10, 2012 at 7:30
  • This answer doesn't explain the difference... What do they do different then?
    – Tvde1
    Dec 29, 2018 at 15:43
  • 1
    @Tvde1: They differ in how things happen around a line-break. ~ inserts a large penalty while \ does not. Does this example explain it better?
    – Werner
    Dec 29, 2018 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.