2021.1

Table Of Contents
Note
Whether page numbering restarts in each section, depends on the settings for page
numbering; see "Configuring page numbers" on page494. By default, page numbering
starts with page 1 for each section.
If the pagination process has changed the page numbers, the TOC needs to be updated as
well.
To do that, the script first has to collect the page numbers from the table of contents. This is
where the number class comes in handy: var $numbers = query('.number');.
Note that this query() function, as opposed to merge.context.query(), only searches the current
section (see "query()" on page1299).
Then, the level 1 and 2 headings are collected from all Print sections again using
merge.context.query("h1, h2").
The callback function in each() retrieves the heading's new page number. It then uses the index
number of the heading in the result set to get the corresponding entry in the TOC: var entry =
$numbers.get(index ); (see "get(index)" on page1327), and replaces it with the new page
number.
Excluding headings
Often there are certain headings that you don't want to appear in the table of contents. The title
of the table of contents itself, for example.
To exclude these headings from the table of contents, do the following:
1. Give all the headings that you want to be ignored the same class (see "ID and class" on
page627), for example ignore-me.
2. Add the:notselector to the queries in the script, specifying that class. Remember to put a
dot before the name of the class. For example: merge.context.query("h1:not
(.ignore-me), h2").
Adding internal hyperlinks
It is possible to create links in a table of contents that point to the respective position in the
document (for example when generating PDF output). An internal hyperlink points to an
element with a specified ID. (See: "Hyperlink and mailto link" on page716.)
Here's how to change the each() function in the script in order to add internal hyperlinks to the
table of contents:
Page 924