danielfrg / mkdocs-jupyter

Use Jupyter Notebook in mkdocs
https://mkdocs-jupyter.danielfrg.com
Apache License 2.0
367 stars 45 forks source link

Rendered pages sometimes do not render math #143

Open iincer opened 1 year ago

iincer commented 1 year ago

The screenshot below was taken from the demo site for this package. As you can see, the math is not rendered correctly. However, sometimes reloading the page fixes the issue, and things are rendered correctly. It seems that the code does not ensure that MathJax functionality has been loaded before using it.

I am using Microsoft edge. I have also tested iOS devices, and they often show this incorrect behavior.

image

iincer commented 1 year ago

For reference, this is what I get on iOS:

IMG_1084

IMG_1085

iincer commented 1 year ago

@danielfrg, mkdocs-jupyter currently places the mathjax imports in the body tag instead of the head tags of the generated html of a notebook--see lines 1440-1472 of https://mkdocs-jupyter.danielfrg.com/variational-inference-nb/index.html. nbconvert places these imports under the head tag.

1) I modified my html to get the imports under the head tag, and performance improved considerably. mkdocs-jupyter should place these imports under the head tag.

2) Even after making this change, reloads are not 100% deterministic: sometimes math won't render correctly when reloading a webpage. Do you have insight into whether MathJax should be configured differently to avoid this?

danielfrg commented 9 months ago

Yes, we have to put the mathjax code in the body because thats where we can add code. I intentionally changed this from the nbconvert template so they render. I am not sure if we can update the head scripts from a plugin.