bookdown
bookdown copied to clipboard
feature request: option to restart endnote numbering after each GitBook-style web chapter
Thanks for bookdown! I previously posted this question on StackOverflow and offered a bounty, but did not receive any answers, so am adding as a feature request here.
I am preparing an historical book manuscript, written in R-Markdown with Bookdown, which will have 8 chapters, each with 100+ Chicago-style endnotes, using the GitBook-style web format.
My goal is to restart endnote numbering after each chapter, to avoid running into high digits and to resemble the appearance of traditional history books.
I have experimented with most of the settings described here (https://bookdown.org/yihui/bookdown/html.html#gitbook-style), but cannot produce the desired web output. Here's the relevant portion of my index.Rmd:
output:
bookdown::gitbook:
dev: svglite
css: css/style.css
split_by: rmd
split_bib: true
See my simplified mockup demo: https://jackdougherty.github.io/bookdown-test/book/ and source code: https://github.com/JackDougherty/bookdown-test
This can be a good and interesting JavaScript challenge, but I have no time to take it.
Thanks @romles for creating this solution in style.css, described here: https://stackoverflow.com/questions/50616517/restart-endnote-numbering-after-each-gitbook-style-web-chapter-in-r-bookdown
Demo here: https://jackdougherty.github.io/bookdown-test/book
If @yihui approves, please consider adding to bookdown code for others.
/* footnote counter to restart numbering for each chapter */
/* don't show the wrong footnote calls */ .footnote-ref sup { display: none; }
/* use a counter for footnote calls */ .level1 { counter-reset: fn-call; }
.footnote-ref { counter-increment: fn-call; }
/* generate new footnote calls */ .footnote-ref::after { content: counter(fn-call); position: relative; top: -.5em; font-size: 85%; line-height: 0; vertical-align: baseline; }
/* use a counter for footnotes numbering */ .footnotes ol { list-style: none; counter-reset: fn-number; }
.footnotes li { counter-increment: fn-number; }
.footnotes p::before { content: counter(fn-number) '. '; }
My suggested code to restart note numbering after each Gitbook-style web chapter is no longer working as intended. (Perhaps something changed from bookdown v 0.8 to 0.9?) So I'm withdrawing this suggestion until I can look at it more closely. Stay tuned.
@JackDougherty Version 0.9 came with some changes to CSS, that's why the CSS tweak described two comments above https://github.com/rstudio/bookdown/issues/589#issuecomment-441386205 doesn't work as desired.
The <a>
tag's class inside the citation changed from .footnote-ref to .footnoteRef. So you need to extend some of your CSS to account for that:
/* don't show the wrong footnote calls */
.footnote-ref sup,
.footnoteRef sup {
display: none;
}
...
.footnote-ref,
.footnoteRef {
counter-increment: fn-call;
}
.footnote-ref::after,
.footnoteRef::after {
content: counter(fn-call);
position: relative;
top: -.5em;
font-size: 85%;
line-height: 0;
vertical-align: baseline;
}
...
Thanks @ilyankou for updating the option to restart note numbering after each web chapter to fit with bookdown 0.9
Demo: https://jackdougherty.github.io/bookdown-test/subchapter.html
Code: https://github.com/JackDougherty/bookdown-test/blob/master/css/style.css#L78
This works great except for multi-paragraph footnotes, each paragraph gets numbered. It's the right number, but it ends up looking like this:
1. Here's my first footnote.
2. Here's my second footnote paragraph one.
2. Here's my second footnote paragraph two.
3. Here's my third footnote.
Is there any way in the CSS to prevent that?
Thanks @cderv for tagging this option to restart endnote numbering as a potential enhancement for Bookdown.
@ilyankou -- Do you have any suggestions about the question raised by @jtbayly on how this feature could be modified to address multi-paragraph notes?
Here's updated CSS that fixes the multi-paragraph notes:
/* don't show the wrong footnote calls */
.footnote-ref sup, .footnoteRef sup {
display: none;
}
/* use a counter for footnote calls */
.page-inner {
counter-reset: fn-call;
}
.footnote-ref, .footnoteRef {
counter-increment: fn-call;
}
/* generate new footnote calls */
.footnote-ref::after, .footnoteRef::after {
content: counter(fn-call);
position: relative;
top: -.5em;
font-size: 85%;
line-height: 0;
vertical-align: baseline;
}
/* use a counter for footnotes numbering */
.footnotes ol {
list-style: none;
counter-reset: fn-number;
}
.footnotes li {
counter-increment: fn-number;
}
.footnotes li p:first-child::before {
content: counter(fn-number) '. ';
width: 1.5em;
float: left;
}
Suggestions provided in this thread (I've tried all three) make footnote counter restart at 1 with each footnote for me (as opposed to restarting at the beginning of each chapter) so all my footnotes are labeled 1. I'm using bs4_book()
as the output if that is relevant.
Output (See chapters 1 and 2): https://mine-cetinkaya-rundel.github.io/bookdown-test Code: https://github.com/mine-cetinkaya-rundel/bookdown-test
Yes, it is quite relevant that you are using bs4_book. These solutions are all dependent on the specific output form from the gitbook style. Sorry.