vincentarelbundock / tinytable

Simple and Customizable Tables in `R`
https://vincentarelbundock.github.io/tinytable
GNU General Public License v3.0
196 stars 16 forks source link

Typst math: MiTeX support #345

Closed kazuyanagimoto closed 4 days ago

kazuyanagimoto commented 5 days ago

Hi @vincentarelbundock,

Related to #311, I found a typst package to convert LaTeX math syntax into Typst math syntax, called MiTeX.

I did a simple experiment and achieved the same math output in Typst and other formats.

---
format:
  html: default
  pdf: default
  typst:
    include-in-header:
      - text: '#import "@preview/mitex:0.2.4": *'
execute:
  echo: false
---

```{r}
library(tinytable)

theme_mitex <- function(x, ...) {
    fn <- function(table) {
        if (isTRUE(table@output == "typst")) {
          table@table_string <- gsub("\\$(.*?)\\$", "#mitex(`\\1`)", table@table_string)
        }
        return(table)
    }
    x <- style_tt(x, finalize = fn)
    x <- theme_tt(x, theme = "default")
    return(x)
}

options(tinytable_html_mathjax = TRUE)
options(tinytable_tt_theme = theme_mitex)
data.frame(Math = c("$\\alpha$", "$a_{it}$", "$e^{i\\pi} + 1 = 0$")) |>
  tt()


I don't know how complex it could be, but it would be a nice feature if it supported the MiTeX package for Typst, as the MathJax package for HTML.
vincentarelbundock commented 5 days ago

This is cool. I dont we need a global option if there's a theme, because we can set themes in global options themselves.

Also, the theme should probably not set default.

I wonder if this is a popular enough feature to warrant inclusion in the main package. Seems cool but a bit niche.

Maybe there can be an archive.of different themes on the website?

kazuyanagimoto commented 4 days ago

I understand. MiTeX may not yet be a mature package. It would be great to introduce it as a theme on the website.

I want to note that compatibility between LaTeX and Typst is essential to me. Since Typst is too young, writing a paper in it is risky. Quarto allows us to use Typst to write and generate a LaTeX source when necessary.

vincentarelbundock commented 4 days ago

Thanks! I added it to a "User-written" section of the themes vignette.