Back to Table of Contents Next: Bibliographies and references

Tables of contents


Introduction to tables of contents

Want a table of contents for your document? Easy. Just enter
.TOC as the very last macro of your input file. Mom will have picked up all document titles (in collated documents) and headings, as well as the endnotes section and bibliography, if they exist, and assigned them the appropriate page number. Talk about a no-brainer!

That said, tables of contents have even more control macros than endnotes. As always, the reason for so many control macros is so that if you want to change just about any aspect of the table of contents’ typographic appearance, you can.

Tables of contents appearance and behaviour

When you output a table of contents (with .TOC), mom finishes processing the last page of your document then breaks to a new page for printing the table of contents.

Mom follows standard typesetting conventions for tables of contents. To this end, if HEADERS are enabled for the document, the first page of the table of contents has no page header, but does have a first page number (roman numeral), always “i”, in the bottom margin. If FOOTERS are enabled for the document, the first page has neither a footer, nor a page number in the top margin. (If you absolutely must have a page footer on the first page of the table of contents, simply invoke .FOOTER_ON_FIRST_PAGE immediately before .TOC.) Subsequent table of contents pages have both page headers or footers and a page number.

Entries in a table of contents are hierarchically indented, as you would expect, and if headings are numbered in the body of the document, you can instruct mom to number them in the table of contents as well (see TOC_ENTRY_NUMBERS).

Tables of contents are never set in columns, regardless of whether the rest of the document is. Lastly, if recto/verso printing is enabled, the table of contents respects it. This sometimes leads to tables of contents that begin with the wrong margins, but the margins can be corrected either by outputting a BLANKPAGE or by using the control macro TOC_RV_SWITCH.

The overall table of contents family, point size and lead can be altered with control macros, as can the family, font, point size and indent of each level of entry. Furthermore, the page numbering style can be changed, as can the amount of visual space reserved for entry page numbers.

PDF output

When files containing a table of contents are processed with pdfmom, entries in the table of contents are clickable links when the document is viewed at the screen. The colour of the links is the last .PDF_LINK_COLOR in effect, so if you wish another colour, it should be set just before issuing .TOC.

When preparing files for printing, coloured links in both the table of contents and elsewhere in the document may not be desirable. You can disable the colour by passing pdfmom the -c option, like this:
pdfmom -c doc.mom > doc.pdf

Positioning the Table of Contents

Because a table of contents can’t be generated until the end of a document (hence the last macro in the file), it is also the last page of the document. While this is desirable for some language conventions—French, for example—it is not desirable for others.

Automatic PDF relocation of the Table of Contents

When pdfmom is used to process files with a table of contents, the macro .AUTO_RELOCATE_TOC can be used to reposition the table of contents to the top of the output document, with the presence of a cover and/or title page sensibly taken into account. Full AUTO_RELOCATE_TOC usage is described in the manual, Producing PDFs with groff and mom.

In order to take advantage of automatic table of contents repositioning, you must use pdfmom with groff’s native PDF driver (i.e. without the -Tps flag). Files that need to be processed with the -Tps flag require you to reposition the table of contents yourself with psselect, described below.

Note: AUTO_RELOCATE_TOC must come before START.

Using psselect to relocate the Table of Contents in PostScript documents

To change the location of the table of contents in files processed with pdfmom -Tps, you have two choices: rearrange the pages by hand (okay for one or two hard copies), or use the psselect programme provided by the psutils suite of tools (which you may have to install as a package from your distribution if it is not already on your system).

The procedure for using psselect to put the table of contents near the beginning of a document begins by you determining how many pages it contains. You can do this by previewing the document with the document viewer of your choice (gv, Okular, Evince, etc).

Once you know the number of pages in the table of contents, you use psselect to place them where you want.

Say, for example, the table of contents runs to just one page. The command to place a one-page table of contents at the start of a document is:
psselect -p _1,1-_2 The -p option instructs psselect that what follows is a comma-separated list of the order in which you want pages of a document rearranged. The underscore character means "counting backwards from the end of the document". Thus, the above says: "Put the last page first (i.e. the table of contents), followed by all pages from the original first page up to the second to last (i.e. the last page before the table of contents)."

