When I try and create a table using kable
and kableExtra
I cannot get math symbols to display correctly. I am able to produce math characters in normal kable
tables like expected. I've tried different variations of the options escape = FALSE
and protect_latex = T
without any luck. The math symbols display correctly if I knit to PDF or HTML, it's just the inline display (and preview) and notebook display that show the raw characters.
As far as I can see from the HTML output, the only difference between the kable
table and the kableExtra
table is that the latter contains some extra info on the class and style. The objects are also of a different class, which makes me wonder if the problem might be that mathjax is not called to render kableExtra
objects? If so, is there a way I can tell Rstudio to call on mathjax when rendering HTML from kableExtra
objects?
I've reproduced this problem on two different computers and using the RStudio Cloud.
Note: i filed a Github Issue but realized that it might be more appropriate to ask here.
Reprex:
---
title: "Kable Extra Math Symbols"
output: html_notebook
---
```{r}
math_symb <- c(1,2,3,4)
kable_table <- knitr::kable(math_symb, col.names = "$r^{2}$")
styled_kable_table <- kableExtra::kable_styling(kable_table)
kable_table
styled_kable_table
```
Session Info:
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=Norwegian Bokmål_Norway.1252 LC_CTYPE=Norwegian Bokmål_Norway.1252
[3] LC_MONETARY=Norwegian Bokmål_Norway.1252 LC_NUMERIC=C
[5] LC_TIME=Norwegian Bokmål_Norway.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 rstudioapi_0.11 xml2_1.3.2 knitr_1.28 magrittr_1.5 hms_0.5.3
[7] munsell_0.5.0 rvest_0.3.5 viridisLite_0.3.0 colorspace_1.4-1 R6_2.4.1 rlang_0.4.6
[13] stringr_1.4.0 httr_1.4.1 highr_0.8 tools_3.6.3 webshot_0.5.2 xfun_0.14
[19] htmltools_0.4.0 ellipsis_0.3.0 yaml_2.2.1 digest_0.6.25 tibble_3.0.1 lifecycle_0.2.0
[25] crayon_1.3.4 kableExtra_1.1.0 readr_1.3.1 vctrs_0.3.0 glue_1.4.1 evaluate_0.14
[31] rmarkdown_2.1 stringi_1.4.6 compiler_3.6.3 pillar_1.4.4 scales_1.1.1 pkgconfig_2.0.3