[Tex/LaTex] Minimize hyphenations with ragged2e

horizontal alignmenthyphenationragged2e

Nearly every guide to LaTeX recommends \RaggedRight from the ragged2e package over the built-in \raggedright. But I've always been frustrated by too many hyphenated words with \RaggedRight. I understand that I will get some (where \raggedright gives none), but I get too many.

I decided to compare \RaggedRight with full justification, and consistently find that I get more hyphens with \RaggedRight than with full justification, which I wouldn't expect. In the example below, I only get one hyphenation with full justification (and that's only at a manually created hyphenation point to solve an overfull \hbox), but I get seven with \RaggedRight. (Text is from Moby Dick, which is in the public domain.)

Can I reduce the hyphenation I get with \RaggedRight so that it's comparable with what I get with full justification?

\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{ragged2e}

% 1 hyphenated word with no ragged right
% 7 hyphenated words with \RaggedRight from ragged2e

\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}

Best Answer

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}

enter image description here

Result: with the default hyphenation penalty, three words are hyphenated; with the increased hyphenation penalty, just one.

The same without microtype

enter image description here

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.

Related Question