Live data from Hacker News

Problems with math rendering on the web (2020)

danilafe.com

31–40 of 87 posts

Re: Problems with math rendering on the web (2020)

#31
The "server-side rendering" aspect of KaTeX is (and always has been, as far as I'm aware) front-and-centre on their landing page [1]. It allows you to input LaTeX and output HTML ready for inclusion server-side - the only thing this HTML needs to support it is the KaTeX CSS. This is very easy to do if your web server or static site generator is running on Node, and only a bit more difficult if it's running on something else (and therefore needs to shell out to Node). So if the author wants a good solution to server-side rendering, just look a little more at KaTeX.

On the flip side, I have reverted some of my server-side rendering of mathematics back to client-side rendering, because of considerations like webpage size. On mathematics-heavy pages, I found that pages that would otherwise be about 50KB in size got inflated up to about 1MB after server-side rendering all of the mathematics. After compression the difference was more like 70K, but this difference is the entire size of the (compressed) KaTeX library. I think it is completely reasonable to only transmit LaTeX markup over the wire, and have a client-side library take care of the presentation (as we do for HTML, SVG, ...).

I've also investigated MathML, but cross-browser support is terrible and has been for years. You also still get the size explosion problem, because LaTeX markup is just so much more compact than whatever MathML soup is equivalent.

[1]: https://katex.org/

Re: Problems with math rendering on the web (2020)

#32
The author treats SVG as equivalent to PNG and complains that

> Images are impossible to use with copy/paste

You can select and copy text in an SVG[0]

> Images are not nearly as responsive, and are difficult to style. Line breaking, fonts, and even colors are difficult to change when using images

This is partially true, but it's not difficult to inherit your page's text colour for SVGs.

> Images are completely opaque to users in need of screen readers

Not true of SVG's with text - and in fact SVGs can have alt text which could in some cases by much more accessible to screen reader users that the raw equations[1].

[0] https://www.w3.org/TR/SVG/text.html

[1] https://css-tricks.com/accessible-svgs/

Re: Problems with math rendering on the web (2020)

#33

I implemented a TeX engine in WebAssembly so you really can run TeX in the browser. You can see a demo of this at https://tex.rossprogram.org/ and at https://github.com/kisonecat/web2js you can find a Pascal compiler that targets WebAssembly which can compile Knuth's TeX. Interesting primitives like \directjs are also implemented, so you can execute javascript from inside TeX. The rendering is handled with https://gi…

Sorry to sidetrack, but I'm also interested in implementing a Tex engine (in another language though). Any suggestions on how to learn how an engine works?

You could also check the implementation in Rust - fully "oxidized" fork[1] of Tectonic.

[1] https://github.com/crlf0710/tectonic/

Re: Problems with math rendering on the web (2020)

#34
I've had a similar argument for years. Before there was CSS to do rounded corners on boxes, it was typical to do a hack with JS building up the rounded corners pixel by pixel. On the project I was working on, since all the rounded boxes were generated by the same component, I eliminated the client-side JS for a statically-generated set of output that did the same thing. It rendered noticeably faster. And I was overridden by the other team members who apparently felt it was better to manage this through having every single client render the rounded corners on their underpowered computers (this was for a company intranet and from the discussions about system requirements, most of the machines were running old versions of Windows on old PCs) instead of doing it once and for all on the server.

Re: Problems with math rendering on the web (2020)

#36
post #30
post #12

The next generation is MathML. It's already implemented in Firefox, Chrome support is coming. https://www.w3.org/Math/

Firefox has supported MathML for a very long time. And I think chrome had an experimental version it for a while then removed it. I wouldn't hold my breath waiting for universal browser support.

Igalia picked up the Chromium development, they actually have it in an amazingly good state at this point. This image compares rendering from Chromium with their patches, Safari, and Firefox (in that order) https://mathml.igalia.com/img/mathml-example-gamma.png

That being said I wouldn't hold my breath it'll ship this year either since there is still some work in LayoutNG to be completed at minimum but maybe 2022 we'll all be amazed it finally happened.

Re: Problems with math rendering on the web (2020)

#37
post #17

This article is kinda weird--it mentions MathML in passing and then spends a large amount of time on MathJax etc. The correct fix is to have MathML natively on all browsers (no JS)--and Igalia is working on that: https://mathml.igalia.com/faq/

The worst part about the MathML debacle is that it actually used to work in Chrome a decade ago or so, but then it got removed because there was no real support for maintaining it within the Chrome team.

Re: Problems with math rendering on the web (2020)

#38
post #37
post #17

This article is kinda weird--it mentions MathML in passing and then spends a large amount of time on MathJax etc. The correct fix is to have MathML natively on all browsers (no JS)--and Igalia is working on that: https://mathml.igalia.com/faq/

The worst part about the MathML debacle is that it actually used to work in Chrome a decade ago or so, but then it got removed because there was no real support for maintaining it within the Chrome team.

Yes, it's been almost eight years since Chrome removed their MathML support. The rationale at the time was unspecified security and performance problems:

https://www.cnet.com/news/google-subtracts-mathml-from-chrom...

A developer who worked on it, David Barton, had this to say in 2015:

> I volunteered for a year and got MathML working in Chrome 24, but Google turned it off in Chrome 25 because I couldn't afford to keep maintaining it for free. (Yes, grumble. Donate your nickels to Google.) There was a security bug, but Google had a fix, which has since been landed in WebKit and the Safari browser, for instance. No one on the Chrome/Blink team cared about MathML, so they preferred removing it to maintaining it. They tell people that a library like MathJax is good enough, but it isn't without native browser support for MathML - it's too slow for many use cases, it doesn't integrate well enough with CSS, etc. (the MathJax team agrees with all this). Presumably as digital textbooks gain in popularity, Google will rethink their position, or schools will have to use a different browser than Chrome (Firefox and Safari would both work). In the meantime, Google has no one working on MathML in Chrome at all, even part-time. Go figure. (And no, I would not work on it again.)

https://www.quora.com/Why-did-Chrome-drop-MathML-support?sha...

There's also a chromium bug report from 2009:

https://bugs.chromium.org/p/chromium/issues/detail?id=6606

and a WebKit bug from 2005:

https://bugs.webkit.org/show_bug.cgi?id=3251

Re: Problems with math rendering on the web (2020)

#40
post #8

Ha! I used to get pretty pissed-off when I was doing my online math homework, only to find that you couldn't copy/paste the equations into Google. I always thought it was a prevention mechanism, but I guess it was a matter of the technology not being ready yet.

> copy/paste the equations into Google.

Just out of curiosity, why would you want to copy/paste an equation into the Google search bar? Can it solve it?

Post reply on HN