Open arthurattwell opened 7 years ago
Jeremy Keith uses Javascript to pop a non-breaking space between the last two words in a paragraph to solve widowed-words. Neat. May cause problems with really long words, but it might be quicker to override those with some kind of tag than to solve each one manually.
@SteveBarnett wrote up his rough notes on poking at the Prince box-tracking API here and saved some bookmarks.
FWIW, AH Formatter has an automated analysis feature that can report on:
See https://www.antenna.co.jp/AHF/help/en/ahf-analyzer.html
Unfortunately, solving these things is much harder than finding them.
When making books, we spend most of our time on print output fixing widows and orphans. I suspect we could automate most, if not all, of this work.
I'm guessing that this would mean using Javascript with Prince, and/or using vivliostyle.js for formatting instead of Prince. (Vivliostyle doesn't yet support as much CSS Paged Media and some other cool stuff that Prince does, but it's getting there and is open.)
'Widows' and 'orphans' refer to three problems in typography:
Good designers will adjust letter-spacing (tracking or kerning in software like InDesign) in various paragraphs to prevent these, usually tightening or loosening spacing by up to 10/1000 em. Where it's impossible to avoid all three problems, the designer finds the least-bad layout. This is in this order from best to worst outcome:
And then, give a choice, one might choose two widows on right-hand pages (not great) over one short-line orphan on a left-hand page (much worse). If we assigned a score to each possible problem, we could make this choice mathematically, possibly weighting the worst problems.
To resolve any given problem, a designer has to consider the impact of their tightening or loosening over a number of pages, sometimes moving forward and back over an entire document.
This design process is so universal and formulaic that I believe it must be possible to automate it, if a script could detect each problem, and iteratively apply tightening or loosening classes to paragraphs to find the best possible outcome.
Incidentally, in our classic theme currently, we use tightening and loosening classes: e.g.
p.tighten-5
tightens a paragraph by 5/1000 em. In the Sass, we set standard letter-spacing for the entire document, defined as$letter-spacing-text
. We then generate classes for tightening and loosening:So a script might insert these classes to use existing CSS.
Or we might take a different approach entirely.