escape_latex is not applied to the stub, which breaks latex compilation when the stub includes invalid characters. Below, the first example produces valid LaTeX, since test_this in cells is properly escaped. The second example does not compile because test_this is in the stub column and escape_latex function is not applied there.
library(gt)
library(magrittr)
# "test_this" is properly escaped
data.frame('first' = c('test_this', 'test'),
'second' = 1:2) %>%
gt() %>%
as_latex %>%
cat()
#> \captionsetup[table]{labelformat=empty,skip=1pt}
#> \begin{longtable}{cr}
#> \toprule
#> first & second \\
#> \midrule
#> test\_this & 1 \\
#> test & 2 \\
#> \bottomrule
#> \end{longtable}
# "test_this" is NOT properly escaped
data.frame('first' = c('test_this', 'test'),
'second' = 1:2) %>%
gt(rowname_col = 'first') %>%
as_latex %>%
cat()
#> \captionsetup[table]{labelformat=empty,skip=1pt}
#> \begin{longtable}{lr}
#> \toprule
#> & second \\
#> \midrule
#> test_this & 1 \\
#> test & 2 \\
#> \bottomrule
#> \end{longtable}
Created on 2019-01-23 by the reprex package (v0.2.1)
Thanks for letting me know about this. I will make sure that escape_latex() is applied to the stub content when rendering to LaTeX.
Most helpful comment
Thanks for letting me know about this. I will make sure that
escape_latex()is applied to the stub content when rendering to LaTeX.