为 bookdown 项目创建随附的幻灯片 [英] creating accompanying slides for bookdown project

查看:57
本文介绍了为 bookdown 项目创建随附的幻灯片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rstudio 中,我创建了一个新项目并使用 bookdown 选择图书项目.内置示例按预期完美运行,我可以编译 4 本书 - gitbook、html、epub 和 pdf.太好了.

In Rstudio, I create a new project and select book project using bookdown. The built in example runs perfectly as expected and i can compile 4 books - gitbook, html, epub, and pdf. Great.

下一个明显的步骤是希望同时拥有幻灯片,非常符合 beamer 包 所做的,允许 beamer 模式 和 <代码>文章模式.因此,我尝试在 _output.yml 代码中添加另一个输出:bookdown::pdf_document2.根据文档,我知道我应该能够定义 base_format 以使用 rmarkdown::beamer, 包作者告诉我我几乎是对的,请参阅此链接进行讨论.Punchline:我将这个修改后的 _output.yml 用于默认项目:

The next obvious step is to want to have slides at the same time, very much in line with what the beamer package does, allowing for both beamer mode and article mode. Therefore, I tried to add another output in the _output.yml code: bookdown::pdf_document2. In line with the documentation, I know I should be able to define the base_format to use rmarkdown::beamer, The package author told me I was almost right, see this link for the discussion. Punchline: I use this amended _output.yml for the default project:

bookdown::gitbook:
  css: style.css
  config:
    toc:
      before: |
        <li><a href="./">A Minimal Book Example</a></li>
      after: |
        <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
    download: ["pdf", "epub"]
bookdown::pdf_book:
  base_format: rmarkdown::beamer_presentation
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
bookdown::epub_book: default
bookdown::pdf_document2:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes

这正是谢一辉好心提出的建议.但是,当需要构建 pdf_book 时,我遇到了编译失败:

which is exactly the suggestion XieYihui kindly made. However, I am getting a compile fail, when the pdf_book needs to be built:

Output created: _book/index.html
Error in base_format(toc = toc, number_sections = number_sections, fig_caption = fig_caption,  : 
  unused argument (number_sections = number_sections)
Calls: <Anonymous> ... <Anonymous> -> create_output_format -> do.call -> <Anonymous>
Execution halted

Exited with status 1.

我迷路了 - 我花了几个小时寻找解决方案但没有成功.任何人都可以帮助我吗?我很抱歉我一直无法弄清楚这一点.谢一辉一直非常支持,他的评论表明这是解决此类问题的合适场所.非常感谢.托马斯

I am lost - I spent hours looking for a solution without success. Could anyone kindly help me? I am so sorry i have not been able to figure this one out. XieYiHui has been incredibly supportive and his comments suggest this is the right venue for such questions. Many thanks. thomas

推荐答案

错误是由于 rmarkdown::beamer_presentation() 没有参数 number_sections>(你不能在 beamer 中给部分编号;至少 Pandoc 似乎不支持它).

The error was due to the fact that rmarkdown::beamer_presentation() does not have the argument number_sections (you cannot number sections in beamer; at least Pandoc doesn't seem to support it).

要解决这个问题,您可以使用以下技巧,它基本上定义了一种丢弃 number_sections 参数的基本格式:

To get around this issue, you may use the following hack, which basically defines a base format that throws away the number_sections argument:

---
title: "Using bookdown with Beamer"
output:
  bookdown::pdf_book:
    base_format: "function(..., number_sections) rmarkdown::beamer_presentation(...)"
    number_sections: false
---

## Plot

See Figure \@ref(fig:foo).

```{r, foo, fig.cap='Hi there', fig.height=4}
plot(1:10)
```

这篇关于为 bookdown 项目创建随附的幻灯片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