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 "tempTOC.tr" 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 "tempTOC.ps", using the groff command shown below at "3." 1. Contents of "tempTOC.tr" --------------------------- .char \[ldr] .\h'1n' .lc \[ldr] .de TOCout .tm .LP .tm .ta 6iR .tm \\$* ^A\\n[PN] .. .LP .so TOCfile .bp 1 .LP Page 1 .TOCout Introduction (page 1) .bp Page 2 .bp Page 3 .TOCout Preliminary Considerations (page 3) .bp Page 4 .bp Page 5 .TOCout Historical Remarks (page 5) .bp Page 6 .TOCout Literature (page 6) .bp Page 7 .TOCout Outline of the Book (page 7) .bp Page 8 .bp Page 9 .TOCout Study Outline (page 9) 2. Command to generate "TOCfile" groff -Tps -ms tempTOC.tr 2>TOCfile >/dev/null 3. Command to generate "tempTOC.ps" groff -Tps -ms tempTOC.tr 2>/dev/null > tempTOC.ps 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, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 27-Sep-05 Time: 20:03:53 ------------------------------ XFMail ------------------------------ _______________________________________________ Groff mailing list Groff@gnu.org http://lists.gnu.org/mailman/listinfo/groff