Skip to content

Instantly share code, notes, and snippets.

@reffort
Created July 31, 2015 00:56
Show Gist options
  • Save reffort/45d2e4d989d045829250 to your computer and use it in GitHub Desktop.
Save reffort/45d2e4d989d045829250 to your computer and use it in GitHub Desktop.
Test file that shows Heirloom's line breaking with various constraints.
.do xflag 3
.
\#
\# This troff source file formats two paragraphs, an easy one and a more
\# difficult one, varying the minimum space size and the hyphenation penalty
\# to show the interaction of the word space size ratio (the badness function)
\# and the hyphenation penalty, and the effect on the formatted output.
\#
\# This file demonstrates how the Heirloom badness function has
\# a strong tendency to pack as many characters on a line as it can in order
\# to avoid using hyphenation, no matter how small the word spaces become.
\# Alternate methods attempt to produce even space sizes.
\#
\# The output PDF can be viewed 2-up, odd pages left, so that when paging
\# through it the differences are readily apparent.
\#
\# Run this file with
\# troff curves.tr | dpost | ps2pdf - > curves.pdf
\#
\# The companion C code provides a mechanism to change the behavior of the
\# penalty() function, so that Heirloom's output can be compared with others.
\#
.
.
.mediasize 6.0i 9.0i
.po 88p
.ll 256.5p\" to match the line breaks for the "Frog Prince" sample
.ps 11p
.vs 14p
.wh 0 pgtop
.de pgtop
. rs
. sp |3
. ns
..
.br
.
.hylang en_US
.
\# Computer Modern 10, v1.00B, 1997
.
.fp 1 R cmr10 pfb
.
.de PP
. br
. ti +11p
. ft R
. ps 11p
. vs 14p
. fspacewidth R 333
. padj
. ss 12 0
. minss 8
. letadj
. hy 4
. hylen 5
. hlm 3
. nhychar - \(en
. hypp 50
..
.
.blm PP
\# SampleText1
\# An easy paragraph that formats well without hyphenation.
\# When using the TeX curve and either the TeX82 or KP81 calculations,
\# the line breaks should match those of Figure 3 on journal page 1128 of
\# "Breaking Paragraphs into Lines," Knuth & Plass, 1981.
\# The end words shown in the article are:
\# there and which shone dark was king's side took it; plaything.
\# The space ratios do not exactly match those shown in the article,
\# but in the 30-odd years since the article was published,
\# the Computer Modern font has been converted to a kerned Type 1 font,
\# the advance width of some of the characters has been slightly
\# altered to improve the spacing (notably the 'i'), and the size of
\# a point has changed a little. There does not seem to be any
\# significant effect from disabling the kerning in the SampleText1
\# paragraph when using the Tex curve and calculations.
\#
\# SampleText2
\# A harder paragraph requiring hyphenation.
\# It readily shows the strong tendency of Heirloom to pack as many characters
\# on an output line as it can. The TeX and symmetrical curves exercise
\# more control of the word space size.
\# The hyphenation override ware\%houses is due to a bug in the troff
\# hyphenation code, where the break warehous-es is allowed when using
\# .hylang xxx even though .hy 4 (don't break off the last two) is
\# specified. This occurs only when the last two characters are followed
\# by punctuation, a comma in this case. You can see this problem by
\# removing the \% below and setting scaletype=4 and calctype=4
\# in the experimental penalty() code. I have a semi-workaround for this,
\# but it breaks the old digraph-based hyphenation and groff compatibility.
\#
\# The <space>\c at the end of each line is important. There is a bug in the
\# troff code so that when an input line ends with <character><\n>
\# and troff inserts an automatic space, the spaces following the
\# automatic space on the output line are not properly adjusted.
\# This is not very noticeable until the word spaces become more uniform.
\# The line breaks are not affected.
\# The workaround is either adding <space>\c to the end of each input line
\# or putting the entire paragraph on one input line.
\#
.
.
.de SampleText1
.ti +11p
In olden times when wishing still helped one, there lived a king whose \c
daughters were all beautiful; and the youngest was so beautiful that the \c
sun itself, which has seen so much, was astonished whenever it shone in her \c
face. Close by the King's castle lay a great dark forest, and under an old \c
lime-tree in the forest was a well, and when the day was very warm, the \c
king's child went out into the forest and sat down by the side of the cool \c
fountain; and when she was bored she took a golden ball, and threw it up on \c
high and caught it; and this ball was her favorite plaything.
.br
..
.
.
.de SampleText2
.ti +0
Call me Ishmael. Some years ago\(emnever mind how long precisely\(emhaving \c
little or no money in my purse, and nothing particular to interest me on \c
shore, I thought I would sail about a little and see the watery part of the \c
world. It is a way I have of driving off the spleen, and regulating the \c
circulation. Whenever I find myself growing grim about the mouth; whenever \c
it is a damp, drizzly November in my soul; whenever I find myself \c
involuntarily pausing before coffin ware\%houses, and bringing up the rear of \c
every funeral I meet; and especially whenever my hypos get such an upper \c
hand of me, that it requires a strong moral principle to prevent me from \c
deliberately stepping into the street, and methodically knocking people's \c
hats off\:\(emthen, I account it high time to get to sea as soon as I can. \c
This is my substitute for pistol and ball. With a philosophical flourish \c
Cato throws himself upon his sword; I quietly take to the ship. There is \c
nothing surprising in this. If they but knew it, almost all men in their \c
degree, some time or other, cherish very nearly the same feelings toward \c
the ocean with me.
.br
..
.
.de h1
. ti +0
. ce
. nop \\$1
. sp
..
.
.de PrintText
. h1 "minss \\$1, hypp \\$2"
. PP
. minss \\$1
. hypp \\$2
. SampleText1
. sp
. SampleText2
. bp
..
\# vary minss keeping hypp constant
\# left page - minss 8, 6, 3, 1, hypp 50
\# right page - minss 8, 6, 3, 1, hypp 25
.
.PrintText 8 50
.PrintText 8 25
.PrintText 6 50
.PrintText 6 25
.PrintText 3 50
.PrintText 3 25
.PrintText 1 50
.PrintText 1 25
\# a hyphenation penalty of zero will eliminate it from the badness calculation,
\# 100 will exaggerate the effect
.
.PrintText 8 100
.PrintText 8 0
.PrintText 6 100
.PrintText 6 0
.PrintText 3 100
.PrintText 3 0
.PrintText 1 100
.PrintText 1 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment