当在Bookdown中提供自定义模板时,标题和作者没有呈现。

问题描述 投票:1回答:1

我的项目结构如下。

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.Rmdc2.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.Rmdc2.Rmd)其实是有的。

通过观察 _index_merged.tex (生成的TEX,我可以访问它,因为我指定了 keep_tex=TRUE 里面 rmarkdown::pdf_document),我可以清楚地看到,。

  • 占位符 $title$$author$ 被空字符串所取代,因此标题和作者都是空的。
  • 占位符 $body$ 了满满的内容。

下面是(相关摘录)的内容。_index_merged.tex:

...
\begin{document}

\author{ }
\title{}

\maketitle
...

为什么模板不能正确地拾取?标题作者?

r r-markdown pandoc bookdown
1个回答
2
投票

在bookdown中,如果你指定 rmd_files_bookdown.yml只有这些文件才会被bookdown处理。由于您的标题和作者在yaml头的 index.Rmd,你需要将这个文件也包含在 rmd_files. 或者在yaml头中添加 c1.Rmd

请看 rmd_files 行为中 廉价书

© www.soinside.com 2019 - 2024. All rights reserved.