I have an exotic problem with RMarkdown and knitting a pdf. Knitting html and word documents works fine. I'm running RStudio Version 1.2.5033 and TeX 3.14159265 (TeX Live 2019 Gentoo Linux).
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. There are several other SO questions on this topic - for example Package inputenc Error & Error: pandoc document conversion failed with error 43 and Package inputenc Error: Unicode char \u8 in RStudio.
The standard advice, to deal with the limits of pdflatex's implementation of Unicode, is to use xelatex, which I'm doing, but it still does not work.
So, first effort - using pdflatex - crashes when knitting a pdf 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
will produce a pdf, but all the ⁸ are blank. This is not the case when knitting to HTML or Word, and in fact the pdf produced by saving the Word document as a pdf in LibreOffice looks fine, with all the 2⁸ correctly rendered.
The output is [output of running R deleted]
/usr/bin/pandoc +RTS -K512m -RTS LatexTest.utf8.md --to latex
--from markdown+autolink_bare_uris+tex_math_single_backslash --output LatexTest.tex
--self-contained --highlight-style tango --latex-engine xelatex --variable graphics
--variable 'geometry:margin=1in' --include-in-header
/tmp/RtmpdLZWBq/rmarkdown-str18dc3dcea436.html
output file: LatexTest.knit.md
Output created: LatexTest.pdf
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.
Package xcolor Warning: Incompatible color definition on input line 164.
The test file, which produces these errors is attached. When running this it claims to be using the xelatex engine.
---
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, I wonder if this is a bug. It should just work with xelatex.