sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.45k stars 481 forks source link

No latex display in the notebook when offline #36914

Open egourgoulhon opened 11 months ago

egourgoulhon commented 11 months ago

Steps To Reproduce

With Sage 10.3.beta2 running on a computer that is offline (not connected to internet), open a new Jupyter notebook with sage -n and type the following code:

%display latex
sin(x^2)

Expected Behavior

The output should be a typeset formula.

Actual Behavior

The output is raw latex:

\(\displaystyle \sin\left(x^{2}\right)\)

Additional Information

There is no such issue with Sage 10.2. It is most likely due to the Notebook upgrade performed in https://github.com/sagemath/sage/pull/36129

Environment

- **OS**: Ubuntu 22.04
- **Sage Version**: 10.3.beta2

Checklist

egourgoulhon commented 9 months ago

A data point: with Sage 10.2, the offline latex display works with jupyterlab (sage -n jupyterlab) as well, while with Sage 10.3.beta6, it works neither with jupyter (now emulated by jupyterlab) nor jupyterlab.

@mkoeppe, @kwankyu do you have any idea or suggestion?

kwankyu commented 9 months ago

I cannot reproduce this with 10.3.beta6 on mac. Is it only on Ubuntu?

egourgoulhon commented 9 months ago

I cannot reproduce this with 10.3.beta6 on mac.

Thanks for the feedback.

Is it only on Ubuntu?

I cannot say. I've tested it on 2 computers both running Ubuntu 22.04. I'll send a query for further tests on sage-devel.

egourgoulhon commented 9 months ago

I'll send a query for further tests on sage-devel.

Here is the post: https://groups.google.com/g/sage-devel/c/sSBryLVqQk4

egourgoulhon commented 9 months ago

Another data point: there is no error message in the console from which sage -n was run when the computer is offline. Simply the MathJax display fails silently.

egourgoulhon commented 9 months ago

For reference, I copy here an extract of https://groups.google.com/g/sage-devel/c/sSBryLVqQk4/m/xepfECrvAQAJ

egourgoulhon commented 9 months ago

For reference, the post on Jupyter forum: https://discourse.jupyter.org/t/notebook-with-mathjax-without-internet-connection/23958

kwankyu commented 8 months ago

"blocker" label is getting overloaded too much.

Let's use "blocker" only for PRs and use "critical" for issues.

dimpase commented 8 months ago

I think this is due to sticking with MathJax-2 rather than moving to MathJax-3 (well, in the latter case you have non-wrapped, although scroll-able, long formlae).

Jupyterlab ships with a copy of MathJax-3, so installing mathjax2 overrides it (but breaks off-line working).

mkoeppe commented 8 months ago

I've added this to https://github.com/sagemath/sage/wiki/Sage-10.3-Release-Tour#known-problems-and-workarounds

mkoeppe commented 8 months ago

Some relevant places in the code

mkoeppe commented 8 months ago

I've added this to https://github.com/sagemath/sage/wiki/Sage-10.3-Release-Tour#known-problems-and-workarounds

Could someone please check whether this workaround works?

kwankyu commented 8 months ago

I checked it works.

As expected, with ./sage -pip uninstall jupyterlab-mathjax2, mathjax3 returns and offline maths work, but also newline, as seen in a markdown cell with

$\sqrt{2} \\ \sqrt{3}$

does not work. Perhaps this should also be noted in the release tour.

mkoeppe commented 8 months ago

Thanks a lot for checking.

mkoeppe commented 8 months ago

In https://github.com/sagemath/sage/pull/37550, I restore our mathjax package from before the upgrade to 3 in #25833. I don't know if it is suitable to work with jupyterlab-mathjax2 or how to configure it. Restoring the package is a possible starting point if someone wants to try this.

dimpase commented 8 months ago

This should not be a "workaround", there should be user's choice what mathjax, or, moreover, what jupyter to use with Sage.

kwankyu commented 8 months ago

