[Tex/LaTex] Avoiding “rivers” in successive lines of type

line-breakingparagraphsrivers

This question led to a new feature in a package:
impnattypo

The following quote is from James Felici, The Complete Manual of Typography (2003), p. 161:

Rivers occur when word spaces stack one above the other in successive lines of type, creating the appearance of fissures running through the text […]. Rivers are accidents of composition, and software isn't yet smart enough to detect them, much less do anything about them.

On the following page, Felici shows an example of a "mighty river" running through a paragraph. Below, you'll find the LaTeX code and the pictured output of my (somewhat abridged) recreation of Felicis example. (The layout is chosen so that the effect also occurs if one uses the microtype package with its default settings.)

\documentclass{article}

\usepackage{mathptmx}
\usepackage{microtype}

\textwidth 247pt
\parindent 23pt
\frenchspacing

\begin{document}

Though the Pearl measures less than 50~miles in total length from its
modest source as a cool mountain spring to the screaming cascades and
steaming estuary of its downstream reaches, over those miles, the
river has in one place or another everything you could possibly ask
for. You can roam among lush temperate rain forests, turgid white
water canyons, contemplative meanders among aisles of staid aspens
(with trout leaping to slurp all the afternoon insects from its calm
surface), and forbidding swamp land as formidable as any that Humphrey
Bogart muddled through in \emph{The African Queen}.

\end{document}

alt text

So, was Felici right that "software isn't yet smart enough" to deal with rivers? Or is this something TeX can handle? And if not TeX, then possibly LuaTeX?

EDIT: As rassie pointed out that TeX is Turing-complete, let me clarify that I'm interested in solutions that either already exist or could be implemented with reasonable time and effort.

Best Answer

I have added a first version of an algorithm to detect rivers using Lua to the impnattypo package on github. To use it, simply use the rivers option:

\usepackage[draft,rivers]{impnattypo}

Here is an example result:

rivers in lipsum

Beware that there might still be some bugs ;-)

Related Question