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

Support for MathJax 2.7.1 in a hakish way! #12

Merged
merged 1 commit into from
Jun 12, 2017

Conversation

OmarIthawi
Copy link
Contributor

@OmarIthawi OmarIthawi commented Jun 11, 2017

Open edX platform Ficus and beyond is using MathJax 2.7. So we need for the extension to support MathJax 2.7 as well.

The array hack caused the extension to partially break. Checkout my mathjax-dev post for more info.

The issue was introduced by: mathjax/MathJax#1523.

@OmarIthawi OmarIthawi force-pushed the omar/support-for-mathjax-2.7 branch from 6d4a6b8 to 9dc90ba Compare June 11, 2017 12:09
@OmarIthawi OmarIthawi force-pushed the omar/support-for-mathjax-2.7 branch from 08904b7 to 9df604f Compare June 12, 2017 08:47
@OmarIthawi
Copy link
Contributor Author

A non-production release v1.1-alpha have been created to demonstrate the bug.

@OmarIthawi
Copy link
Contributor Author

I've added another hack to solve it. This needs to be fixed but I'm still not sure how, let's make it in a future release.

@OmarIthawi OmarIthawi changed the title (WIP) Support for MathJax 2.7 Support for MathJax 2.7.1 in a hakish way! Jun 12, 2017
@OmarIthawi OmarIthawi merged commit 5860249 into master Jun 12, 2017
@dpvc
Copy link

dpvc commented Jun 14, 2017

Sorry for the delay in getting back to you. Hope this helps anyway.

Here is my recommendation. You don't want to set copyEnv = true because that will allow other things to bleed through to the table that shouldn't be. Instead, we want to copy the lang to the env after the array stack item is created. Ideally, that would be done in the Init() call, but because the env isn't set up until the array pushed onto the stack (and the Init() function doesn't have access to the stack), you can't do it then. Instead, you have to wait for it to be pushed on the stack. So my suggestion is overriding the stack's Push() function and transfer the lang if the pushed time is an array.

The following should do it.

MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
  var STACK = MathJax.InputJax.TeX.Stack;
  var PUSH = STACK.prototype.Push;
  STACK.Augment({
    Push: function (item) {
      var lang = this.env.lang;
      PUSH.apply(this,arguments);
      if (lang && item instanceof STACK.Item.array) {
        this.env.lang = lang;
      }
    }
  });
  var CLEAR = STACK.Item.array.prototype.clearEnv;
  STACK.Item.Augment({
    clearEnv: function () {
      let lang = this.env.lang;
      CLEAR.call(this);
      if (lang) this.env.lang = lang;
    }
  });
});

This only copies the lang property, so doesn't bleed any other properties like copyEnv does.

Hope that helps.

@OmarIthawi
Copy link
Contributor Author

OmarIthawi commented Jun 15, 2017

No worries at all @dpvc. Yeah, I know that the I'm doing a terrible hack here, but it works for my basic test suite.

I'll create a test case for the environment bleed 🔪 that I've done. I'll use the code you've suggested to make sure it was fixed, then follow up with another release.

Thanks a lot!

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

Successfully merging this pull request may close these issues.

2 participants