No MathJax display in Sage 10.3.beta notebooks when offline

305 views
Skip to first unread message

Eric Gourgoulhon

unread,
Feb 14, 2024, 7:47:53 AM2/14/24
to sage-devel
Hi,

While working on a Sage 10.3.beta  notebook in a train without any internet connection, I've noticed that there is no LaTeX rendering via MathJax, neither in the markdown cells nor in the output cells within the scope of  %display latex. There is no such issue with Sage 10.2 and I've opened
for this. 

Apparently, the problem arises with Ubuntu 22.04, but not with macOS. It would be nice to have more tests, possibly on various OS, to identify the issue. Thanks for your feedback!

Eric.

Dima Pasechnik

unread,
Feb 14, 2024, 8:13:04 AM2/14/24
to sage-...@googlegroups.com
For off the grid working with MathJax, you need it locally installed. It might be that by default it doesn't happen, and MathJax is dynamically loaded from the net.

Eric Gourgoulhon

unread,
Feb 14, 2024, 8:18:20 AM2/14/24
to sage-devel
Le mercredi 14 février 2024 à 14:13:04 UTC+1, Dima Pasechnik a écrit :
For off the grid working with MathJax, you need it locally installed. It might be that by default it doesn't happen, and MathJax is dynamically loaded from the net.

The Ubuntu packages libjs-mathjax and fonts-mathjax are installed on my system. Moreover, on the same computer, MathJax display works well when offline with Sage 10.2.


Eric Gourgoulhon

unread,
Feb 14, 2024, 8:51:01 AM2/14/24
to sage-devel
Le mercredi 14 février 2024 à 14:18:20 UTC+1, Eric Gourgoulhon a écrit :
Le mercredi 14 février 2024 à 14:13:04 UTC+1, Dima Pasechnik a écrit :
For off the grid working with MathJax, you need it locally installed. It might be that by default it doesn't happen, and MathJax is dynamically loaded from the net.

The Ubuntu packages libjs-mathjax and fonts-mathjax are installed on my system.

More precisely, the Ubuntu 22.04's libjs-mathjax is version 2.7.9.
When the computer is online and I right-click on "About MathJax" in a displayed cell, I get "MathJax v2.7.7", which is not the system version...
What is puzzling is that MathJax 3.2.0 seems to have been successfully installed in the Sage tree during the install of Sage 10.3.beta*, cf. the attached log (SAGE_ROOT/logs/pkgs/mathjax-3.2.0.log), but apparently it is not used in the notebook.


mathjax-3.2.0.log

Eric Gourgoulhon

unread,
Feb 14, 2024, 8:55:41 AM2/14/24
to sage-devel
Le mercredi 14 février 2024 à 14:51:01 UTC+1, Eric Gourgoulhon a écrit :
What is puzzling is that MathJax 3.2.0 seems to have been successfully installed in the Sage tree during the install of Sage 10.3.beta*, cf. the attached log (SAGE_ROOT/logs/pkgs/mathjax-3.2.0.log),

Well, maybe not: the log contains:

Package 'mathjax' is currently not installed
No legacy uninstaller found for 'mathjax'; nothing to do


Eric Gourgoulhon

unread,
Feb 14, 2024, 9:09:27 AM2/14/24
to sage-devel
Le mercredi 14 février 2024 à 14:51:01 UTC+1, Eric Gourgoulhon a écrit :

More precisely, the Ubuntu 22.04's libjs-mathjax is version 2.7.9.
When the computer is online and I right-click on "About MathJax" in a displayed cell, I get "MathJax v2.7.7", which is not the system version...

If I do the same thing when the computer is offline with Sage 10.2, I get "MathJax v2.7.9", which is the system version.
The partial conclusion is thus:

- Sage 10.2 uses Ubuntu 22.04's MathJax (v2.7.9), so there is no issue when the computer is offline.
- for some reason, Sage 10.3.beta* refuses to use Ubuntu 22.04's MathJax and the MathJax 3.2.0 shipped with Sage is not installed/used either. 
  

Kwankyu Lee

unread,
Feb 14, 2024, 9:39:05 AM2/14/24
to sage-devel
The log below this says mathjax 3.2.0 was installed. 

Dima Pasechnik

