Hello list,

I've been using groff for years, but mostly solving problems as they
came up.  Lately I decided to study the documentation more deeply, the
last thing I did was learn how to use diversions.  After a week of
struggling, I got the code below, it's to automatically get rid of the
last line of the last paragraph of a page end hanging alone on the next
page (just to avoid arguments about whether she was abandoned by her
parents or her husband died ;-)).

As far as I've tested it works, but it only works if you avoid using
vertical spaces without rounded values in 'v' units, like ".sp .3v" or
equivalents.  If, for example, you want to give unequal spaces above and
below in titles or subtitles, at least the sum must be a rounded value
in 'v' units (for example 1.3v above and .7v below will be counted as
two lines), otherwise the translation from the vertical space in \n[nl]
to lines won't tell the truth and problems will appear. :-)

I'd appreciate if anyone could give me some clues on how to get a more
solid solution or a better approach.

The values I set are for a 9x6 inches page (pass to groff the option
-P-p9i,6i).


.ps 13
.vs 16 
.po .5i
.pl 9i
.ll 5i
.
.nr header 3v/1v
.nr page \n[.p]u/1v
.nr lines_per_page \n[page]-5
.nr shorter_page \n[page]-6
.
.wh 0 hd
.wh \n[lines_per_page] fo
.
.hla us
.hpf hyphen.us
.hy 1
.
.de hd
'       sp \n[header]
.       ie (\\n[page_number] = \\n[%]) .ch fo \n[shorter_page]
.       el .ch fo \n[lines_per_page]
..
.de fo
'       bp
..
.de begin_paragraph
.       br
.       ti 2n
.       di paragraph \" begin diversion
..
.de end_paragraph
.       br
.       di \" end diversion
.       nr last_line \\n[nl]u/1v
.       nr par_lines \\n[dn]u/1v
.       nr reach \\n[last_line]+\\n[par_lines]
.       if (\\n[reach] = ((\\n[lines_per_page]*2)-\\n[header]+1) \
.               nr page_number \\n[%]+1
.       if (\\n[reach] = ((\\n[lines_per_page]*3)-(\\n[header]*2)+1) \
.               nr page_number \\n[%]+2
.       if (\\n[reach] = ((\\n[lines_per_page]*4)-(\\n[header]*3)+1) \
.               nr page_number \\n[%]+3
.       if (\\n[reach] = ((\\n[lines_per_page]*5)-(\\n[header]*4)+1) \
.               nr page_number \\n[%]+4
.       if (\\n[reach] = (\\n[lines_per_page]+1)) \{\
.               ie (\\n[par_lines] < 4) .bp
.               el .ch fo \n[shorter_page]
.       \}
.       if (\\n[par_lines] > 1) .ne 2
.       paragraph \" print diversion
..



-- 
Walter

Reply via email to