Hacker News new | ask | show | jobs
by maninalift 3952 days ago
Is anyone aware of any line-breaking algorithm which penalises for rivers or typesetting algorithm which adjusts spacing to compensate for it.

I'm interested that rivers are such a concern of manual typesetting but I have never heard mention of it in typesetting algorithms.

2 comments

It is a very difficult problem to solve see http://tex.stackexchange.com/questions/4507/avoiding-rivers-.... With TeX most of the time you will not see any rivers.
I understand that it is hard to integrate into TeX. I don't see how the general problem is hard to solve. Detecting rivers is not hard (maybe hard to do optimally) and adding a penalty accordingly is all the Knuth-Plass line breaking algorithm needs to avoid rivers.
Knuth-Plass is fundamentally a dynamic programming algorithm that depends on being able to say "If in the future I determine that there is a line break at point X, I know for certain that the way I should have broken the paragraph up until X is B", where B depends only on information before X.

If you're trying to avoid rivers, then based on information after point X you might find that your sequence of breaks B wasn't actually the best after all, because it ended up interacting badly with later spaces and producing rivers. So you can no longer prove that you've achieved a global optimum of the penalty function.

Of course you may be willing to take this hit and settle for non-optimum line-breaking (and you still might do better than an algorithm that doesn't take rivers into account at all).

If you google something like "latex rivers" or "latex microtype river" then you will see that there have been discussions, and some attempts. (Perhaps the issue is not as pronounced for mathematics, because of authors shying away from overly long paragraphs and because displayed equations break up paragraphs?)