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


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")

  • 2
    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
  • 1
    You may also wish to consider playing with looseness of paragraphs. May 21 '13 at 6:26
  • 1
    @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

This is not exactly what you are calling for, but since you wanted any other relevant typographic quality indicator I believe is useful, let me mention two packages:

  • Patrik Gundlach's lua-check-hyphen, which lets you review all hyphenations actually used in a document, and

  • Raphaël Pin­son's impnattypo, which implements quite a few rules of French typography; a few of them are not specific to French (like inserting ties after one-letter words, which is also required in Polish and (AFAIK) Czech), and some are even universal (like avoiding rivers); impnattypo can fix some of these issues and highlight other ones.

Both packages require LuaLaTeX (well, some features of impnattypo work without it). See their docs for the exact feature list.

  • Thanks for the links! I didn't knew about lua-check-hyphen; as for impnattypo, it doesn't answer my quantification need, but it's quite impressive; I just read on TeX.SX that it can detect rivers!
    – Xavier
    May 23 '13 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.