[Top][All Lists]

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

RE: [Groff] moving TOC to start

From: Ted Harding
Subject: RE: [Groff] moving TOC to start
Date: Tue, 27 Sep 2005 20:04:02 +0100 (BST)

On 26-Sep-05 Jason St Armand wrote:
> Hi,
> does anyone have any simple methods for placing the table of contents
> at the start of the output file ?
> I have done it manually with Postscript output and should be able to
> script that, but if anyone has other suggestions I would appreciate
> hearing from them.
> Many thanks.

As Larry and Tadziu have pointed out, there is a variety of approaches
to this. All will involve a double pass over the file with groff,
however, since the first pass is required in order to ascertain the
page numbers, and the second one in order to be able to work at the
beginning of the file again.

The following toy example (which will work "natively" on Unix/Linux
systems; Windows systems might need some modification but I don't
know anything about that) shows a very minimal approach.
If one wanted to make it more elaborate, there is any amount of scope
for developing its elements.

The strategy is:

1. Edit the example file "" to have the contents below.
   NB that what is shown as "^A" must be entered as the
   character Ctrl-A (ASCII code = 1); I use 'vim' as editor, where
   a control character would be typed in using the keystrokes

     Ctrl-V Ctrl-A

2. Run groff on it (I'm using ms macros) to generate a file
   "TOCfile" which will contain the commands to format the TOC,
   using the groff command shown below at "2."

3. Run groff again, this time to generate the PS file "",
   using the groff command shown below at "3."

1. Contents of ""
.char \[ldr] .\h'1n'
.lc \[ldr]
.de TOCout
.tm .LP
.tm .ta 6iR
.tm \\$* ^A\\n[PN]
.so TOCfile
.bp 1
Page 1
.TOCout Introduction (page 1)
Page 2
Page 3
.TOCout Preliminary Considerations (page 3)
Page 4
Page 5
.TOCout Historical Remarks (page 5)
Page 6
.TOCout Literature (page 6)
Page 7
.TOCout Outline of the Book (page 7)
Page 8
Page 9
.TOCout Study Outline (page 9)

2. Command to generate "TOCfile"

   groff -Tps -ms 2>TOCfile >/dev/null

3. Command to generate ""

   groff -Tps -ms 2>/dev/null >

This puts a "TOC" entry into TOC for pages 1, 3, 5, 6, 7,
and 9, which appears at the start of the final document.
The individual pages 1-9 simply have "Page 1" , ... , "Page 9"
on them!

Hoping this is useful,

E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 27-Sep-05                                       Time: 20:03:53
------------------------------ XFMail ------------------------------

reply via email to

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