According to the docs, Xaringan should
turn normal quotes " "
into smart quotes “ ”, and
turn a sequence of 3 hyphens "---
" into an em-dash "—"
The problem I have is that these transformations only occur for the strings in the yaml metadata (which appear in the title slide), but not for the text in the normal slides.
File minimal.Rmd
contains the following code:
---
title: "\"It works, doesn't it?\" --- this is the title slide"
subtitle: "Smart quotes and em dash work in yaml"
output:
xaringan::moon_reader
---
# This is a normal slide
It works in the slides too, doesn't it? --- "I hope so", he said.
No, it doesn't.
After knitting, I get the following slides in minimal.html
:
I am pretty sure Xaringan does not use Pandoc to generate the html. If Pandoc were used in the process, it would beautify the quotes by default.
I tried using smart: true
in the yaml metadata as shown in the RMarkdown book, but it has no effect.
Looking at the code for the moon_reader
function, I see it calls rmarkdown::html_document
to generate the html.
This open issue in the RMarkdown
Github repository discusses the smart: true
option and the equivalent option in the call to Pandoc. The author of the issue suggests to drop the yaml option and leave it up to Pandoc to beautify the quotes etc.
But Xaringan does not use Pandoc, so could this be relevant?
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS
xaringan_0.15
knitr_1.28
rmarkdown_2.1
Thanks in advance for your help.
https://github.com/fnaufel/smartify
Neither xaringan nor remarkjs was responsible for beautifying the quotes and the dashes, after all.
I looked around for Javascript solutions for my problem, but eventually decided to implement my own. With a couple of lines added to in_header.html
and after_body.html
, you can load and run my Javascript hack to smartify the quotes and the dashes in your slides. No need to install anything.
More details at https://github.com/fnaufel/smartify.
I hope this will be useful to other people.
Again, thank you @YihuiXie for your comments.