The facilities in the ms macro package for creating a table of
contents are semi-automated at best. Assuming that you want the table
of contents to consist of the document's headings, you need to repeat
those headings wrapped in XS and XE macros.
These macros define a table of contents or an individual entry in the table of contents, depending on their use. The macros are very simple; they cannot indent a heading based on its level. The easiest way to work around this is to add tabs to the table of contents string. The following is an example:
.NH 1 Introduction .XS Introduction .XE .LP ... .CW .NH 2 Methodology .XS Methodology .XE .LP ... You can manually create a table of contents by beginning with the
XSmacro for the first entry, specifying the page number for that entry as the argument toXS. Add subsequent entries using theXAmacro, specifying the page number for that entry as the argument toXA. The following is an example:
.XS 1 Introduction .XA 2 A Brief History of the Universe .XA 729 Details of Galactic Formation ... .XE
no]Prints the table of contents on a new page, setting the page number to i (Roman lowercase numeral one). You should usually place this macro at the end of the file, since
groffis a single-pass formatter and can only print what has been collected up to the point that theTCmacro appears.The optional argument
nosuppresses printing the title specified by the string registerTOC.
no]Prints the table of contents on a new page, using the current page numbering sequence. Use this macro to print a manually-generated table of contents at the beginning of your document.
The optional argument
nosuppresses printing the title specified by the string registerTOC.
The Groff and Friends HOWTO includes a sed script that
automatically inserts XS and XE macro entries after each
heading in a document.
Altering the NH macro to automatically build the table of
contents is perhaps initially more difficult, but would save a great
deal of time in the long run if you use ms regularly.