certik / theoretical-physics

Source code of the Theoretical Physics Reference online book
https://theoretical-physics.com
MIT License
222 stars 48 forks source link

Use SVG math instead of png or mathjax #90

Open certik opened 6 years ago

certik commented 6 years ago

I switched to SVG for math in #76. All math is vectorized and looks good in all resolutions.

@asmeurer, would you mind checking some math heavy page, say this one: https://www.theoretical-physics.net/dev/elmag/elmag.html on your retina and tell me if the equations looks good now?

Also does it load relatively quickly?

asmeurer commented 6 years ago

The math looks fine on a retina display. I think MathJax would still be more accessible, so maybe it would be worth having a separate build with it.

certik commented 6 years ago

@asmeurer thanks for checking it. The MathJax is still available, e.g., the above link becomes:

https://www.theoretical-physics.net/dev/html_mathjax/elmag/elmag.html

There are some math errors which I didn't have time to fix yet, but most equations show fine. The MathJax equations look a bit bigger (about 140% larger it seems) and also they seem to be a bit nicer: the font seems "fuller" and so it looks better.

I would prefer to have just one version, so that I can ensure that one looks good and be done with it. In terms of robustness, I really like the SVG approach. I'll see if I can make the equations look a bit better, in principle I can't see why the svg version couldn't look pretty much identical to MathJax.

asmeurer commented 6 years ago

That page renders instantly on my iPhone. I think Mathjax has gotten a lot faster.

asmeurer commented 6 years ago

I'm guessing the errors are from a preamble (like \L). Supposedly preambles are supported at least in Sphinx master now. https://github.com/sphinx-doc/sphinx/pull/5230

certik commented 6 years ago

I tested on two different computers and an Android device and the MathJax version doesn't load immediately at all, it takes about 30s to fully load.

I think the SVG is the way to go, but I still need to improve the way it looks. I reported the problem upstream:

https://github.com/sphinx-doc/sphinx/issues/5301

asmeurer commented 6 years ago

Well Android is known to have poor Javascript performance, but I would expect your desktop to be comparable to mine. For me in Chrome desktop it loads in a couple of seconds. In Firefox it is a little slower but still a few seconds. Maybe the difference is my internet speed (MathJax does have to download some fonts, though I imagine they are cached).

Anyway, as I said, the main advantage of MathJax is accessibility. Try loading the pages in a text based browser and you can see the difference. You can also select the math with MathJax, right click it to make it larger or show the TeX source, and so on.

certik commented 6 years ago

Yes, I think MathJax shows latex if you use some text based browser.

I use Firefox on a pretty fast machine desktop machine. Ok, I'll leave both SVG and mathjax in there as an option.