[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] Problem with diversion
From: |
Werner LEMBERG |
Subject: |
Re: [Groff] Problem with diversion |
Date: |
Sat, 26 Apr 2003 17:47:19 +0200 (CEST) |
> Now, in the code I'm attaching, the footnotes (or `lemmas') are set
> in a diversion. What should happen is this: when the size of the
> footnote block grows, because a lemma has run onto a second line,
> the end-of-text trap should be moved upwards. This is not working,
> because \n(dn always remains at the same value: 10000 units (i.e.,
> one line of text). This is the first time I've tried to do anything
> clever with diversions and traps, and, to be honest, I don't quite
> understand what I'm doing here with breaks, environments etc. Can
> anyone tell me *why* groff thinks that the footnote diversion is
> always just one line long? I've tried moving the environment switch
> inside and outside the diversion, as well the .br's, but to no
> effect.
Below is my solution using a diversion. The reason for \n[dn] always
being 10000 is simple: groff sets \n[dn] to zero if it starts with
`.di' or `.da'. With other words, what has already been stored away
in a macro doesn't count. Since you flush the current partial line
with `.br', the diversion is always exactly one line high (10pt=10000u
for the PS device). Admittedly, this isn't documented properly. I'll
add something to groff.texinfo.
There are some fundamental problems with your code.
. Using only a single trap for the page bottom doesn't work
reliably. Without a second diversion, you don't have a buffer
zone to catch for different vertical spacing in the main body.
. Since you set up the traps before emitting something, they are
already called on the first page. Doing `.sp 1i' explicitly at
the beginning of the text causes additional vertical space.
. Diversions collect already processed material (this is, the
horizontal spaces between words are fixed). You *must* emit
diversions with `.nf' active, otherwise they are formatted again
which usually produces very ugly spacing.
. Using \h'2n' to insert a big horizontal space between footnote
entries doesn't work as expected. At the end of lines, it isn't
discarded. Instead, you should use the `.ss' trick as shown in
the code below to artificially increase the inter-word spaces
temporarily.
. Calling `.br' after each footnote entry flushes the current
partially filled line into the diversion. This fixes the
inter-word spaces which is bad since the line isn't full yet.
Additionally, it works only if you omit the `.nf' while emitting
the diversion which causes ugly spacing as explained above.
Avoiding calls to `.br' is the right solution. Remember that the
current partially filled line is part of the environment.
I've also simplified and beautified the code a bit to make it more
readable. Enjoy!
Werner
======================================================================
.wh 0 top-of-page
.wh -1i-2v end-of-page
.wh -1i end-of-text
.
.\" We need an extra trap to assure that there is a gap between the main
.\" text and the footnotes.
.de end-of-page
' bp
..
.
.de top-of-page
' sp 1i
. nr fn-flag 0
. nr lastline 0
. rm footnote
. ch end-of-page -1i-2v
. ch end-of-text -1i
. nr ET (-1i)
..
.
.de end-of-text
. if \\n[fn-flag] \{\
. ev fn-ev
. \" Append last partially filled line before emitting diversion.
. da footnote
. br
. da
. \" Don't reformat.
. nf
. tm nl = \\n[nl]
. footnote
. fi
. ev
. \}
..
.
.\" Set up footnote environment.
.ev fn-ev
. ps 8
. vs 10
. ll 5i
. po 1i
.ev
.
.de lemma
. nr fn-flag 1
. ie (\\n[lastline] = \\n[ln]) \
. ds flabel
. el \{\
. ds flabel \f[B]\\n[ln]\f[]\~\"
. nr lastline \\n[ln]
. \}
. nop \\$1\\$3
.
. ev fn-ev
. \" Don't call .br! The current partially filled line is part of
. \" the environment.
. da footnote
. nop \\*[flabel]\f[I]\\$1\/\f[]]\~\\$2\c
. \" The idea is to have a big space between footnote entries. Using
. \" \h'...' doesn't work since it isn't removed at the end of a line.
. ss 48
. nop
. ss 12
. da
. ev
.
. tm Size of footnote diversion: \\n[dn]
. \" For .da, only the appended material changes \n[dn].
. if (\\n[dn] > 0) \{\
. tm !!!!!!!!!!!!! MOVING TRAP !!!!!!!!!!!!!!
. nr ET -\\n[dn]
. tm ET = \\n[ET]
. ch end-of-page \\n[ET]u-2v
. ch end-of-text \\n[ET]u
. \}
..
.
.\"-------------------------------------------------------------------
.
.ps 8
.ft I
.nm 1 2
.ft
.ps
.ll 3i
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
Now we fill up the page with meaningless sentences which are really boring.
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
This is some
.lemma text "A: test"
and this is some
.lemma more "F: moron" .
Let's add some more text, which extends over several lines,
and
.lemma see "J: observe"
whether it all behaves as it should.
I hope this is going to
.lemma work "A: function"
correctly.
This is some text
and this is some
more
Let's add some more text, which extends over several lines,
and see
whether it all behaves as it should.
I hope this is going to
work
correctly.