-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
init_printing/init_session shouldn't generate png math by default #24983
Comments
I use the suggested default in my "Learn Multibody Dynamics" text: One possible downside, is that when you aren't connected to the internet mathjax may not work. I'm not sure what happens when use_latex is mathjax and there is no internet. |
I just tested it and when I turn my internet off, the notebook can still render mathjax, because mathjax is installed locally in one of the jupyter packages. However, I did try converting the notebook to html using nbconvert, and that does load mathjax from the CDN. If I turn my internet off, it just shows the raw latex. It doesn't seem to fallback to png, and as far as I can tell, the pngs aren't even saved there. |
I've noticed (seemingly) that mathjax can sometimes be left in the browser cache and it works without internet but then sometimes it doesn't. But I'm mostly working with jupyter-sphinx which likely uses nbconvert under the hood. |
This was prompted by this issue jupyter-book/jupyter-book#1833. I don't know what the relationship is between jupyter-sphinx and jupyter-book, but with jupyter-book, notebooks with pngs saved in them will render the png instead of the latex. |
It is possible the jupyter-book uses jupyter-sphinx. I'm not that familiar with jupyter-book though. Either way, they do similar things. |
Looks like jupyter-book used to depend on jupyter-sphinx: https://github.com/search?q=org%3Aexecutablebooks+jupyter-sphinx&type=code |
PNG output gets saved in notebooks, which makes their size much bigger, but it isn't ever actually used because the MathJax LaTeX output is preferred. I thought this might affect the qtconsole, which uses png output, but it doesn't seem to. init_printing() wiht no arguments still enables png output there. So the impact of this change should be minimal. Fixes sympy#24983
I have a fix at #25374. I thought this might break the qtconsole but it apparently still uses png even with this change. |
If you call
init_printing
orinit_session
in a Jupyter notebook, by default it generates both mathjax and png output. For example, this notebookgenerates this JSON:
Notice the
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAA0AAAArCAYAAACjHgJXAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABPUlEQVRIDe2VMW7CQBBF7cABouQGHAFIbymhS5srwA2gtFtSpiRlKpLcAAqfICWlWzpER2neXy3WetdWonQgRvramdn5u57xaDYuyzJqkizL+vi/wAB978Z0XYPNW+x3sAND0AOB+CSd+KIoDpiy6LZAbgLPHxxXki3SGRfi3qZw5//v2G9Y2kdNKnkC6sUfUIAVewvWKCDJ+ZuccfVaU7vEnOI0TZtnWGsZrh1RleYSO+JfOVXvE0NjTnnGQMOkTRbETcxgsQQFroBID2AJ9BrKXoOIOE2mqAP02h1wvCVJUuR5/oz9gb1Bf0RfK5i9LbqRrmWbE6xvhO/V6rrRzDprm6VWCIJ1694J6ONz7ZCEZwKU10l6J8Vdq5s4UQmrep9uAH6N55pUJLwiFA2fM6oxMFySNmdewLdnG/MIWJ5aYR6r8pQAAAAASUVORK5CYII=\n",
, which is a png of the LaTeX:It does this by default as long as latex is installed.
This can be controlled by the
use_latex
flag. If it isTrue
(the default), it generates both png and mathjax.However, I don't know if it really should generate a png by default.
I think we should change the default of
use_latex
to be'mathjax'
. The only benefit of png images is in renderers that don't support mathjax, like the qtconsole. We can detect if the frontend is the notebook and default to mathjax there and the currentTrue
otherwise.The text was updated successfully, but these errors were encountered: