Live data from Hacker News

Problems with math rendering on the web (2020)

danilafe.com

41–50 of 87 posts

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

#41
I have use MathML with Latex2mathml python library https://github.com/roniemartinez/latex2mathml. And is great, the fact that you can render math without a single line of java script. But at the end, only Firefox fully supports MathML, without Chrome support is kind of useless.

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

#42
This wasn’t very in-depth at all if I’m being honest.

I recently used KaTeX for server-side equation rendering with node. I think people tend to just use mathjax because it’s the more popular solution for web-based equations, but after spending a week trying to render server-side with mathjax and failing, I used KaTeX and haven’t looked back.

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

#43
post #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?

So I tried it and it seems Google knows the quadratic equation, but it didn't know how to integrate.

i.e. this worked in the Google search bar "solve 1x^2 - 2x - 3 = 0" this didn't "Integrate e^x from 0 to 1"

Wolfram Alpha did a pretty decent job with the same text string. https://www.wolframalpha.com/input/?i=Integrate+e%5Ex+from+0...

Looks like you have to go Pro to see the steps though, which is fair enough.

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

#44

> ...they use client-side rendering for static content. In my opinion, this is absurd. Rendering equations client-side doesn't seem absurd to me. All of HTML and CSS and SVG is rendered client-side, why shouldn't equations be too? I'm completely unclear why the author thinks equations specifically should be rendered server-side. Do they think HTML pages should be delivered as prerendered images or SVG's too...? Becau…

Yeah that is my take as well, and I'm rather perplexed at what the author would like server-side rendering to output given they don't like PNG and SVG either. HTML and CSS weren't designed with math in mind, and while you can force them to do the job (like KaTeX), the result is sub-optimal. It looks fine, but it requires you to transmit orders of magnitude more data, which isn't very suitable to accessibility software (well the HTML/CSS part that is - it also includes a MathML representation which is more screen-reader friendly).

I definitely agree that is crummy for pages to display the markup first, then swap it out with rendered content later. Does anyone know why common libraries do it this way? Web development isn't my strong point, but I thought it was pretty easy to make the browser run some javascript before it renders the page.

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

#46
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/

I agree. There mainly 3 options to render math

1- You either use a JS library (MAthJax) 2- Use PNGs or vector graphics (there are tools for that) 3- Use MthML which only works well in Firefox.

Clearly fixing the issue in #3 brings the most benefits.

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

#48
post #10
post #6

Earlier quoted context omitted.

given the origin of the web at cern, it's actually surprising that it didn't include LaTeX from day 1.

The web would be so pretty if “HTML” was actually hyperlinked TeX.

I dunno about that.. imagine npm, but with millions of one line TeX packages.

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

#49
post #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 somethi…

MathJax can also (apparently) render MathML on Chrome.

Maybe the answer is:

Write maths notation on your site with MathML. (You'd probably want to preprocess LaTeX notation into MathML some way, because MathML isn't fun to write by hand in the same way that septic tanks aren't fun to unblock by hand.) This will be displayed natively in Safari/Firefox, and be accessible to screen readers (apparently.. I don't use one so don't know what it's like in practice).

Serve MathJax to Chrome users so they can see your maths.

?

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

#50
The state of maths on the web, as someone who uses a lot of maths on their website[1] is to recognise that loading times on the web shouldn't exist, and you should just turn your formulae into images that you load using `loading="lazy"`. And of course, to make sure they fit any resolution: generate SVG images.

And no, MathML is irrelevant: you don't care about MathML, and your users don't care about MathML: all you care about is that users can read your formulae, and all your users care about is that they see decent-looking maths. As much as I like the idea of MathML, there is simply no reason to ever use it. Nothing is mining the web for maths, and semantic markup for maths buys you nothing.

You have a build system (because your content is generated from markdown or the like. No one who wants to deploy a real site writes pure HTML in 2021), make that generate SVG images by literally just running LaTeX during your build, to replace all your maths with SVG code instead. Because why would you even bother with MathJax or KaTeX, they put the burden on your users, which is ridiculous: you're building your content already, just build static content for your formulae)

And sure, does your site have maybe 10 formulae? By all means, use MathJax or KaTeX. But if it relies on maths, generate your graphics offline using actual LaTeX (and this is trivial using github actions[3]) and use elements that point to those SVG images.

(I run my maths through xelatex, then losslessly convert the resulting PDF to SVG by first cropping the PDF, then running pdf2svg[2]. Is that a lot of work? No, it is not. It's a one-time setup and it simply runs whenever content gets updated. It's about as no-effort as it gets)

[1] https://pomax.github.io/bezierinfo

[2] https://github.com/Pomax/BezierInfo-2/blob/master/src/build/...

[3] https://github.com/Pomax/BezierInfo-2/blob/master/.github/wo...

Post reply on HN