kableExtra
kableExtra copied to clipboard
save_kable() saves .tex with ANSI encoding; expecting UTF-8
Describe the bug
save_kable() saves .tex files with ANSI encoding; expecting UTF-8
reprex:
library(tidyverse)
library(kableExtra)
test <- lm(mpg ~ cyl + wt, mtcars) %>% tidy() %>%
kbl(format = "latex") %>%
footnote(number = c("Testa å ä ö"))
save_kable(test, file = "plain.tex")
The problem is that when I convert the .tex file to pdf using pandoc, It won't work because the encoding is wrong. I will get an error like:
Invalid UTF-8 byte sequence (´┐¢´┐¢´┐¢).
If I open the .tex file in notepad and re-save it with UTF-8, it will work. However, this is tedious, as I modify my tables a lot before it is finished.
EDIT: I found one kind of hacky solution:
writeLines(test, file('test.tex', encoding = 'UTF-8'))
But there must be a better way?