Forum How do I...?

Table of contents for dummies...

lindm
How do I create a table of contents?

I have my chapters within h1 tags (html doc). What to do next? Looked at http://www.w3.org/TR/css3-gcpm/#toc but can not get it to work...

Need help from the css handling to what to enter in my html doc.

Thanks
lindm
Solved it myself. Small guide for others, using html.

Step 1: In css create the following
#navig a::after { content: leader(".") target-counter(attr(href), page); }


Step 2: Create chapters, headlines or what you call it in your html file like this:
<h1 id="item1">item1</h1>

Done for each "chapter"

Step 3: Create TOC-area in html file


<div id="navig" style="width:400px">
Table of contents<br />
<div><a href="#item1">item1</a></div>
<div><a href="#item2">item2</a></div>
<div><a href="#item3">item3</a></div>
</div>


Ready.

Now what I would have liked to have is an automatic TOC that generates chapters based on existing h1 tags. Example: script searches through html and finds all tags h1 and uses the text between h1 tags as chapters...
mikeday
It is possible to do this automatically with a Perl script or XSLT transform, and there is a proposal for generated lists in the CSS3 module Generated Content for Paged Media that will also allow table of contents generation.
Alastair
Does version 6 of Prince support the css3 toc-entry element? Edit: - I've re-read the original post and realised that it doesn't.


I tried the instructions in post#2. They worked, sort of, but didn't produce page numbers in the toc. What has to be done to produce a table of contents with page numbers?
mikeday
The target-counter part should do that, assuming that the links are correctly pointing to the chapters.
Alastair
thanks - I'd forgotten to add the target counter to the css.
alyda
could you post your findings per the instructions in post #2?
williamle8300
Would it be possible implement lindm's solution for a collection of HTML files?

It seems to only work when all of the <h1>'s are in one document, but doesn't work when the links are resolve to different HTML documents.
mikeday
Are you passing multiple HTML documents to Prince on the command-line?
williamle8300
I process the XML file on the command-line. The XML file links to each of the HTML docs (xi:include).
mikeday
This works for me, here is a simple example:
<?xml version="1.0"?>
<html xmlns:xi="http://www.w3.org/2001/XInclude">
<head>
<style>
a[href]::after { content: leader(".") target-counter(attr(href), page) }

div.chapter { page-break-before: always }
</style>
</head>
<body>

<div><a href="#chap1">Chapter 1</a></div>
<div><a href="#chap2">Chapter 2</a></div>

<xi:include href="chapter1.html"/>
<xi:include href="chapter2.html"/>

</body>
</html>

Where chapter1.html looks like this:
<div class="chapter" id="chap1">
<h1>Chapter 1</h1>
</div>

and chapter2.html looks like this:
<div class="chapter" id="chap2">
<h1>Chapter 2</h1>
</div>
williamle8300
Thanks for the help again Mike!

I ended up merging my HTML docs, and the ToC worked as expected. I'll give this a try to see if this workflow is more quick. Thanks again!
RichardForrester
I'm getting "0" for may page numbers. Any idea what I'm doing wrong?

The links are working in the html file in the browser.
mikeday
Are the links pointing to empty inline elements? There is a current limitation of Prince where these can fail, so it may help to change the links to point at inline elements containing text, or block elements.
RichardForrester
No, they are pointing to block elements (<h1>). I did see that thread and a few others, with nothing really addressing what I am experiences so I created a different thread as I feel I'm probably doing something else wrong. Currently examining whether there are some setup issues I've failed to account for. New thread here: http://www.princexml.com/forum/topic/3226/internal-links-not-working-in-pdf-prince-pdf-link-type-css