为bookdown书的定理创建ToC(目录)

时间:2017-11-01 22:49:19

标签: r latex bookdown

我想在bookdown pdf书中为所有定理创建一个ToC(目录)列表。这似乎是关于如何Create index of definitions / theorems at end of bookdown book的类似问题,但我想在章节的ToC之后和主体之前插入定理的ToC。此外,还需要页码。

TeX社区中有一些线索:

在其中使用the closest answer,我可以得到一个不完美的类似ToC的定理列表。我可重复的迷你示例如下,其中包括三个文件。

index.Rmd:

--- 
title: "A Minimal Book Example"
site: bookdown::bookdown_site
documentclass: book
output:
  bookdown::pdf_book:
    includes:
      in_header: preamble.tex
      before_body: before_body.tex
    latex_engine: xelatex
    keep_tex: yes
---

# Prerequisites

```{block, type='tip', name = 'My Important Tip'}
This is Tip One.
```

```{lemma}
This is Lemma One.
```

```{example}
This is Example One.
```

preamble.tex:

% format of tips
\usepackage{amsthm}
\usepackage{etoolbox}
\newtheoremstyle{mystyle}
{\topsep}{\topsep}{}{}{\bfseries}{:}{\newline}
{\thmname{#1}\thmnumber{ #2}\thmnote{ (#3)}%
    \ifstrempty{#3}%
    {\addcontentsline{def}{subsection}{#1~\thetip}}%
    {\addcontentsline{def}{subsection}{#1~\thetip~(#3)}}}


\theoremstyle{mystyle}
\newtheorem{tip}{Tip}[chapter]

% toc of tips
\makeatletter
\newcommand\tipname{Tip}
\newcommand\listtipname{List of Tips}
\newcommand\listoftips{
    \section*{\listtipname}\@starttoc{def}}
\makeatother

before_body.tex:

\listoftips

本书制作完成后,我很高兴在pdf输出中看到一个带有页码的提示列表:

enter image description here

然而,有两个问题:

  1. 表中列出了不仅是'tip'块,还有我书中的lemmas。我怎么能从表中排除这些引理?

  2. 标题应为Tip 1.1: My Important Tip。如何在列表中显示标题My Important Tip

  3. 另一个不重要的问题是:我在迷你示例中也有'示例'环境。为什么引理列表中的引理1,但示例1不是?如果我想分别创建提示列表,列表列表和示例列表,我该怎么办?

    我想我非常接近解决方案,但我不知道如何向前迈出一步。

    更新

    我刚发现.tex文件中的以下代码可以将提示标题“我的重要提示”传递给ToC:

    \begin{tip}[My Important Tip]
    This is Tip One.
    \end{tip}
    

    这会在提示的ToC中产生Tip 1.1 (My Important Tip)。我怎么能在knitr块中指定它? name = 'My Important Tip'不起作用。

0 个答案:

没有答案
相关问题