rednotebook icon indicating copy to clipboard operation
rednotebook copied to clipboard

Use locally installed MathJax package when available

Open cameel opened this issue 1 year ago • 5 comments

I recently noticed that on my machine rednotebook tries to connect to cdn.jsdelivr.net every time it starts. Apparently to download mathjax.

This seems wasteful and will make math rendering impossible without an Internet connection in an application that otherwise is perfectly usable offline. Some distributions, like Arch Linux ship a mathjax package in their official repositories. Would it be possible to make rednotebook use that when available and only if not fall back to downloading it? Even better would be a setup.py flag to make rednotebook always use a local installation at a given path and never download anything.

I found this https://github.com/jendrikseipp/rednotebook/issues/264#issuecomment-288039970, which says that the reason for not using a local copy was a concern about the package size. It seems that relying on distros to provide it would be a perfect solution here.

cameel avatar Feb 05 '23 17:02 cameel

Allowing to use a local MathJax copy via distro packages is a nice idea and I'm happy to review a PR for this. Some things to keep in mind while working on this issue:

  • The code needs a list of paths where the MathJax files are put by the most common distros.
  • The changelog needs a note for packagers which informs them about this list.
  • Journals exported to HTML should always use remote MathJax to allow moving the HTML file between computers.

jendrikseipp avatar Feb 05 '23 17:02 jendrikseipp

The code needs a list of paths where the MathJax files are put by the most common distros.

I did some initial research into that. Here's what I found in some common distros:

Distro Package Version Installation path tex-svg.js location
Arch Linux mathjax 3.2.2 /usr/share/mathjax/ tex-svg.js
Ubuntu libjs-mathjax in Lunar 2.7.9 /usr/share/javascript/mathjax/ missing
Debian libjs-mathjax in Sid 2.7.9 /usr/share/javascript/mathjax/ missing
Fedora mathjax 2.7.4 /usr/share/javascript/mathjax/ missing
OpenSUSE mathjax in Factory 2.6.0 /usr/share/javascript/mathjax/ missing

So, looks like there's a problem. Many distros still ship Mathjax 2.x. Perhaps it has something equivalent to tex-svg.js (I see a file called TeX-AMS_SVG.js for example) but I guess it might not be fully compatible.

In that case I think if would be best if it was possible to just specify the location of tex-svg.js during rednotebook setup and not try to detect it. Then the packager could use it if available in the distro and if not, maybe even download and include just that one file (depending on how strict the distro is on that). For my own use case, this would be enough (since I'm on Arch Linux anyway) and it would still be flexible enough to accommodate other cases.

cameel avatar Feb 13 '23 01:02 cameel

Thanks for doing the research! Your proposed solution could work, but I have my doubt that it will be used by lots of people and it has the drawback that we need to test two different MathJax modes: online and offline.

Maybe we should think about bundling it again. How much space would a bundled MathJax need? How about the competitor KaTex? Are they both equally easy to bundle? Also, which of them can be fully embedded into journals exported as HTML?

jendrikseipp avatar Feb 13 '23 08:02 jendrikseipp

I have my doubt that it will be used by lots of people and it has the drawback that we need to test two different MathJax modes: online and offline.

Yeah, you're probably right on that. I think Arch might adopt it for the official package if asked to but other distros would very likely ignore it or be at least reluctant. Not even saying anything about other platforms.

How much space would a bundled MathJax need?

On my system the whole mathjax package is 23 MB. But tex-svg.js on its own is 2 MB.

Maybe we should think about bundling it again.

If not at setup time then I think this would be my preferred solution.

But just wanted to note that you could also cache in user's home dir after the first download. It would be worse for me because rednotebook would still have to hit the servers at least once but IMO better than nothing.

How about the competitor KaTex? Are they both equally easy to bundle? Also, which of them can be fully embedded into journals exported as HTML?

I don't know the answers right away but, if that seems like a better solution to you, I could check when I have a bit of time.

cameel avatar Feb 13 '23 12:02 cameel

It's probably wise to do this small research before deciding on a solution, yes. Of course this is not urgent.

jendrikseipp avatar Feb 13 '23 12:02 jendrikseipp