jay.sf
jay.sf

Reputation: 72803

How to place footnotes in rmarkdown html under specific header?

I want to place Rmarkdown footnotes under the header Endnotes. Whereas References can be placed with <div id="refs"></div>, that method seems not to work with footnotes, though. I opened the html document produced by Rmarkdown that revealed footnotes are collected under a tag called <div class="footnotes"></div>. I also tried <div id="footnotes"></div>, but that won't work either. How do I do this right?

Code I'm using:

---
output: html_document
references:
- id: hawking_thermodynamics_1983
  author:
  - family: Hawking
    given: S. W.
  - family: Page
    given: Don. N.
  publisher: Communications in Mathematical Physics
  title: Thermodynamics of Black Holes in Anti-de Sitter Space.
  volume: 87
  type: article-journal
  issued:
    year: 1983
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Section 1
Lorem ipsum dolor^[always look on the bright side of life] sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua [@hawking_thermodynamics_1983]. 

## Endnotes
<div class="footnotes"></div>

## References
<div id="refs"></div>

## Appendix
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 

Output produced:

enter image description here

Expected output:

Section 1

Lorem ipsum dolor1 sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua (Hawking and Page 1983).

Endnotes

  1. always look on the bright side of life

References

Hawking, S. W., and Don. N. Page. 1983. “Thermodynamics of Black Holes in Anti-de Sitter Space.” 87.

Appendix

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

Upvotes: 1

Views: 2655

Answers (1)

RLesur
RLesur

Reputation: 5910

In the context of a HTML document, JavaScript can be used.

For instance, this Rmd file renders as you want.

---
output: html_document
references:
- id: hawking_thermodynamics_1983
  author:
  - family: Hawking
    given: S. W.
  - family: Page
    given: Don. N.
  publisher: Communications in Mathematical Physics
  title: Thermodynamics of Black Holes in Anti-de Sitter Space.
  volume: 87
  type: article-journal
  issued:
    year: 1983
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Section 1
Lorem ipsum dolor^[always look on the bright side of life] sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna
aliquyam erat, sed diam voluptua [@hawking_thermodynamics_1983]. 

## Endnotes {#endnotes}

## References
<div id="refs"></div>

## Appendix
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 

```{js, echo=FALSE}
$(document).ready(function() {
  $('.footnotes ol').appendTo('#endnotes');
  $('.footnotes').remove();
});
```

Here, the JS script moves the list of footnotes in the endnotes section and finally removes the footnotes section.

Upvotes: 2

Related Questions