Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preserving character sequences like <- or != in Xaringan, preventing substitution

I am building a Xaringan deck for a short course on R. I need students to learn the character sequences for assignment <- and relational operators like !=.

However, knitting to slides replaces several character sequences with more elegant display characters. For example, <- becomes a left-pointing arrow (←).

Can I preserve the original characters in slide output?

I still get the replacement inside single backticks (`) for code formatting and even inside R code chunks (```). Escaping the characters with \ does not help.

---
# Two ways to save variables to memory

R has two ways to assign variables: `=` and `<-`.  

The following expressions are equivalent:

`turnout_rate = .598` and `turnout_rate <- .598`

When knit to slides, all <- above are replaced with a left arrow (←) . I would like to keep the original characters <-.

Thanks in advance for your help!

like image 260
dizhihong Avatar asked Sep 20 '25 22:09

dizhihong


1 Answers

You probably have a CSS style sheet in place that calls for a font like Fira Code where <- is rendered as a ligature. You can test this by using Right Click -> Inspect Element in the preview/browser.

You can change the used font via some custom CSS code, e.g.:

.remark-code, .remark-inline-code {
    font-family: 'Fira Mono', 'Source Code Pro', monospace;
}

You have to specify the custom CSS file in the YAML header, e.g. for the default theme and a file named custom.css:

---
output:
  xaringan::moon_reader:
    css: ["default", "custom.css"]
---

References:

  • https://github.com/yihui/xaringan/wiki/Changing-fonts
  • https://github.com/yihui/xaringan/wiki/Prerequisites
like image 187
Ralf Stubner Avatar answered Sep 22 '25 11:09

Ralf Stubner