A user already has choices. No one prevents users from using system jupyter. What do you mean?

dimpase commented 8 months ago

I mean that we should not saddle the user with a particular Jupyter installation at all. E.g. with Sage's macOS app it's not even used!

kh-abd-kh commented 5 months ago

./sage -pip uninstall jupyterlab-mathjax2 solves the problem partialy but not completely.

Over Win11, WSL Ubuntu 22.04 If you use ~/sage-10.4.beta9/sage --notebook jupyterlab
and then someting like tutorial(), now for the first time, the help system works prefectly. (google-chrome) -congrats- :)

But if you use ~/sage-10.4.beta9/sage --notebook jupyterlab --no-browser and go open jupyter from inside Win11 edge NO LATEX appears in the help at all.

Just to be aware, for me I am happy to see the help is working.

kwankyu commented 5 months ago

In

$ sage --notebook jupyterlab --no-browser
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.4.beta9, Release Date: 2024-06-09              │
│ Using Python 3.12.3. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Sage doc server started running at http://127.0.0.1:58147

http://127.0.0.1:58147 is the url to a local doc server running in WSL. Try to open the url. I am curious how it works (or not) in WSL.

dimpase commented 5 months ago

On which side the LaTeX fonts matter? on the remote side (WSL), or on the local (Windows).

Locally one can try different clients, e.g. VSCode has nice Jupyter support

kh-abd-kh commented 5 months ago

That what i used ~/sage-10.4.beta9/sage --notebook jupyterlab --no-browser and then paste the localhost address. (sudo make install didn't "link" sage)

On the Win11 side, 1- I am using Jupyter from Win11 as unified platform for different pythons. OpenCL Ryzen 7 Renoir gpu only works from Win11 no WSL 2- CUDA sometimes faster from WSL but also Win11 can be faster. It depends. for the time being sage has zero-support for these stuff even Numba Jit is broken in sage. 3- WSL had problems with gui apps. Connecting/Disconnecting the internet. Crashs google-chrome and Jupyter so I was forced to use the Win side. It is almost fixed with the last update but still i have RAM crashs. When you do some calculations that exceeds the RAM. Now, sometimes kernel restart (the normal) but still sometimes the whole WSL crashs, now, less but still. I feel it in Sage/Jupyter more than anything else actually i don't remember it happened out of Sage. due to extinsive RAM calculations, not sage but may be jupyter. Sage without Jupyter can make kernel(sage) crashs but not the whole WSL.


I have no latex installed in Win11, I use Scientific Workplace 5.5 for Latex Win11. I am not using any MS for prog (VScode). sorry.


Sorry, this is a little summary of WSL problems as far as i have gone through.

Last Monday, for the first time in 5 years, i downloaded and compiled Sage without any crashs.

dimpase commented 5 months ago

Putting WSL aside for a while, do you get LaTeX in notebooks (say, just Python) running on your Windows Jupyter? If not, that's where the problem is, I think.

kh-abd-kh commented 5 months ago

~/sage-10.4.beta9/sage --notebook jupyterlab --no-browser then from Win/Edge/Jupyter

%display latex sin(x^2)

yes it works without problems

kh-abd-kh commented 5 months ago

wsl_latex

dimpase commented 5 months ago

~/sage-10.4.beta9/sage --notebook jupyterlab --no-browser then from Win/Edge/Jupyter

%display latex sin(x^2)

yes it works without problems

So it does work, contrary to what you wrote above?

And what exactly does not work, if anything?

kh-abd-kh commented 5 months ago

The Help System


If you use ~/sage-10.4.beta9/sage --notebook jupyterlab and then someting like tutorial(), now for the first time, the help system works prefectly. (google-chrome) -congrats- :)

But if you use ~/sage-10.4.beta9/sage --notebook jupyterlab --no-browser and go open jupyter from inside Win11 edge NO LATEX appears in the help at all.


Sorry for the confusion

kh-abd-kh commented 5 months ago

wsl_latex _ help