Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Markdown 2 to EPUB How?

There is a suggestion on the RStudio blog that one can convert an R Markdown document into the EPUB format. But I can't find any documentation on how to do this. I suspect I may have to use pandoc arguments, but as someone new to R Markdown I am finding this a bit confusing. And silly ideas of mine such as the YAML metadata below don't work. All help appreciated. It would be particularly great if I could do this via the YAML metadata section of the R Markdown file.

---
title: "An epub"
output: epub_document
---
like image 662
mathlawguy Avatar asked Mar 19 '23 15:03

mathlawguy


1 Answers

With the bookdown package installed, you can specify a version of the following output format in the yaml header:

output:
    bookdown::epub_book:
      number_sections: true

There are a number of other options. See Epub options. A quirk of my version of Reader for Mac (2.0.02.15180) is that $p$ appears as pp, and $\alpha$ appears as α\alpha. With Calibre, it imports without problem.

An alternative is to make a new RMarkdown custom format (until some kind soul makes a custom format for EPub that they're willing to share!). All the documentation you should need to make this happen is here:

http://rmarkdown.rstudio.com/developer_custom_formats.html

It's technically true that you can add Pandoc arguments to coerce one of the existing output documents to spit out an EPub book. For instance, try this:

output:
  html_document:
    pandoc_args: ["--to", "epub"]

You'll find that the .html that's emitted is actually an EPub book! But it's unlikely to look nice or work correctly, because all of the knitr options and Pandoc options set by html_document are designed to produce HTML documents, not books.

like image 82
Jonathan Avatar answered Mar 28 '23 01:03

Jonathan