Create index of definitions / theorems at end of bookdown book

后端 未结 2 872
忘了有多久
忘了有多久 2021-01-03 01:11

For reader convenience, I\'d like to include, at the end of my bookdown book, written in markdown, a simple list or index of definitions from the body of the book. i.e. ones

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 01:27

    Perfect, so adding on from Yihui's suggestion, this prints out the definitions as well, and no need to bother with names, just labels will do:

    ```{definition, 'Bar',echo=T,cache=F}
    Bar is defined as something
    ```
    
    ```{definition, 'Bar2',echo=T,cache=F}
    Bar2 is defined as something else.
    ```
    
    Here are all the definitions in this book.
    
    ```{r comment="",results="asis",echo=FALSE,cache=F}
    
    
    for(x in knitr::all_labels(engine == 'definition')){
       paste0("\n\n","\\@ref(def:",x,"): ",x,"\n\n>",knitr:::knit_code$get(x),collapse="\n\n") %>% cat
    } 
    
    ```
    

    ... produces this:

    Here are all the definitions in this book.

    1: Bar

    Bar is defined as something

    2: Bar2

    Bar2 is defined as something else.

提交回复
热议问题