# When should I use non-breaking space?

DEK gained a reputation of painting red the draft dissertations of his students, taking particular note of incidents when they omitted a non-breaking space that should have been included.

I have this list of places where you have to place non-breaking space:

1. before \cite
2. before \ref
3. before inlined equation

But, I am not sure if I got the rules right; is a non-breaking space mandatory before all inline equations? How about numbers which occur in the text? And what if I refer to a program variable, or to program text, for example,

The 371 programmers who read, on 11 different occasions, the
Java program in Figure~\ref{Program:Example}  noticed that it is peculiar since
parameter \texttt{i} is never read by functions \texttt{f()}
and \texttt{thisLongFuncgtionName()}...


Do I have to write The 371 programmers or The~371 programmers? on 11 different occasions or on~11 different occasions?

Do I need to write parameter~\texttt{i}? I think I should. What about functions~\texttt{f()}? And should I write and~\texttt{thisLongFuncgtionName()}? How about citations that use author, year convention?

In short, I think have an idea, but no exact definition of when you should add non-breaking space.

-
I would write The 371~programmers because having The 371 at the end of a line is much worse than The \\ 371 programmers. The same for on 11~different occasions. –  Martin Scharrer Apr 11 '11 at 15:42
See also this question –  Lev Bishop Apr 11 '11 at 20:42

In general where the break will create orphans that would distract the reader.

Some less obvious examples:

I~am
I~definitely
mod~1

The matching $(AW,BX,CY,DZ)$ is unstable, because for example
$A$ prefers~$Z$ to~$W$ and at the same time $Z$ prefers~$A$ to~$D$.
But the matching $(AZ,BW,CX,DY)$ is stable;

(we say that girl~$h$ rejects the proposal)

step~A2 stops when $P$ has nobody left to propose~to,
but step~B2 keeps making redundant proposals ad~infinitum when

The details of Algorithm~B

has local probability~${1\over n}$,


The "I am", "I definitely" etc., is a bit controversial, but personally like a lot of other people don't like them at the end of a line break.

-

To quote Knuth. Ties should appear:

• In references to named parts of a document:
Chapter~12   Theorem~1.2
Appendix~A   Table~\hbox{B-8}
Figure~3   Lemmas 5 and~6
• Between a person's forenames and between multiple surnames:
Donald~E. Knuth   Luis~I. Trabb~Pardo
Bartel~Leendert van~der~Waerden   Charles~XII
but be careful of names like Charles Louis Xavier~Joseph de~la Vall\'ee~Poussin.
• Between math symbols in apposition with nouns:
dimension~$d$ width~$w$ function~$f(x)$
string~$s$ of length~$l$~
but compare with
string~$s$ of length $l$~or more.
• Between symbols in series:
1,~2, or~3
$a$,~$b$, and~$c$
1,~2, \dots,~$n$.
• When a symbol is a tightly bound object of a preposition:
of~$x$
from 0 to~1
increase $z$ by~1
in common with~$m$. but compare
of $u$~and~$v$.
• When mathematical phrases are rendered in words:
equals~$n$ less than~$\epsilon$ (given~$X$)
mod~2 modulo~$p^e$ for all large~$n$
Compare is~15 with is 15~times the height.
• When cases are being enumerated within a paragraph:
(b)~Show that $f(x)$ is (1)~continuous; (2)~bounded.
-
This is almost a duplicate of my answer here! –  Lev Bishop Apr 11 '11 at 20:43
Indeed, and if may, I would like to join a comment made there: "I must be really dense, I can't seem to figure out any "rules" from these examples; these look quite arbitrary to me. Perhaps I should bite the bullet and read the chapter. Thanks for the pointer. – gphilip Aug 16 '10 at 4:23" –  Yossi Gil Apr 12 '11 at 4:18
@Lev: Yikes! The question isn't a duplicate but the answer is! Hmm. –  TH. Apr 12 '11 at 6:07
• between a number and its unit: 4.5~m or 12~min –  Florian Oct 3 '11 at 10:35
@Florian: Probably best to use something like siunitx for that. It'll get the formatting right. ~ gives a space that's probably too large. –  TH. Oct 5 '11 at 0:34
The 371~programmers who read, on 11~different occasions, the
Java program in Figure~\ref{Program:Example} noticed that it is peculiar since
parameter~\texttt{i} is never read by functions~\texttt{f()}
and \texttt{thisLongFuncgtionName()}...


That's my take and I put it up for debate. In short, I'd use a "tie" (~) whenever a line break would split a unit of thought. See also Why I should put a ~ before \ref command? Edit: the tie before f() is debatable and probably should be exchanged for a tie before thisLongFuncgtionName(), which might cause hyphenation problems.

-
Dieses Mal~-- anders als vorher~-- wurde er überrascht.

Interesting. In French, I tend to put the ~ inside, to prevent having a -- at the end of a line (it's like opening a bracket at the end of a line really). –  ℝaphink Oct 2 '11 at 22:09
Could you cite a source for this? Personally I tend to the "French" rule, whenever the en-dashes are used parenthetically: Dieses Mal --~anders als vorher~-- wurde er überrascht. but I keep the dash together with the first part of the sentence, when it could be replaced by a colon or full stop: Hans kam plötzlich herein~-- dieses Mal waren alle überrascht. But I don't know where I learned this and whether it is correct. –  Florian Oct 3 '11 at 10:29