groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Groff] problem with nested diversions


From: Werner LEMBERG
Subject: Re: [Groff] problem with nested diversions
Date: Sun, 17 Aug 2008 11:14:16 +0200 (CEST)

> I can't figure out how a nested diversion fits into the text flow
> when its parent diversion is being output.  The calls for the macro
> containing the nested diversion seem out of place relative to the
> text flow.

This appears to be a limitation of `\!' which is present in
traditional troff also.  I still have to debug this so that I can
document it properly.  It seems that a call to the stuff embedded with
`\!' is triggered by a newline in a diversion and not the position of
`\!' in the data stream.

> For reasons outlined at the end of this message (which gives the
> details of the project where this problem arose), I can't process
> the footnote when the parent diversion is being read; it must only
> be processed when the diversion is being output.  And so I re-embed
> the pair of macro calls in the text with "\!".  But when the macros
> are finally called on the output of the parent text, they don't
> properly capture the footnote text that they had originally
> surrounded.

Regardless of the non-functioning of `\!', you've made one logical
mistake:

> .de fn))
> .ie '\\n[.z]'a' \!.fn))

This test will never work: At this very place, you are always in
diversion `fnote'.  It's not possible, BTW, to access the diversion
name stack (this is one of the possible TODO items which James Clark
has collected 10 years ago).

The tricky thing of your request is to assure that the footnote gets
really defined in the call to the diversion and not while the
diversion is defined.  Otherwise, these trivial definitions would be
sufficient:


  .de fn((
  .  nop \s-2\u\\$1\d\s0
  .  ev note
  .  di fnote
  .  nop \\$1.
  ..
  .
  .de fn))
  .  br
  .  di
  .  ev
  ..


After some experimentation, I found the following solution, using
`\?...\?' instead of `\!'.  To check exactly the place of definition,
I used a string register to hold the name of the footnote diversion.
As you can see, it's really after calling the diversion that the
footnote gets defined.

This works with groff version 1.18.1.  Note that those macros fail if
called outside of a diversion.

The standard trick to call a macro as a string (from within a macro)
is

  \\*[xx]\\

where `xx' starts with \c.  However, it's not possible to embed `\\'
within `\?...\?', thus I have used a string argument instead.

With other words, we can use a TeX-like syntax:


  .de test
  \c
  \\$1, \\$2, and \\$3.
  ..
  .
  Arguments 1-3 are \*[test "foo bar" baz grumpf].


  -> Arguments 1-3 are foo bar, baz, and grumpf.


    Werner


======================================================================


.de fn((
.       nop \s-2\u\\$1\d\s0
.       nop \?\\\\*[fn*(( \\$1]\?\c
..
.
.de fn*((
\c
.       ev note
.       di \\*[div-name]
.       nop \\$1.
..
.
.de fn))
.       nop \?\\\\*[fn*))]\?\c
..
.
.de fn*))
\c
.       br
.       di
.       ev
..
.
.
.ds div-name fnote1
.
.di a
Even without publication, Nightingale's \fISuggestions for
Thought\fP attracted much scholarly attention. Several editions
of excerpts have been published. Three books of excerpts, and a
separate edition of ``Cassandra,'' were published later in the
twentieth century.\c
.fn(( 1
Michael D. Calabria and Janet A. Macrae, eds.,
\fISuggestions for Thought by Florence Nightingale\fP.
.fn))
As usual the official biography, E.T. Cook's \fIThe Life of
Florence Nightingale\fP, can be counted on for excellent
background on the purpose and writing.
.br
.di
.
.ds div-name fnote2
.
.unformat a
.a
.
.sp
.
.unformat fnote2
.fnote2
.
.\" eof

Attachment: di.pdf
Description: Adobe PDF document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]