Scratchpad:Balance Ragged Lines

It would definitely be cool to balance ragged lines: http://indesignsecrets.com/wp-content/uploads/2009/10/balance-3.jpg It can be done with javascript, go over slide text line-by-line to measure line width: http://stackoverflow.com/questions/118241/calculate-text-width-with-javascript or maybe even word-by word, then find the best combination of words per line and insert line breaks.

LaTeX uses "baddness" value to decide between the variants, so the variant with smallest total badness wins. One of the simplest ways to find badness is to find the average width of lines on slide and then power the difference of current line with two (standard deviation). Then the variant with most balanced lines should win.

Variants which are wide on top or on bottom or on middle may look good as well (but need different approach).