0

With a bib.bib file:

@article{mycite,
  title = {title},
  author = {author name},
  pages = {45-50},
  year = {2020},
  url = {https://example.com}
}

and an index.rmd file like this:

---
title: title
author: author
bibliography: bib.bib
output:
  pdf_document:
    latex_engine: xelatex
---

lorem \autocite[48]{mycite}

I get an error when compiling (using Rscript -e "rmarkdown::render('index.rmd')"):

! Undefined control sequence.
l.70 lorem \autocite
                    [48]{mycite}

Error: LaTeX failed to compile index.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See index.log for more info.
Execution halted

(Lorem @mycite, on the other hand, works.)

How to make citing with LaTeX aware of the bib.bib file?

Same question when using a csl file to change citation style:

---
csl: chicago-fullnote-bibliography-with-ibid.csl
---

Are csl files and LaTeX compatible?

EDIT: A possible solution:

---
title: title
author: author
bibliography: bib.bib
output:
  pdf_document:
    latex_engine: xelatex
    pandoc_args: ["--biblatex"]
header-includes:
  - \usepackage[]{biblatex} # \userpackage[]{biblatex-chicago} instead of csl file
---

lorem \autocite[48]{mycite}

Compiles with these warnings:

Warning message:
LaTeX Warning: There were undefined references.
Package biblatex Warning: Please rerun LaTeX.
(biblatex)                Page breaks have changed.

successfully add \autocite citation in r markdown


Note: this question is different from Using biblatex with R Markdown as the errors in that question stem from loading the same package twice. But a possible answer has been found from the question itself. Furthermore, the question uses bookdown which requires familiarity with it.

simohamed
  • 67
  • 6
  • CSL works only with pandoc-citeproc and \autocite is a biblatex command, so you must ensure, that you are using biblatex instead of bibtex. See: https://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.htm – DG' May 16 '20 at 17:04
  • actually, any latex citation for that matter: \cite[48]{mycite} doesn't work. Errors out with:

    Warning message: LaTeX Warning: Citation 'mycite' on page 1 undefined on input line 70. LaTeX Warning: There were undefined references.

    – simohamed May 16 '20 at 17:07
  • Actually, you should use the markdown syntax for citations when writing markdown: https://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html#Citation_Syntax – DG' May 16 '20 at 17:08
  • 1
    As far as I understand pandoc-citeproc supports several citation/bibliography backends. One of them is biblatex, but another one just uses CSL files to generate the citations and bibliography and does not involve LaTeX in the citation processing. I don't know about the default, but as far as I understand you are getting rid of LaTeX's involvement in citations and the bibliography at the very latest when you start using .csl files. – moewe May 16 '20 at 17:20
  • @DG', the suggested answer uses bookdown, which requires familiarity with it to understand. The answer, in fact, is situated in the question. Marking that thread as an answer to this one could be misleading. Plus, the answer still throws some errors (but, it's better than not compiling.) – simohamed May 16 '20 at 17:50
  • 1
    Only because the solution is different from what you use, it is not wrong to link these questions. And if your question is about using biblatex in Rmd, it is the right duplicate (you can add an answer there). Unfortunately, I don't think your question How to make citing with LaTeX aware of the bib.bib file? is very clear in terms of what you actually want to achieve and with which tooling. – TeXnician May 17 '20 at 08:13

0 Answers0