Closed xmarti6 closed 4 years ago
I could also find a couple of improvements more in order to use special characters in caption and filenames that might be helpful for someone:
In report() function one can add this other function on top (ref1)
escapeLatexSpecials <- function(x) {
x <- gsub("\\", "$\\backslash$", x, fixed = T)
x <- gsub("#", "\\#", x, fixed = T)
x <- gsub("$", "\\$", x, fixed = T)
x <- gsub("%", "\\%", x, fixed = T)
x <- gsub("&", "\\&", x, fixed = T)
x <- gsub("~", "\\~", x, fixed = T)
x <- gsub("_", "\\_", x, fixed = T)
x <- gsub("^", "\\^", x, fixed = T)
x <- gsub("\\{", "\\{", x, fixed = T)
x <- gsub("\\}", "\\}", x, fixed = T)
x <- gsub(">", "$>$", x, fixed = T)
x <- gsub("<", "$<$", x, fixed = T)
return(x)
}
and then modify "caption" command with:
\\caption{",escapeLatexSpecials(figtitle),"}
Then, where packages are loaded:
paste("
\\documentclass[a4paper,titlepage,12pt]{article}
it is possible to add these two packages (ref2):
\\usepackage{graphicx}
\\usepackage{grffile}
Greetings
Hi, when I was testing the full report() function I realized that character encoding in the .tex file is not utf-8, but ansi. Thus, when using characters with accents, for instance, they are not correctly interpreted showing odd characters. Overriding the "report()" function with the following solves the issue, and PDF and .tex file show characters correctly:
file.tex <- sub("pdf$","tex",file) con<-file(file.tex,encoding="UTF-8") #added write(text,file=con) #added
write(text,file=file.tex) #skip
Greetings