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

2024-01-05

我跟着bookdown https://bookdown.org/yihui/bookdown/latex-index.html创建索引的指令。尽管代码运行没有错误,但它没有在 pdf 输出中显示索引。还有说明here https://github.com/rstudio/bookdown/issues/149。我一定是做了什么傻事!

可重现的代码在这里:

#####################
##### 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

The 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    

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

索引.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")

Output:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法为 LaTeX/PDF 输出创建索引 的相关文章

随机推荐