# Evaluate typographical beauty of a document (widow, orphans, hyphens, etc) in order to optimize the page geometry

When finalizing documents, one of the last things I do is usually to play with the page geometry to improve the overall layout: get rid of a few orphans or widows, reduce the number of hyphenations, etc.

I usually start by designing my documents with an acceptable or imposed/suggested page geometry, say

\usepackage[scale=0.75]{geometry}

but more often than not (if not always), I can actually replace that 0.75 (as an example) by anything in between 0.73 and 0.77 (because even when the page geometry is supposedly "mandatory", most people won't notice the difference...).

My process so far is however manual, tedious and quite subjective, basically trying out different scale options and picking the one most pleasing to my eye...

A better process would be to have TeX output a few typographical indicators or, better, a global "badness" indicator for the whole document, and then use a small script to optimize the scale factor based on this. So here are my few related questions:

1. a) Is it possible to have TeX output such typographic quality indicators such as:

• The number of widows,
• The number of orphans,
• The number of hyphens,
• The standard and maximum inter-word spacing,
• The number of lines with inter-word spacing greater than twice the standard value, and
• Any other relevant typographic quality indicator you believe is useful? (I am assuming cardinal sins like overfull boxes have been dealt with in all cases).

b) For widows, orphans, hyphens and similar relevant grave sins, would it be possible to modify TeX's output routine to identify where they happen? Either directly inside the document, as a Warning in the log, or both at choice (as happens for over- and under-full hboxs).

2. Is it possible to get TeX to output a global quality / badness indicator for the whole document? I know TeX works with a system of penalties internally; is it possible to output the penalty total for the whole document, and would that be an appropriate metric for my optimization desire?

(Note: the answer does not have to work on every engine; in particular, Lua code is perfectly acceptable as I guess the question draws to some of the stated objectives of luatex to "open up the internals of TeX")

• You may be interested in the new CTAN 'package' wheretotrim. It is a 'Perl script that anal­y­ses a doc­u­ment, and re­ports the page and col­umn on which the least amount of text needs to be trimmed to re­duce the page count.' Caveat: only tested so far on Linux. – jon May 20 '13 at 18:14
• @jon Thanks for the pointer. My question though is not about how to minimize the number of pages, but rather how to maximize their beauty. – Xavier May 20 '13 at 19:15
• Indeed; but the thought behind the suggestion is that changing the size of paragraphs can have beneficial aesthetic side-effects. If you are enlarging the page to reduce widows, e.g., these are exactly the paragraphs that wheretotrim should identify as easy to 'fix' paragraphs in terms of reducing the overall length of the document. That is, these two goals overlap in many cases. – jon May 20 '13 at 19:25
• You may also wish to consider playing with looseness of paragraphs. – Andrew Swann May 21 '13 at 6:26
• @ienissei I understand, but I don't really see the point of comparing the badness of a 700-page document to a 1-pager. They just can't be compared in my mind, but maybe I am wrong. Good news is, as you said, if we can get either total or average badness, we can get the other easily :) – Xavier May 23 '13 at 15:08