creating accompanying slides for bookdown project
Asked Answered
B

1

5

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

Blotto answered 20/9, 2018 at 16:59 Comment(0)
C
5

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)
```
Changeable answered 20/9, 2018 at 18:44 Comment(6)
This works - thank you so much! I just need to understand how to change the file name - because bookdown::pdf_book and bookdown::pdf_document2 output to the same file - which gets therefore overwritten! I know how to change filenames and locations for all files at once using _bookdown.yml, but I do not know how to do it for individual files.... i will search more online, but did not see anything so far - do I need to post another question for this if I cannot find anything? many thanks, thomasBlotto
could not find an answer anywhere about how to customize the individual book filenames... apologies.Blotto
Unfortunately you cannot customize the output filename through any YAML options.Changeable
Thank you so much for the prompt response. Really appreciated. There is no way to throw in some pandoc command? So you are saying that if I want to compile all books at once, I am doomed to overwrite the pdf built with the first bookdown::pdf_book when i run the second bookdown::pdf_document2?? Many thanks, thomasBlotto
So... i guess the only option if so would be to hope for a future version of bookdown to allow for some extra options such as bookdown::slides for instance? ;-pBlotto
Fyi... I tried to pass "-o", "FILE.pdf" and variations to pandoc, but that did not seem to work.Blotto

© 2022 - 2024 — McMap. All rights reserved.