gt
gt copied to clipboard
`latex unicode conversion` leads compiling error for CJK document
Prework
- [x] Read and agree to the code of conduct and contributing guidelines.
- [x] If there is already a relevant issue, whether open or closed, comment on the existing thread instead of posting a new issue.
Description
latex unicode conversion leads compiling error for CJK document. Only gt 1.1.0 has this issue, gt 1.0.0 does not.
Reproducible example
---
title: "quote test"
date: today
lang: zh
engine: knitr
format:
pdf:
pdf-engine: xelatex
keep-tex: true
---
```{r}
library(gt)
df <- data.frame(
'en' = c('\'test\'', '"test"'),
'zh' = c('“测试”', '‘测试’')
)
gt(df)
```
For gt 1.1.0, it generates the follow latex code:
\begin{table}
\fontsize{12.0pt}{14.0pt}\selectfont
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}ll}
\toprule
en & zh \\
\midrule\addlinespace[2.5pt]
'test' & \textquotedblleft测试\textquotedblright \\
"test" & \textquoteleft测试\textquoteright \\
\bottomrule
\end{tabular*}
\end{table}
There is no spacing between latex code and text characters in \textquotedblleft测试\textquotedblright, which make this an Undefined control sequence. I think this issue may be related with the follwing code: https://github.com/rstudio/gt/blob/77c3bb9945e37da877c6ee3c76f2edde02379a4e/R/helpers.R#L3130-L3147.
Expected result
Should be compiled successfully.
Session info
R version 4.5.1 (2025-06-13)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.0
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.5-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.1
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Asia/Shanghai
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.5.1 tools_4.5.1 rstudioapi_0.17.1 remotes_2.5.0
Similar to #2037 (but without the xelatex subtlety)