
The ECN No Name Newsletter is no longer being published. This is an archived issue.
[previous article] [next article]Most formal papers have headings in them and often sub-headings too. Unfortunately, it is difficult to keep track of all of these headings. Plus, you might have to delete or add material as you edit your paper that will alter your heading numbers and your table of contents.
But the inventor of the mm macros must have foreseen this difficulty in advance because mm has a built-in automatic heading counter and table of contents creator. This automatic tabulator of information also makes it possible for you to pre- and post- reference a heading number without knowing yet what the final heading number will be. However, in order to do this, TROFF has to be run twice. This dual processing of your paper allows TROFF to assign information to various number registers on the first pass, outputting code to stderr, then on the second pass deposit the collected code where applicable.
In the following example, I have used a number register ".nr", called " s?", for each section referenced (with s for "s"ection and a second uppercase letter for that particular reference). My first reference I named sA and my second reference sB; both parts of the number register name are arbitrary, but this method assists my memory. The following is a example of code that has pre- and post-referencing of sections.
.so refs.nr include this file .H 1 "This is the first title" title number 1 Ideas text to output shown in Section \n(sA post-referencing and Section \n(sB post-referencing .H 1 "This is the second title" title number 2 .tm .nr sA \n(H1 output to stderr Some code blah blah blah blah text to output .H 1 "This is the third title" title number 3 Text text text text text to output .H 2 "This is a subheading" subheading Text text text text text to output .tm .nr sB \n(H1 output to stderr .H 1 "This is the fourth title" title number 4 Words words words text to output as mentioned in Section \n(sB pre-referencing .TC make contents table
To automate the process of running my paper through TROFF twice, I created a Bourne shell script in a file called scrpt. This processes my paper through TROFF and grabs the stderr output and throws it into a file called refs.nr. Note that the second line in this file removes any old copy of refs.nr that may exist before loading it with new data. The exact contents of the scrpt file are shown below.
#!/bin/sh rm -f refs.nr mmt -Tpsc $1 2> refs.nr 1> /dev/null mmt -Tpsc $1 2> /dev/null | lpr -n
To use this script, you will have to make sure that this file is in executable mode. You can alter the permission associated with a file by using the change mode command; type "chmod 700 scrpt". To print your paper with the referenced notations included, type "scrpt filename". Remember to check your refs.nr file for other important error messages that relate to your paper. This shell script has this file collecting all error messages; therefore, many people do not like to use this script until the final few runs of their paper...after all other production problems have been solved.
The following is a sample of what you can expect when using this shell script.
1. This is the first title
Ideas shown in Section 2 and Section 3
2. This is the second title
Some code blah blah blah blah
3. This is the third title
Text text text text
3.1 This is a subheading
Text text text text
4. This is the fourth title
Words words words as mentioned in Section 3
1. This is the first title . . . . . . 1
2. This is the second title . . . . . . 17
3. This is the third title . . . . . . 26
3.1 This is a subheading . . . . . 28
4. This is the fourth title . . . . . . 34
This magic of pre- and post-referencing can also be done for figures. To read more about this look in the ECN #335 DOCUMENTER'S WORKBENCH: Reference Manual, Section 3.9 Technical Discussion. This manual is available in the Siegesmund Engineering Library in Potter Center or may be purchased at the Armory bookstore.