r-lib / hugodown

Make websites with hugo and RMarkdown
https://hugodown.r-lib.org
Other
166 stars 23 forks source link

Support citations? #22

Closed maelle closed 4 years ago

maelle commented 4 years ago

A bit vague since I don't fully follow how Rmd &pandoc handle citations.

With hugodown would there be a less hacky way to use refs from a .bib file than what I show in https://ropensci.org/technotes/2020/05/07/rmd-citations/ ? Ideally something that'd just work with the user referencing a .bib file in the YAML and refs with [@key] as they do in other R Markdown format. Having the citations as footnotes is I think ok.

That's the only missing part in the README, if I compare it to https://bookdown.org/yihui/blogdown/output-format.html

jemus42 commented 4 years ago

Would that not require the generated .md to be processed to HTML via pandoc / pandoc-citeproc?
Please correct me if I'm very wrong, but I think having RMarkdown (and therefore pandoc)-style citations would not be (directly) compatible with using Hugo's goldmark to convert .md -> .html.

Maybe it's possible to convert the .md as produced by hugodown to a second markdown file by having pandoc convert it to markdown again, just to resolve citations, and have the second .md file be the "final" file that hugo eventually converts to HTML?

The process would then be

.Rmd -> hugodown things -> .md -> pandoc(-citeproc) -> .md -> hugo -> .html

...But I can't tell if that's silly or not.

maelle commented 4 years ago

ah I was hoping the citations processing could happen in the current hugodown pandoc step "somehow". :cry: (there's already pandoc involved which is why I started hoping :-D)

jemus42 commented 4 years ago

Oh! Right! I totally forgot about that. I'll have to actually dig through the internals sometime soon.

Well, nevermind then.

hadley commented 4 years ago

Yeah, I think it should be possible. @maelle if you have in the next 3 hours, do you think you could make a minimal blog post (i.e. a couple of citations + bib file) that you would hope would work? That'll make it a little easier for me to work on it (after I get back from yoga).

maelle commented 4 years ago

Cool! Not sure how to provide them, so code blocks below.

Rmd:

---
title: Yay refs
output: hugodown::hugo_document

description: > 
  Refs are the best
author: Jane Doe
date: '2020-06-01'
slug: dplyr-1-0-0
bibliography: refs.bib
---

I like R [@my-citation-key-for-r] and packages [@jqr][@refmanager]

Bib

@Manual{my-citation-key-for-r,
  title = {R: A Language and Environment for Statistical Computing},
  author = {{R Core Team}},
  organization = {R Foundation for Statistical Computing},
  address = {Vienna, Austria},
  year = {2020},
  url = {https://www.R-project.org/},
}

@Article{refmanager,
    author = {Mathew William McLean},
    title = {RefManageR: Import and Manage BibTeX and BibLaTeX References in R},
    journal = {The Journal of Open Source Software},
    year = {2017},
    doi = {10.21105/joss.00338},
  }

@Manual{jqr,
    title = {jqr: Client for 'jq', a 'JSON' Processor},
    author = {Rich FitzJohn and Jeroen Ooms and Scott Chamberlain and {Stefan Milton Bache}},
    year = {2018},
    note = {R package version 1.1.0},
    url = {https://CRAN.R-project.org/package=jqr},
  }

Expected md

---
title: Yay refs
output: hugodown::hugo_document

description: > 
  Refs are the best
author: Jane Doe
date: '2020-06-01'
slug: dplyr-1-0-0
bibliography: refs.bib
---

I like R [^my-citation-key-for-r] and packages [^jqr][^refmanager]

[^refmanager]: McLean MW (2017). "RefManageR: Import and Manage BibTeX
and BibLaTeX References in R." _The Journal of Open Source Software_.
, https://doi.org/10.21105/joss.00338.

[^my-citation-key-for-r]: R Core Team (2020). _R: A Language and
Environment for Statistical Computing_. R Foundation for Statistical
Computing, Vienna, Austria. https://www.R-project.org/.

[^jqr]: FitzJohn R, Ooms J, Chamberlain S, Milton Bach S (2018). _jqr: Client for 'jq', a 'JSON' Processor_ https://CRAN.R-project.org/package=jqr

I was thinking that if you workflow depends on having a CSL file, it'd be nice to let users provide their own CSL (but I suppose it's not hard once the basic stuff works). Footnotes are nice because they work with most themes (all themes?) but they're not specific.

hadley commented 4 years ago

Do you have some existing pandoc sequence for generating footnotes for citations? The closest I can get is:

I like R (R Core Team [2020](#ref-my-citation-key-for-r)) and packages (FitzJohn et al. [2018](#ref-jqr); McLean [2017](#ref-refmanager))

references
==========

<div id="refs" class="references hanging-indent">

<div id="ref-jqr">

FitzJohn, Rich, Jeroen Ooms, Scott Chamberlain, and Stefan Milton Bache. 2018. *Jqr: Client for 'Jq', a 'Json' Processor*. <https://CRAN.R-project.org/package=jqr>.

</div>

<div id="ref-refmanager">

McLean, Mathew William. 2017. "RefManageR: Import and Manage Bibtex and Biblatex References in R." *The Journal of Open Source Software*. <https://doi.org/10.21105/joss.00338>.

</div>

<div id="ref-my-citation-key-for-r">

R Core Team. 2020. *R: A Language and Environment for Statistical Computing*. Vienna, Austria: R Foundation for Statistical Computing. <https://www.R-project.org/>.

</div>

</div>
hadley commented 4 years ago

Figured it out — I just need a "footnote" style CSL:

I like R[^1] and packages[^2][^3]

[^1]: R Core Team, *R: A Language and Environment for Statistical Computing* (Vienna, Austria: R Foundation for Statistical Computing, 2020), <https://www.R-project.org/>.

[^2]: Rich FitzJohn et al., *Jqr: Client for 'Jq', a 'Json' Processor*, 2018, <https://CRAN.R-project.org/package=jqr>.

[^3]: Mathew William McLean, "RefManageR: Import and Manage Bibtex and Biblatex References in R," *The Journal of Open Source Software*, 2017, <https://doi.org/10.21105/joss.00338>.

That has yaml metadata:

bibliography: refs.bib
csl: chicago-fullnote-bibliography.csl
suppress-bibliography: true

So technically it already just works.

maelle commented 4 years ago

Yay, awesome! Since these use numbers, could there be conflicts with normal footnotes (which is fine, one could remember to use alphanumeric keys for other footnotes)?

hadley commented 4 years ago

Doesn't looks like it; pandoc-citeproc appears to respect existing footnotes.