If your table of contents runs to two pages, the option to psselect would look like this:
psselect -p _1-_2,1-_3 If your table of contents runs to two pages and you have a cover page, the command would look like this:
psselect -p 1,_1-_2,2-_3

Note: psselect outputs to stdout, so you have to redirect the output to a new file.
psselect -p <page list> <file>.ps > <new-file>.ps

The TOC macro

Macro: TOC [ INCLUDE_TITLE ]

If you want a table of contents, just place .TOC at the very end of your document. Mom takes care of the rest.

The optional argument, INCLUDE_TITLE, is needed only if your document is standalone, i.e. is not collated, for example an essay. By default, mom does not include the title (and page number) of standalone documents in the Table of Contents since it is largely redundant. If you would like her to include the title, invoke .TOC with INCLUDE_TITLE.

Note: If the last line of text in a document, before .TOC, falls too close to the bottom margin, or if the line is followed by a macro likely to cause a linebreak (e.g. .LIST OFF or .IQ), mom may output a superfluous blank page before the Table of Contents.

In order to avoid this, insert .EL after the last line of text, before .TOC and/or any concluding macros. For example,
some concluding text. .EL .TOC or
some concluding text. .EL .LIST OFF .TOC

TOC heading

Macro: TOC_HEADING "<single line TOC heading>"

• Argument must be enclosed in double-quotes

You may sometimes want to insert a line of text into the table of contents without it referring to a page number, for example to identify a “Part I” and a “Part II”.

Placed before any instance of the START macro, TOC_HEADING inserts its text into the table of contents before the next section title or heading. A modest amount of whitespace is introduced above and beneath to distinguish it easily from table of contents entries.

The appearance of the heading may be controlled with the macro TOC_HEADING_STYLE.


Control macros for tables of contents

Aside from allowing you to set the style of table of contents entries on a per-level basis, the control macros let you design the table of contents as if they were a complete document unto themselves (overall family, headers/footers, pagination, etc).

Table of contents control macros

  1. General table of contents style control
    • TOC_FAMILY – base family for tables of contents
    • TOC_PT_SIZE – base point size for tables of contents
    • TOC_LEAD – leading of tables of contents
  2. Page numbering
  3. Header string (e.g. “Contents”) and style
  4. Entries and reference page number style
  5. Additional table of contents control macros
  6. I still need more!

1. General tables of contents style control

Macro: TOC_FAMILY <family>

TOC_FAMILY establishes the default family for every page element in a table of contents, including the table of contents’ header string (by default, “Contents”) and the page number in the top or bottom margin. The default is the prevailing document family.

All page elements in the table of contents also have their own _FAMILY control macros, which can be used on a case-by-case basis to override the default family set with TOC_FAMILY.

Macro: TOC_PT_SIZE <base type size of the toc>

• Does not require a unit of measure; points is assumed

Unlike most other control macros that deal with size of document elements, TOC_PT_SIZE takes as its argument an absolute value, relative to nothing. (Compare this with the _SIZE control macros.) The argument represents the base point size of tables of contents from which the size of all other table of contents elements are calculated.

The default for PRINTSTYLE TYPESET is 12.5 points (the same default size used in the body of the document).

Macro: TOC_LEAD <leading of the toc> [ ADJUST ]

• Does not require a unit of measure; points is assumed

Unlike most other control macros that deal with leading of document elements, TOC_LEAD takes as its argument an absolute value, relative to nothing. Therefore, the argument represents the leading of tables of contents in points unless you append an alternative unit of measure. For example,
.TOC_LEAD 14 sets the base leading of tables of contents to 14 points, whereas
.TOC_LEAD .5i sets the base leading of tables of contents to 1/2 inch.

If you want the leading of tables of contents adjusted to fill the page, pass TOC_LEAD the optional argument ADJUST. (See DOC_LEAD_ADJUST for an explanation of leading adjustment.)

The default for PRINTSTYLE TYPESET is the prevailing document lead (16 by default), adjusted.

Note: Even if you give mom a .DOC_LEAD_ADJUST OFF command, she will still, by default, adjust the leading of the table of contents. You must enter TOC_LEAD <lead> with no ADJUST argument to disable this default behaviour.

Additional note: Tables of contents are always double-spaced in PRINTSTYLE TYPEWRITE, regardless of whether the body of the document is single-spaced.