unread,
Feb 14, 2024, 9:47:33 AM2/14/24
to sage-...@googlegroups.com
That's why we should just stop shipping jupyterlab, and instead use one offered by the OS or some other standard Jupyter way.

Here we are trying to solve already solved problems, what's the point of it?

Eric Gourgoulhon

unread,
Feb 14, 2024, 9:49:45 AM2/14/24
to sage-devel
Indeed, but the indicated CPU time looks very short.
FWIW, here is the output of
find . -name "*mathjax*"
in my Sage 10.3.beta8 root tree:

./build/pkgs/mathjax
./build/pkgs/jupyterlab_mathjax2
./src/doc/en/reference/spkg/mathjax.rst
./src/doc/en/reference/spkg/jupyterlab_mathjax2.rst
./logs/pkgs/jupyterlab_mathjax2-4.0.0.log
./logs/pkgs/mathjax-3.2.0.log
./upstream/mathjax-3.2.0.tar.gz
./upstream/jupyterlab_mathjax2-4.0.0-py3-none-any.whl
./local/var/lib/sage/venv-python3.10/var/lib/sage/installed/jupyterlab_mathjax2-4.0.0
./local/var/lib/sage/venv-python3.10/var/lib/sage/wheels/jupyterlab_mathjax2-4.0.0-py3-none-any.whl
./local/var/lib/sage/venv-python3.10/var/lib/sage/scripts/jupyterlab_mathjax2
./local/var/lib/sage/venv-python3.10/share/jupyter/lab/schemas/@jupyterlab/mathjax-extension
./local/var/lib/sage/venv-python3.10/share/jupyter/nbconvert/templates/base/mathjax.html.j2
./local/var/lib/sage/venv-python3.10/share/jupyter/labextensions/@jupyterlab/mathjax2-extension
./local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/jupyterlab/schemas/@jupyterlab/mathjax-extension
./local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/jupyterlab_mathjax2-4.0.0.dist-info
./local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/jupyterlab_mathjax2
./local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sphinx/ext/__pycache__/mathjax.cpython-310.pyc
./local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/sphinx/ext/mathjax.py
./local/var/lib/sage/installed/mathjax-3.2.0
./local/share/mathjax
./local/share/mathjax/mathjax
./local/share/giac/doc/mathjax.sty
./local/share/doc/sage/doctrees/en/reference/spkg/jupyterlab_mathjax2.doctree
./local/share/doc/sage/doctrees/en/reference/spkg/mathjax.doctree
./local/share/doc/sage/html/en/reference/spkg/_sources/mathjax.rst.txt
./local/share/doc/sage/html/en/reference/spkg/_sources/jupyterlab_mathjax2.rst.txt
./local/share/doc/sage/html/en/reference/spkg/jupyterlab_mathjax2.html
./local/share/doc/sage/html/en/reference/spkg/mathjax.html

and that of find . -name "*mathjax-3*" :

./logs/pkgs/mathjax-3.2.0.log
./upstream/mathjax-3.2.0.tar.gz
./local/var/lib/sage/installed/mathjax-3.2.0

Eric Gourgoulhon

unread,
Feb 14, 2024, 11:04:30 AM2/14/24
to sage-devel
Le mercredi 14 février 2024 à 15:09:27 UTC+1, Eric Gourgoulhon a écrit :
The partial conclusion is thus:

- Sage 10.2 uses Ubuntu 22.04's MathJax (v2.7.9), so there is no issue when the computer is offline.
- for some reason, Sage 10.3.beta* refuses to use Ubuntu 22.04's MathJax and the MathJax 3.2.0 shipped with Sage is not installed/used either. 
 

Sage's MathJax 3.2.0 is definitely installed in my Sage 10.3.beta8 root tree for if I look at the locally generated reference manual (i.e. local/share/doc/sage/html/en/reference/index.html), the math formulas there are rendered by MathJax 3.2.0 (as one can see by right-clicking on them and selecting "About MathJax"); this works even in the offline mode.

So it appears that Sage's MathJax 3.2.0 is used for the documentation but not for Jupyter/Jupyterlab notebooks.
 

Matthias Koeppe

