Forum How do I...?

counter-reset in @page rules?

jlange
Hi there!

Is it possible to do things with counters inside @page rules yet? I found some forum posts saying that it's on the roadmap from before Prince 14's release, and that "Support for custom page counters." is included on the release notes for 14. I also saw the docs say this should work (assuming I'm not misinterpreting!):

https://www.princexml.com/doc/gen-content/#initializing-and-incrementing-counters
Note that the counter-increment and counter-reset properties can also be used in @page at-rules to create counters that track the page number, for example to number the pages within each chapter separately from the normal page and pages counters.


but when I try it it doesn't work how I expect:

<script>
    Prince.addScriptFunc("dollarsOnFirstRow", function (page) {
        return page == 1 ? "$" : "";
    });
</script>

<style>
table {
    counter-reset: rowOnPage;
}

@page {
    counter-reset: rowOnPage;
}

.row {
    counter-increment: rowOnPage;
}

.cell:before {
    content: prince-script(dollarsOnFirstRow, counter(rowOnPage));
    color: green;
}
</style>

<table>
    <tr class="row">
        <td class="cell">10</td>
        <td class="cell">20</td>
        <td class="cell">30</td>
        <td class="cell">40</td>
    </tr>
    <!-- repeated a bunch for page breaks -->
</table>

I'm trying to get the rowOnPage counter to reset at the start of each page, so that there'll be $s at the first row of each page.

I've actually tried a few different approaches here with no luck (using page-policy, nasty hacks with JavaScript, etc.). Is there something I'm missing or is this impossible at the moment?
mikeday
Custom page counters reset on @page rules can only be incremented by @page rules, I don't think it's possible to interleave element counters with page counters like this. Currently I think it would be necessary to use the JavaScript two-pass process to identify the rows at the start of each page and then apply a custom class to them for the second layout pass.
jlange
Ah that explains it, thanks! I'll take a look at a two-pass approach.