如何在Bookdown中更改参考文献的样式

6

我希望在Bookdown中使用另一种文献引用样式,而不是apalike。当我更改为数字样式的nature并构建图书时,它提示:

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

Exited with status 1.

有解决方法吗? 标题、作者和描述中是否包含中文字符,这是原因吗?

YAML 头部

--- 
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
---

会话:

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    

1
你的示例中没有包含任何中文字符。它能编译吗?除了你引用的最后一个错误消息之外,还有其他错误消息吗?如果不更改参考文献样式,你的文档是否能够编译?在这种情况下,[mcve]是最有帮助的! - Ralf Stubner
1
@ Ralf Stubner 它还提示说:顶级辅助文件:bookdown.aux 我无法打开样式文件nature.bst ---文件bookdown.aux的第18行 : \bibstyle{nature : } 我正在跳过此命令的其余部分 在读取文件bookdown.aux时,我找不到样式文件 (有2个错误消息) 错误:通过bibtex构建参考书目失败 请在调试错误后删除bookdown.Rmd。 已退出,状态为1。 - Minyi Han
@ hpesoj626 抱歉打错字了,colorlinks 没有缩进。 - Minyi Han
“-output.yml” 显示了它是 “latex_engine: xelatex”。 - Minyi Han
1
额外的错误信息表明您缺少所需的参考文献样式。您使用哪个TeX发行版? - Ralf Stubner
显示剩余5条评论
2个回答

6
  • https://www.zotero.org/styles?q=nature下载您的.csl文件并将其复制到项目的根目录中。
  • 在_output.yml中设置citation_package: none
  • 在所有格式(gitbook,pdf_book,epub_book)的_output.yml中添加以下一行:pandoc_args:[“--csl”,“your-csl-file.csl”]
  • 在index.Rmd中删除或注释掉以下一行:biblio-style:apalike

有关完整过程,请参见使用csl文件在bookdown中输出pdf


2
您指定了BibTeX样式“nature.bst”,但该样式在您的系统上不可用。我也无法在CTAN上找到它。在CTAN上搜索会得到两个结果:

因此,请使用

 biblio-style: naturemag

或者(更好的选择,请见下文)使用biblatex切换。
bookdown::pdf_book:
  citation_package: biblatex

在`_output.yml`文件中。在这两种情况下,您都必须确保所需的TeX包已安装。这取决于TeX发行版。在我的情况下(打包为Debian的TeXLive),这意味着:
sudo apt-get install texlive-publishers texlive-bibtex-extra

对于TeXLive proper或TinyTeX,您可以在命令行上使用以下命令:
tlmgr install nature
tlmgr install biblatex-nature

对于TinyTeX,您也可以在R中执行以下操作:
library(tinytex)
tlmgr_install('nature')
tlmgr_install('biblatex-nature')

请参阅维护部分以获取更多详细信息。

不幸的是,只有bbilatex解决方案与bookdown生成的默认引用命令兼容。可能可以改变插入LaTeX命令的引用,但这会使生成其他格式更加复杂。此外,在LaTeX中,对于许多参考文献问题,biblatex是“正确的选择”...


我不使用Linux系统,而是Windows。 - Minyi Han
@MinyiHan 你使用哪个TeX发行版?MikTeX、TeXLive、TinyTeX等等? - Ralf Stubner
我安装了TinyTex。 - Minyi Han
@MinyiHan,你能安装(其中之一)所需的TeX包了吗?现在它工作了吗? - Ralf Stubner
library(tinytex) tlmgr_install('nature') 使用了 tlmgr_install('biblatex-nature') 并且遵循了 biblio-style: naturemag,但是出现了以下提示:! Package natbib Error: Bibliography not compatible with author-year citations.错误:无法编译 bookdown.tex。请查看 bookdown.log 以获取更多信息。 在调试错误后,请删除 bookdown.Rmd 文件。 状态 1 下退出。 - Minyi Han
@MinyiHan 我明白了。那就试试 biblatex 的解决方案吧。在我的测试中有效。 - Ralf Stubner

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接