unread,
Feb 14, 2024, 12:21:04 PM2/14/24
to sage-devel
You  may recall that we use jupyterlab_mathjax2 because of the discussion in https://github.com/sagemath/sage/pull/36129#issuecomment-1729218062

Eric Gourgoulhon

unread,
Feb 14, 2024, 1:18:06 PM2/14/24
to sage-devel
Le mercredi 14 février 2024 à 18:21:04 UTC+1, Matthias Koeppe a écrit :
You  may recall that we use jupyterlab_mathjax2 because of the discussion in https://github.com/sagemath/sage/pull/36129#issuecomment-1729218062

Thanks for reminding me about this. Then I guess the question is: why Jupyterlab in Sage 10.3.beta8 is using MathJax 2.7.7 (available only online) and not the system's MathJax (2.7.9) ? Again, there was no such issue with Sage 10.2. 
 
 

Kwankyu Lee

unread,
Feb 14, 2024, 10:54:42 PM2/14/24
to sage-devel
I checked again on mac. Yes, jupyterlab (and notebook 7 as well) of Sage 10.3.beta8 fails in loading mathjax 2.7.7. (Before it worked because of the cache, I guess)

It seems that jupyterlab(notebook 7) only uses mathjax cdn. (As far as I know, jupyter never used system mathjax or sage mathjax). 

I guess that before notebook 7, jupyter vendored mathjax with it, but after notebook 7, jupyter only uses cdn.  Hence there is nothing to do on sage side. 

Eric Gourgoulhon

unread,
Feb 15, 2024, 4:18:06 AM2/15/24
to sage-devel
Le jeudi 15 février 2024 à 04:54:42 UTC+1, Kwankyu Lee a écrit :

I checked again on mac. Yes, jupyterlab (and notebook 7 as well) of Sage 10.3.beta8 fails in loading mathjax 2.7.7. (Before it worked because of the cache, I guess)


OK, thanks for the feedback!  Hence this is not a Ubuntu-specific issue.
 
It seems that jupyterlab(notebook 7) only uses mathjax cdn. (As far as I know, jupyter never used system mathjax or sage mathjax). 

I guess that before notebook 7, jupyter vendored mathjax with it, but after notebook 7, jupyter only uses cdn. 

This sounds a strange policy from Jupyter, since it prevents people from using notebooks offline. Are you sure about this?
 
Hence there is nothing to do on sage side. 

With the previous version of Jupyterlab shipped with Sage 10.2, the system's MathJax was used. Can't we tweak the new Jupyterlab shipped with Sage 10.3 to use the system's MathJax as well?

Dima Pasechnik

unread,
Feb 15, 2024, 5:20:27 AM2/15/24
to sage-...@googlegroups.com


On 15 February 2024 09:18:06 GMT, Eric Gourgoulhon <egourg...@gmail.com> wrote:
>Le jeudi 15 février 2024 à 04:54:42 UTC+1, Kwankyu Lee a écrit :
>
>
>I checked again on mac. Yes, jupyterlab (and notebook 7 as well) of Sage
>10.3.beta8 fails in loading mathjax 2.7.7. (Before it worked because of the
>cache, I guess)
>
>
>OK, thanks for the feedback! Hence this is not a Ubuntu-specific issue.
>
>
>It seems that jupyterlab(notebook 7) only uses mathjax cdn. (As far as I
>know, jupyter never used system mathjax or sage mathjax).
>
>I guess that before notebook 7, jupyter vendored mathjax with it, but after
>notebook 7, jupyter only uses cdn.
>
>
>This sounds a strange policy from Jupyter, since it prevents people from
>using notebooks offline. Are you sure about this?

I am sure it is configurable, just as well as you can configure delimiters used (i.e. $$ vs \(\), etc), etc.

Kwankyu Lee

unread,
Feb 15, 2024, 5:20:40 AM2/15/24
to sage-devel
With the previous version of Jupyterlab shipped with Sage 10.2, the system's MathJax was used. 
Can't we tweak the new Jupyterlab shipped with Sage 10.3 to use the system's MathJax as well?

We don't do that. Perhaps tweaking is more severe sin than sage vendoring jupyter, from Dima's viewpoint :-)  

You may ask the feature to the Jupyter project. 


Kwankyu Lee