2. Page numbering

The pagination style of tables of contents is controlled by the same macros that control document page numbering, except PAGENUM (tables of contents always start on page 1). The defaults are the same as for the rest of the document, with the exception that tables of contents, by default, have roman numeral page numbers.

Therefore, if you wish to change some aspect of table of contents pagination style, use the document pagination control macros immediately prior to .TOC.

A special macro, TOC_PAGENUM_STYLE, controls the style of table of contents pagination (i.e. the actual table of contents pages’ numbers, not the page number references of entries).

Macro: PAGINATE_TOC <toggle>

By default, mom paginates tables of contents. If you’d like her not to, do
.PAGINATE_TOC OFF (or NO, X, etc).

Note: Simply invoking .PAGINATION OFF or .PAGINATE OFF disables table of contents pagination for the first page of the table of contents only. You must use .PAGINATE_TOC OFF to disable table of contents pagination completely, even if pagination is turned off elsewhere in your document.

Macro: TOC_PAGENUM_STYLE <DIGIT | ROMAN | roman | ALPHA | alpha>

See PAGENUM_STYLE for an explanation of the arguments.

By default, mom uses roman numerals to number table of contents pages. Use TOC_PAGENUM_STYLE if you’d prefer something else. For example, to have standard digits instead of roman numerals, do the following:
.TOC_PAGENUM_STYLE DIGIT

3. Header string and style

The table of contents header string is the title that appears at the top of the table of contents. By default, it’s “Contents”.

Macro: TOC_HEADER_STRING <string>

If you’d like the title of the table of contents to read something other than “Contents”, do, for example
.TOC_HEADER_STRING "Table of Contents"

Header string vertical placement
Macro: TOC_HEADER_V_POS <distance from top of page>

• Requires a unit of measure

Normally, the TOC header string falls at the same vertical position as the docheader. If you’d like it to fall at a different position, say 2 inches, use
.TOC_HEADER_V_POS 2i

Header string control macros and defaults

See Arguments to the control macros.
The following TOC_HEADER control macros may also be grouped using TOC_HEADER_STYLE.

.TOC_HEADER_FAMILY default = prevailing doc family .TOC_HEADER_FONT default = bold .TOC_HEADER_SIZE default = +4 .TOC_HEADER_QUAD default = left .TOC_HEADER_COLOR default = black .TOC_HEADER_CAPS default = no .TOC_HEADER_SMALLCAPS default = no .TOC_HEADER_UNDERSCORE default = none

4. Entries and reference page numbers style

“Entries” refers to the hierarchical arrangement of section titles (in collated documents) and headings as they appear in the table of contents: Section title Head level 1 Head level 2 Head level 3 ... The style for title entries (e.g. chapter numbers or titles) and heading levels is controlled by TOC_TITLE_STYLE and TOC_ENTRY_STYLE respectively.

“Reference page numbers” means the page numbers associated with entries. Macros to control their style take the form .TOC_PN_<SPEC>, and the defaults are listed here.

See Arguments to the control macros. .TOC_PN_FAMILY default = prevailing doc family .TOC_PN_FONT default = roman .TOC_PN_SIZE default = 0

Macro: TOC_TITLE_STYLE <see below for args>

TOC_TITLE_STYLE allows you to set all the style parameters for title entries in the tables of contents with one macro. The number of arguments can run long, so you may want to break them into several lines with the backslash character (\). The arguments are:
FAMILY <family> FONT <font> SIZE +|-<n> COLOR <color> INDENT <amount> CAPS | NO_CAPS The arguments may be entered in any order.

The family, font, size, and color arguments behave identically to the individual control macros that govern other tags, therefore see Arguments to the control macros for usage. Their defaults are the same as for paragraphs in running text.

INDENT lets you indent title entries by the amount specified, and requires a unit of measure. The default is zero.

CAPS instructs mom to capitalize title entries. Capitalization may be enabled or disabled on a per-entry-level basis.

As an example, if you want title entries bold, slightly larger than other entries and capitalized, you could do either
.TOC_TITLE_ENTRY FONT B SIZE +.5 CAPS or
.TOC_TITLE_ENTRY \ FONT B \ SIZE +.5 \ CAPS

