jfbercher / jupyter_latex_envs

(Some) LaTeX environments for Jupyter
Other
112 stars 27 forks source link

Math formulas can not display in headlines. #14

Open shanhaiying opened 7 years ago

shanhaiying commented 7 years ago

Math formulas can not display in headlines if the LaTeX_envs activated.

image

The result is : image

when the LaTeX_envs deactivated the result is:

image

jfbercher commented 7 years ago

Thanks. Good spot. I can reproduce. It seems that something has changed between notebook 4.2 and 4.3 in the sanitize_html step. A quick fix is just to exchange two lines in the MarkdownCell.prototype.renderin latex_envs.js to read

                html = security.sanitize_html(html);
        html = thmsInNbConv(marked, html); //<----- thmsInNb patch here

I will fix that shortly (but I have also some other little things to include).

shanhaiying commented 7 years ago

I have tried to fix this as you suggest. I find it is not always effective.
If there are some code cell changed to text cell, then the math formulas in headlines will disappear again until the page is refreshed.

jfbercher commented 7 years ago

Sorry, I can not reproduce. Can you describe step by step the scenario?

shanhaiying commented 7 years ago

The following screencap show what happen. But I can not reproduce it every time. test

jfbercher commented 7 years ago

Actually, I think that this is a rather involved issue involving an interaction between latex_envs and toc2: toc2 copies the headers into links in order to populate: the toc2 widow/sidebar, the table of contents (if enabled) in the notebook, the navigate menu. When latex_envs is enabled, it has the capability to keep all equations and environments correctly numbered: each markdown rendering entails the reset of all equations nubers and the recomputation of all math renderings. Maths are stored as a preview in html, with styling, classes, ids, end embedded scripts. When copying the headers into links, these previews are copied as well. The duplication of ids than cause a mess to the webpage rendering: maths in the toc window/sidebar is sometimes duplicated, maths can disappear in the toc and/or in the navigation menu. I have made a PR to jupyter_contrib_nbextensions to remove mathjax previews when creating links in toc2. This has also the advantage of restoring a simpler html source (see the toc_cell source for instance).