radiasoft / sirepo

Sirepo is a framework for scientific cloud computing. Try it out!
https://sirepo.com
Apache License 2.0
65 stars 32 forks source link

katex in svg labels #3384

Open e-carlin opened 3 years ago

e-carlin commented 3 years ago

Investigate using katex for rendering in svg labels.

e-carlin commented 3 years ago

Maybe look into https://university.webflow.com/integrations/mathjax. The problem is making sure that the labels are present in the downloadable png

moellep commented 3 years ago

It does look like MathJax does this well out-of-the box: https://viereck.ch/latex-to-svg/ I tried a few of the more complicated formulas we are using with KaTeX, and it rendered the same, except in svg.

moellep commented 2 years ago

I found the html2canvas library does both html and svg and can render KaTeX math as well. And it is as easy as supplying the element and receiving a canvas:

    html2canvas(el).then(canvas => {
        ....
    });
moellep commented 3 months ago

This issue is important for plot improvements. I'll take a look. I found the png download was displaying the 2 different renderings of the label, so the code below hides the katex-html version.

         html2canvas(el, {
             scale: outputHeight / $(el).height(),
             backgroundColor: '#ffffff',
             ignoreElements: (element) => {
                 return element.matches("path.pointer.axis") || element.classList.contains('katex-html');
             }
         }).

Also, the global css doesn't make it into the foreignObject, so the label css needs to get added to the svg within a style tag.

moellep commented 1 month ago

This was implemented for parameterPlots with 59b71d0, but should be expanded to include plot3d and heatmaps.