【问题标题】:Why does _output.yml prevent me from moving references in bookdown::pdf_book()?为什么 _output.yml 阻止我在 bookdown::pdf_book() 中移动引用?
【发布时间】:2021-05-19 18:10:32
【问题描述】:

对该问题的最高投票答案How to move the bibliography in markdown/pandoc 表示,您可以通过在应该出现引用的位置添加<div id="refs"></div> 来控制 rmarkdown/pandoc 中引用的位置。如果 _output.yml 包含 pdf_book 输出,则这不适用于 bookdown 包中的 pdf_book 格式。一个例子是一个包含两个文件的目录:

_output.yml

bookdown::gitbook:
bookdown::pdf_book:
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes

index.Rmd

--- 
title: "An example"
author: "Me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: book
bibliography: [packages.bib]
biblio-style: apalike
link-citations: yes
---

# Prerequisites

```{r include=FALSE}
# automatically create a bib database for R packages
knitr::write_bib(c(
  .packages(), 'bookdown'
), 'packages.bib')
```

I want references *here*

<div id="refs"></div>

# Introduction

We are using the **bookdown** package [@R-bookdown].

调用bookdown::render_book(output_format = 'bookdown::pdf_book') 会创建一个pdf 文件,该文件的引用位于文档末尾,而不是&lt;div id="refs"&gt;&lt;/div&gt; 指定的位置。相反,调用bookdown::render_book(output_format = 'bookdown::gitbook') 确实会将引用放置在指定位置。

如果我删除 _output.yml 或删除 pdf_book 部分,

_output.yml

bookdown::gitbook:

然后运行bookdown::render_book(output_format = 'bookdown::pdf_book') 确实会将引用放置在正确的位置。

我的包版本信息是:

R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042), RStudio 1.4.1103

Locale:
  LC_COLLATE=English_Canada.1252  LC_CTYPE=English_Canada.1252   
  LC_MONETARY=English_Canada.1252 LC_NUMERIC=C                   
  LC_TIME=English_Canada.1252    

Package version:
  assertthat_0.2.1  base64enc_0.1.3   bookdown_0.21.6   callr_3.5.1      
  cli_2.3.0         compiler_4.0.3    crayon_1.4.1      curl_4.3         
  desc_1.2.0        digest_0.6.27     evaluate_0.14     glue_1.4.2       
  graphics_4.0.3    grDevices_4.0.3   highr_0.8         htmltools_0.5.1.1
  jsonlite_1.7.2    knitr_1.31        magrittr_2.0.1    markdown_1.1     
  methods_4.0.3     mime_0.10         pkgbuild_1.2.0    prettyunits_1.1.1
  processx_3.4.5    ps_1.5.0          R6_2.5.0          remotes_2.2.0    
  rlang_0.4.10      rmarkdown_2.7.1   rprojroot_2.0.2   rstudioapi_0.13  
  stats_4.0.3       stringi_1.5.3     stringr_1.4.0     tinytex_0.29     
  tools_4.0.3       utils_4.0.3       withr_2.4.1       xfun_0.21        
  yaml_2.2.1  

为什么拥有一个有效的 _output.yml 会阻止我更改引用的位置?有没有我可以添加到 _output.yml 的选项来让 pdf_book 尊重&lt;div id="refs"&gt;&lt;/div&gt;

【问题讨论】:

    标签: r r-markdown bookdown


    【解决方案1】:

    来自我在 Github 上发布的答案https://github.com/rstudio/bookdown/issues/1082#issuecomment-811026589

    https://bookdown.org/yihui/rmarkdown-cookbook/bibliography.html#include-appendix-after-bibliography 中所述,使用 ID 为 refs 的 div 更改书目位置是 Pandoc 引文处理器功能。见https://pandoc.org/MANUAL.html#placement-of-the-bibliography

    使用 Pandoc 的 citeprocpdf_document()pdf_book() 的默认值,但在您的输出文件 _output.yml 中,您将 citation_package 显式更改为 natbib 格式的 bookdown::pdf_book

    当您拨打bookdown::render_book(output_format = 'bookdown::pdf_book')时,根据您测试的情况,会发生这种情况

    • 如果格式在_output.yaml 中定义,它将使用那里定义的配置并使用natbib
    • 如果格式未在_output.yaml 中定义,它将使用格式的默认配置并使用--citeproc

    在第二种情况下,您只能使用 id 为 refs 的 div 来控制书目的位置。

    您只需根据需要更改citation_package:,如果您想使用 Pandoc 处理器中的引文功能,请删除该字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-24
      • 1970-01-01
      相关资源
      最近更新 更多