# Discourage line breaking after short words

I’m typesetting a book in DIN A5 format which produces a lot of line breaks right after the “I” character, which doesn’t look very pleasing. Inserting a ~ right after would introduce more badboxes in my conditions (microtype is already employed with protrusion and expansion).

Is there a way to tell LaTeX (I’m compiling with pdftex) that breaking after the “I” is bad, so discouraging it, but still let it break if it would introduce a badbox otherwise?

MWE:

\documentclass[a5paper,10pt]{article}
\usepackage[left=18mm,right=25mm,top=18mm,bottom=25mm]{geometry}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[protrusion=true,expansion=true,stretch=20,shrink=20]{microtype}

\newcommand\sentence{This is the first long long sentence with interword spaces. I am broken off from the rest.}

\begin{document}
\pagestyle{empty}
\rule{4mm}{.5pt}\sentence\\
\rule{8mm}{.5pt}\sentence\\
\rule{12mm}{.5pt}\sentence\\
\rule{16mm}{.5pt}\sentence\\
\rule{20mm}{.5pt}\sentence\\
\rule{24mm}{.5pt}\sentence\\
\end{document}


• I\nolinebreak[2] ? – David Carlisle Aug 20 '15 at 20:07
• Please elaborate on this command a bit more (and mention the space needed after it) and I'll accept is as an answer. It would also be handy to know how to define this globally, without having to replace every occurrence of I with the command. – lblb Aug 20 '15 at 20:30
• For reference, David Carlisle already explained this command here: tex.stackexchange.com/a/94220/75284 – lblb Aug 20 '15 at 20:38

You can use

I\nolinebreak[2] said this


To discourage linebreaking at this point (or [1] or [3]) using [4] would essentially be the same as using ~ in this context.

You could define a command such as

\newcommand\I{I\nolinebreak[2]}


and then use \I{} rather than I but you need the {} so that the following space is seen unless you use a non-letter such as \1 or you could use xspace but I don't really recommend that

As noted in comments there are some more notes on \nolinebreak in this answer: What is the difference between \nobreak and \nolinebreak?

• Thanks! Is there a more elegant way of calling the nolinebreak command after I besides the newcommand structure? For uses when I like to keep the source text clean (without \I commands)? Sadly \DeclareUnicodeCharacter refuses to work with alphabetic characters. – lblb Aug 20 '15 at 20:54
• @lblb short answer, no:-) longer answer, with xetex or luatex, possibly, for pdftex, not really. – David Carlisle Aug 20 '15 at 20:57
• OK. By the way, the solution is working flawlessly and didn't introduce a single new badbox on 600 pages of text. I use a level 2 penalty. – lblb Aug 20 '15 at 21:01

As David show, although a more o less strong \nolinebreak discourage the break after "I", exactly as you asked, even with your microtype settings, sometimes this command can only be ignored or produce some overfull \hbox, when this become equivalent to ~.

Then, a workaround to hold together two words without causing a overfull \hbox is add some extra stretchability to the spaces in each line with \emergencystretch so that, I\nolinebreak[4] xxx or \mbox{I xxx} or I~xxx can jump to the next line only at the cost of some extra interword spacing. But I leave open if this is better than a break after "I ".

Examples:

\documentclass[draft]{article}
\usepackage[protrusion=true,expansion=true,stretch=20,shrink=20]{microtype}
\usepackage[rmargin=2in,showframe,paperwidth=4in]{geometry}
% rest of preamble just to format the example
\usepackage[svgnames]{xcolor}
\usepackage[obeyspaces]{url}
\makeatletter
\def\Gm@hrule{}%
\def\Gm@vrule{\color{olive!50}\vrule width .4pt height\textheight depth\z@}%
\def\Gm@hruled{}%
\makeatother
\parskip0em\parindent0pt
\def\opt#1{\medskip{\color{orange}\scriptsize\url{#1}\par}}
\begin{document}
\fontsize{10}{8}\selectfont %just to format the example

\opt{plain text}
This is a text where I express myself.

% non-working option, but typographicaly correct
\opt{\nolinebreak[1-3]}
This is a text where I\nolinebreak[3] express myself.

% non-working option, giving a overfull \hbox
\color{red!40!black}
\opt{\nolinebreak[4]}
This is a text where I\nolinebreak[4] express myself.

\opt{non-break space (~)}
This is a text where I~express myself.

\opt{\mbox{I express}}
This is a text where \mbox{I express} myself.

% working options
\color{Navy}
\opt{\emergencystretch plus ...}
\opt{+ \nolinebreak[4]}
\emergencystretch.5em
This is a text where I\nolinebreak[4] express myself.

\opt{+ non-break space}
This is a text where I~express myself.

\opt{+ \mbox{}}
This is a text where \mbox{I express} myself.

\end{document}

• I will surely make use of these settings if I run into problems in the future, right now the first solution doesn't produce any new badboxes on 600 pages of text. Thanks for the excellent visualisations of different line breaking controls. – lblb Aug 21 '15 at 19:14
• @lblb Well, not bad boxes, but how many times LaTeX disobeyed the \nolinebreak command for your sake? I hope that scarcely if you use one column text in A4 paper, since LaTeX has more leeway to make a nice work. Tangled situations (to break or not to break, that is the question) arise often in narrow multi-columns, tables, margin notes, boxes, etc. where any solution seem far from perfection (except rewriting). – Fran Aug 21 '15 at 20:19

The chickenize package offers a command that will suppress linebreaks after single-letter words by inserting penalties using the Lua backend. Compile with LuaLaTeX.

\documentclass[a5paper,10pt]{article}
\usepackage[left=18mm,right=25mm,top=18mm,bottom=25mm]{geometry}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[protrusion=true,expansion=true,stretch=20,shrink=20]{microtype}

\usepackage{chickenize}
\suppressonecharbreak

\newcommand\sentence{This is the first long long sentence with interword spaces. I am broken off from the rest.}

\begin{document}
\pagestyle{empty}
\rule{4mm}{.5pt}\sentence\\
\rule{8mm}{.5pt}\sentence\\
\rule{12mm}{.5pt}\sentence\\
\rule{16mm}{.5pt}\sentence\\
\rule{20mm}{.5pt}\sentence\\
\rule{24mm}{.5pt}\sentence\\
\end{document}


• Nice to hear this. I haven't looked into the implementation in the chickenize package, but I did something similar for a similar question. – ShreevatsaR Oct 8 '17 at 0:21