unread,
Feb 15, 2024, 5:23:36 AM2/15/24
to sage-devel
I guess that before notebook 7, jupyter vendored mathjax with it, but after notebook 7, jupyter only uses cdn. 

This sounds a strange policy from Jupyter, since it prevents people from using notebooks offline. Are you sure about this?

No. I would be happy if it is configurable as Dima said. 

Dima Pasechnik

unread,
Feb 15, 2024, 7:16:56 AM2/15/24
to sage-...@googlegroups.com
Ideally, this should be possible to specify in the Sage's Jupyter kernel, how you want MathJax for the notebooks set up.

As this is the only (?) regular way to communicate the wishes about a class of notebooks to the Jupiter(lab) server.

Dima
>
>

Eric Gourgoulhon

unread,
Feb 15, 2024, 7:25:13 AM2/15/24
to sage-devel
Le jeudi 15 février 2024 à 11:20:40 UTC+1, Kwankyu Lee a écrit :
With the previous version of Jupyterlab shipped with Sage 10.2, the system's MathJax was used. 
Can't we tweak the new Jupyterlab shipped with Sage 10.3 to use the system's MathJax as well?

We don't do that. Perhaps tweaking is more severe sin than sage vendoring jupyter, from Dima's viewpoint :-)  

Yes of course. By "tweaking" I actually meant "configuring". 
 

Dima Pasechnik

unread,
Feb 15, 2024, 7:36:46 AM2/15/24
to sage-...@googlegroups.com
A possible solution does not involve changing Sage/Jupyter config. It's  by capturing http requests to CDN and replacing them with the local resources.

See e.g. https://discourse.jupyter.org/t/running-voila-without-internet/13823/3

where this is proposed for another MathJax-dependent project.

Eric Gourgoulhon

unread,
Feb 15, 2024, 12:30:10 PM2/15/24
to sage-devel
Le jeudi 15 février 2024 à 13:36:46 UTC+1, Dima Pasechnik a écrit :
A possible solution does not involve changing Sage/Jupyter config. It's  by capturing http requests to CDN and replacing them with the local resources.

Thank you Dima! Could you indicate how to do this? (looks quite technical to me)
 

See e.g. https://discourse.jupyter.org/t/running-voila-without-internet/13823/3

where this is proposed for another MathJax-dependent project.


I am quite surprised that Jupyter does not offer a simple way to do this... In some countries, being offline is unfortunately more common than being online. 

Matthias Koeppe

unread,
Feb 15, 2024, 12:37:31 PM2/15/24
to sage-devel
I would suggest to raise the question what the best practices for offline deployment are with the Jupyter project.

Nils Bruin

unread,
Feb 15, 2024, 4:13:56 PM2/15/24
to sage-devel
According to the jupyter notebook documentation:


it should be possible to switch jupyter from using mathjax 2 to mathjax 3 by some configuration option (no clue where those configuration options would go, and no indication is given in the tip either). I would think that if one can switch to a different mathjax by just changing a URL in the config, one should be able to point that at local resources (a "file:" URL instead) to avoid any use of https, and hence hopefully the internet.

I'd be interested in hearing if someone figures out how to do that, since on my own (system) jupyter mathjax is severely hobbled: at some point jupyter decided to ship a stripped-down mathjax, so I don't get any dedicated mathfont goodness; only unicode approximations. I've tried to convince the server to use proper mathjax but failed. The jupyter server that comes packaged with sagemath does work well -- a small case where we're getting a benefit from sage-the-distribution.

Michael Orlitzky

unread,
Feb 15, 2024, 4:19:47 PM2/15/24
to sage-...@googlegroups.com
On Thu, 2024-02-15 at 13:13 -0800, Nils Bruin wrote:
> According to the jupyter notebook documentation:
>
> https://jupyterbook.org/en/stable/content/math.html
>
> it should be possible to switch jupyter from using mathjax 2 to mathjax 3
> by some configuration option (no clue where those configuration options
> would go, and no indication is given in the tip either).

The notebook release process minifies all of its javascript code. The
bit that sets the MathJax options is in there somewhere but good luck
finding it.

Dima Pasechnik

unread,
Feb 15, 2024, 5:05:31 PM2/15/24
to sage-devel

Nils Bruin

