2

The problem

According to the docs, Xaringan should

  1. turn normal quotes " " into smart quotes “ ”, and

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

Example

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:

  1. Title slide (note the smart quotes and the em-dash):

    first slide

  2. Second slide (ugly quotes and 3 hyphens):

    second slide

Ideas

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

  2. I tried using smart: true in the yaml metadata as shown in the RMarkdown book, but it has no effect.

  3. Looking at the code for the moon_reader function, I see it calls rmarkdown::html_document to generate the html.

  4. 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?

My setup

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.

Community
  • 1
  • 1
Julian Neuer
  • 306
  • 1
  • 8
  • You are right that for xaringan slides, Markdown is rendered through remark.js in your web browser, instead of Pandoc. – Yihui Xie Mar 30 '20 at 03:03
  • 1
    Thanks @YihuiXie. I just realized pandoc is called to generate the title slide only; that's why the title slide has smart quotes. So it is up to remark to beautify the quotes and the em dashes in the other slides? – Julian Neuer Mar 30 '20 at 13:30
  • 1
    That's completely correct. – Yihui Xie Mar 30 '20 at 15:32
  • Thanks for this solution, it has been quite useful! However, I notice that it only solves the issue for quotes and dashes, while multiple other Pandoc markdown elements (?) like the [vertical bar `|` for indentation](https://bookdown.org/yihui/rmarkdown-cookbook/indent-text.html#) still do not work. Is there any other solution for this? @YihuiXie – Karthik Thrikkadeeri Jun 19 '22 at 02:59

1 Answers1

4

Link to solution

https://github.com/fnaufel/smartify

Details

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.

Julian Neuer
  • 306
  • 1
  • 8
  • This was helpful to me, since I was scratching my head at this behavior just the other day. I’ll definitely have a look at your GitHub repo. – Tyler R. Jul 20 '20 at 10:55