8000 Math not rendered in downloaded documentation when offline · Issue #20951 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Math not rendered in downloaded documentation when offline #20951

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

Open
cwfoo opened this issue Sep 6, 2021 · 6 comments
Open

Math not rendered in downloaded documentation when offline #20951

cwfoo opened this issue Sep 6, 2021 · 6 comments

Comments

@cwfoo
Copy link
cwfoo commented Sep 6, 2021

Describe the issue linked to the documentation

I downloaded the zipped HTML documentation for Scikit-learn 0.24.2 from https://scikit-learn.org/dev/versions.html. However, the math in the documentation is not rendered when I am not connected to the internet. This is what I see when I view section 1.1 of the User Guide when offline:

2021-09-06_15-55-2

The problem is caused by the following line, which will fail to load the MathJax script when offline.

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>

Suggest a potential alternative/fix

The solution is to bundle the MathJax script in the zipped HTML docs.

@rth
Copy link
Member
rth commented Sep 6, 2021

Thanks! Feel free to open a PR to bundle that js file.

@cwfoo
Copy link
Author
cwfoo commented Sep 6, 2021

The other possible solution is to add export NO_MATHJAX=1 to build_tools/circle/build_doc.sh to render math as SVG images.

@cwfoo
Copy link
Author
cwfoo commented Sep 15, 2021

@rth I'm not familiar with the existing code. Perhaps this could work:

diff --git a/build_tools/circle/build_doc.sh b/build_tools/circle/build_doc.sh
index 8facdc5..8f11569 100755
--- a/build_tools/circle/build_doc.sh
+++ b/build_tools/circle/build_doc.sh
@@ -136,7 +136,7 @@ make_args="SPHINXOPTS=-T $make_args"  # show full traceback on exception
 # notation in the HTML documentation and to optimize the image files
 sudo -E apt-get -yq update --allow-releaseinfo-change
 sudo -E apt-get -yq --no-install-suggests --no-install-recommends \
-    install dvipng gsfonts ccache zip optipng
+    install dvipng dvisvgm gsfonts ccache zip optipng
 
 # deactivate circleci virtualenv and setup a miniconda env instead
 if [[ `type -t deactivate` ]]; then
@@ -195,6 +195,9 @@ then
     python build_tools/circle/list_versions.py > doc/versions.rst
 fi
 
+# Render math in HTML documentation for offline use
+export NO_MATHJAX=1
+
 # The pipefail is requested to propagate exit code
 set -o pipefail && cd doc && make $make_args 2>&1 | tee ~/log.txt

Issues:

  • Would this change affect the online docs at https://scikit-learn.org? From my understanding, we want to continue using MathJax for the online docs.
  • Can dvipng be removed?

@thomasjpfan
Copy link
Member

Can dvipng be removed?

I think so. Most likely a old requirement from when we built the PDF.

I would prefer to use svg instead of loading mathjax just to reduce the amount of javascript that needs to be loaded. Although, the downside is that it adds another requirement for building the docs. I think one needs to install latex to install dvisvgm. Secondly, I recall setting NO_MATHJAX=1 increases the build time of the docs, but I have not checked in a while.

We can have the hosted version build with svg and recommend contributors build locally with mathjax enabled, but that leads to a different local build.

As a temporary fix, I think we should stick with bundling the mathjax for now. I see three options:

  1. Vendor Mathjax's tex-chtml.js and configure sphinx to use it.
  2. When we build the docs, download Mathjax's tex-chtml.js and configure sphinx to use it.
  3. Use mathjax CDN on the hosted version. When packaging the zip, download Mathjax's tex-chtml.js , and use sed to rewrite every HTML file to link to the packaged text-chtml.js.

@rth
Copy link
Member
rth commented Sep 15, 2021

Mathjax also appears to load a bunch of of fonts, which we might need to include if we bundle Mathjax.

image

note that all of these should be cached by the browser so they would only be loaded once. And once they are cached, it would likely mean less things to download than with SVG (where one would need to make one HTTP call per svg image I imagine)

@cserpell
Copy link

I have the same issue, local documentation does not show latex properly. Is there any way I could help to move this forward?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0