gt icon indicating copy to clipboard operation
gt copied to clipboard

Characters generated using `fmt_number()` with the `pattern` argument are not escaped when rendered with `as_latex()`

Open JohannesNE opened this issue 4 years ago • 1 comments

If I try to add a % after a number, with fmt_number(pattern = "{x} %"), the % is not escaped when the table is converted to latex. (I know I should use fmt_percent() but my actual pattern is a bit more complicated).

library(gt)

test_table <- gt(exibble[1:2,1:2]) %>% 
  fmt_number(columns = "num", rows = 1, pattern = "{x} %")

test_table

image

test_table %>% 
  as_latex() %>% 
  as.character() %>% 
  cat()
#> \captionsetup[table]{labelformat=empty,skip=1pt}
#> \begin{longtable}{rl}
#> \toprule
#> num & char \\ 
#> \midrule
#> $0.11$ % & apricot \\ 
#> 2.222 & banana \\ 
#>  \bottomrule
#> \end{longtable}

Created on 2021-10-27 by the reprex package (v2.0.0)

JohannesNE avatar Oct 27 '21 07:10 JohannesNE

Thanks for filing this issue. This is a pretty bad bug so I’m hoping to get a fix for it sooner than later!

rich-iannone avatar Mar 01 '22 05:03 rich-iannone