R 在Bookdown中提供自定义模板时未呈现标题和作者
我有以下项目结构:R 在Bookdown中提供自定义模板时未呈现标题和作者,r,r-markdown,pandoc,bookdown,R,R Markdown,Pandoc,Bookdown,我有以下项目结构: mybook/ ├── _bookdown.yml ├── index.Rmd ├── c1.Rmd ├── c2.Rmd ├── template.tex 文件\u bookdown.yml是: rmd_files: - c1.Rmd - c2.Rmd output_dir: _out book_filename: _index_merged.Rmd --- title: A simple book author: Andrea Tino --- % !TeX pro
mybook/
├── _bookdown.yml
├── index.Rmd
├── c1.Rmd
├── c2.Rmd
├── template.tex
文件\u bookdown.yml
是:
rmd_files:
- c1.Rmd
- c2.Rmd
output_dir: _out
book_filename: _index_merged.Rmd
---
title: A simple book
author: Andrea Tino
---
% !TeX program = pdfLaTeX
\documentclass{monograph}
\usepackage{hyperref}
\usepackage{newtxmath}
\makeindex
\begin{document}
\author{ $for(authors)$ $authors.name$ \and $endfor$ }
\title{$title$}
$if(subtitle)$
\subtitle{$subtitle$}
$endif$
\maketitle
\tableofcontents
$body$
\printindex
\end{document}
文件index.Rmd
是:
rmd_files:
- c1.Rmd
- c2.Rmd
output_dir: _out
book_filename: _index_merged.Rmd
---
title: A simple book
author: Andrea Tino
---
% !TeX program = pdfLaTeX
\documentclass{monograph}
\usepackage{hyperref}
\usepackage{newtxmath}
\makeindex
\begin{document}
\author{ $for(authors)$ $authors.name$ \and $endfor$ }
\title{$title$}
$if(subtitle)$
\subtitle{$subtitle$}
$endif$
\maketitle
\tableofcontents
$body$
\printindex
\end{document}
文件c1.Rmd
和c2.Rmd
的内容微不足道:只有一个标记标题和一些文本
文件模板.tex
是:
rmd_files:
- c1.Rmd
- c2.Rmd
output_dir: _out
book_filename: _index_merged.Rmd
---
title: A simple book
author: Andrea Tino
---
% !TeX program = pdfLaTeX
\documentclass{monograph}
\usepackage{hyperref}
\usepackage{newtxmath}
\makeindex
\begin{document}
\author{ $for(authors)$ $authors.name$ \and $endfor$ }
\title{$title$}
$if(subtitle)$
\subtitle{$subtitle$}
$endif$
\maketitle
\tableofcontents
$body$
\printindex
\end{document}
问题 当我从R shell(其中工作目录是
mybook/
)运行此命令时:
bookdown::render\u book(“index.Rmd”,rmarkdown::pdf\u document(template=“template.tex”,keep_utex=TRUE))
我得到一份PDF,其中:
- 标题和作者不见了
- 内容(c1.Rmd和c2.Rmd的结果)实际上就在那里
\u index\u merged.tex
(生成的tex,我可以访问,因为我在r标记::pdf\u文档中指定了keep\u tex=TRUE
),我可以清楚地看到:
- 占位符
$title$
和$author$
被空字符串替换,因此标题和作者为空
- 占位符
$body$
已被内容填充
以下是\u index\u merged.tex
的内容(相关摘录):
...
\begin{document}
\author{ }
\title{}
\maketitle
...
为什么模板没有正确拾取标题和作者?在bookdown中,如果在\u bookdown.yml
中指定rmd\u文件
,则bookdown只处理这些文件。由于您的标题和作者位于index.Rmd
的yaml标题中,因此您需要将此文件也包括在Rmd\u文件中。或者在c1.Rmd
请参阅中的关于rmd_文件的行为