rstudio / gt

Easily generate information-rich, publication-quality tables from R
https://gt.rstudio.com
Other
1.99k stars 202 forks source link

Math rendering with Quarto and html #1822

Open kelliemac opened 1 month ago

kelliemac commented 1 month ago

Prework

Description

Math equations in gt headings and subheading are not displaying properly when rendering qmd files to html.

Reproducible example

The following is in a .qmd file:

---
output: html
html-table-processing: none
---

```{r}
library(gt)
library(tidyverse)

head(mtcars) |>
  gt() |>
  tab_header(md('**mtcars** dataset'),
             md('Testing a math formula: $e^{i \\pi}+1 = 0$'))

## Expected result

The math formula $e^{i \\pi}+1 = 0$ should display nicely (LaTeX-style) in the table subheading. When running the code interactively in RStudio everything looks good in the viewer, but when rendering the .qmd file to .html it does not work.

Screenshot from RStudio viewer:

<img width="576" alt="Screenshot 2024-08-12 at 12 40 38 PM" src="https://github.com/user-attachments/assets/73715774-3247-408b-9100-a48c39727cbf">

Screenshot from rendered html:

<img width="619" alt="Screenshot 2024-08-12 at 12 41 26 PM" src="https://github.com/user-attachments/assets/d5554871-a820-4a05-8dfd-901e352b63fe">

## Session info

R version 4.4.0 (2024-04-24) Platform: aarch64-apple-darwin20 Running under: macOS Sonoma 14.5

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.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

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: America/Los_Angeles tzcode source: internal

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

other attached packages: [1] lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4
[5] purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
[9] ggplot2_3.5.1 tidyverse_2.0.0 gt_0.11.0

loaded via a namespace (and not attached): [1] katex_1.4.1 jsonlite_1.8.8 gtable_0.3.5
[4] compiler_4.4.0 Rcpp_1.0.13 tidyselect_1.2.1 [7] xml2_1.3.6 scales_1.3.0 fastmap_1.2.0
[10] R6_2.5.1 commonmark_1.9.1 generics_0.1.3
[13] curl_5.2.1 knitr_1.48 munsell_0.5.1
[16] pillar_1.9.0 tzdb_0.4.0 rlang_1.1.4
[19] V8_4.4.2 utf8_1.2.4 stringi_1.8.4
[22] xfun_0.46 sass_0.4.9 timechange_0.3.0 [25] cli_3.6.3 withr_3.0.1 magrittr_2.0.3
[28] digest_0.6.36 grid_4.4.0 rstudioapi_0.16.0 [31] markdown_1.13 hms_1.1.3 lifecycle_1.0.4
[34] vctrs_0.6.5 glue_1.7.0 fansi_1.0.6
[37] colorspace_2.1-1 tools_4.4.0 pkgconfig_2.0.3
[40] htmltools_0.5.8.1



My Quarto version is 1.5.56 (from running `quarto --version` in the Terminal) and my RStudio version is 2024.04.0+735.
olivroy commented 3 weeks ago

Thanks for the report!

It works correctly for me if I remove html-table-disable-processing: none from the front matter

https://quarto.org/docs/authoring/tables.html#disabling-quarto-table-processing

---
format: html
---

```{r}
library(gt)
library(tidyverse)

head(mtcars) |>
  gt() |>
  tab_header(md('**mtcars** dataset'),
             md('Testing a math formula: $e^{i \\pi}+1 = 0$'))

Since you may need to disable processing for some tables, but not for others, I suggest you use it as a chunk option. 

Or `tab_options(quarto.disable_processing = TRUE)`

![image](https://github.com/user-attachments/assets/ee2ac86a-47c4-4057-9ce6-a337f37abe7c)

i.e.

````qmd
---
format: html
---

```{r}
library(gt)
library(tidyverse)

head(mtcars) |>
  gt() |>
  tab_header(md('**mtcars** dataset'),
             md('Testing a math formula: $e^{i \\pi}+1 = 0$'))
#| html-table-processing: none
gt(mtcars)