EDIT: After some investigation, this question is really about the following option in the output yml:
citation-package: biblatex
Without this option, bookdown is using the default citeproc and it's not clear how to modify the number of authors. However, when this option is used, the referencing is not working anymore and my document contains only the refnames in bold instead of inline citations. So I really need to know why the citation-package: biblatex is not working
===== original question below
I can't get bookdown to honour my maxcitename=2 settings. I have tried using this output yml
output:
bookdown::pdf_book:
includes:
in_header: preamble.tex
keep_tex: yes
toc_depth: 3
toc_appendix: yes
with this line in the preamble.tex file:
\usepackage[backend=bibtex, maxcitenames=2, style=authoryear]{biblatex}
I have also tried using this output yml:
bibliography: [likertimputebiblio.bib, packages.bib]
biblatexoptions: [maxcitenames=2]
csl: harvard-university-of-wolverhampton.csl
link-citations: true
nocite: |
#R-bookdown
and I have also tried this output yml:
site: bookdown::bookdown_site
documentclass: book
header-includes:
- \usepackage[backend=bibtex, maxcitenames=2, style=authoryear]{biblatex}
but nothing seems to work.
Please help. Thanks.
The solution to this problem was found after much perseverence!
When setting the output yml, indented under output: etc...
citation_package: biblatex
... the in line references were failing to link to the .bib file and so the refnames were just showing up in bold and failing to make any inline citations.
The expected solution should be to use the additional option:
biblatexoptions: [backend=bibtex, maxcitenames=2]
(maxcitenames=2 is the main reason I want to use biblatex) but this was failing with the error "option backend not recognized."
Finally the solution was to modify the default template in the directory
C:\Program Files\R-3.4.0\library\rmarkdown\rmd\latex
at line 100, from
\usepackage$if(biblio-style)$[style=$biblio-style$]$endif${biblatex}
to
\usepackage$if(biblio-style)$[backend=bibtex, style=$biblio-style$]$endif${biblatex}
I would like to suggest to the package author that this is a bug that needs fixing, because backend=bibtex is a valid option and should have been passed through
Related
My problem arises from here, with the help of #shafee and #samcarter_is_at_topanswers.xyz, where the demo .tex and .rmd are also supplied therein.
My idea is that I want to use biblatex other than natbib to get the same goals. There are several obstacles, since the default biblatex doesn't hold for the unsrt style with super-compact-numeric in square brackets. I try my best to solve them one by one.
the unsrt style (bibstyle)
From https://tex.stackexchange.com/questions/58152/ , we resort to style=trad-unsrt in biblatex-trad, i.e.
\usepackage[backend=bibtex,style=trad-unsrt]{biblatex}
the compact numeric (citestyle)
From https://tex.stackexchange.com/questions/61524, we resort to citestyle=numeric-comp in biblatex, i.e.
\usepackage[backend=bibtex,style=trad-unsrt,citestyle=numeric-comp]{biblatex}
the super style (citestyle; position-of-citation)
From https://tex.stackexchange.com/questions/355111/, we resort to autocite=superscript in biblatex, i.e.
\usepackage[backend=bibtex,style=trad-unsrt,citestyle=numeric-comp,autocite=superscript]{biblatex}
finally; current .tex and .rmd files
tex
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage[backend=bibtex,style=trad-unsrt,citestyle=numeric-comp,autocite=superscript]{biblatex}
\addbibresource{ref.bib}
\newcommand{\citep}[1]{\autocite{#1}}
\begin{document}
statistics \citep{anderson2003introduction,efron2004least,hastie2009elements}
\printbibliography[heading=bibliography,title=References]
\nocite{*}
\end{document}
rmd
---
output:
pdf_document:
keep_tex: yes
citation_package: biblatex
bibliography: ref.bib
biblatexoptions:
- backend=biber
- style=trad-unsrt
- citestyle=numeric-comp
- autocite=superscript
link-citations: yes
colorlinks: no
header-includes:
- \newcommand{\citep}[1]{\autocite{#1}}
---
statistics [#anderson2003introduction; #efron2004least; #hastie2009elements]
\nocite{*}
question?
Both .tex and .rmd can compile smoothly and it is nearly successful, while the remaining one thing is that I don't know how to add square brackets to the super-compact-numeric citation. Btw, I also search for similar issues such as here, where the biblatex-ext therein maybe helpful. However, I don't know how to make compatible between biblatex-ext and biblatex-trad. Any other ways?
Normally you could redefine the \mkbibsuperscript macro to add the square brackets. Unfortunately rmarkdown for some inexplicable reasons delays loading the biblatex package until after the header includes, so one needs to hack a bit:
---
output:
pdf_document:
keep_tex: yes
citation_package: biblatex
bibliography: ref.bib
biblatexoptions:
- backend=biber
- style=trad-unsrt
- citestyle=numeric-comp
- autocite=superscript
link-citations: yes
colorlinks: no
header-includes:
- \newcommand{\citep}[1]{\autocite{#1}}
- \makeatletter\AtEndPreamble{\renewrobustcmd{\mkbibsuperscript}[1]{\unspace\allowhyphens\textsuperscript{[\begingroup\protected\long\def\mkbibsuperscript##1{\blx#warning{Nested superscript}\mkbibbrackets{##1}}#1\endgroup]}}}\makeatother
---
statistics [#anderson2003introduction; #efron2004least; #hastie2009elements]
\nocite{*}
You could use the chem-angew style:
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage[style=chem-angew,autocite=superscript]{biblatex}
\addbibresource{ref.bib}
\newcommand{\citep}[1]{\autocite{#1}}
\begin{document}
statistics \citep{anderson2003introduction,efron2004least,hastie2009elements}
\printbibliography[heading=bibliography,title=References]
\nocite{*}
\end{document}
I am rather experienced with R but new to markdown and especially bookdown. I wonder how to render a single chapter and merge it with the existing book without re-building the whole book. The reason why I am asking is that I am creating a book that contains parameterised chapters and each chapter runs very long (1-2 hours). All in all, it will be hundreds of chapters with the same analysis, but different input data and would time-wise add up. I am aware of the knit-and-merge approach, in fact, that's the reason why I chose bookdown, but somehow it is not working as expected.
I am honestly also a little bit confused by the different rendering possibilities. There is the built-book button, the knit button, serve_book(), render_book(), preview_chapter(), ... I figured that one should avoid using the knit button in bookdown and that serve_book() will automatically compile changes. My approach so far is entering serve_book() into console, where it renders the whole book, then I create a new chapter, hit save and it runs the chunks of only that chapter (exactly what I want!) and the single HTML file of the new chapter appears. However, it doesn't show them when I look at the book via the index.html file.
I am only interested in an HTML book and do not need any other output formats.
In order to recreate the problem, I am just using the bookdown example and adding chapters to it.
_bookdown.yaml
book_filename: "book_name"
new_session: yes #true
before_chapter_script: _common.R
delete_merged_file: true
language:
ui:
chapter_name: "Chapter "
_output.html
bookdown::bs4_book:
css: style.css
theme:
primary: "#10395B"
#repo: https://github.com/rstudio/bookdown-demo
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
_index.yaml
---
title: |
![](./Logo_PureGene.png){width=200px}|
|-|
||
author: "Name"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
#output: bookdown::bs4_book
documentclass: book
bibliography: [book.bib, packages.bib]
# url: your book url like https://bookdown.org/yihui/bookdown
# cover-image: path to the social sharing image like images/cover.jpg
description: |
This is a minimal example of using the bookdown package to write a book.
The HTML output format for this example is bookdown::bs4_book,
set in the _output.yml file.
biblio-style: apalike
csl: chicago-fullnote-bibliography.csl
---
# About {-}
I would appreciate any help!
Thanks in advance :)
I want to change the default template of the Rmarkdown document. I edited the file named document.Rmd in the templates in the RStudio application folder so that the YAML is:
---
title: 'document'
output:
html_document:
self_contained: true
toc: true
toc_float: true
bookdown::pdf_document2:
extra_dependencies: ["float"]
toc: true
---
However, when I open a new Rmarkdown document from RStudio, I get a prompt that asks what type of Rmarkdown document I want. I choose HTML, click OK, and then I get the file opened with these two YAMLs!
---
title: "Untitled"
output: html_document
---
---
title: 'document'
output:
html_document:
self_contained: true
toc: true
toc_float: true
bookdown::pdf_document2:
extra_dependencies: ["float"]
toc: true
---
I do not want to go through the hustle of creating a package or a template. This simple solution should work, I think.
My question: Does anybody know how to work around this? Thank you in advance!
After reading your question, I found this source, which indicated that you could add a template. I also read that document.RMD does not include the YAML. That's why you are getting a double-YAML.
Since I had never added a template for R Markdown, I went through the steps to see how it all came together. That led me to create a repository on Github, and well, here we are. Essentially, I made a Github repository that you can install with the exact template you wanted.
You can also look at the code, as well. Since it was created just to answer this question, if you wanted it to be different, you can change it, as well.
You'll find the repository here: fraupflaume/customYAML
If you want to install it:
devtools::install_github("fraupflaume/customYAML")
To use it, you don't have to call the library (there's no R code). Start an R Markdown script, select "From Template," then choose "Custom YAML."
I am writing my thesis using the bookdown package and the memoir latex class. Everything works relatively fine when I am exporting to pdf or to html but I am unable to export the thesis to a word document...
I get the following mysterious error:
Error in files2[[format]] :
attempt to select less than one element in get1index
It is difficult to provide a reproducible example though, as I am working from my messy dissertation repository.
But here is (a part of) my _output.yml file:
bookdown::pdf_book:
includes:
in_header: latex/preamble.tex # defines style and latex options
before_body: latex/before_body.tex # defines cover page
latex_engine: xelatex # lualatex or xelatex
citation_package: none # needs to be "none" in order to use the csl file
keep_tex: true # keeps the .tex file
dev: "cairo_pdf"
toc: false # deactivates default table of contents
highlight: pygments # code highlighting
pandoc_args: [ "--csl", "./csl/apa6.csl" ] # specifies the csl file to be used
bookdown::word_document2:
pandoc_args: [
"--csl", "./csl/apa6.csl",
"--bibliography", "./bib/packages.bib",
"--bibliography", "./bib/thesis.bib",
#"--reference-doc", "./assets/2018-05-17-aim1-draft.docx",
"--filter", "pandoc-citeproc"
#"--filter", "./assets/fix-apa-ampersands.py"
]
Any idea ?
This is a bug of the bookdown package, which I just fixed on Github. Please try the development version there:
remotes::install_github('rstudio/bookdown')
I started using bookdown to generate a longer report, but came into some touble as I wanted to customize the pdf output. \documentclass[]{} does not work in the preamble.tex file. I think that comand is somehow executed by pandoc beforhand, unfortunately I did not find out how to pass options to it so far.
I worked around a few things like setting the fontsize via \usepackage[12pt]{moresize} but I was wondering how to acces the set up options properly. The bookdown documentation does not cover this subject in sufficient detail for me to understand.
Look at this BookDown Documentation,
You can just add following in your header yaml,
---
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
---
I found the answer in the Pandoc documentation