交叉引用 bookdown::html_document2 不起作用

jon*_*030 1 r cross-reference pandoc r-markdown bookdown

我正在 Rmarkdown 中写一篇论文,并使用它bookdown::html_document2来编织输出。交叉引用图形和表格使用常见的 Bookdown 语法,例如\@ref(tab:example_table)。但是,交叉引用章节/标题不起作用:\@ref(introduction)不起作用。我最终会发现??这很奇怪,因为链接指向正确的标签:/example_path/example_filename.html#introduction。我正在处理一个文档。

我检查了源代码,章节标题的标签 ID 也正确。当我使用 Pandoc 的本机语法引用章节部分/标题时,它确实有效:[introduction]works。但是,这将打印介绍部分/标题的标签,而不是标题本身,因此“介绍”而不是带有大写“I”的“介绍”。一个明显的解决方法是使用[Introduction][introduction],但这在我的例子中违背了交叉引用的目的。我还尝试给我的章节部分/标题自定义标签,但这也行不通。它也不适用于bookdown::pdf_document2.

根据“使用 R Markdown 创作书籍”的这一部分,我使用的语法应该有效,那么我在这里缺少什么?

我正在使用 Pandoc 版本2.7.3

编辑

删除了会话信息,因为它与问题无关。

编辑

@RalfStubner 请求了一个 mre(我应该首先提供 - 感谢 Ralf 的建议!):

---
title: "Document Title"
author: "Jono3030"
date: "Last updated: `r Sys.time()`"
output:
  bookdown::html_document2:
    number_sections: no
  bookdown::pdf_document2:
    keep_tex: no
    number_sections: no
  bookdown::word_document2: default
---

# Introduction

This is the introduction

# Chapter_one

This is chapter one.

# Chapter_two

This is chapter two. Trying to reference the Introduction.

This does not work: \@ref(introduction)

This works: [Introduction][introduction]

This does not result in the title but in the tag: [introduction]
Run Code Online (Sandbox Code Playgroud)

渲染输出

这是我收到的错误消息:

Output created: mre.html
Warning message:
The label(s) introduction not found
Run Code Online (Sandbox Code Playgroud)

但标签似乎根据html正确分配:

<div id="introduction" class="section level1">
<h1>Introduction</h1>
<p>This is the introduction</p>
</div>
Run Code Online (Sandbox Code Playgroud)

这是href:

<p>This does not work: <a href="#introduction"><strong>??</strong></a></p>
<p>This works: <a href="#introduction">Introduction</a></p>
<p>This does not result in the title but in the tag: <a href="#introduction">introduction</a></p>
Run Code Online (Sandbox Code Playgroud)

在创建 mre 的过程中,我还注意到,\@ref(introduction)如果未禁用部分编号,则行为会有所不同。在这种情况下,\@ref(introduction)返回节的编号,即“1”。

先生:

---
title: "Document Title"
author: "Jono3030"
date: "Last updated: `r Sys.time()`"
output:
  bookdown::html_document2: default
  bookdown::pdf_document2:
    keep_tex: no
    number_sections: no
  bookdown::word_document2: default
---

# Introduction

This is the introduction

# Chapter_one

This is chapter one.

# Chapter_two

This is chapter two. Trying to reference the Introduction.

This does work - returns number: \@ref(introduction)

This works: [Introduction][introduction]

This does not result in the title but in the tag: [introduction]
Run Code Online (Sandbox Code Playgroud)

渲染输出

ssp*_*c3r 8

参考 ids 不适用于_id: 例如,{#hello_world}并且\@ref(hello_world)不起作用,但是 {#helloworld}\@ref(helloworld)应该没问题。