Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probably a problem upstream or elsewhere: incorrect rendering of MathML in Chromium-based web browsers #3

Closed
jmcastagnetto opened this issue Jul 13, 2021 · 6 comments

Comments

@jmcastagnetto
Copy link

The output of the code I have in the gist: https://gist.github.com/jmcastagnetto/e1f985c210b4b0251d8665f484d751b8 renders OK in Firefox, when using MathML for complex, multiline formulas (HTML doesn't work with those, for some reason), but it doesn't work with Chromium-based browsers. At leas under Ubuntu Linux 20.04LTS.

Attached some screenshots showing the HTML output rendered Firefox, Chromium and Brave browsers.

katex-firefox-browser-2021 07 12-18_59_12

katex-chromium-browser-2021 07 12-18_53_51

katex-brave-browser-2021 07 12-18_49_33

@jeroen
Copy link
Member

jeroen commented Jul 13, 2021

I think chrome does not claim to support mathml? https://caniuse.com/mathml
Why can't we use html?

@jmcastagnetto
Copy link
Author

The equations 6, 7 and 8, do not render in any of the three browsers I tried when using katex_html(). That is the first thing I tried.

Just for completeness, I redid again the tests, changing to html rendering:

A bit more complex latex environment do not render

The following html does not work in Firefox, Brave or Chromium browsers.

    ## A bit more complex latex environment do not render
    
    The following **html** does not work in Firefox, Brave or Chromium browsers.
    
    ```{r}
    tex6 <- "f(n) = \\begin{cases} \\frac{n}{2}, & \\text{if } n\\text{ is even} \\\\ 3n+1, & \\text{if } n\\text{ is odd} \\end{cases}"
    eq6 <- katex_html(tex6, include_css = FALSE)
    ```
    
    Equation 6: `r eq6`
    
    
    ```{r}
    tex7 <- "\\begin{aligned}
    \\dot{x} & = \\sigma(y-x) \\\\ 
    \\dot{y} & = \\rho x - y - xz \\\\ 
    \\dot{z} & = -\\beta z + xy 
    \\end{aligned}"
    eq7 <- katex_html(tex7, include_css = FALSE)
    ```
    
    Equation 7: `r eq7`
    
    ```{r}
    tex8 <- "\\begin{pmatrix} 
    a_{11} & a_{12} & a_{13}\\\\ 
    a_{21} & a_{22} & a_{23}\\\\ 
    a_{31} & a_{32} & a_{33} 
    \\end{pmatrix}"
    eq8 <- katex_html(tex8, include_css = FALSE)
    ```
    
    Equation 8: `r eq8`
    

The HTML es generated OK (AFAICT) but for some reason it does not render, as is shown in the screenshots below (using Brave, but the same happens with RStudio viewer and Firefox):

katex-brave-using-html-source-2021-07-13_08-57-45

katex-brave-using-html-rendering-2021-07-13_08-57-45

@jeroen
Copy link
Member

jeroen commented Jul 13, 2021

I think the reason that it doesn't show up is because you are using single-quote inline for printing the math, maybe the large equations just do not fit inline.

You can print the math directly in displaymode by wrapping the html in htmltools::HTML() or equivalently, adding a class "html" to the string. For example try this:

```{r}
tex6 <- "f(n) = \\begin{cases} \\frac{n}{2}, & \\text{if } n\\text{ is even} \\\\ 3n+1, & \\text{if } n\\text{ is odd} \\end{cases}"
htmltools::HTML(katex_html(tex6))
```

Your updated Rmarkdown file, which works for me: https://gist.github.com/jeroen/3209a68bc7d1b1562e8234b154d7ab6b

@jeroen
Copy link
Member

jeroen commented Jul 13, 2021

I've added your these as a test vignette: https://ropensci.r-universe.dev/ui#view:katex/katex-tests.html

@jmcastagnetto
Copy link
Author

Very cool, and you are correct, wrapping the output using {htmltools} does work, and also the solution of assigning explicitly the output class (what you put in the gist). Both work even with some other gnarly latex equations I had tested.

@jmcastagnetto
Copy link
Author

jmcastagnetto commented Jul 13, 2021

I just reinstalled from the rOpenSci dev repo, and with your commit 44f0f45 which now does the class assignment explicitly, it all works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants