Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

r - creating accompanying slides for bookdown project

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.

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).

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)
```

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...