MathJax icon indicating copy to clipboard operation
MathJax copied to clipboard

MathML mathjax fallback stumbles over links (<span> tags).

Open lqas opened this issue 4 years ago • 4 comments

Issue Summary

I simplified the problem when I used solr to search for returned results and highlight them, my highlight tag is ; Here is an error: "Unknown node type: span"

These use the tag which seems to be what mathjax is having issues with.

Steps to Reproduce:

The problem can be seen by saving the code to an html file.

I found this solution https://github.com/mathjax/MathJax/issues/2860#issuecomment-1092044356, which works very well in v3.

I'm sorry to ask you this unpleasant question

How can this be done in V2? I have been trying for a long time to find a solution, so if you can help me with an answer, would be very grateful! Thanks in advance!

Technical details:

MathJax Version: 2.7.9 Client OS: (Mac OS X 13.1) Browser: (Chrome 92.0.4541)

I am using the following code:

<html>
<body>

<math>
	<mi>Hello</mi>
	<mi>
		<span>10</span>
	</mi>
</math>

</body>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        config: ["MMLorHTML.js"],
        jax: ["input/MathML"],
        extensions: ["tex2jax.js","mml2jax.js"]
    });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=default' defer></script>
</html>

Supporting information:

image

lqas avatar Jul 21 '22 13:07 lqas

The MathML specification provides for the option of allowing HTML embedded in MathML, and the HTML5 specification does include that option, but MathJax does not yet implement that (yet). It will be part of the next release of v3, but it is not expected to be back-ported to v2.

It is possible to put HTML inside a <semantics> element and have it displayed, but it uses a legacy "loophole" that is not really valid MathML, and it can't be inside an <mi>.

Can you say more about what you are trying to accomplish? It might help to know what you are really after.

dpvc avatar Jul 21 '22 15:07 dpvc

Hi guys,

I would like to remove the span tag in MathML.

The V3 solution you implemented here https://github.com/mathjax/MathJax/issues/2860#issuecomment-1092044356 , I see that you said some changes need to be made in v2.

I want to know how to do it in V2.

lqas avatar Jul 22 '22 00:07 lqas

Here is a configuration that will do it:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  config: ["MMLorHTML.js"],
  jax: ["input/MathML"],
  extensions: ["tex2jax.js","mml2jax.js"]
});
MathJax.Hub.Register.StartupHook('MathML Jax Ready', function () {
  var MathML = MathJax.InputJax.MathML;
  MathML.DOMfilterHooks.Add(({math}) => {
    const tags = Array.from(math.querySelectorAll('span'));
    tags.forEach(tag => tag.parentNode.innerHTML = tag.innerHTML);
  });
});
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=default' defer></script>

dpvc avatar Jul 23 '22 16:07 dpvc

Thank you very very very very much.

lqas avatar Jul 25 '22 00:07 lqas