@technocrat Thanks. How could I take the output of gsub and use it inline in an Rmd? For example, the output of the gsub function, "The temperature is 20 \\textdegreeC" breaks as an "undefined control sequence" when dropped inline within the following Rmarkdown document:
---
title: "test"
output:
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
test <- "The temperature is 20 °C"
output <- gsub("\\x{00B0}", "\\\\textdegree", test)
```
`r output`
will work in a tex file using the XeLaTeX engine (provided your system font defaults contain the degree character). So, the question is how are you getting from the Rmd file to the tex file and what do you have in the preface to your tex file. Please post a reproducible example, called a reprex
@technocrat I think I figured it out. The above example:
---
title: "test"
output:
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
test <- "The temperature is 20 °C"
output <- gsub("\\x{00B0}", "\\\\textdegree", test)
```
`r output`
was breaking because \textdegreeC isn't valid latex. Changing "\\\\textdegree" to "\\\\textdegree " allowed for the correct encoding of the degree symbol. That was frustrating. Thanks for sticking with me.
Here's the working example that will compile:
---
title: "test"
output:
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
test <- "The temperature is 20 °C"
output <- gsub("\\x{00B0}", "\\\\textdegree ", test)
```
`r output`