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

LaTeX code in annotation-xml leads to parsing error #484

Closed
pkra opened this issue May 27, 2013 · 24 comments

Comments

Projects
None yet
3 participants
@pkra
Copy link
Member

commented May 27, 2013

I'm not sure what the problem is, but the code below gives a parsing error. "Show original MathML" indicates that the LaTeX preprocessor is processing the annotation-xml.

<math display="inline"><mrow></mrow><annotation encoding="application/x-tex">\{\begin{array}[]{cl}n &amp;\end{array}</annotation></math>
@pkra

This comment has been minimized.

Copy link
Member Author

commented May 27, 2013

Sorry, I oversimplified. This happens with a semantics tag as well.

<math><semantics><mrow></mrow><annotation encoding="application/x-tex">\begin{array}[]{cl} &amp; \end{array}</annotation></semantics></math>``
@dpvc

This comment has been minimized.

Copy link
Member

commented May 27, 2013

OK, looks like another case of where running tex2jax before mml2jax causes problems. I guess we should force mml2jax to run first (this is not hard, since the preprocessors can be given priorities for just this reason).

@ghost ghost assigned fred-wang Jun 27, 2013

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2013

I'm setting adding this to the 2.3 milestone list.

Another option seems to add annotation element to the list of tags that the tex2jax should not process. I'm going to try this first so that we can keep the tex2jax and mml2jax to run in parallel.

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2013

So adding annotation to the ASCIIMath/TeX's skipTags indeed works. I just modified the default config though, I think the other will work when I run the script to combine the config files (IIRC, Peter and I wonder the same for some localization config).

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2013

So people could actually also do

           <math><mtext>\begin{array}[]{cl} &amp; \end{array}</mtext></math>

and so probably the skipTags should actually contains the math element...

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2013

Parsing/issue484.html

@pkra

This comment has been minimized.

Copy link
Member Author

commented Jun 27, 2013

@fred-wang I'm wondering if some people use math tags as TeX delimiter. Maybe skipping the annotation tag is less intrusive?

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 1, 2013

I think it is OK to use the <math> tag, because you can't use that as a delimiter for the tex2jax preprocessor. The people who use <math> to delimit TeX use content management systems that handle the <math> tags on the server before sending it to the browser, long before MathJax runs. So that should work.

I'm wondering about the HTML5 use of HTML tags in <mtext>, so that you could have something like

<math>
  <mtext>
    <span>This is math: $x+1$</span>
  </mtext>
</math>

where math does want to be processed inside the <math> tag. But we don't handle such HTML tags anyway, and even if we did, this would have to be handled differently, so I guess this isn't a problem.

One problem with this approach is that IE < 8 doesn't properly nest unknown tags, so adding "math" to the skipTags array won't fix the problem in early versions of IE (or later versions emulating earlier versions).

The alternative is to use the preprocessor priority mechanism to ensure that the mml2jax extension runs before the tex2jax extension, so that the <math> will be removed from the page (into the MathJax <script> tags) before tex is processed. That might be more reliable.

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Aug 5, 2013

Can you tell me how the preprocessor priority mechanism works? (or should I listens signals for input MathML ready in the TeX and AsciiMath extensions?)

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 5, 2013

The MathJax.Hub.Register.PreProcessor() call takes an optional second argument that is the pre-processor's priority. The default is 10, as I recall, so setting the mml2jax priority to something like 5 should do the trick (lower priorities are run first).

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2013

OK, I've created a new branch issue485-bis

=> Ready For Review

BTW, this was also In testsuite:
Parsing/issue484.html

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 7, 2013

Line 215 of unpacked/extensions/mml2jax.js should be

MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.mml2jax],5);

The ,5 should be outside the array, so that it is the second argument to MathJax.Hub.Register.PreProcessor not the third element of the callback array (where it would become the first argument passed to MathJax.Extension.mml2jax.PreProcess).

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 7, 2013

PS, I don't see the Parsing/issue484.html file. Can you check that you committed it?

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2013

The ,5 should be outside the array

argh, time to take vacation... I've updated the branch

PS, I don't see the Parsing/issue484.html file. Can you check that you committed it?

It seems that I incorrectly commited that to the (private) fuzzer branch... Anyway the test does not seem to work very well so I must rewrite it.

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2013

test updated.

=> Ready For Review

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 7, 2013

OK, this looks good.

==> Ready for Release

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 7, 2013

I'm not sure if the test file will always fail in the earlier version. It relies on the tex2jax extension loading before the mml2jax extension. If the tests are running locally (as file:// URL's) then it probably will be OK, but if it runs over a network, it is possible for mml2jax to arrive before tex2jax (since they are requested in parallel). I don't think the framework allows for it, but one solution would be to force the loading order by loading the components by hand.

It might be possible to use a text/x-mathjax-config script (or maybe a listener on the "End Config" signal) within the test file to alter the extensions array (empty it) and force the loading via MathJax.Ajax.Require calls in a MathJax.Callback.Queue (to get the order maintained). Something like

<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("End Config", function () {
  MathJax.Hub.Config({extension:[]});  // clear extensions.
  var queue = MathJax.Callback.Queue(
    ["Require",MathJax.Ajax,"[MathJax]/extensions/tex2jax.js"],
    ["Require",MathJax.Ajax,"[MathJax]/extensions/mml2jax.js"]
  );
  return queue.Push({});  // this should make the End Config signal wait until
                                   //   the queue is complete before going on
});
</script>

should force loading tex2jax first and mml2jax second. (This is untested code.) The idea is that in the earlier version, tex2jax will register itself first, and so will run first, and mess up the MathML, whereas in the corrected version, the priority on the Register.PreProcess() will cause mml2jax to run first, even though it was loaded second.

I think that guaranteeing the order to loading is the heart of the test.

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 8, 2013

@fred-wang, Did I accidentally mark this "Ready for Development", rather than "Ready for Release" or did you change it for some reason? I think the branch is ready for a pull request.

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2013

Yes, sorry I think I removed "Ready for release" this morning because I thought there were other things to address. But that was for the test. I'll send a pull request.

dpvc pushed a commit that referenced this issue Aug 8, 2013

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 8, 2013

==> Merged

I'm leaving open so you can see the comment about the test. If you want to close it, that's fine.

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2013

Test updated.

@fred-wang fred-wang closed this Aug 8, 2013

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2013

I'm reopening this. When only the TeX or AsciiMath are used, they should still not process the annotation in MathML elements. So I guess "annotation" should be marked skipped. This will allow

<math>
  <mtext>
    <span>This is math: $x+1$</span>
  </mtext>
</math>

to be rendered correctly I guess.

@fred-wang fred-wang reopened this Aug 8, 2013

@dpvc

This comment has been minimized.

Copy link
Member

commented Aug 9, 2013

OK, I don't have a problem adding annotation to the skipTags list. What about annotation-xml? Processing them would not produce anything illegal, but depending on the encoding, it might not be appropriate to process them.

@fred-wang

This comment has been minimized.

Copy link
Contributor

commented Aug 9, 2013

Yes, I think we don't want to process annotation-xml either.

dpvc pushed a commit that referenced this issue Aug 27, 2013

@dpvc dpvc closed this Aug 27, 2013

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.