
Fast Math Rendering on the Web - bollu
http://bollu.github.io/#blazing-fast-math-rendering-on-the-web
======
mbeex
>I can write math that loads instantly on your browser, using no MathJax,
KaTeX or any client side processing

You can render math statically with KaTeX and some standard static site-
generator too. Here an example from my blog (using Pelican):

[https://depot.traits.de/pages/2020/02/21-markdown-
example.ht...](https://depot.traits.de/pages/2020/02/21-markdown-
example.html#mathematics)

------
oefrha
The rendering reminds me of typeset math from the 60s. Not a fan.

Instead of trying to come up with a compromise on rendering, a better idea
might be simply not rendering your entire blog on one page... A plain HTML
page with svg images weighing in at a shocking 2.6MB is not gonna load
“instantly” anyhow. You can keep the source in a single markdown file if you
wish, but there’s no reason you can’t split up the posts during processing,
and that’s a much easier technical problem than this math rendering
compromise.

~~~
bollu
I explained why I don't want to do this, right?

> Far more importantly, it provides spatio-temporal locality. I add things in
> chronological order to tbe blog, as I learn thing. If I need to recall
> something I had studied, go to that location in the blog based on a sense of
> when. > When I do get to a location I want, the scrollbar gives me a sense
> of where I am in the file. this is important to me, since it hepls me reason
> spatially about what i know and what I've learnt. It's someting I love about
> books, and deeply miss when navigtaing the web.I'm determined to keep this
> spatio-temporal locality on my little slice of the internet.

And:

> I need a single file to edit, so I can rapidly jot down new ideas. This is
> the essence of why I'm able to log most of what I study: because it's
> seamless.

I really wish I _could_ get used to the usual way of doing things, but it just
doesn't sit right with me, unfortunately.

~~~
oefrha
I thought those are all about your single markdown source file, not the HTML
output. Still, this may work well when the website is sitting on your local
disk, but probably not so well when it’s served remotely, especially not when
it grows to say 10MB.

------
Fudgel
Looks like chrome are working on a MathML implementation, so you might be able
to use that at some point since it already works in Firefox.

[https://mathml.igalia.com/](https://mathml.igalia.com/)
[https://bugs.chromium.org/p/chromium/issues/detail?id=6606](https://bugs.chromium.org/p/chromium/issues/detail?id=6606)

[https://developer.mozilla.org/en-
US/docs/Web/MathML](https://developer.mozilla.org/en-US/docs/Web/MathML)

~~~
xmmrm
Specifically, MathML Core: [https://mathml-refresh.github.io/mathml-
core/](https://mathml-refresh.github.io/mathml-core/)

~~~
dvfjsdhgfv
For the time being, Firefox and Webkit are the only serious options for
MathML.

------
anderskaseorg
Obviously you should use whatever language you want on your projects, but in
case you’re interested:

> unfortunately, asking rust to treat UTF-8 string as a "ball of bytes" is
> hard, when it's stupidly easy with C.

String::as_bytes seems pretty easy, and there are byte literals b'?' of type
u8 and b"???" of type [u8]. You can avoid interacting with the UTF-8 types at
all if you don’t want to.

> Plus, I wanted to use arena-style-allocation where I make huge allocations
> in one go and then don't think about memory, something that I don't have
> control over in Rust.

Perhaps the bumpalo and typed-arena crates would interest you.

[https://docs.rs/bumpalo/](https://docs.rs/bumpalo/) [https://docs.rs/typed-
arena/](https://docs.rs/typed-arena/)

~~~
kevincox
Unfortunately `&[u8]` is missing a lot of convenience methods that are on
`&str`. It is getting better over time but I have definitely encounter the
problem before where I tried to switch some string-based code to byte-based
and was disappointed by the missing functionality.

~~~
llogiq
Then perhaps the bstr crate
([https://docs.rs/bstr/0.2.12/bstr](https://docs.rs/bstr/0.2.12/bstr)) might
be what you want.

------
londons_explore
That page is kinda laggy to load on my machine...

Specifically Chrome on Linux the GPU tile rendering is far slower than I can
scroll, perhaps because some text blocks are large enough that the out-of-tile
culling leaves too much work for each tile rendered?

Perhaps the custom font has something that really slows down rendering or
something?

~~~
contravariant
The more likely cause is that (for some reason) this entire blog is one single
html page.

Which explains why they needed a better math rendering solution, although it
raises numerous other questions.

~~~
londons_explore
Just because the page is huge shouldn't _theoretically_ make the top bit of
the page load slowly... After all, the number of words on the screen for my
GPU to render isn't higher just because the scrollbar is a mile long...

Practically, if the draw culling algorithm is bad, rendering will get slow,
which looks like it might be happening here.

------
Koshkin
I like Knuth’s attempt at math typesetting much more, and I think that we’d be
in a better place right now if all web browsers supported Plain TeX out of the
box.

~~~
krasjet
I tried to partially bring the ecosystem of TeX to the Web via SVG[1] a while
ago, but I really hope there is an alternative to TeX for the Web to avoid the
hassle of conversion. Matthew Butterick's Pollen[2] seems to be a good start,
but currently the ecosystem is too small. It needs some more attention.

[1]: [https://krasjet.com/voice/karasu/](https://krasjet.com/voice/karasu/)

[2]: [https://docs.racket-lang.org/pollen/](https://docs.racket-
lang.org/pollen/)

------
kekeblom
Why don’t these things just generate svg and serve that embedded in the html?

