Endnotes in Rmarkdown

Hello all,

I’m finalizing a draft article for submission to peer review. I originally wrote it as an Rmarkdown paper with footnotes that include citations but need to convert footnotes to endnotes. I haven't been able to get this to work and found a stack overflow article claiming that endnotes are not supported in Rmarkdown.

The solution I found was to use LaTex code using the following format:

\endnote{I do not consider a Spatial Lag of Y model because these models are difficult to interpret [@Ruttenauer2019] and because any spatial autocorrelation in outcome will be captured in the error term in either an SDEM or SEM [@LeSage2014].}

Unfortunately, the citations are no longer rendered correctly and just appear as the text (i.e., @Ruttenauer2019) instead of being properly included in the citation. I found this explanation that describes why the citations no longer work when using this LaTex formatting.

Does anyone have any experience with this? Either (1) how to use the traditional ^ format for endnotes or (2) how to get LaText to read my citations?

[I should note that I am trying to render the document as a pdf for peer-review submission]

This does look nasty.

Can you supply us with a cut-down example of the article, and a few bibliography items. What style manual are you using?

Hey @jrkrideau , below is a sample of the YAML and a cut down version of the endnote issue. I'm using ASA_format.csl. Unfortunately, I'm beginning to think there's not a clear solution, which is odd to me because endnotes are common enough:


---
  title: "Paper title"
author: 
  - Kasey Zapatka^[University of California, Berkeley, 410 Social Sciences Building, Berkeley, CA 
date: " `r format(Sys.time(), '%B %d, %Y')`"
csl: ASA_format.csl
output:
  bookdown::pdf_document2:
  toc: no
fig_caption: yes
latex_engine: xelatex
keep_tex: true
geometry:
  - top=1in
- bottom=1in
- right=1in
- left=1in
bibliography: "references/manuscript.bib"
link-citations: yes
mainfont: Times New Roman
fontsize: 12pt
header-includes:
  - \usepackage{rotating}
- \usepackage{setspace}
- \newcommand{\beginsupplement}{\setcounter{table}{0}  \renewcommand{\thetable}{A\arabic{table}} \setcounter{figure}{0} \renewcommand{\thefigure}{A\arabic{figure}}}
- \usepackage{lineno}
- \setlength\parindent{24pt}
- \usepackage{fancyhdr}
- \usepackage{caption}
- \usepackage{enotez}
abstract: |
  
  abstract text...
  
---
  
\pagenumbering{gobble}
\pagebreak

\fancyhf{} 
\renewcommand{\headrulewidth}{0pt} 
\rfoot{\thepage}
\pagestyle{fancy}
\pagenumbering{arabic}
\doublespacing
  
Sample text  \endnote{While there is an important distinction... I support this approach [@Ruttenauer2019]}. 


\newpage
\singlespacing

\printendnotes

Thanks for the example. I have done a bit of poking around with no luck. I can get endnotes and a reference list easily enough but no luck on getting the reference in the endnote.

…there's not a clear solution, which is odd to me because endnotes are common enough.

Well as the President and founder of The Society for the Abolition of Footnote and Endnotes, (SAFE), I disprove. But as you say, it should be a normal request. The last two or three books I bought have the pesky things.

It looks to me that this probably a LaTeX problem rather than a Pandoc issue but, if it is, it's well beyond my LaTeX knowledge. Still it must be possible as I am reasonably sure Chicago Style calls for it.

You might want to try Tex Stack Exchange

BTW, where does one find ASA_format.csl? I can find three or four Sociology csl files but not ASA_format.csl. I've been using apa.csl as a substitute.

Thanks. I will try this to post on Tex Stack Exchange. This issue has been maddening, honestly. I can't find a solution anywhere. I think it's a Pandoc-Rmarkdown-LaTex issue too. I'll let you know if I figure anything out.

I can't exactly remember where I found the ASA.csl--I think it was from this repo?.

Ah, I had found that but it had a different name :grinning: .

Yes please get back to me if you find a solution. I'm an APA type and try to avoid footnotes/endnotes as much as possible but it is really frustrating. It should be easy enough!

How desperate are you?

I found a simple approach to doing what you want in LyX – The Document Processor

Anything you can do in Rmarkdown you can do in LyX, and probably a lot more though it can be a bit fussier. Here is a quick example.
Endnotes.pdf (154.6 KB)

I cannot upload the .lyx file but if you are interested I can e-mail it to you.

I have not tried it yet but you should be able to transfer anything in R to Rmarkdown to LyX "as is" . The only difference is in LyX the statement looks like this and in written inside a LaTeX insert.

<< xtable-example, results = "asis",echo = FALSE >>=
library(xtable)  
data(tli)  
tli.table <- xtable(tli[1:10, ])   
digits(tli.table)[c(2, 6)] <- 0   
print(tli.table, floating = FALSE)
@

Here is the text and results of my query on the LyX mailing list.

Richard Kimberly Heck rikiheck@gmail.com 1 Dec 2023, 20:23 (16 hours ago)

to me

On 12/1/23 11:15, John Kane wrote:

I was reading a post in a Rmarkdown forum where the writer said that
he had been using footnotes with a citation embedded to produce a
pdf.. His editor has requested a change from footnotes to endnotes
and he cannot get it to word.

Rmardown uses pandoc to convert from Rmarkdown to pdf. I thought that
this should fairly easy to do in LyX or LaTeX but it does not seem so.

If I add
\usepackage{endnotes}
\let\footnote=\endnote

Note that there is a FootToEnd module that does exactly this. There is
also an Endnotes module that provides an Endnote inset. If you load
that, then you can open the LyX file itself in a text editor and do a
search and replace to convert the Footnote insets to Endnote insets.
Obviously, work on a copy of the file, in case something goes wrong.

to the LaTeX preamble I lose the footnote and citation but still get
the endnote indicator.

I'm afraid it won't work for every citation style (I don't know for ASA), but one possible workaround would be to write your citations manually with the intended format, and add the references in the nocite field of your front matter.

For example, in APA-format:

---
[...]
nocite: @Ruttenauer2019, @LeSage2014
[...]
---

[...]

\endnote{I do not consider a Spatial Lag of Y model because these models are
difficult to interpret (Ruttenauer, 2019) and because any spatial autocorrelation
in outcome will be captured in the error term in either an SDEM or SEM
(LeSage, 2014).}
[...]

As I say though, it won't work for every citation format. For APA it works because it is an "(Author, Year)" format, but e.g. in Vancouver where the citations are numbered it won't.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.