liffiton / dokuwiki-plugin-mathjax

MathJax plugin for DokuWiki
https://www.dokuwiki.org/plugin:mathjax
12 stars 11 forks source link

Popup for footnotes doesn't show maths properly #27

Closed msakuta closed 8 years ago

msakuta commented 8 years ago

Popup window for footnotes which is shown when the mouse hovers over it doesn't show MathJax maths correctly. Footnote itself, shown at the bottom of the page, has no problem.

Markup like this:

 * Math $\sqrt{x^2+y^2}$
 * Footnote math:
((Footnote: $\sqrt{x^2+y^2+z^2}$))

ends up like this:

image

Any idea why this is happening?

liffiton commented 8 years ago

What browser are you using, and on what platform? In Firefox on Windows, I actually get javascript errors when hovering a footnote with math, and it doesn't display at all. I'll need to look into that more, but I'd like to try to reproduce your symptom as well.

msakuta commented 8 years ago

Confirmed in Chrome on Windows 10. Apparently Chrome does not show any error on debugger console.

Also checked Microsoft Edge on Windows 10. It does not show popup window at all when I hover the cursor on the footnote link (I guess it's the same response as your Firefox). Its debugger outputs error "SCRIPT1014: Invalid character" at js.php (3,2613).

image

liffiton commented 8 years ago

Thanks. The javascript error is almost certainly a bug in Dokuwiki (the script shouldn't crash based on the contents of a footnote), so that might take some time and a Dokuwiki bug report to fix. I'll try to look into it in the next few days, though. And I'm guessing the Chrome issue is somehow related, but I'll look to see if there is something different going on there as well.

liffiton commented 8 years ago

It looks like it's an interaction between Mathjax and jQuery, actually. When Mathjax parses a math formula, it replaces it with the markup to render it and creates a <script> tag of type "math/tex" with the original text of the formula. When Dokuwiki shows a footnote popup, it grabs whatever is in corresponding footnote at the bottom of the page and adds it to a new <div> using jQuery. JQuery sees the <script> tag and tries to execute it, not "realizing" that it isn't actually javascript. The error occurs and the footnote display code doesn't complete.

I don't believe there is anything reasonable that I can do in the plugin to correct this. Unfortunately, I'm not sure whether it can be fixed in Dokuwiki, or if it is an issue with jQuery or even with Firefox. I'll keep looking into it a bit, but I can't promise much.

Meanwhile, for me in Chrome, the footnote popups display with incorrect rendering, as you showed, but the different renderers give different types and levels of incorrect. If I switch Mathjax to render with the "SVG" renderer, though, the footnote popup displays correctly for me in Chrome.

So that may be the best workaround I have right now: Use Chrome and set Mathjax's renderer to SVG.

liffiton commented 8 years ago

Ah, I think I found it. It looks like a bug in Dokuwiki. When it's pulling the contents of the footnote to create the popup, it mangles them intentionally but incorrectly... If I'm understanding this correctly, I should be able to submit a bug report to Dokuwiki soon.

liffiton commented 8 years ago

See the referenced dokuwiki bug for a fix (editing one line in lib/scripts/page.js).

Thanks for the really clear bug report, by the way.

msakuta commented 8 years ago

Yup, the solution in the referenced DokuWiki issue worked for me. I only tested Firefox and IE11 but I don't think Chrome will have an issue. (I'll check later when I'm home.)

Thank you and I appreciate this issue is addressed so quickly.

Edit: Chrome worked, too.