3

Is there a way to specify natibib options when outputting a PDF with bookdown? I want the tex output to have the command

\usepackage[sort&compress]{natbib}

But there doesn't seem to be any way to specify it in the YAML. I can't add the command to my preamble, because the template already adds \usepackage{natbib}. What's the correct way to pass package options to natbib?

mikeck
  • 3,534
  • 1
  • 26
  • 39
  • I guess the only way is to define your own LaTeX template: https://bookdown.org/yihui/bookdown/templates.html – Yihui Xie Jun 27 '17 at 03:05
  • @yihui I was afraid of that... – mikeck Jun 27 '17 at 03:40
  • It is not that bad. Just copy Pandoc's LaTeX template, and make a single change. – Yihui Xie Jun 27 '17 at 04:09
  • @Yihui, I copied the default latex template from the [pandoc templates repository](https://github.com/jgm/pandoc-templates) and the output document looks different. Does bookdown use a different template as the "default"? – mikeck Jun 27 '17 at 15:49
  • @Yihui, I also checked the Latex template living in the `rmarkdown` package folder. It is consistent with the template on the repository, but I cannot reproduce bookdown's default style with it and I can't find an alternative latex template in the `bookdown` package folder. – mikeck Jun 27 '17 at 16:44
  • bookdown uses rmarkdown's LaTeX template, which is a modified version based on Pandoc's template. – Yihui Xie Jun 27 '17 at 16:58
  • @Yihui, it looks like `bookdown` passes additional options to the default template (or something like that) when specifying `template: default` in the YAML. I cannot reproduce the document style with the template included with the `rmarkdown` package. – mikeck Jun 27 '17 at 17:45

1 Answers1

2

As of this commit, the default LaTeX template supports natbib options in the YAML via the variable natbiboptions. I presume this will propagate to rmarkdown when pandoc gets it's next official update. Until then, you can set bookdown to use the new template and pass the geometry: "margins=1in" to get the default bookdown pdf style with custom natbib options.

mikeck
  • 3,534
  • 1
  • 26
  • 39