Line Breaking – When to Use Non-Breaking Space in LaTeX

best practicesline-breakingtypography

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.

Best Answer

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 "I" at the end of a line break.