Bug 1581899 - Math/Latex fails to render properly in Jupyter
Summary: Math/Latex fails to render properly in Jupyter
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: python-notebook
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Miro Hrončok
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On: 1580129
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-05-23 21:06 UTC by Jonathan Underwood
Modified: 2018-06-21 14:19 UTC (History)
3 users (show)

Fixed In Version: python-notebook-5.5.0-3.fc29
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-06-21 14:19:49 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
Math input (94.75 KB, image/png)
2018-05-23 21:06 UTC, Jonathan Underwood
no flags Details
Rendered math (82.87 KB, image/png)
2018-05-23 21:07 UTC, Jonathan Underwood
no flags Details

Description Jonathan Underwood 2018-05-23 21:06:37 UTC
Created attachment 1440784 [details]
Math input

Description of problem:
Markdown cells containing LaTeX aren't rendered properly in Jupyter on Fedora 28 using the distro packages. The problem is not seen if pip installing and running Juyter from a virtualenv, so something is hokey with the Fedora packages.

Version-Release number of selected component (if applicable):
python3-jupyter-client-5.2.3-1.fc28.noarch
python3-jupyter-core-4.4.0-2.fc28.noarch
python3-notebook-5.4.0-2.fc28.noarch
mathjax-caligraphic-fonts-2.7.1-2.fc27.noarch
mathjax-size4-fonts-2.7.1-2.fc27.noarch
mathjax-math-fonts-2.7.1-2.fc27.noarch
mathjax-size2-fonts-2.7.1-2.fc27.noarch
mathjax-typewriter-fonts-2.7.1-2.fc27.noarch
mathjax-fraktur-fonts-2.7.1-2.fc27.noarch
mathjax-sansserif-fonts-2.7.1-2.fc27.noarch
mathjax-2.7.1-2.fc27.noarch
mathjax-script-fonts-2.7.1-2.fc27.noarch
mathjax-size3-fonts-2.7.1-2.fc27.noarch
mathjax-ams-fonts-2.7.1-2.fc27.noarch
mathjax-main-fonts-2.7.1-2.fc27.noarch
mathjax-winchrome-fonts-2.7.1-2.fc27.noarch
mathjax-winie6-fonts-2.7.1-2.fc27.noarch
mathjax-size1-fonts-2.7.1-2.fc27.noarch


How reproducible:
Everytime

Steps to Reproduce:
1. Enter some maths eg $$\left(\frac{a}{b}\right)$$ into a markdown cell
2. Render the cell
3. Observe messed up maths

Actual results:
Incorrect rendering. See screenshots.

Expected results:
Beautiful maths :)

Additional info:

Comment 1 Jonathan Underwood 2018-05-23 21:07:11 UTC
Created attachment 1440785 [details]
Rendered math

Comment 2 Jonathan Underwood 2018-05-23 21:08:50 UTC
I also see this in the console:

[I 21:54:13.796 NotebookApp] Accepting one-time-token-authenticated connection from ::1
[W 21:54:16.677 NotebookApp] Notebook mirror_trading.ipynb is not trusted
[W 21:54:16.720 NotebookApp] 404 GET /nbextensions/widgets/notebook/js/extension.js?v=20180521215413 (::1) 8.05ms referer=http://localhost:8888/notebooks/mirror_trading.ipynb
[I 21:54:17.074 NotebookApp] Kernel started: 072c7e3b-559b-4bb7-8665-c9db10dd9a05
[I 21:54:17.559 NotebookApp] Adapting to protocol v5.1 for kernel 072c7e3b-559b-4bb7-8665-c9db10dd9a05
[W 21:54:17.636 NotebookApp] 404 GET /static/components/MathJax/fonts/HTML-CSS/STIX-Web/woff/STIXMathJax_Main-Italic.woff?V=2.7.1 (::1) 1.24ms referer=http://localhost:8888/notebooks/mirror_trading.ipynb
[W 21:54:17.644 NotebookApp] 404 GET /static/components/MathJax/fonts/HTML-CSS/STIX-Web/otf/STIXMathJax_Main-Italic.otf?V=2.7.1 (::1) 1.33ms referer=http://localhost:8888/notebooks/mirror_trading.ipynb

Comment 3 Miro Hrončok 2018-05-23 21:15:43 UTC

*** This bug has been marked as a duplicate of bug 1580129 ***

Comment 4 Jonathan Underwood 2018-05-23 22:31:27 UTC
Although I have reported the Mathjax font issue in 1580129, I don't believe that's the root cause of this issue, so re-opening.

Comment 5 Jonathan Underwood 2018-05-23 22:35:41 UTC
It looks like the Jupyter package is missing /usr/share/jupyter/nbextensions/jupyter-js-widgets/extension.js - that is present in the pip installed package.

Comment 6 Miro Hrončok 2018-05-23 22:39:27 UTC
Oh, sorry. Will check where is that file coming from.

Comment 7 Miro Hrončok 2018-05-23 22:46:14 UTC
$ python3 -m venv venv
$ . venv/bin/activate
$ pip install notebook
$ find -name extension.js
(nope)

Not sure if the missing extension is to blame here.

