Skip to contents

Producing a PDF file from a R Markdown (.Rmd) document requires several steps:

  • knitR (Xie 2015) runs the code chunks to produce results and figures.
  • bookdown (Xie 2016) (or rmarkdown: Xie, Allaire, and Grolemund 2018) produces a plain Markdown document. memoiR templates all rely on bookdown to benefit from cross references and figure/table numbering.
  • Pandoc1 is run to produce either directly an HTML document or a LaTeX file (.tex). The bibliography of HTML documents is processed by Pandoc at this stage2. memoiR templates delay it for LaTeX documents.
  • A LaTeX engine is run to compile the LaTeX file and produce a PDF document. It uses reference management software (BibTeX3 or Biber4) and a LaTeX package (natbib5 or biblatex6) for bibliography.

memoiR templates rely on XeLaTeX7 to compile LaTeX documents to PDF files. Among XeLaTex advantages over the classical pdflatex engine8, including native UTF-8 encoding, the language support by Polyglossia9 rather than Babel10 (required by pdflatex) is similar to that of Pandoc to produce HTML formats, based on IETF language tags11 such as “en-US”. In short, this solution is simpler and more robust: just fill the lang field in the document header.

In the memoir template, bibliography is managed by biber and biblatex. This appears to be the best solution for long documents, allowing sidenote citations and cross-references from the bibliography to the text containing the citation. The bibliographic style is verbose-inote12 by default: it can be changed in the memoir header.

In short documents, i.e. articles and presentations, bibtex and natbib are preferred because the advanced formatting abilities of biblatex are not very useful, more citation styles are available (.bst files13) and many journals expect them to be used.

References

Xie, Yihui. 2015. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. https://yihui.org/knitr/.
———. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://github.com/rstudio/bookdown.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.