无法为LaTeX / PDF输出创建索引

时间:2018-07-27 00:01:08

标签: bookdown

我遵循了bookdown指令来创建索引。尽管代码运行没有错误,但它没有在pdf输出中显示索引。还有说明here。我一定在做傻事!

可复制的代码在这里:

#####################
##### index.Rmd #####
#####################

--- 
title: "Linear Models using R"
author: 
- J Smith
- ABC Inc
site: bookdown::bookdown_site
bookdown::gitbook:
fontsize: 12pt
geometry: margin=0.8in
bookdown::pdf_book:
    template: null
    keep_tex: yes
    toc: yes
includes:
  in_header:
    - \usepackage{makeidx}
    - \makeindex  
  after_body:
    - \printindex
documentclass: book
classoption: openany
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
description: "Linear Models using R"
---


####################
###### 01.Rmd ######
####################

# Model

This is an R Markdown\index{rmarkdown} document\index{document}.

This book\index{book} describes linear\index{linear} model.

In this chapter\index{chapter}, we will discuss polynomial\index{polynomial} model.


# Index{-}

####### Error
####### \printindex 

只是为了增加清晰度,带有多个“#”的行是注释或文件名。请注意,如果我在文档末尾运行简单的\printindex(上面已注释),则会显示以下错误:

! Undefined control sequence. \printindex

sessionInfo()在这里:

R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS: /cm/shared/apps/R/3.4.1/lib64/R/lib/libRblas.so
LAPACK: /cm/shared/apps/R/3.4.1/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17     bookdown_0.7.15  digest_0.6.15    withr_2.1.2     
 [5] R6_2.2.2         jsonlite_1.5     git2r_0.18.0     magrittr_1.5    
 [9] evaluate_0.11    httr_1.3.1       stringi_1.2.2    curl_3.1        
[13] rmarkdown_1.10.8 devtools_1.13.4  htmldeps_0.1.1   tools_3.4.1     
[17] stringr_1.3.1    xfun_0.3         yaml_2.2.0       compiler_3.4.1  
[21] memoise_1.1.0    htmltools_0.3.6  knitr_1.20.8    

1 个答案:

答案 0 :(得分:3)

未正确指定YAML。以下对我有用。

index.Rmd

--- 
title: "Linear Models using R"
author: 
- J Smith
- ABC Inc
site: bookdown::bookdown_site
fontsize: 12pt
geometry: margin=0.8in
output:
  bookdown::pdf_book:
    template: null
    keep_tex: yes
    toc: yes
    includes:
      after_body: after_body.tex
      in_header: include_header.tex
bibliography: [book.bib, packages.bib]
---

# Model

This is an R Markdown\index{rmarkdown} document\index{document}.

This book\index{book} describes linear\index{linear} model.

In this chapter\index{chapter}, we will discuss polynomial\index{polynomial} model.

include_header.tex

\usepackage{makeidx}
\makeindex

after_body.tex

\printindex

在您书本目录的控制台上运行

bookdown::render_book("index.Rmd", "bookdown::pdf_book")

输出:

index