Highlighting error in latex when R Markdown has special characters in chunks

I'm trying to render the following .Rmd to latex.

---
title: "R Notebook"
output:
  pdf_document: default
---

``{r}
nombre <- c("Alumno Alúmnez1", "Alumno Alúmnez2")
``

(I remove one tilde of the beginning and end of the chunk so it renders properly here)

And the highlight for the strings is misplaced when I include the accents. It happens only when I try to render the pdf version, the html works fine.

The problem is that when I include the accents the \StringTok in the .tex is misplaced.

Here is my sessionInfo()

R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/es_ES.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] renv_0.12.0     lubridate_1.7.9 knitr_1.29     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        highr_0.8.2       compiler_4.0.2    base64enc_0.1-3  
 [5] rticles_0.14      prettyunits_1.1.1 remotes_2.2.0     tools_4.0.2      
 [9] testthat_2.3.2    digest_0.6.25     pkgbuild_1.1.0    pkgload_1.1.0    
[13] jsonlite_1.7.0    evaluate_0.14     memoise_1.1.0     rlang_0.4.7      
[17] cli_2.0.2         rstudioapi_0.11   curl_4.3          yaml_2.2.1       
[21] xfun_0.18         withr_2.2.0       stringr_1.4.0     fs_1.4.2         
[25] generics_0.0.2    desc_1.2.0        devtools_2.3.1    rprojroot_1.3-2  
[29] glue_1.4.1        R6_2.4.1          processx_3.4.3    fansi_0.4.1      
[33] rmarkdown_2.3     sessioninfo_1.1.1 callr_3.4.3       magrittr_1.5     
[37] usethis_1.6.1     backports_1.1.8   ps_1.3.3          ellipsis_0.3.1   
[41] htmltools_0.5.0   assertthat_0.2.1  tinytex_0.25      stringi_1.4.6    
[45] markdown_1.1      crayon_1.3.4 

I tried changing the engine. It does not work with xelatex neither with pdflatex.

I think this is a pandoc issue. It does not work with Pandoc 2.7.3 but work with higher like pandoc 2.9.2.1

I think you should try to install a newer pandoc than the one shipped with RStudio for now (https://pandoc.org/installing.html#macos)

It is possible that the new preview of RStudio include a newer pandoc if you want to try.
(RStudio Preview - RStudio)

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.