3

I have a Xaringan slide that looks like this:

---
title: "Xaringan test"
output: 
  xaringan::moon_reader:
    self_contained: false
    chakra: 'assets/remark-latest.min.js'
    css: 'assets/presentation.css'
---

### This is a heading

This is some text and numbers 01235.

`Here is some inline code`.

```
block code
```

```{r}
cat("Some R code")
```

$e^{i\pi} + 1 = 0$

The rendered HTML looks like below. Custom font, CSS styles and mathjax all render well. This is how it is intended to look.

enter image description here


Exporting to PDF using Pagedown.

pagedown::chrome_print("test.html",output="test.pdf")

enter image description here

The custom font and css styles are preserved. The default code font has changed and the mathjax expression is not displayed. Apart from the missing mathjax, it is doing a pretty good job.


Exporting to PDF using webshot.

webshot("test.html","test.pdf")

enter image description here

Custom font and css styles are not preserved. The default code font and mathjax is preserved.


Anyone got any tips on how to preserve fonts, CSS style and mathjax while exporting to PDF through function?

R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS
webshot_0.5.1      
pagedown_0.1
xaringan_0.8
4

2 回答 2

7

I've been building on a package that builds xaringan slides to multiple output types: html, pdf, pptx, gif, and a couple options for a png of the first slide. It should render to PDFs well.

https://github.com/jhelvy/xaringanBuilder

Install the package

# install.packages("remotes")
remotes::install_github("jhelvy/xaringanBuilder")

library(xaringanBuilder)

Build a pdf file from a Rmd or html file:

build_pdf("slides.Rmd")
build_pdf("slides.html")

Include "Complex" or partial slides:

“Complex” slides are slides that contain panelsets or other html widgets / advanced features that might not render well as a pdf. To render these, set complex_slides = TRUE. If you want to build a new slide for each increment on incremental slides, set partial_slides = TRUE.

build_pdf("slides.Rmd", complex_slides = TRUE, partial_slides = TRUE)
build_pdf("slides.html", complex_slides = TRUE, partial_slides = TRUE)
于 2021-02-18T22:13:47.557 回答
3

At this moment, you have to use the development versions of pagedown and xaringan: https://github.com/yihui/xaringan/issues/168#issuecomment-461638520

于 2019-03-04T05:08:40.130 回答