Ian
Ian

Reputation: 173

How to print special Latin characters in Markdown pdfs

I need to knit my Markdown script into a pdf file, but when knitted, the pdf file does not show special Latin characters, such as those used in the International Phonetic Alphabet (IPA).

---
title: "MarkdownIPA"
date: '2022-07-06'
output: 
  pdf_document:
    latex_engine: xelatex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
`Print IPA`
```{r}
'[aɪ.pʰiː.ɛɪ]'
```

Which rends:

enter image description here

How can I fix this?

Upvotes: 1

Views: 404

Answers (1)

tarleb
tarleb

Reputation: 22599

You'll need to use a font that supports those glyphs. A (IMHO) rather nice one is Source Sans Pro and the monospace variant Source Code Pro.

To use Source Code Pro, you can add the respective LaTeX code directly:

---
title: "MarkdownIPA"
date: '2022-07-06'
output:
  pdf_document:
    latex_engine: xelatex
header-includes:
 - \usepackage{sourcecodepro}
---

Result:

Screenshot of the resulting PDF file, showing IPA characters set in a monospace font

The sourcecodepro package is likely already installed; otherwise you'd have to install it first.

Upvotes: 1

Related Questions