如何在 Windows 上使用 Rstudio 将索引添加到从 Rmarkdown 文档渲染的 PDF 中?

jcl*_*use 5 r-markdown

下面的示例文档旨在在附录后包含索引。在 Sweave 文档中,Rstudio 将运行 shell 转义命令来创建索引 .idx 文件,但我无法找到对 Rmarkdown 文档执行此操作的方法。我缺少一个简单的标题命令吗?

---
title: "Untitled"
output:
  pdf_document:
    toc: yes
header-includes:
- \usepackage{makeidx}
- \makeindex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

# R Markdown

This is an \index{R Markdown} R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

# Appendix - A
End of the document

\printindex
Run Code Online (Sandbox Code Playgroud)

我已经通过“编织”按钮尝试过此操作并使用:

rmarkdown::render(rmd.file, output_format = "pdf_document", clean = FALSE)
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种可以作为自动化流程的一部分运行的解决方案。

更新:我能够通过将输出类型更改为 bookdown::pdf_document2 来使索引正常工作。索引、交叉引用和格式化的组合需要额外的乳胶包。

---
title: "Untitled"
output:
  bookdown::pdf_document2:
    toc: no
geometry: margin=0.8in
header-includes:
- \usepackage{attachfile2}
- \usepackage{booktabs}
- \usepackage{caption}
- \usepackage{float}
- \usepackage[utf8]{inputenc}
- \usepackage{makeidx}
- \makeindex
- \usepackage{multirow}
- \usepackage{setspace}
- \usepackage{relsize}
- \usepackage[table]{xcolor}
- \setcounter{tocdepth}{5}
- \setcounter{secnumdepth}{0}
- \hypersetup{unicode=true,pdfusetitle,bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=2,breaklinks=false,backref=false,colorlinks=true,linkcolor=blue}
---
Run Code Online (Sandbox Code Playgroud)

虽然这在手动按下创建 PDF 按钮时可以工作,但调用rmarkdown::render()仍然不会处理索引。