Discourage line breaking after short words
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?
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}
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}