Minimize hyphenations with ragged2e
The "raggedness" of \RaggedRight
can be configured by length \RaggedRightRightskip
, which is inserted at the right end of a line, when
TeX breaks the paragraph. The default is 0pt plus 2em
, which means the line can be full or short with upto 2em white space at the right side.
Increasing the value to 2.8em
reduces the number of hyphenations to one at the cost of a more ragged right side of the paragraph.
\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{ragged2e}
\setlength{\RaggedRightRightskip}{0pt plus 2.8em}
\begin{document}
\RaggedRight
Call me Ishmael. Some years ago---never mind how long
precise\-ly---having little or no money in my purse, and nothing
particular to interest me on shore, I thought I would sail about a
little and see the watery part of the world. It is a way I have of
driving off the spleen and regulating the circulation. Whenever I
find myself growing grim about the mouth; whenever it is a damp,
drizzly November in my soul; whenever I find myself involuntarily
pausing before coffin warehouses, and bringing up the rear of
every funeral I meet; and especially whenever my hypos get such an
upper hand of me, that it requires a strong moral principle to
prevent me from deliberately stepping into the street, and
methodically knocking people's hats off---then, I account it high
time to get to sea as soon as I can. This is my substitute for
pistol and ball. With a philosophical flourish Cato throws himself
upon his sword; I quietly take to the ship. There is nothing
surprising in this. If they but knew it, almost all men in their
degree, some time or other, cherish very nearly the same feelings
towards the ocean with me.
\end{document}
Some words about line breaking. TeX assigns a badness to each line, based on the amount of stretching of the glue in it. In a ragged right setting, there's only stretchable glue at the right (\rightskip
), which has the consequence that this glue (if finite) will usually stretch more than stated. The default for \RaggedRight
has an the “optimal” stretching of at most 2 em, but it's quite likely that lines will not be able to reach this near the right margin, so high badness is expected. With the default \hyphenpenalty
of 50, TeX will find it cheaper, in order to minimize the total demerits, to hyphenate so as to get nearer the margin.
If we make hyphenation less convenient, glue stretching will have a lighter impact on the total demerits than hyphenation.
Note that with the standard \raggedright
setting, hyphenation will never happen (well, hardly ever), because \rightskip
has infinite stretching (0pt plus 1fil
), so lines will have zero badness and the demerits will only be added from \linepenalty
, so TeX will just minimize the number of lines.
Finding a good compromise is not easy: increasing the stretching of \rightskip
might make TeX more willing to set shorter lines. I propose to increase the \hyphenpenalty
, instead, together with microtype
that usually has a quite good impact on paragraph setting.
\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{microtype}
\usepackage{ragged2e}
\begin{document}
\newcommand\incipit{Call me Ishmael. Some years ago---never mind how long
precise\-ly---having little or no money in my purse, and nothing
particular to interest me on shore, I thought I would sail about a
little and see the watery part of the world. It is a way I have of
driving off the spleen and regulating the circulation. Whenever I
find myself growing grim about the mouth; whenever it is a damp,
drizzly November in my soul; whenever I find myself involuntarily
pausing before coffin warehouses, and bringing up the rear of
every funeral I meet; and especially whenever my hypos get such an
upper hand of me, that it requires a strong moral principle to
prevent me from deliberately stepping into the street, and
methodically knocking people's hats off---then, I account it high
time to get to sea as soon as I can. This is my substitute for
pistol and ball. With a philosophical flourish Cato throws himself
upon his sword; I quietly take to the ship. There is nothing
surprising in this. If they but knew it, almost all men in their
degree, some time or other, cherish very nearly the same feelings
towards the ocean with me.}
\RaggedRight
\noindent With \texttt{microtype}
\bigskip
\noindent\texttt{\string\hyphenpenalty=50}
\incipit
\bigskip
\noindent\texttt{\string\hyphenpenalty=500}
\hyphenpenalty=500
\incipit
\end{document}
Result: with the default hyphenation penalty, three words are hyphenated; with the increased hyphenation penalty, just one.
The same without microtype
Result: with the default hyphenation penalty, seven words are hyphenated; with the increased hyphenation penalty, just two.
In all cases, the hyphen in precisely
is unavoidable, because of the em-dash.