Forum Samples, Tips and Tricks

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

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».

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

To make sure you run the correct version, run:

prince --version

To format the the test document yourself, run:

prince --javascript -o musick.pdf

More on multipass here:

Edited by howcome