简体   繁体   English

Bookdown:章节/章节交叉引用不起作用(gitbook)

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

I was having trouble with one of my bookdown projects where the chapter/section cross-references were no longer working in the html output.我在我的一个 bookdown 项目中遇到了问题,其中章节/部分交叉引用不再在 html 输出中工作。

The problem is the html links work but they are displayed as ??问题是 html 链接有效,但它们显示为?? -- lacking section number. -- 缺少节号。 This is only a problem in the html version of the book.这只是本书 html 版本的问题。 The pdf version compiles properly. pdf 版本编译正确。

In searching for a solution I tried creating a new bookdown project using the default demo install and it has the same error as highlighted in this image:在寻找解决方案时,我尝试使用默认的演示安装创建一个新的 bookdown项目,它与此图像中突出显示的错误相同:

bookdown 中损坏的交叉引用 . .

As noted -- this error is occurring in the default install of bookdown... excerpt from the 01-intro.Rmd (ie in Rstudio: File >> New Project >> New Directory >> Book project using bookdown).如前所述 - 此错误发生在 bookdown 的默认安装中...摘自01-intro.Rmd (即在 Rstudio 中:文件 >> 新建项目 >> 新目录 >> 使用 bookdown 的图书项目)。

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

Here is my sessionInfo()这是我的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

Found a workaround找到了解决方法

This is a known issue that the Rstudio group is working on.这是 Rstudio 小组正在研究的一个已知问题。
https://github.com/rstudio/bookdown/issues/787 https://github.com/rstudio/bookdown/issues/787

I was able to work around this problem by using the version of pandoc that is installed with Rstudio (currently 2.7.2).通过使用与 Rstudio 一起安装的 pandoc 版本(当前为 2.7.2),我能够解决这个问题。 In windows I did this by removing pandoc from the PATH and then restarting my Rstudio session.在 Windows 中,我通过从 PATH 中删除 pandoc 然后重新启动我的 Rstudio 会话来做到这一点。

只是留在这里以防其他人像我一样卡住:标签不能以数字开头,因此例如 {#1.1} 将不起作用,但 {#s1.1} 与 Yihui 在评论中的修复程序引用的修复程序一起使用多于。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM