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

Feature request: Add ignoreClass to mml2jax configuration options #505

Open
samdooley opened this issue Jun 20, 2013 · 11 comments
Open

Feature request: Add ignoreClass to mml2jax configuration options #505

samdooley opened this issue Jun 20, 2013 · 11 comments

Comments

@samdooley
Copy link

It would be useful to allow a class name of elements whose contents should NOT be processed by mml2jax, similar to the tex2jax option. The use case I have in mind is to allow MathJax to process presentation MathML fragments in a page, while allowing other tools to process the content MathML in the page.

Here's a patch file for MathJax 2.2 that implements the support for ignoreClass.

Thanks,
Sam Dooley

From 9f4a491a68bc7fd49709363acb3d5470e87b6964 Mon Sep 17 00:00:00 2001
From: Sam Dooley sam.dooley@pearson.com
Date: Thu, 20 Jun 2013 13:21:35 -0600
Subject: [PATCH] Added ignoreClass to mml2jax configuration options
---
unpacked/extensions/mml2jax.js | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)

  diff --git a/unpacked/extensions/mml2jax.js b/unpacked/extensions/mml2jax.js
  index 1110a31..6d388be 100644
  --- a/unpacked/extensions/mml2jax.js
  +++ b/unpacked/extensions/mml2jax.js
  @@ -29,6 +29,12 @@
   MathJax.Extension.mml2jax = {
     version: "2.2",
     config: {
  +    ignoreClass: "mml2jax_ignore",
  +      // The class name of elements whose contents should
  +      // NOT be processed by mml2jax. Note that this is a
  +      // regular expression, so be sure to quote any regexp
  +      // special characters.
  +
       preview: "alttext"      // Use the <math> element's alttext as the 
                               //   preview.  Set to "none" for no preview,
                               //   or set to an array specifying an HTML snippet
  @@ -86,16 +92,18 @@ MathJax.Extension.mml2jax = {
     },

     ProcessMathArray: function (math) {
  -    var i;
  -    if (math.length) {
  -      if (this.MathTagBug) {
  -        for (i = math.length-1; i >= 0; i--) {
  -          if (math[i].nodeName === "MATH") {this.ProcessMathFlattened(math[i])}
  -                                      else {this.ProcessMath(math[i])}
  -        }
  -      } else {
  -        for (i = math.length-1; i >= 0; i--) {this.ProcessMath(math[i])}
  -      }
  +    if ( !math.length )
  +      return;
  +    if ( !this.ignoreClass )
  +      this.ignoreClass = new RegExp("(^| )("+this.config.ignoreClass+")( |$)");
  +    for ( var i = math.length - 1; i >= 0; i-- ) {
  +      var cname = math[ i ].className || "";
  +      if ( this.ignoreClass.exec( cname ) )
  +        continue;
  +      if ( this.MathTagBug && math[ i ].nodeName === "MATH" )
  +        this.ProcessMathFlattened( math[ i ] );
  +      else
  +        this.ProcessMath( math[ i ] );
       }
     },
@pkra
Copy link
Contributor

pkra commented Jun 20, 2013

I'm curious what "other tools for ContentMathML" you're thinking of. Also, are you aware of the ContentMathML extension?

@samdooley
Copy link
Author

Hi Peter,

I have written a working content MathML equation editor in JavaScript (ported from ActionScript, actually) that creates content and presentation MathML in parallel as the user types. Previous versions of the editor included a custom MathML rendering engine optimized for incremental updates needed by the editor.

I have the editor working using the browser native MathML rendering support, where it exists, and using the MathJax MathML rendering support.

The equation editor is set up to attach to instances of content MathML it finds in the page, so I would like to be able to ask MathJax to stand by until I'm ready to give it presentation MathML for it to render. Alternatively, there may be other instances of presentation MathML in the page that I would like MathJax to render, and that the editor should ignore.

I realize that having an equation editor call MathJax in this way asks it to do things for which it was not really designed, but it performs surprisingly well under the circumstances, and I am quite pleased with the result.

Sam

@pkra
Copy link
Contributor

pkra commented Jun 24, 2013

Hi Sam,

Thanks for the details -- that's sounds very interesting! Any chance this will end up open source?

In general, I'd be in favor of this feature -- simply because of consistency with other input-jax's.

[I don't quite understand why you'd let MathJax render the entire page, tough. I'd rather make individual typesetting calls for those elements that have been added to the page. But that's not my call, of course.]

@samdooley
Copy link
Author

Hi Peter,

Unfortunately I don't think this will become open source anytime soon, but it does have some likelihood of showing up in Pearson assessment offerings at some point.

While testing the patch I noticed that if MathJax gets in too early, Opera hasn't yet created the className attribute for the math elements, so I added a call to getAttribute( "class" ) as a fallback in the line that collects the class name. Somehow I don't think this is quite the right fix, but it seems to work. I'm sure you can find other appropriate tweaks in any case.

The display model I have in mind is that a page will contain static content that may include (presentation) MathML, and one or more math input areas (equation editors) where the markup is constantly changing. So I let MathJax do its thing when the page loads, and then make MathJax calls each time the editor input changes. But I admit my level of control over MathJax still feels a bit naive. What would be really nice would be the ability to reach inside a jax, replace a presentation subtree, and have MathJax update only what changes, rather than the entire jax, but there doesn't seem to be an API call for that, and I wouldn't expect one to be easy to add.

Sam

@fred-wang
Copy link
Contributor

Thanks Sam. You patch looks good to me. Some remarks:

  • We don't really have an official "coding style" yet, but the rule of thumb is to use Davide's "dense syntax" so in particular not add too much white spaces in the code.
  • We don't have official way to accept contributions either, but if possible please create a GitHub branch.
  • I think you should also define the new option in unpacked/config/default.js
  • As I read it, the other input modes merge ignoreClass with the preRemoveClass config. For consistency, I guess the MathML input Jax should do that too.

While testing the patch I noticed that if MathJax gets in too early, Opera hasn't yet created the className attribute for the math elements

I'm not sure why. Perhaps a sync issue. Are you creating the className via javascript?

What would be really nice would be the ability to reach inside a jax, replace a presentation subtree, and have MathJax update only what changes, rather than the entire jax, but there doesn't seem to be an API call for that, and I wouldn't expect one to be easy to add.

Yes I'm afraid this could really be properly done via Native MathML implementation.

@pkra pkra added this to the Next Release milestone Aug 23, 2014
@pkra
Copy link
Contributor

pkra commented Aug 23, 2014

@samdooley could you make a pull request to develop and sign http://www.mathjax.org/CLA/ ?

@pkra
Copy link
Contributor

pkra commented Aug 24, 2014

@samdooley actually scratch that. @dpcv has a broader fix in mind.

@pkra pkra removed this from the Next Release milestone Aug 24, 2014
@pkra pkra self-assigned this Aug 24, 2014
@pkra pkra added this to the A future release milestone Aug 27, 2014
@dixon
Copy link

dixon commented Dec 9, 2014

@pkra I'm curious about the broader fix - would it apply to core MathJax processing, similar to how the elements config works, except as an exclusion?

@dpvc
Copy link
Member

dpvc commented Dec 12, 2014

The broader fix would be to use the same approach as is used in tex2jax and ascimath2jax, where you can use classes to control the processing. There would be an ignore class and a process class that would allow you to turn off and on the processing of MathML within the document. This would make all three input format consistent in how they are controlled. RIght now the MathML has no control over which elements are processed by MathJax.

@pkra pkra modified the milestones: A future release, The next release Feb 26, 2015
@pkra pkra removed their assignment Feb 26, 2015
@pkra pkra modified the milestones: A future release, MathJax v2.6 Aug 4, 2015
@davecarpie
Copy link

Is there a status update on this mathml2jax ignore? I cant find it in the current docs.

@pkra
Copy link
Contributor

pkra commented Mar 3, 2016

This issue is marked Feature Request and open which indicates it has not been implemented. It is also not on any near-term milestone. PRs are always welcome of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants