bookdown::word_document2 中的 Cross-referencing 部分无法正常工作

Cross-referencing of sections in bookdown::word_document2 not working

标题说明了一切。请参阅下面的最小(非)工作示例。

---
title: "Untitled"
author: "Anonymous"
date: "09/01/2020"
output: bookdown::word_document2
---

# First Section {#sec1}

Etc.


# Second Section

See section \@ref(sec1).

当我编织上面的内容时,我收到以下警告:

Output created: mre.docx
Warning message:
The label(s) sec1 not found 

输出中的引用替换为两个问号 (??)。当我将 YAML header 中的输出选项替换为 pdf_document2 时,没有错误。我的 template.docx 为所有标题样式启用了章节编号,并且章节编号正确(只是参考文献没有)。

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.9.0
LAPACK: /usr/lib/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8    LC_PAPER=en_GB.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

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

loaded via a namespace (and not attached):
 [1] compiler_3.6.2  Matrix_1.2-18   bookdown_0.16   htmltools_0.4.0 tools_3.6.2     yaml_2.2.0      reticulate_1.13 Rcpp_1.0.3      rmarkdown_1.17  grid_3.6.2      knitr_1.26      jsonlite_1.6   
[13] digest_0.6.22   xfun_0.11       rlang_0.4.1     lattice_0.20-38 evaluate_0.14  

> pandoc --version
pandoc 2.8
Compiled with pandoc-types 1.20, texmath 0.12, skylighting 0.8.3

我一直在为同样的问题而苦苦挣扎,我找到了解决方法

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

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