How to configure default mathjax rendering method in jupyter notebook

1,261 views
Skip to first unread message

Jan Groenewald

unread,
Sep 19, 2017, 6:12:40 AM9/19/17
to sage-devel
Hi

I am running the debian 9 packaged sagemath-common and sagemath-jupyter.
This gives a jupyter notebook which can open sage-7.4 worksheets.

LaTeX is rendering horribly by default: short ugly integral signs shorter than the expression that follows, and broken square root signs, amongst other.

It can be fixed by on each formula, each time you open the notebook, right click, math settings. Math Renderer, change HTML-CSS to Common HTML or SVG.

How can this setting be made permanent? (For oneself or many users across a campus.)

Mathjax is loaded from libjs-mathjax, a locally installed package, not from the internet. However editing /usr/share/javascript/mathjax.config/default./js does not help either:

0 root@jan-desktop:/usr/share/javascript/mathjax/config#grep input/TeX default.js
  //      input/TeX
  jax: ["input/TeX", "output/SVG"], # default was output/HTML-CSS

Any idea?

Regards,
Jan

--
  .~.
  /V\     Jan Groenewald
 /( )\    www.aims.ac.za
 ^^-^^ 

Ximin Luo

unread,
Sep 19, 2017, 3:08:49 PM9/19/17
to Development issues of sagemath and related tools, Samuel Lelièvre, sage-devel, Jan Groenewald
Samuel Lelièvre:
> Dear debian-science-sagemath,
>
> There is a question on sage-devel about SageMath
> on Debian and MathJax:
>
> https://groups.google.com/d/topic/sage-devel/sL_iYHfFB2M/discussion
>
> Could anyone on this list answer it?
>

Hi, (I think) the default is actually controlled by Jupyter Notebook and not SageMath. You can hack it locally by editing:

/usr/lib/python2.7/dist-packages/notebook/templates/notebook.html

I believe you just need to change, near the top:

{{mathjax_url}}?config=TeX-AMS_HTML-full
to:
{{mathjax_url}}?config=TeX-AMS_SVG-full

Afterwards, restart the notebook server. You might also need to clear your cookies / local storage if you've specifically overridden that setting for particular formulas.

I'm not sure the best way we could make this configurable across your whole campus, but perhaps it's best to open an issue and discuss it with the Jupyter Notebook people.

X

--
GPG: ed25519/56034877E1F87C35
GPG: rsa4096/1318EFAC5FBBDBCE
https://github.com/infinity0/pubkeys.git

Jan Groenewald

unread,
Sep 19, 2017, 3:19:01 PM9/19/17
to Ximin Luo, Development issues of sagemath and related tools, Samuel Lelièvre, sage-devel
Thanks

On 19 September 2017 at 21:08, Ximin Luo <infi...@debian.org> wrote:
Samuel Lelièvre:
> Dear debian-science-sagemath,
>
> There is a question on sage-devel about SageMath
> on Debian and MathJax:
>
> https://groups.google.com/d/topic/sage-devel/sL_iYHfFB2M/discussion
>
> Could anyone on this list answer it?
>

Hi, (I think) the default is actually controlled by Jupyter Notebook and not SageMath. You can hack it locally by editing:

/usr/lib/python2.7/dist-packages/notebook/templates/notebook.html

I believe you just need to change, near the top:

{{mathjax_url}}?config=TeX-AMS_HTML-full
to:
{{mathjax_url}}?config=TeX-AMS_SVG-full

Afterwards, restart the notebook server. You might also need to clear your cookies / local storage if you've specifically overridden that setting for particular formulas.

I'm not sure the best way we could make this configurable across your whole campus, but perhaps it's best to open an issue and discuss it with the Jupyter Notebook people.


Yes, seems to work! Discuss where with jupyter notebook people?  Seems irc and gitter is quiet. On github itself?

Regards,
Jan

Jan Groenewald

unread,
Sep 19, 2017, 3:26:01 PM9/19/17
to Ximin Luo, Development issues of sagemath and related tools, Samuel Lelièvre, sage-devel
Hi

Okay not sure from user feedback. Will have to check in person tomorrow. whether it is working.

Regards,
Jan
 

Ximin Luo

unread,
Sep 20, 2017, 5:21:55 AM9/20/17
to Development issues of sagemath and related tools, Jan Groenewald, sage-devel, Samuel Lelièvre
Jan Groenewald:
Yes I meant on Github. But actually in the latest version of that file they have replaced the hardcoded config with a {{mathjax_config}}:
https://github.com/jupyter/notebook/blob/master/notebook/templates/notebook.html#L8

According to this https://jupyter-notebook.readthedocs.io/en/latest/config.html the user can set it in ~/.jupyter/jupyter_notebook_config.py
NotebookApp.mathjax_config = 'TeX-AMS-MML_HTMLorMML-full,Safe'

(This version is not packaged yet for Debian, but hopefully soon.)

> Okay not sure from user feedback. Will have to check in person tomorrow.
> whether it is working.
>

Did they reset their cookies / local storage? I'm not sure of the easiest way to selectively do that, but ctrl-shift-delete in Chrome and Firefox will get rid of a whole chunk of stuff.

Jan Groenewald

unread,
Sep 20, 2017, 6:17:34 AM9/20/17
to Ximin Luo, Development issues of sagemath and related tools, sage-devel, Samuel Lelièvre
Hi

Yes, I completely removed ~/.mozilla, it still does not work to edit /usr/lib/python2.7/dist-packages/notebook/templates/notebook.html.
Maybe {{mathjax_url}} is not set and so that if statement is never entered?

Anyway, this worked for now, it seems. I will deploy this:

cd /usr/share/javascript/mathjax/config
mv TeX-AMS_HTML-full.js{,.orig}
ln -s TeX-AMS_CHTML-full.js tex-AIMS_HTML-full.js

so I get a symlink to use Common HTML instead of HTML-CSS:

root@muizenberg:/usr/share/javascript/mathjax/config#ls -l TeX-AMS_HTML-full.js                       
lrwxrwxrwx 1 root root 21 Sep 20 12:16 TeX-AMS_HTML-full.js -> TeX-AMS_CHTML-full.js

Regards,
Jan

Jan Groenewald

unread,
Sep 20, 2017, 6:40:02 AM9/20/17
to sage-devel
Hi

This will be configurable in future versions of jupyter (not the version on debian stable) in ~/.jupyter via mathjax_config.

For now had to move aside the following file and instead create a symlink /usr/share/javascript/mathjax/config/TeX-AMS_HTML-full.js to my preferred config instead.

Regards,
Jan


 
Reply all
Reply to author
Forward
0 new messages