Macro: TOC_ENTRY_STYLE <level> <see below for remaining args>

TOC_ENTRY_STYLE allows you to set individually all the style parameters for any level of entry (beneath titles) in the tables of contents. The number of arguments can run long, so you may want to break them into several lines with the backslash character (\).

<level> corresponds to a HEADING level assigned in the body of the document. The remaining arguments are as follows.
FAMILY <family> FONT <font> SIZE +|-<n> COLOR <color> INDENT <amount> CAPS | NO_CAPS The arguments may be entered in any order.

The family, font, size, and color arguments behave identically to the individual control macros that govern other tags, therefore see Arguments to the control macros for usage. Their defaults are the same as for paragraphs in running text.

INDENT lets you indent entries by the amount specified, and requires a unit of measure. Mom sensibly indents and aligns all levels of entry. If you change the indent for any level, all levels beneath it are still indented according to mom’s normal arrangement, but with the indent assigned to level taken into account. When you use INDENT, the indent is measured from the left edge of the text of the previous level, including numbering, if any.

CAPS instructs mom to capitalize title entries. Capitalization may be enabled or disabled on a per-title basis.

As an example, if you want a particular entry level, say “2”, to be in Helvetica, italics, and slightly larger than other entries, you could do either
.TOC_ENTRY_STYLE 2 FAMILY H FONT I SIZE +.25 or
.TOC_ENTRY_STYLE 2 \ FAMILY H FONT I \ SIZE +.25

Macro: TOC_PREFIX_CHAPTER_NUMBER <none> <anything>

Alias: TOC_PREFIX_SECTION_NUMBER

By default, mom does not prefix a chapter number to chapters or section titles in the table of contents. If you would like her to do so, invoke .TOC_PREFIX_CHAPTER_NUMBER without an argument before START.

You may subsequently disable the prefixing of chapter numbers by supplying the macro with any argument (OFF, QUIT, Q, X...) prior to the .START that comes after .COLLATE.

This macro is useful you want chapters numbered in the table of contents but the chapters themselves are identified by title only. It can be used with both DOCTYPE CHAPTER and DOCTYPE DEFAULT. The alias TOC_PREFIX_SECTION_NUMBER may be preferable in the latter case.

Macro: PAD_TOC_CHAPTER_NUMBERS <number of chapters>

Alias: PAD_TOC_SECTION_NUMBERS

If the number of chapters or major sections (DOCTYPE DEFAULT) exceeds 9, you can have mom pad the numbers so the rightmost numerals of the chapter numbers align. Simply invoke PAD_TOC_CHAPTER_NUMBERS with the number of chapters in the document.

Without padding:
9. Chapter Title.....................100 10. Chapter Title....................123 With padding:
9. Chapter Title....................100 10. Chapter Title....................123

Macro: TOC_ENTRY_NUMBERS <FULL> <TRUNCATE> <NONE>

If numbering is enabled for any level of HEADING, mom, by default, includes the numbering in that level’s entries in table of contents. If you would prefer that numbering not be included in the table of contents, issue .TOC_ENTRY_NUMBERS NONE. If you’d like to include numbering, but not the full, concatenated numbering used in the body of the document, issue .TOC_ENTRY_NUMBERS TRUNCATE.

Assuming numbering is enabled for HEADINGs 1, 2, and 3, .TOC_ENTRY_NUMBERS FULL (mom’s default), would result in
1. Level-1 entry 1.1. Level-2 entry 1.1.1. Level-3 entry 2. Level-1 entry 2.1. Level-2 entry 2.1.1. Level-3 entry whereas .TOC_ENTRY_NUMBERS TRUNCATE would produce
1. Level-1 entry 1. Level-2 entry 1. Level-3 entry 2. Level-1 entry 1. Level-2 entry 1. Level-3 entry and .TOC_ENTRY_NUMBERS NONE would remove numbering completely.
Level-1 entry Level-2 entry Level-3 entry Level-1 entry Level-2 entry Level-3 entry

Note: .TOC_ENTRY_NUMBERS TRUNCATE removes the numbering associated with table of contents chapter or section titles when PREFIX_CHAPTER_NUMBER is enabled. To enable the numbering of chapter or section titles in this circumstance, use TOC_PREFIX_CHAPTER_NUMBER.

5. Additional table of contents control macros

The following five macros allow you to

Macro: TOC_APPENDS_AUTHOR <none> | "<name(s) of authors>"

In certain kinds of collated documents, different authors are responsible for the articles or stories contained within them. In such documents, you may wish to have the author or authors appended to the table of contents’ title entry for each story or article.

If you invoke .TOC_APPENDS_AUTHOR without an argument, mom appends the first argument you passed to AUTHOR to table of contents title entries, separated by a front-slash.

If you invoke .TOC_APPENDS_AUTHOR with an argument (surrounded by double-quotes), mom will append it to the table of contents title entries instead. This is useful if you have multiple authors you wish to identify by last name only. For example, if three authors—Joe Blough, Jane Doe, and John Deere—are responsible for a single article
.TOC_APPENDS_AUTHOR "Blough et al." would be a good way to identify them in the table of contents.

Macro: TOC_TITLE_ENTRY "<alternate wording for a title entry in the toc>"

In collated documents, the title of each chapter appears in the table of contents. It may sometimes happen that you don’t want the title as it appears in the table of contents to be the same as what appears in the docheader. You might, for example, want to shorten it. Or, in the case of chapters where the docheader contains both a chapter number and a chapter title, like this
Chapter 6 Burning Bush — Maybe God Was Right you might want only the chapter title, not the chapter number, to show up in the table of contents. (By default, .TOC generates both.)

If you want to change the wording of a title entry in the table of contents, simply invoke
.TOC_TITLE_ENTRY with the desired wording, enclosed in double-quotes. Using the example, above,
.CHAPTER 6 .CHAPTER_TITLE "Burning Bush — Maybe God Was Right" .TOC_TITLE_ENTRY "Burning Bush" .DOCTYPE CHAPTER would identify chapter 6 in the table of contents simply as “Burning Bush”.

Macro: SPACE_TOC_ITEMS

If you’d like mom to add a small amount of space between table of contents entry levels, use .SPACE_TOC_ITEMS. Mom will visually group entry levels in a way that’s pleasing to the eye. The only catch to this macro is that the bottom margins of table of contents pages may not align perfectly.

Please note that SPACE_TOC_ITEMS is only available with PRINTSTYLE TYPESET.

Macro: TOC_PADDING <number of placeholders to allow for page number listings>

By default, mom allows room for 3 digits in the page number references of table of contents entries. If you’d like some other number of placeholders, say 2 (if your document runs to less than 100 pages), do
.TOC_PADDING 2

Macro: TOC_RV_SWITCH

TOC_RV_SWITCH doesn’t take an argument. It simply instructs mom to switch the left and right margins of the first table of contents page in recto/verso documents should the table of contents happen to begin on an even page when you want an odd, or vice versa.

The same result can be accomplished by outputting a BLANKPAGE.

6. I still need more!

If there is some aspect of Table of Contents formatting for which no TOC control macros are provided, mom has a special toggle macro to help out: TOC_PAGE_SETTINGS.

TOC_PAGE_SETTINGS allows you to enter extra formatting changes for the Table of Contents as if it were simply another collated section or chapter of a document. Because it’s a toggle macro, invoking it by itself begins collecting your formatting directives, and invoking it with any argument (OFF, QUIT, END...) stops the collection.

TOC_PAGE_SETTINGS is special in that the formatting commands contained within it must be preceded by \! (that’s backslash-exclamation point).

For example, say you want to redesign the default page headers for the Tables of Contents so that it only contains the document title on the left and “Contents” in italics on the right, and furthermore adjust the footer margin and footer gap, this is how you’d do it:
.TOC_PAGE_SETTINGS \!.HEADER_RECTO L "^\E*[$TITLE]#\*[IT]Contents\*[PREV]^" \!.FOOTER_MARGIN 3P \!.B_MARGIN 6P+3p .TOC_PAGE_SETTINGS END (For an explanation of why the example uses .B_MARGIN to set/change the footer gap, see here.)

TOC_PAGE_SETTINGS can be put in the stylesheet section of a document (i.e. after PRINTSTYLE and before START) or invoked just before TOC.


Back to Table of Contents Top Next: Bibliographies and references