6

I want to another bibliography style instead of apalike in Bookdown, and when I changed to nature which is number style, and built the book, it prompted me,

����: Failed to build the bibliography via bibtex
Please delete bookdown.Rmd after you finish debugging the error.
ִֹͣ��

Exited with status 1.

Is there a solution? There are some Chinese character in the title author and description, is this the reason?

The YAML header

--- 
title: "title"
author: "aa"
date: "`r Sys.Date()`"
documentclass: ctexbook
bibliography: [book.bib]
biblio-style: nature
link-citations: yes
colorlinks: yes
lot: no
lof: no
geometry: [b5paper, tmargin=2.5cm, bmargin=2.5cm, lmargin=3.5cm, rmargin=2.5cm]
site: bookdown::bookdown_site
description: "dd。"
github-repo: yihui/bookdown-chinese
#cover-image: images/cover.jpg
---

Session:

R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.1.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16     rstudioapi_0.7   xml2_1.2.0       knitr_1.20       magrittr_1.5     xtable_1.8-2    
 [7] R6_2.2.2         rlang_0.2.0      bibtex_0.4.2     plyr_1.8.4       httr_1.3.1       stringr_1.3.1   
[13] tools_3.5.0      xfun_0.1         miniUI_0.1.1     htmltools_0.3.6  yaml_2.1.19      assertthat_0.2.0
[19] rprojroot_1.3-2  digest_0.6.15    bookdown_0.7     RefManageR_1.2.0 later_0.7.2      promises_1.0.1  
[25] curl_3.2         evaluate_0.10.1  mime_0.5         rmarkdown_1.9    stringi_1.1.7    compiler_3.5.0  
[31] citr_0.2.0       backports_1.1.2  lubridate_1.7.4  jsonlite_1.5     httpuv_1.4.3    
Minyi Han
  • 807
  • 1
  • 8
  • 15
  • 1
    Your example does not contain any Chinese characters. Does it compile? Are there any other error messages than the last one you quoted? Does your document compile if you do not change the bibliography style? A [mcve] is most helpful in a case like this! – Ralf Stubner May 30 '18 at 04:35
  • Potentially related: https://stackoverflow.com/a/49689554/8416610 – Ralf Stubner May 30 '18 at 04:36
  • @ Ralf Stubner they can be compiled to pdf when I used apalike, and it would prompt error when I changed to nature. – Minyi Han May 30 '18 at 04:41
  • Off the bat, I can see that `colorlinks` is indented. Beyond that, I prefer using [csl](https://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html) when using other citation style. I am not familiar with ctexbook but I was able to run your YAML after some [tweaking](https://tex.stackexchange.com/questions/284881/chinese-ctex-tex-live-2015-on-ubuntu) in my manjaro machine. – hpesoj626 May 30 '18 at 04:43
  • I can also confirm that this runs with `pdflatex`. But then again the `.bib` file I am using doesn't have Chinese characters. – hpesoj626 May 30 '18 at 04:45
  • 1
    @ Ralf Stubner it also prompted:The top-level auxiliary file: bookdown.aux I couldn't open style file nature.bst ---line 18 of file bookdown.aux : \bibstyle{nature : } I'm skipping whatever remains of this command I found no style file---while reading file bookdown.aux (There were 2 error messages) ����: Failed to build the bibliography via bibtex Please delete bookdown.Rmd after you finish debugging the error. ִֹͣ�� Exited with status 1. – Minyi Han May 30 '18 at 04:51
  • @ hpesoj626 sorry for the typo, the `colorlinks` is not indented. – Minyi Han May 30 '18 at 05:00
  • the `-output.yml` showed it is `latex_engine: xelatex` – Minyi Han May 30 '18 at 05:02
  • 1
    The additional error message indicates that you are missing the required bibliography style. Which TeX distribution do you use? – Ralf Stubner May 30 '18 at 06:23
  • @ Ralf Stubner, got it, thanks, how can I obtain the `nature.bst?` – Minyi Han May 30 '18 at 14:45

2 Answers2

6
  • Download your .csl file from https://www.zotero.org/styles?q=nature and copy it to the root of your project.
  • Set in _output.yml citation_package: none
  • Add in all formats (gitbook, pdf_book, epub_book) in _output.yml the line pandoc_args: [ "--csl", "your-csl-file.csl" ]
  • Delete or comment out in index.Rmd the line biblio-style: apalike

See for the full procedure use csl-file for pdf-output in bookdown

petzi
  • 1,430
  • 1
  • 17
  • 32
2

You specify the bibtex style nature.bst, but that is not available on your system. Neither can I find it on CTAN. A search on CTAN gives two things:

So either use

 biblio-style: naturemag

or (prefered, see below) switch to biblatex using

bookdown::pdf_book:
  citation_package: biblatex

in _output.yml. In both cases you have to make sure that the required TeX packages are installed. This depends on the TeX distribution. In my case (TeXLive packaged for Debian) this meant

sudo apt-get install texlive-publishers texlive-bibtex-extra

For TeXLive proper or TinyTeX you can use on the command line:

tlmgr install nature
tlmgr install biblatex-nature

For TinyTeX you can also do this within R:

library(tinytex)
tlmgr_install('nature')
tlmgr_install('biblatex-nature')

See the maintenance section for more details.

Unfortunately only the bbilatex solution is compatible with the default citation commands produced by bookdown. One probably could change insert LaTeX commands for the citations, but that would make producing other formats more complicated. In addition, biblatex is "the way to go" for many bibliography questions in LaTeX ...

Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
  • I don't use Linux system but Windows – Minyi Han May 30 '18 at 23:28
  • @MinyiHan And which TeX distribution do you use? MikTeX, TeXLive, TinyTeX, ...? – Ralf Stubner May 31 '18 at 04:29
  • I installed the TinyTex – Minyi Han May 31 '18 at 06:00
  • @MinyiHan Where you able to install (one of) the required TeX packages? Does it work now? – Ralf Stubner Jun 01 '18 at 08:43
  • `library(tinytex)` `tlmgr_install('nature')` `tlmgr_install('biblatex-nature')` was used and `biblio-style: naturemag` followed. it prompted: ! Package natbib Error: Bibliography not compatible with author-year citations. Error: Failed to compile bookdown.tex. See bookdown.log for more info. Please delete bookdown.Rmd after you finish debugging the error. Execution halted Exited with status 1. – Minyi Han Jun 02 '18 at 01:11
  • @MinyiHan I see. Try the `biblatex` solution then. That worked in my tests. – Ralf Stubner Jun 02 '18 at 06:36