unread,
Feb 15, 2024, 6:56:50 PM2/15/24
to sage-devel
On Thursday 15 February 2024 at 13:19:47 UTC-8 Michael Orlitzky wrote:

The notebook release process minifies all of its javascript code. The
bit that sets the MathJax options is in there somewhere but good luck
finding it.

Well, the text in the tip looks more like config file content than javascript, so whoever wrote the tip probably didn't propose to change javascript. Supposedly, they had a config file in mind somewhere, which would not be minified. I have very limited knowledge of the configuration mechanics of jupyter.

The snippet looks like this:
------------------------------------
sphinx:
    config:
-----------------------------------
(that's the URL that should change to mathjax 3. Supposedly one might be able to change that to a local resource)

Hopefully jupyter can provide a more obvious way to tweak this option, but even knowing where one can change this option effectively might already be useful (especially in cases where the default doesn't do what one wants).

Dima Pasechnik

unread,
Feb 15, 2024, 8:02:14 PM2/15/24
to sage-...@googlegroups.com
On Thu, Feb 15, 2024 at 11:56 PM Nils Bruin <nbr...@sfu.ca> wrote:
On Thursday 15 February 2024 at 13:19:47 UTC-8 Michael Orlitzky wrote:

The notebook release process minifies all of its javascript code. The
bit that sets the MathJax options is in there somewhere but good luck
finding it.

Well, the text in the tip looks more like config file content than javascript, so whoever wrote the tip probably didn't propose to change javascript. Supposedly, they had a config file in mind somewhere, which would not be minified. I have very limited knowledge of the configuration mechanics of jupyter.

The snippet looks like this:
------------------------------------
sphinx:
    config:
-----------------------------------
(that's the URL that should change to mathjax 3. Supposedly one might be able to change that to a local resource)

but that's sphinx (Python), not jupyter.
jupyter is javascript, and its MathJax config is essentially a js script which one puts into html files
inside <script></script> tags. Generation of this html happens whenever a notebook is rendered, so there should be a template somewhere with this js script.

        mathjax_url = self.settings.get(...)

being defaulted to a CDN, if an env.var. "mathjax_url" is not set. And after that line you see code which looks like generation of an html page.

I believe the answer is somewhere in https://github.com/jupyterlab/jupyterlab/issues/9911 
(but now it's 1am here, and I'm lost there :-))





Hopefully jupyter can provide a more obvious way to tweak this option, but even knowing where one can change this option effectively might already be useful (especially in cases where the default doesn't do what one wants).

--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/d4823c77-7dba-4210-9192-e286d4f109abn%40googlegroups.com.

Nils Bruin

unread,
Feb 15, 2024, 10:37:28 PM2/15/24
to sage-devel
On Thursday 15 February 2024 at 17:02:14 UTC-8 Dima Pasechnik wrote:
but that's sphinx (Python), not jupyter.
I see. The page I linked to is from Jupyter{book} which is, despite the similarity in name, not the jupyter notebook server.

Eric Gourgoulhon

unread,
Feb 16, 2024, 4:50:46 AM2/16/24
to sage-devel
Hi Nils,
You are not alone: I did exactly the same thing ;-) After a google-search for "jupyter custom mathjax", I ended up on the same page and for a second I thought it contains the solution, before realizing that this page is dedicated to the Sphinx generation of a book about Jupyter, not to Jupyter itself.

Eric.

Dima Pasechnik

unread,
Feb 23, 2024, 7:16:54 PM2/23/24
to sage-devel
My experiments with a pure upstream jupyterlab show that this is not reproducible there.
Namely:
1) clean up cache of your browser
2) create a fresh venv and pip install jupyterlab there, and the corresponding mathjax package:

$ python3 -m venv foo
$. foo/bin/activate
(foo) $ pip install jupyterlab
(foo) $ pip install jupyterlab-mathjax3

3) Disconnect the internet. Launch notebook

(foo) $ jupyterlab textest.ipynb # attached

4) Try evaluating cells (they all show nice mathjax - probably from a system package, but certainly not from a CDN)

-----------------------------------------------------------------

IMHO it's yet another reason for stopping to vendor Jupyter(lab), and just
using what's readily provided by the pure upstream!

Dima
textst.ipynb
Reply all
Reply to author
Forward
0 new messages