Forum How do I...?

Problem with flow header and custom counter

Snemis
Hi,

I want to create a document with a custom header. So I use a table that I place in the top margin-box with prince-flow: static.

In this header, I'd show the book name, chapter name, chapter number and page number.

I put in attachment an html file describing the example, as well as the pdf file created by Prince.

The book title, chapter title and page number is ok, but the problem is that the "custom" counter chapter is incremented, but not updated in the header.

What am I doing wrong?

Any help would be appreciated.

Thanks
  1. Example.zip68.4 kB
Snemis
Nobody has any idea where can be the problem ?
mikeday
Sorry for the delay. The problem here is that Prince is taking the chapter counter value where the table originally appears, and not updating it each time like it does for string-set values and page counters.

You can workaround this issue by putting the chapter counter in a named string, like this:
.header .chapter-number:after
{
    content: string(chapter-number)
}

...

h2:before
{
    counter-increment: chapter;
    content: "Chapter n°" counter(chapter) " : ";
    string-set: chapter-number counter(chapter)
}

This indirection will force Prince to evaluate it on each page, so it will update properly.
Snemis
Dear Michael,
Thank you very much for the time you took to answer my question and solve my problem.

Your solution works perfectly.

Best regards