how to specify a csl bibliography style on bookdown Chinese Bookdown Chinese example, for example a zotero one CSL.
I downloaded the csl file to the working directory, and specify it in index.Rmd YAML header as
bibliography: book.bib
biblio-style: chinese-gb7714-2005-numeric
or
bibliography: book.bib
biblio-style: chinese-gb7714-2005-numeric.csl
but Rstudio promted me:
Error: Failed to build the bibliography via bibtex
Please delete bookdown.Rmd after you finish debugging the error.
Execution halted
Exited with status 1.
when I changed it to
bibliography: book.bib
csl: chinese-gb7714-2005-numeric
or
bibliography: book.bib
csl: chinese-gb7714-2005-numeric.csl
I can build the book, however the reference list style was not the one the CSL expected.
All the YAML header
---
title: "题名"
author: "姓名"
date: "`r Sys.Date()`"
bibliography: book.bib
description: "矮脚黄"
documentclass: ctexbook
geometry:
- b5paper
- tmargin=2.5cm
- bmargin=2.5cm
- lmargin=3.5cm
- rmargin=2.5cm
github-repo: yihui/bookdown-chinese
indent: 2m
link-citations: yes
lof: no
lot: no
colorlinks: yes
site: bookdown::bookdown_site
biblio-style: unsrt
whitespace: none
---
updated:
today I found the header of Chapter reference was not correct. It should be "Reference" instead of the previous chapter's.
You probably missed two lines:
Set in _output.yml citation_package: none
Add in all formats (gitbook, pdf_book, epub_book) in _output.yml the line pandoc_args: [ "--csl", "chinese-gb7714-2005-numeric.csl" ]
See the full procedure at use csl-file for pdf-output in bookdown
Related
Following the R Markdown Cookbook (along with a number of the posts here) and I'm trying to insert a collection of LaTeX packages in the YAML header for my R Markdown file.
When I copy/paste the header from that website into my file:
output:
pdf_document:
extra_dependencies:
caption: ["labelfont={bf}"]
hyperref: ["unicode=true", "breaklinks=true"]
lmodern: null
I get the error: ! LaTeX Error: Option clash for package hyperref. This only happens when I include the options in square brackets - if I remove them, everything works as expected.
In a similar instance, I tried to add the babel package in the same manner. When I include it like this:
extra_dependencies:
babel: ["hebrew", "english"]
I get the error: ! You can't use end-group character }' after \the.`
I am even more confused (if that's possible), because when I include options for the threeparttable package, everything runs without issue.
Here is a file to test:
---
title: "R Notebook"
author:
- Me
date: "Last compiled on `r format(Sys.time(), '%d %B %Y')`"
output:
pdf_document:
highlight: tango
keep_tex: yes
number_sections: yes
toc: yes
fig_caption: yes
extra_dependencies:
cjhebrew: null
babel: ["hebrew", "english"]
---
# Section 1
Test
When I knit this to PDF, I get the error:
! You can't use `end-group character }' after \the.
\everypar #1->\o#everypar {\rl#everypar #1}
The log file is at this repo.
rmarkdown automatically loads the hyperref package. You can't load it again with conflicting options.
You can change its settings with \hypersetup{...}:
---
output:
pdf_document:
keep_tex: true
header-includes:
- \hypersetup{breaklinks=true}
---
test
However are you sure you need all your options and packages?
rmakdown already uses the unicode option, so no need to add it a second time
rmarkdown also automatically loads the lmodern package, no need to load it again
The other problem is the interaction of the babel and the microtype package, which rmarkdown loads by default. With real latex, you could simply avoid loading every package but the kitchen sink and you would never have had this problem, or at least you could add the nopatch option directly to microtype (if you would really need it) ... but rmarkdown makes this unnecessarily complicate.
Here a dirty hack, hoping that no other packages also uses this name for an option:
---
title: "R Notebook"
author:
- Me
date: "Last compiled on `r format(Sys.time(), '%d %B %Y')`"
output:
pdf_document:
highlight: tango
keep_tex: yes
number_sections: yes
toc: yes
fig_caption: yes
extra_dependencies:
cjhebrew: null
babel: ["hebrew", "english"]
classoption: "nopatch"
---
# Section 1
Test
I have a large bookdown project. My YAML header below.
My only desired output is a PDF. However, bookdown by default produces a HTML as well. This makes compilation take more time, and also uses more caching space on my disk. Any chance I can disable producing HTML output? I have tried to play around with the site parameter in the YAML heading, but no luck.
title: "Title"
subtitle: "Subtitle"
author:
- "Name"
- "Institution"
date: "September 2020"
output:
bookdown::pdf_book:
toc: false
includes:
in_header: preamble.tex
keep_tex: yes
latex_engine: xelatex
citation_package: natbib
fontsize: 12pt
linestretch: 1.5
site: bookdown::bookdown_site
documentclass: book
bibliography: [references.bib]
biblio-style: "apalike"
geometry: "left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm"
bookdown doesn't really have a "default" output format. If it produces HTML, the output format must have been provided somewhere. Check if you have a _output.yml under the root directory of your book project. If you do, you may delete it. Then bookdown will use the output field that you specified in the YAML frontmatter of your Rmd document.
I'm not getting a pdf output from my rnotebook.
My header in my "index.Rmd" is:
---
title: "some title"
author: "me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
description: "Notes on a Leasing Company busines risk and opportunities."
---
I'm rendering the book in the console with the following code:
bookdown::render_book("index.rmd", output_format = "bookdown::pdf_book")
Output is:
Error: Functions that produce HTML output found in document targeting latex output.
Please change the output type of this document to HTML. Alternatively, you can allow
HTML output in non-HTML formats by adding this option to the YAML front-matter of
your rmarkdown file:
always_allow_html: yes
Note however that the HTML output will not be visible in non-HTML formats.
How do I go about changing the output type?
My file "_output.yml" file is:
toc:
before: |
<li>A Minimal Book Example</li>
after: |
<li>Published with bookdown</li>
download: ["pdf", "epub"]
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: natbib
keep_tex: yes
bookdown::epub_book: default
I want to change the bibliographystyle in R Markdown but nothing I found could help.
I do not want any "and"s in the bibliography (before the last author).
My preferred option was if I could use alphadin (bst-file here) but I could not get it to work.
Here is my YAML so far:
---
output:
pdf_document
bibliography: literatur.bib
biblio-style: alphadin.bst
header-includes:
- \usepackage{graphicx}
- \usepackage{float}
- \usepackage[ngerman]{babel}
- \usepackage{fancyhdr}
- \usepackage{hyperref}
- \pagenumbering{gobble}
- \usepackage{booktabs}
- \usepackage{natbib}
---
The bst-file is in the same directory as the R Markdown file.
If you want to set the bibliography style to use a bst file, you need to force R Markdown to use natbib or biblatex as the citation manager. By default, it will use pandoc to build the citation. This article explains the behaviour more.
Secondly, once you have that working, you need to change the citation style of the file. By default, natbib will use author-year citations, but the bst file you provided does not work with these. So I have change the citation styles to numbers.
Below is a minimal example. It will create a bibliography file test.bib but you need to make sure the alphadin.bst file is in the same directory.
---
output:
pdf_document:
citation_package: natbib
bibliography: test.bib
biblio-style: alphadin
header-includes:
- \setcitestyle{numbers}
---
[#R-rmarkdown]
```{r}
knitr::write_bib(x = "rmarkdown", file = "test.bib")
```
There is another way to set the citation style of natbib: natbiboptions: round in YAML. The combination of citation_package: natbib and natbiboptions: round is equivalent to \usepackage[round]{natbib}. Note that natbiboptions: round comes outside of the output key.
(In the following example, I used biblio-style: apalike but the example should work with any biblio-style.)
---
output:
pdf_document:
citation_package: natbib
bibliography: test.bib
biblio-style: apalike
natbiboptions: round
---
[#R-rmarkdown]
```{r}
knitr::write_bib(x = "rmarkdown", file = "test.bib")
```
I would like to use a .csl-file for formatting references with bookdown. Adding csl: some-style.csl to index.Rmd affects the output to gitbook, but not to pdf_book. I know that I can specify biblio-style, but this only accepts some standard styles and not csl-files. Is there a proper workaround?
Steps to reproduce:
Create new project with RStudio and choose "Book Project using bookdown" as option.
Download some .csl file from https://www.zotero.org/styles and copy to root of project.
Add csl: my_csl_file.csl to the header in index.Rmd.
Build the book to pdf and html, and observe the differences in the references (either in the references section, or in the introduction)
Header in index.Rmd:
---
title: "A Minimal Book Example"
author: "Yihui Xie"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [book.bib, packages.bib]
csl: american-sociological-review.csl
link-citations: yes
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
---
HTML output (correct):
PDF output (incorrect):
I had the same problem. The following procedure worked for me:
Create new project with RStudio and choose "Book Project using
bookdown" as option.
Download some .csl file from https://www.zotero.org/styles and copy to root of project. In my case: chicago-author-date-de.csl
Set in _output.yml citation_package: none
Add in all formats (gitbook, pdf_book, epub_book) in _output.yml the line pandoc_args: [ "--csl", "chicago-author-date-de.csl" ]
Delete or comment out in index.Rmd the line biblio-style: apalike
Replace the content of 06-references.Rmd with # References {-}
Here is my _output.yml file:
bookdown::gitbook:
css: style.css
pandoc_args: [ "--csl", "chicago-author-date-de.csl" ]
config:
toc:
before: |
<li>A Minimal Book Example</li>
after: |
<li>Published with bookdown</li>
download: ["pdf", "epub"]
bookdown::pdf_book:
includes:
in_header: preamble.tex
latex_engine: xelatex
citation_package: none
pandoc_args: [ "--csl", "chicago-author-date-de.csl" ]
keep_tex: yes
bookdown::epub_book:
pandoc_args: [ "--csl", "chicago-author-date-de.csl" ]