Problem with unicode in Rmarkdown

I have an exotic problem with RMarkdown and knitting a pdf. I have a file, which among other things recodes user input data. Some user has (God knows how) entered '2⁸' into the data file, and I need to recode this to 2.

So, first effort - using pdflatex - crashes when knitting with the message
'! Package inputenc Error: Unicode character ⁸ (U+2078) (inputenc) not set up for use with LaTeX.'

Replacing this with xelatex by
output: pdf_document: latex_engine: xelatex
(As the RStudio global option doesn't work) will produce a pdf, but all the ⁸ are blank. There are also a slew of warning messages :-

Warning message:
Package xcolor Warning: Incompatible color definition on input line 129.
Package xcolor Warning: Incompatible color definition on input line 133.
Package xcolor Warning: Incompatible color definition on input line 133.
Package xcolor Warning: Incompatible color definition on input line 139.
Package xcolor Warning: Incompatible color definition on input line 143.
Package xcolor Warning: Incompatible color definition on input line 143.
Package xcolor Warning: Incompatible color definition on input line 149.
Package xcolor Warning: Incompatible color definition on input line 154.
Package xcolor Warning: Incompatible color definition on input line 154.
Package xcolor Warning: Incompatible color definition on input line 160.
Package xcolor Warning: Incompatible color definition on input line 164.

The test file, which produces these errors is attached.

---
title: "Latex test"
author: "Anthony Staines"
date: "13/04/2020"
output:
  pdf_document:
    latex_engine: xelatex
  html_document: default
---
```{r setup, include=FALSE}
library(knitr)
library(kableExtra)
library(tidyverse)
knitr::opts_chunk$set(echo = TRUE)

cat('2⁸')
print('2⁸')

Test = ('2⁸')
cat(Test)
print(Test)
## 2⁸
 2⁸
 2⁸
 2⁸

Any suggestions? The Latex advice is to add the offending character to the Latex file, which would suit me fine, but I don't know how to give arbitrary Latex commands in Markdown or YAML. In any event, this is a bug. It should just work with xelatex.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.