Forum Samples, Tips and Tricks

How to generate table of contents (ToC) and index from HTML source

howcome
A table of contents (ToC) and an index are basic ingredients in a book. It is hard for authors to write these, as page numbers will change during formatting. This HTML document shows how to offload the task to JavaScript, which happily keeps track of page numbers. Also, the script is able to combine page ranges so that the index doesn't show «3, 4, 5», but rather «3-5».

https://css4.pub/2020/musick/musick.html
https://css4.pub/2020/musick/musick.pdf

The script uses the new multipass feature which has recently been added. Therefore, you will need the latest Prince build to test:

https://www.princexml.com/latest/

To make sure you run the correct version, run:

prince --version


To format the the test document yourself, run:

prince --javascript https://css4.pub/2020/musick/musick.html -o musick.pdf


More on multipass here:

https://www.princexml.com/forum/topic/4401/sidenotes-and-layout-driven-styling?p=1#22025

Edited by howcome