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
Add options preview=mathml and preview=altimg to the mml2Jax preprocessor #557
Comments
The behavior is: none => no preview I'm wondering if we should change the default to be 'mathml' as it is a better preview for browsers with (even limited) MathML support. Also, the preview for altimg and alttext may be nothing if the attributes are not specified on the math element, which is the case for most MathML content I guess (perhaps they should fallback to the math rather than showing nothing). I haven't tried to see if the Safe extension can be used to filter altimg. |
I'd be in favor of switching to the default to 'mathml'. Or even better: jqmath (but that's out of scope for v2.3). |
Not sure about how to do jqmath, from my limited experiments I think the work done is significant enough so that we may not want that during the mml2jax parsing (especially if we want to optimize the MathML input steps in the future). Whether or not 'mathml' becomes the default, what about my comment about falling back to mathml for the altimg/alttext modes when the relevant attributes are missing? Or should we continue to show nothing in these modes? |
OK, I've changed the default to 'mathml'. => Ready for review |
The idea is a good one, and adding both MathML and altimg previews is great. There is a problem, however, with IE < 9 (or perhaps it is just 8), which is that the So I guess that means either 1) abandon earlier versions of IE, at least for previews, 2) use DOMParser to parse the MathML string now (at least for IE) when a MathML preview is requested. Thoughts? |
Note, this will require an update to the documentation when it is added. (Not sure if that gets added to the milestone or not.) |
Regarding doc: I'm guessing this should be added to #534 I didn't really try with IE but since it does not have MathML support and since MathPlayer is only loaded in the NativeMML output, perhaps we can abandon the mathml previews for IE and just come back to the altext? |
(also when MathPlayer is installed, the preview is not really needed since the rendering will be fast) |
Let's open issues on the docs repository and create a milestone there as well. |
There is no guarantee that the output will be NativeMML, so the output may be slow. (Not every configuration picks NativeMML for IE, namely I'm OK with not having MathML previews for IE, but if not having support for MathML is a reason not to use the mathml preview, are we now really talking about a conditional preview that is mathml when native MathML is available and alttext/altimg otherwise? The logic becomes a little more complicated. I'm wondering if |
alttext/altimg might not be available either (actually I think that's the case for most MathML content). I think mathml preview is what we want in most cases. That at least give the opportunity to compare MathML support and encourage browser developments, so Gecko/WebKit users could get an acceptable preview (this seems particularly important on mobile devices that are using WebKit) and Chrome/Opera users a bad one (but I hope this will improve). IE is particular, so let's ignore the mathml preview. Also people creating MathML input and intentionally creating alt-content will probably want to configure MathJax themselves. In general I think people creating MathML input are more tolerant regarding the quality of the native MathML, so a mathml preview is best for them. |
Right, which is why I was wondering about an ordered list of preview options, rather than just one.
They may not want to, but they certainly can in order to override the default. In any case, you are correct that that gives them what they need. Code up what you think it should be. It sounds reasonable. |
Yes, I meant, in general we don't have anything but the math tag and otherwise people intentionally creating alt content do the same for all math and know whether they want to use one alt content or the math tag. So it's not really necessary to create an orderered list in my opinion, they just need to specify the one they want. |
OK. That does makes things easier for MathJax. |
OK, this takes care of IE, but I'm afraid I found another problem. The preview can no longer be an HTML snippet (as it could originally). That is because you have changed the Also, I'd move line 192 into the |
argh, I thought I had taken care of this case :( I'll fix that. |
OK, I've commited a change to fix the HTML snippet issue.
altext is use in the img alt text of the altimg preview. |
Looks good. => Ready for Release |
=> Merged |
preview=mathml seems to double the number of "New Math" signal for one MathML input. See for example |
Configuration/mml2jax/preview-1b.html must be updated now that preview=alttext is not the default. Probably need more tests for the different options. => Unit test wanted |
This seems to be the reason why Configuration/MMLorHTML/prefer-2.html fails too: the MathML preview is parsed and removed so MathJax-Span-1 no longer exists. |
When the MathML tree contains "id" attributes, copying it leads to duplicate attribute. This seems to cause these tests to fail: |
This also makes the tests for |
It would probably be a good idea to remove id's from the MathML before inserting it into the preview, or perhaps prefix them with something like "MJX-preview-". The only place I can think of where the id's would be needed is in the line breaking where you use breaking at the same place as an element given by an id. But MathJax doesn't yet support that (and I don't think FF does either), so it is not an immediate concern., but may be in the future. |
So before handling duplicate id's, the big problem here is that the <math> preview seems to be sent to the output Jax, while it should not. Not sure why, but perhaps inserting a math element modifies a dynamic getElementByTagName('math') list somewhere. If the preview only exists at the same time as the script tag and if only the script tag is considered by the output Jax, I suspect this would fix all the problems. |
I haven't had the chance to look at the double signal issue, but commented on the id issue since I had something to say about that. Your suggestion is a plausible one, as the mml2jax preprocessor uses |
I'm looking into it right now. Indeed, that seems to happen in the mml2jax preprocessor, the double <script> being created. That's actually slightly more complex because the mml2jax does several calls to getElementByTagName to handle the different cases. I'm trying to create a single array before preprocessing the math elements. |
It may also be a good idea to check the class of the parent element and skip any that are the |
OK, I've commited something that seems to fix the issues on Chrome & Firefox. I'll try to do more testing. |
Looks good over all. A couple of comments: The
This also keeps the order in the array rather than reversing it, so if you want to process the math top down rather than bottom up as it was originally, you could also change the The test for the math preview should use Finally, shouldn't |
I'm not really sure to be honest, I tried true, false and no cloneNode at all. Only false worked on Chrome & Firefox. |
I updated the branch. That seems to work on Firefox, Opera, IE (all modes) and Chrome. There is one issue with skipping the MathJax.Hub.config.preRemoveClass: this will skip everything if the user set that to "". This was done in some tests to prevent the preview removal. However, the solution is to modify the tests to set them to null instead. |
Davide, can you check that one so that I can launch the tests again? |
I don't think I'm going to be able to work on this again until Monday or Tuesday, but will as soon as I can. |
That looks OK. Technically, we should check for |
OK, should I update the branch or can we just go with that? |
=> Ready to Release |
WE can let it go for now. But keep in mind for the future. |
By default, the mml2Jax removes the <math> tag and replaces it by the alttext if there is one (preview="altext"). The other known preview is "none". We could add twi other values: preview=mathml (original MathML element) and preview=altimg (altimg tag).
The text was updated successfully, but these errors were encountered: