Skip to content
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

MathJax can't find its script tag in XHTML if XHTML tags use an explicit prefix #1016

Closed
sdh4 opened this issue Jan 22, 2015 · 10 comments

Comments

Projects
None yet
3 participants
@sdh4
Copy link

commented Jan 22, 2015

If I create an xhtml page that uses explicit prefixes on the html tags, MathJax's code for finding its <script> tag fails. There also seems to be a similar issue with the <head> tag.

Test case:

<html:html xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml">
  <html:head>
    <html:script type="text/javascript" src="MathJax/MathJax.js?config=default"/>
    <html:title>test</html:title>
  </html:head>
  <html:body>
    <html:h1>This is a test</html:h1>
    <html:div>
      Here is an equation: \( x=5 \)
    </html:div>
  </html:body>

</html:html>

Expected results: Correctly render the equation x=5
Actual results: No rendering (tested with Firefox 35)

The issue can be worked around by

  • removing the namespace prefix from the <head> and <script> tags, or
  • Modifying MathJax.js to use getElementsByTagName("html:script") instead of getElementsByTagName("script"), and similarly getElementsByTagName("html:head") in place of getElementsByTagName("head")
@pkra

This comment has been minimized.

Copy link
Member

commented Jan 22, 2015

I cannot reproduce this. Are you serving the xhtml file with the correct mimetype?

@dpvc

This comment has been minimized.

Copy link
Member

commented Jan 22, 2015

I can reproduce it (on a local document with extension .xhtml) in Firefox, though it works as expected in Safari and Chrome. I haven't tried IE. Yes, having namespaces on those element can be problematic.

It's not actually the script tags that are the problem (since these are created without namespaces by the tex2jax preprocessor, and so will be found by getElementsByTagName()), it is the document head that is the problem (MathJax isn't even getting to the place where it looks for the script tags). I guess MathJax could use document.head when available and look it up otherwise (conveniently, document.head is set in Firefox even with the namespaces).

@dpvc

This comment has been minimized.

Copy link
Member

commented Jan 22, 2015

OK, I see, finding its own script tag is what you mean. Yes, that is also a problem. I'll think about that further.

dpvc pushed a commit to dpvc/MathJax that referenced this issue Jan 22, 2015

@dpvc

This comment has been minimized.

Copy link
Member

commented Jan 22, 2015

The issue1016 branch of my fork of MathJax includes the work-arounds that I suggest above.

@dpvc dpvc added this to the MathJax 2.5 milestone Jan 22, 2015

@sdh4

This comment has been minimized.

Copy link
Author

commented Jan 22, 2015

This is not quite yet solving it for me, at least not on files served through the web server.
My server, or the various transformations therein, put a <!DOCTYPE html> at the top of the document. So when document.getElementsByTagName("head")[0] on line 3041 gives a null, the fall-through creates HEAD from document.childNodes[0]. Unfortunately, document.childNodes[0] is the <!DOCTYPE html>, not the actual HEAD tag or any other meaningful tag, so namespaceURI is null and the problem is not solved.

Possible fixes:

dpvc pushed a commit to dpvc/MathJax that referenced this issue Jan 22, 2015

@dpvc

This comment has been minimized.

Copy link
Member

commented Jan 22, 2015

Oops, I thought I had caught them all. See if the change I just made to the issue1016 branch takes care of it for you.

@sdh4

This comment has been minimized.

Copy link
Author

commented Jan 22, 2015

Yes, it does. Works great! Thanks for the quick responses!

@dpvc

This comment has been minimized.

Copy link
Member

commented Jan 22, 2015

Glad it worked. Thanks for helping diagnose the problem, and checking the fixes. I'll merge into the v2.5 candidate soon.

dpvc pushed a commit to dpvc/MathJax that referenced this issue Jan 24, 2015

@dpvc

This comment has been minimized.

Copy link
Member

commented Jan 24, 2015

==> Merged.

@dpvc dpvc added Test Not Needed and removed Test Needed labels Jan 24, 2015

@dpvc

This comment has been minimized.

Copy link
Member

commented Jan 24, 2015

It turns out the test suite can't be used to test this issue, due to the way that MathJax is injected into the page.

@dpvc dpvc added Merged and removed Ready for Review labels Jan 24, 2015

@dpvc dpvc closed this Jan 24, 2015

@dpvc dpvc added Fixed v2.5 and removed Merged labels Jan 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.