2

an R markdown file index.rmd:

---
title: title
author: author
bibliography: bib.bib
output:
  pdf_document:
    latex_engine: xelatex
    toc: true
    pandoc_args: ["--biblatex"]
header-includes:
  - \usepackage[]{biblatex}
---

# heading
lorem \autocite{mycite}

Results in:

pdf page with table of content with the first section, and references not included in table of contents

I want to add the references section to ToC. I tried half a dozen of solutions, one of which is Bibliography not in ToC when using biblatex/biber.

Much like all other solutions, adding \printbibliography[heading=bibintoc] resulted in duplicating the references section: enter image description here

Is there a way to suppress the references section entirely to configure it manually?

(Being able to rename the references section would be nice, too)

simohamed
  • 67
  • 6

3 Answers3

2

Usually

\printbibliography[heading=bibintoc, title={Works Cited}]

would be the correct choice. But with Rmarkdown/pandoc the bibliography is produced automatically for you, so adding a \printbibliography in the code yourself produces a second bibliography.

The pandoc template located at https://github.com/jgm/pandoc-templates/blob/master/default.latex suggests that there is no way to inject options like heading=bibintoc into the \printbibliography produced by pandoc. But it is possible to set the bibliography title with

biblio-title: Works Cited

If pandoc does not sanitise the input you give there with braces, it may be possible to inject options that way

biblio-title: Works Cited, heading=bibintoc

I'm not sure if that works, but even if did, it would be an incredibly dirty trick.


With a modern biblatex version (at least v3.12 from 2019-08-17) you can add

\DeclarePrintbibliographyDefaults{heading=bibintoc}

to your preamble to make heading=bibintoc the default for all \printbibliography calls.

If that command is not available because you biblatex is too old you can add

\csletcs{blx@head@bibliography}{blx@head@bibintoc}

to your preamble. That makes the default bibliography heading bibliography have the same definition as bibintoc.


If I understand correctly it should be possible to use

output:
  pdf_document:
    citation_package: biblatex
biblio-style: numeric
biblatexoptions: [backend=biber, maxbibnames=999]

to have Rmarkdown/pandoc load biblatex for you instead of adding it via \usepackage[]{biblatex} and the --biblatex option.

Compare for example Using biblatex with R Markdown.

simohamed
  • 67
  • 6
moewe
  • 175,683
  • I couldn't get biblatex-chicago to work with the piece of code at the end. – simohamed May 21 '20 at 19:22
  • 1
    @simohamed Ah yes, biblatex-chicago is a special case since it should generally be loaded via its own wrapper package \usepackage{biblatex-chicago} instead of \usepackage[style=<style>]{biblatex}. You could try citation_package: biblatex+biblio-style: chicago-authordate/biblio-style: chicago-notes, but this may not get everything right. Maybe that's worth a feature request to the pandoc developers? – moewe May 21 '20 at 19:27
1

Add the following:

\section*{Works Cited} % adds section
\addcontentsline{toc}{section}{Works Cited} % adds section to table of content
\defbibheading{bibliography} % replaces bibliography heading with nothing 
simohamed
  • 67
  • 6
0

This is clearly not ideal, but you can try an approach like

\printbibliography[label=references, heading=bibintoc, title={Works Cited}]
\let\printbibliography\relax

to

  1. Insert the list of references where you want,
  2. Make sure that whenever pandoc tries to re-insert the list of references, nothing will be displayed.
Clément
  • 5,591