A table of contents (TOC) is represented by an odf_toc object, which is created using the odf_create_toc() constructor.
A table of contents is created as a free element using the odf_create_toc() constructor, with a mandatory unique name as its first argument, and the following parameters:
A table of contents object, after creation, may be put somewhere in a document using a generic method such as insert_element().
An existing table of contents may be retrieved by name using the context method get_toc().
It’s possible to retrieve the full list of the TOCs in a context through get_tocs(), without argument.
The odf_toc elements provide the following methods:
The fill method does an effective generation of the TOC content according to the current content of a document. Beware, this method is far less rich than the TOC generation feature of a typical interactive text processor, so it should be use if an automatic TOC generation is required only.
As long as the odf_toc object is not attached to a odf_document, the fill method requires an ODF document as argument. If the object belongs to a document and if the argument is omitted, the content of the TOC is generated from the content of the host document. However, it’s possible to insert a TOC in a document then fill it using the content of another document: the fill method generates a content according to the document provided as argument, if any.
The TOC is populated by fill using the outline (i.e. the hierarchical headings of the document), the TOC index marks, or both, according to the corresponding flags. Note that fill can’t generate any content if both use outline and use index marks are false.