如何使用 bookdown 将执行摘要放在 TOC 之前?

How can I put an executive summary before the TOC using bookdown?

我有一个 bookdown 项目,其中包含自定义 template.tex 和自定义 my-format.cls。我可以在 template.tex:

中执行以下操作
$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

\tableofcontents

\begin{body}
...

并获取摘要以采用我的自定义格式。这部分有效,因为摘要的内容只是一段文本,可以放在 YAML 前面。

但是,是否可以在 的 table 内容之前添加执行摘要

我知道我可以使用(在我的index.Rmd


# Executive Summary {-}

a summary here

# Introduction

this is the first numbered section

但在那种情况下,即使“执行摘要”部分 header 没有编号,它也会出现在目录之后。是否可以修改 template.tex 以便使用类似的东西:

$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$

$if(executive_summary)$
\begin{executivesummary}
% insert summary content here
\end{executivesummary}
$endif$

\tableofcontents

\begin{body}
...

我可以从未编号的执行摘要部分(即使它必须来自不同的 .Rmd 文件)中删除内容(包括 figures/tables/etc.)并将其分配给某些(pandoc ) 变量可以代替上面的 % If I insert summary content here 引用?我还需要从默认分配的 (pandoc) $body$ 变量中 removed 相同的内容。

谢谢@tarleb!我怀疑我可以通过 Lua 过滤器得到我想要的东西,但我想我找到了一种更简单的方法,与您的回答 https://whosebug.com/a/53885034/1785752

一致

在我添加的 index.Rmd YAML 中

executivesummary: |
  
    ```{r, echo=FALSE, results='asis'}
    res <- knitr::knit_child(quiet = TRUE, 'executive-summary.Rmd')
    cat(res, sep = '\n')
    ```

但这需要一些东西:

  • “阴影”环境在 template.tex
  • 的序言中定义
$if(highlighting-macros)$
$highlighting-macros$
$endif$
  • executive-summary.Rmd 已定义,没有 YAML 和级别 1 header(“执行摘要”标题来自 template/class 文件)

有趣的是,我 可以 只是将内容放在 executivesummary YAML 部分(即跳过 child 文档呈现),但是代码块选项在这种情况下,include 字符串有时会被解析为 YAML 键,这会导致渲染失败。此外,2-space 缩进代码块没有 IDE 语法检查帮助或 auto-complete.