Forum How do I...?

deal with block-level footnotes and previous calls?

mrwarper
While I love how simple Prince makes turning some inline text into footnotes, that solution just doesn't cut it for some of my documents. For these, due to the nature of the text, the extension of the notes, or both, I use different markup. I've tried to make these work, but I'm kind of stuck halfway.

First, the markup. I use

<p>[...]blah blah blah[...] <a href="#footnote_xyz" class="footnote_call">and there's a reason why this is so</a> [...] more text [...] </p>
<div class="footnote" id="footnote_xyz">
<p>A really lengthy aside.</p>
<p>These even take some paragraphs sometimes.</p>
</div>

which degrades gracefully when reading on a text-only browser like Links or Lynx, whereas inline text wouldn't. As I style them, these footnotes appear on screen when the call is clicked on (pure CSS, no js),
footnotes_screen.png

or as paragraphs interspersed with the main text on paper:
footnotes_paper.png

The latter is what I want to turn into 'proper' footnotes. The functionality provided by Prince quickly got me to:
footnotes_halfway.png

which shows the two problems I don't know how to solve yet:

1) Footnote-calls: I've tried to hide them, float them into the previous paragraph, make them 1 or 0 pixels (see the two red pixels above?). They still take up one full line in the text flow, even with "content: none;". This appears to be a long-standing issue, BTW.

I understand Prince needs to know where footnote elements were, but can't it be done invisibly? This I can live with, but it doesn't look good if paragraph separation on paper is zero lines.

2) Since I use my own footnote call elements, which appear before the footnotes themselves, the footnote counter is not updated yet when their ":after" pseudoelements are generated. I.e., their number is always one unit less than it should.

I thought this could be solved with "counter-increment: footnote" either inside "a.footnote_call { }" or "a.footnote_call:after { }", and maybe decrement the counter again from the footnotes themselves. But the footnote counter wasn't incremented in the first place.

Am I doing something obviously wrong, or...?
  1. footnotes_halfway.png19.8 kB
    Almost there, but not quite...
  2. footnotes_paper.png18.8 kB
    Crude yet effective rendering on print
  3. footnotes_screen.png9.9 kB
    This is how my markup looks on screen

Edited by mrwarper

dauwhe
I've made up a quick example (pdf and html attached), although my markup is a tiny bit different due to what I'm used to.

For [1] the secret is to put a negative margin on div.footnote + p, to eliminate the blank line. I hid it in a print media query to avoid messing with browser display.
  1. footnote.html1.8 kB
  2. footnote.pdf28.7 kB
mrwarper
Thanks for the tip, dauwhe! I hadn't think of negative margins :/
Now I'm a bit annoyed because you seem to solve [2] by doing exactly what I tried to do, which means I must just have overlooked something, or maybe I have a typo somewhere. Let me have a real look and play a bit with it. Anyway thank you for showing it's possible -- I'm not totally crazy! ;)
mrwarper
OK, I finally found the time to come back here with my homework done.

The difference between dauwhe's code and mine is that he completely made up his own counters and stuff, whereas I tried to keep using those supplied by Prince as much as possible. Turns out it is a very important difference, because not all counters are created equal...

Below you'll see some markup* that mixes both Prince simple inline and my own block-level footnotes. Orange stuff is generated by Prince, mine is red.

* And its rendering both in Prince and FireFox.

Now, there are two counters named 'footnote' and 'mycall' that start at 10, just to test. Just as well we could test counter reset, couldn't we? -- To simplify, I'll be breaking pages at H2s, and counter reset will be tested at DOM selectors in one version of the CSS and at pages in the other. So, what do we see when printing from a browser?

counters_+h2.htm‎
counters_+h2_FX.png


FireFox does not really do footnotes yet when printing. D'oh. It does counters, though.

Now, as expected, Firefox only renders the counter 'mycall' (in red), and it is shown correctly reset for sections #2 and #3, but not for #1. This means FireFox honors the counter-reset at the * + h2 selector. So far, so good. How about pages?

counters_page.htm‎
counters_page_FX.png


FX ignores the counter reset at @page, which should be numbered 1-2-3 in all three sections. I take it the reason is that 'pages' are not an integral part of the DOM. However, we came here to discuss Prince, didn't we?

From its output we can deduce some interesting facts about how it handles counters. Counter reset at * + h2 first again:
counters_+h2.pdf‎
counters_+h2.png


So, this is like FireFox, only with footnotes working for real ;) i.e. counters are properly set at body and reset at * +h2 elements, and you can see where I stood before with my own footnote calls always lagging behind those kept by Prince. This might seem trivial now, but the lesson implied is: anything floated as 'footnote' counter-increments "footnote" only, and anything else should be done manually.

How about pages, then?

counters_page.pdf‎
counters_page.png


First, the "footnote" counter is reset, but not "mycall".

Second, "footnote" is apparently not reset on the first page, implying that @page is interpreted more like 'turning a page' than some kind of container in the document, as far as that counter is concerned. I don't know if this is a bug or working as intended, but I think it is worth keeping in mind.

Now I can do what I wanted in the first place by simply keeping my own counters everywhere, but I thought I'd share my findings here in case others might find all of this useful.

As always, any further comments on obvious mistakes or oversights are welcome.
  1. counters_+h2.htm2.9 kB
    Counter reset at * + H2
  2. counters_+h2.pdf43.4 kB
    Reset@*+H2, Prince output
  3. counters_+h2.png6.0 kB
    Reset@*+H2, Prince output
  4. counters_+h2_FX.png12.3 kB
    Reset@+H2, FX print preview
  5. counters_page.htm2.9 kB
    Counter reset at @page
  6. counters_page.pdf44.6 kB
    Reset@page, Prince output
  7. counters_page.png6.2 kB
    Reset@page, Prince output
  8. counters_page_FX.png12.4 kB
    Reset@page, FX print preview

Edited by mrwarper