【发布时间】:2020-04-11 22:17:04
【问题描述】:
我的项目结构如下:
mybook/
├── _bookdown.yml
├── index.Rmd
├── c1.Rmd
├── c2.Rmd
├── template.tex
文件_bookdown.yml是:
rmd_files:
- c1.Rmd
- c2.Rmd
output_dir: _out
book_filename: _index_merged.Rmd
文件index.Rmd是:
---
title: A simple book
author: Andrea Tino
---
文件 c1.Rmd 和 c2.Rmd 有一些琐碎的内容:只是一个 Markdown 标题和一些文本。
文件template.tex是:
% !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_book("index.Rmd", rmarkdown::pdf_document(template="template.tex", keep_tex=TRUE))
我得到一个 PDF,其中:
- 标题和作者不见了。
- 内容(
c1.Rmd和c2.Rmd的结果)实际上是存在的。
通过查看_index_merged.tex(生成的TEX,我可以访问它,因为我在rmarkdown::pdf_document 中指定了keep_tex=TRUE),我可以清楚地看到:
- 占位符
$title$和$author$被空字符串替换,因此标题和作者为空。 - 占位符
$body$已填满内容。
这里是_index_merged.tex的内容(相关摘录):
...
\begin{document}
\author{ }
\title{}
\maketitle
...
为什么模板没有正确选择title和author?
【问题讨论】:
标签: r r-markdown pandoc bookdown