Comment 8 Miro Hrončok 2018-05-23 22:50:24 UTC
It seems to work for me with newer ipykernel:

https://koji.fedoraproject.org/koji/taskinfo?taskID=27152209

Could you try?

Comment 9 Miro Hrončok 2018-05-23 22:51:18 UTC
Actually no, it works even with the old one on my machine :(

Comment 10 Jonathan Underwood 2018-05-24 07:48:20 UTC
(In reply to Miro Hrončok from comment #7)
> $ python3 -m venv venv
> $ . venv/bin/activate
> $ pip install notebook
> $ find -name extension.js
> (nope)
> 
> Not sure if the missing extension is to blame here.

Hm.

$ find -name extension.js
./share/jupyter/nbextensions/jupyter-js-widgets/extension.js
./lib/python3.6/site-packages/widgetsnbextension/static/extension.js

But I also had done a pip install jupyter - so presumably that's why.

$ pip freeze
appdirs==1.4.3
args==0.1.0
asn1crypto==0.24.0
astor==0.6.2
autoflake==1.1
awscli==1.15.19
backports.ssl-match-hostname==3.5.0.1
botocore==1.10.19
certifi==2018.4.16
cffi==1.11.2
chardet==3.0.4
clint==0.5.1
colorama==0.3.7
conda==4.4.11
configparser==3.5.0b2
cookies==2.2.1
cryptography==2.2.1
docutils==0.14
enum34==1.1.6
flake8==3.4.1
funcsigs==1.0.2
futures==3.1.1
hy==0.14.0
idna==2.5
ipaddress==1.0.18
jedi==0.12.0
jmespath==0.9.3
json-rpc==1.10.8
mccabe==0.6.1
mock==2.0.0
ordereddict==1.1
parso==0.2.0
pathlib2==2.1.0
pbr==3.1.1
pipenv==11.10.0
ply==3.9
pwquality==1.4.0
pyasn1==0.4.2
pycairo==1.16.3
pycodestyle==2.3.1
pycosat==0.6.3
pycparser==2.14
pycrypto==2.6.1
pyflakes==1.6.0
Pygments==2.2.0
pygobject==3.28.2
pyOpenSSL==17.3.0
PySocks==1.6.8
python-dateutil==2.7.3
PyYAML==3.12
requests==2.18.4
responses==0.9.0
rply==0.7.5
rpm==4.14.1
rsa==3.4.2
ruamel.ordereddict==0.4.9
ruamel.yaml==0.13.14
s3transfer==0.1.13
service-factory==0.1.5
six==1.11.0
typing==3.6.2
urllib3==1.22
virtualenv==15.2.0
virtualenv-clone==0.3.0

Comment 11 Jonathan Underwood 2018-05-24 07:51:46 UTC
OK, I tried the new kernel, and that didn't seem to fix it, alas.

Comment 12 Thomas Kluyver 2018-05-24 08:34:52 UTC
The kernel shouldn't affect how Markdown cells are rendered - the kernel doesn't even know about markdown cells.

Comment 13 Miro Hrončok 2018-05-24 09:41:19 UTC
Does 5.5.0 from https://bodhi.fedoraproject.org/updates/FEDORA-2018-3a88ea58d2 still have this issue?

Comment 14 Jonathan Underwood 2018-05-25 22:04:46 UTC
I can confirm that python3-notebook.noarch 5.5.0-2.fc28 fixes this problem. However, to install it I had to remove all the mathjax packages first, due to file conflicts - so I guess those will need to be resolved before pushing to stable.

Comment 15 Jonathan Underwood 2018-05-25 22:10:22 UTC
It seems to me a coordinated update of notebook to 5.5.0 and mathjax to 2.7.4 without the missing font files is what's needed here. It's a shame the mathjax maintainer has been unresponsive to #1580129.

Comment 16 Jonathan Underwood 2018-05-26 18:02:32 UTC
OK, after some more digging. I think there's two issues t play:

1. MathJax as packaged by Fedora doesn't ship the MathJax STIXWeb fonts, but just the TeX fonts.
2. The python-notebook package doesn't set the preferred font for maths rendering.

The first issue is being addressed in BZ #1580129. 

The second issue should also be addressed, as the TeX fonts are better quality than the STIXWeb ones.

Here is a useful discussion:

https://stackoverflow.com/questions/28909747/how-do-i-configure-mathjax-for-ipython-notebooks

From here you can see that the preferred font to use for rendering can be set in:

/usr/lib/python3.6/site-packages/notebook/static/notebook/js/main.min.js

which I think the Fedora package should do.

What do you think?

Comment 17 Jonathan Underwood 2018-05-26 20:27:27 UTC
Created a PR which attempts to address the font issue:

https://src.fedoraproject.org/rpms/python-notebook/pull-request/4

Unfortunately I couldn't test this, since fedpkg mockbuild complains about this on the f28 branch:

No matching package to install: 'python2-ipykernel >= 4.8'
No matching package to install: 'python3-ipykernel >= 4.8'

And on master the mock build was failing before i even made any changes.

Comment 18 Jonathan Underwood 2018-05-26 20:41:46 UTC
Oh, nice, the koschei CI build for that PR passes.


Note You need to log in before you can comment on or make changes to this bug.