Table of contents
How IDML stores a table of contents — TOCStyle and TOCStyleEntry in Styles.xml, and the generated story that names its TOC style in AppliedTOCStyle.
A table of contents is an ordinary story that InDesign generated; a TOCStyle records the recipe it was generated from.
In short The recipe is a TOCStyle in Resources/Styles.xml: a title, the
paragraph style for the title, and one TOCStyleEntry per paragraph style to collect.
Each entry names the style to collect (IncludeStyle), the style to format the entry
with (FormatStyle), an outline Level, and how to place the page number. The result
is a normal story of styled paragraphs with the page numbers typed out, and the story
names the recipe in its AppliedTOCStyle attribute. Nothing in the file updates the
list when pages move; regenerating it is the application's job.
The recipe: TOCStyle
A TOCStyle is a direct child of the idPkg:Styles root, with no group element around
it. InDesign writes a default one into every document: 271 documents in the census carry
one, almost all of them without entries. A document that has a real table of contents
adds a style with entries.
Titleis the heading text, andTitleStylethe paragraph style it is set in.IncludeHiddendecides whether paragraphs on hidden layers count;IncludeBookDocumentsextends the collection to the other documents of a book.RunInsets all entries of a level in one paragraph instead of one per line.CreateBookmarksturns the entries into PDF bookmarks on export, andMakeAnchorplaces a text anchor at each source paragraph.RemoveForcedLineBreakstrips forced line breaks from the collected text, andNumberedParagraphsdecides whether a list number is kept.
| Attribute · TOCStyle | Values | Paged | paged.set |
|---|---|---|---|
| Name | enum / text | read | |
| Self | TOCStyle reference | read | |
| Title | enum / text | read | |
| TitleStyle | ParagraphStyle reference | read | |
| CreateBookmarks | true | not read | |
| IncludeBookDocuments | false | read | |
| IncludeHidden | false | read | |
| NumberedParagraphs | IncludeFullParagraph | not read | |
| RunIn | false | read | |
| SetStoryDirection | Horizontal | not read |
The entries: TOCStyleEntry
Each TOCStyleEntry child of a TOCStyle collects the paragraphs in one paragraph
style:
IncludeStyleis the paragraph style to collect, for example a "Heading 1".FormatStyleis the paragraph style the entry is set in. InDesign writes it as an attribute or as a typedPropertieschild.Levelis the outline depth, 1 for the top level.PageNumberandPageNumberPositionsay whether the entry carries a page number and where;Separatoris the text between the entry and the number, andSeparatorStyleandPageNumberStyleare the character styles for the two.SortAlphabetsorts the entries of a level alphabetically instead of in page order.
Entries are rare in real files: only three documents in the census have any.
| Attribute · TOCStyleEntry | Values | Paged | paged.set |
|---|---|---|---|
| FormatStyle | reference | read | |
| Level | integer | read | |
| Name | builtin / enum / text | read | |
| Separator | builtin / text | read | |
| PageNumberPosition | enum | not read | |
| PageNumberStyle in Properties | — | not read | |
| Self | text | not read | |
| SeparatorStyle in Properties | — | not read | |
| SortAlphabet | boolean | not read | |
| IncludeStyle | reference | read |
The result: a generated story
Generating a table of contents walks the document's pages, picks every paragraph whose
style is an entry's IncludeStyle, and writes one paragraph per match, set in the
entry's FormatStyle, followed by the separator and the page number. The title comes
first, in TitleStyle. The output is placed in a text frame like any other story.
In the file, that story is ordinary text: ParagraphStyleRanges and
CharacterStyleRanges with the entries and page numbers as Content. What marks it as
a table of contents is the Story element's AppliedTOCStyle attribute, which names
the TOCStyle it came from. Every other story says AppliedTOCStyle="n". In the census,
91 documents write the attribute and one of them points it at a TOC style.
Because the page numbers are typed out, a table of contents goes stale when text moves to other pages, until it is regenerated.
In Paged: a text frame whose
AppliedTOCStylenames a TOC style has its story replaced by a fresh list: entries in story order, each with the label of the page its story starts on (section numbering included), set in the entry'sFormatStyle. The title paragraph andRunInare not applied yet. Paged does not yet read the attribute onStory, where InDesign writes it, so a table of contents made in InDesign shows its saved text. Supported · verified
Frequently asked questions
Where is a table of contents defined in IDML?
The recipe is a TOCStyle with TOCStyleEntry children in Resources/Styles.xml. The
table itself is an ordinary story elsewhere in the package.
How do I find the table-of-contents story in a package?
Look for a Story whose AppliedTOCStyle names a TOCStyle. Other stories carry
AppliedTOCStyle="n".
Are the page numbers in a table of contents live? No. They are saved as text when the table is generated and are only correct until the pages change.
What does IncludeStyle mean?
It names the paragraph style whose paragraphs the entry collects. FormatStyle names
the style the collected entry is then set in.
Why does every document have a TOCStyle?
InDesign writes a default TOC style into every document, whether or not it contains a
table of contents.
Cross-references & the index
CrossReferenceSource in the story, CrossReferenceFormat and its building blocks, the Hyperlink that joins them, and the Topic and PageReference index markers.
Sections, numbering & variables
How IDML numbers its pages with sections and fills text with computed values — page-number markers, the section marker, the chapter number and text variables.