Bookdown:Chapter/Section 交叉引用不起作用(gitbook)

Bookdown: Chapter/Section cross referencing not working (gitbook)

我的一个 bookdown 项目遇到了问题,其中 chapter/section 交叉引用在 html 输出中不再起作用。

问题是 html 链接有效,但它们显示为 ?? -- 缺少节号。这只是本书 html 版本中的一个问题。 pdf 版本编译正确。

在寻找解决方案时,我尝试使用默认的演示安装创建一个 new bookdown 项目,但它有与此图中突出显示的相同的错误:

.

如前所述——此错误发生在 bookdown 的默认安装中... 摘自 01-intro.Rmd(即在 Rstudio 中:文件 >> 新项目 >> 新目录 >> 使用 bookdown 的 Book 项目)。

# Introduction {#intro}

You can label chapter and section titles using `{#label}` 
after them, e.g., we can reference Chapter \@ref(intro). 
If you do not manually label them, there will be automatic labels anyway,
e.g., Chapter \@ref(methods).

Figures and tables with captions will be placed in `figure`
and `table` environments, respectively.

这是我的sessionInfo()

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

loaded via a namespace (and not attached):
 [1] compiler_3.6.1  bookdown_0.16   htmltools_0.4.0 tools_3.6.1    
 [5] yaml_2.2.0      Rcpp_1.0.3      rmarkdown_2.0   knitr_1.26     
 [9] xfun_0.11       digest_0.6.23   rlang_0.4.2     evaluate_0.14

找到解决方法

这是 Rstudio 小组正在解决的一个已知问题。
https://github.com/rstudio/bookdown/issues/787

我能够通过使用与 Rstudio 一起安装的 pandoc 版本(当前为 2.7.2)来解决这个问题。在 windows 中,我通过从 PATH 中删除 pandoc 然后重新启动我的 Rstudio 会话来做到这一点。

把这个留在这里以防其他人像我一样被卡住:标签不能以数字开头,例如{#1.1} 不会工作,但 {#s1.1} 可以使用上面评论中 Yihui 的修复程序引用的修复程序。