. \" GLOBAL CONSTANTS " . .nr B 3v .nr T 2v \"page top margin .nr M 3n \"page horizontal margin .nr W 8.5i-\nMu-\nMu \"page content width .nr H (\n(.pu-\nTu-\nBu) \"max page height .nr G 2n \"inter-columns gap . . \" INTERNAL MACROS FOR LAYOUT " . \"record the content into a trap .de C{ . di C* \"save text content . ll \\n($Wu-\nGu \"line length column content .. . \"place the recorded content into columns, now that we have the height .de C} . br . di \"end C* diversion . . nr $H 0 1v . nr $P 0 1u . . mk . C? \"find optimal column height . rt . . C0 \"top of first column .\" tm Running with C=\\n($c/\\n($C P=\\n($p/\\n($P H=\\n($H h=\\n($h . C* \"print the formatted content . sp \\n(.tu \"consume space until the trap . . po \nMu \"back to page margin . ll \nWu \"back to full width . .. . \"Trap context: \" .----------------. .----------------. .----------------. \" | | | :::: :::: :::: | | :::: :::: :::: | \" | | | :::: :::: :::: | | :::: :::: :::: | \" | C0:: :::: :::: | | :::: :::: :::: | | :::: :::: :::: | \" | :::: :::: :::: | | :::: :::: :::: | | :::: :::: :::: | \" | :::: :::: :::: | | :::: :::: :::: | | ::C1 ::C1 ::C3 | \" | ::C1 ::C1 ::C2 | | ::C1 ::C1 ::C2 | | | \" '----------------' '----------------' '----------------' . \"test to print the content to check the height .de C? . C+ \"use more space . di _ \"catch output . C0 \"top of column .\" tm Trying with C=\\n($c/\\n($C P=\\n($p/\\n($P H=\\n($H h=\\n($h . C* \"try to fit the text in this setup . br . di . rm _ \"remove dummy content . . if \\n($o \{\ . rt \"back to top . C? \"need more room start over . \} . . ch C# \"remove real trap . dt \"remove diversion trap .. . \"set the minimal column width \" $C number of column per page width \" $W width of each column .de CW . nr $C \nW/\\$1 . nr $W (\nW+\nG)/\\n($C .. . \"increase the space used for extra pages and last columns height \" $P number of extra pages \" $H Height of the last serie of columns .de C+ . \"note: on first call, $H == $h == 0 . ie \\n($H>\\n($h \{ \"if rest of page is not enough . nr $P \\n($P+1 \"increase extra page count . nr $H 3v \"back to top of next page . \} . el \{ . nr $H \\n($H+1v . \} .. . \"column trap \" $t height of column for setting trap \" $o is there an overflow? (0=no 1=yes) \" $c current column within diversion/trap \" $p current number of extra pages spent within diversion/trap \" $h height of the page available for our content .de C# . \"pick apropriate trap context . ie \\n($p=\\n($P \{\ . ie \\n($c=\\n($C .C3 \"end of last column of last page . el .C1 \"end of some column of last page . \} . el\{\ . ie \\n($c=\\n($C .C2 \"end of last column of some page . el .C1 \"end of some column of some page . \} . . \"page offset . ie \\n($p=\\n($P \ . nr $t \\n($H \"height to last page height . el \ . nr $t \\n($h \"height to available height . . \"bump the trap . ch C# . wh \\n(.du+\\n($tu C# . dt \\n(.du+\\n($tu C# .. . \"top of article .de C0 . nr $o 0 \"no overflow yet . nr $c 0 1 \"will be increased by C#{...C+...} . nr $p 0 1 \"no extra page spent yet . nr $h \nT+\nH-\\n(nl \"rest of page available . mk \"mark top-of-column . C# \"initial trap setup . po \\nMu \"reset offset .. . \"bottom of some column of some page .de C1 . nr $c \\n($c+1 . rt \"back to top-of-column . po +\\n($Wu \"no effect in diversions .. . \"bottom of last column of some page .de C2 . nr $c 1 . nr $p \\n($p+1 \"bump this column's page count . bp \"new page . nr $h \\nH \"a whole empty page just for us . po \\nMu \"reset offset . mk .. . \"bottom of last column of last page .de C3 . nr $o 1 \"column overflow! must start over . po \\nMu .. . \"page header .de HE . ps 10p . vs 12p . po \nMu \"page margin . tl |#1 - 20\n(yr/\n(mo/\n(dy||PAGE \\n%| . po 0 \v'-1v'\l'101' . po \nMu \"page margin .. . \"open hook .de ?{ . if '\\*?'C{' .C{ \"if want a column layout, open it . ds ? C} \"next step: close column layout .. . \"close hook .de ?} . if '\\*?'C}' \{\ . C} \"if in a column layout, close it . F} \"if collected footnotes, print them . \} . ds ? C{ \"next step: open column layout .. . \"heading hook .de ?H . if '\\*?'HE' \{\ . br . HE . \} .. . .de F} . F* \"flush any footnote there was . rm F* \"then remove the associated macro . if \\n($F>0 .br . nr $F 0 1 .. . . \" MS-STYLE MACRO FRONTEND " . \"document name .de TL . ad c . ps 40p . vs 40p . ds ? HE . wh 0 HE \"set the trap for subsequent pages .. . \"section heading .de SH . ?H \"maybe show a heading separator . ?} \"maybe close previous column layout . ad l . ps 17p . vs 17p*3u/2u . ft 3 \"bold .. . \"paragraph .de PP . ?H \"maybe show a heading separator . br . ps 10p . vs 12p . sp 0.5v \"BUG: does not honor 0.5 . ft 1 . ad b . ?{ \"maybe open a new column layout .. . \"footnote start .de FN [\\n+($F] \"add this footnote's reference . da F* \"append this footnote . IP [\\n($F] \"as a numbered paragraph .. . \"footnote end .de FE . di .. . . \" SETUP LAYOUT " . .CW 30n .po \nMu .ll \nWu