From 9df604f9b7002350ab6a5255bc02ac77acc26109 Mon Sep 17 00:00:00 2001 From: Omar Al-Ithawi Date: Sun, 11 Jun 2017 15:00:23 +0300 Subject: [PATCH] Support for MathJax 2.7.1 in a hakish way! --- dist/arabic.js | 2 +- dist/unpacked/arabic.js | 12 ++++++++++++ src/tex.js | 12 ++++++++++++ testcases/index.html | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/dist/arabic.js b/dist/arabic.js index ecbaea6..884f2b9 100644 --- a/dist/arabic.js +++ b/dist/arabic.js @@ -24,4 +24,4 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -MathJax.Hub.Register.StartupHook("HTML-CSS Jax Require",function(){MathJax.Hub.Config({"HTML-CSS":{styles:{".MathJax .mfliph":{display:"inline-block !important","-moz-transform":"scaleX(-1)","-webkit-transform":"scaleX(-1)","-o-transform":"scaleX(-1)",transform:"scaleX(-1)","-ms-filter":"fliph",filter:"fliph"},".MathJax .mar":{"font-style":"normal !important"},".MathJax .mar > span":{"font-style":"normal !important"}}}})}),MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function(){MathJax.Hub.Register.StartupHook("Arabic TeX Ready",function(){var a=MathJax.ElementJax.mml,t=function(t){var r=a[t].prototype.toHTML;a[t].Augment({toHTML:function(){var a=r.apply(this,arguments);if(this.arabicFlipH){var t=document.createElement("span");for(t.className="mfliph","ar"===this.arabicFontLang&&(t.className+=" mar");a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t)}return a}})};["mfrac","mi","mn","mo","mrow","ms","msqrt","msubsup","mroot","mtext"].forEach(t),MathJax.Hub.Register.StartupHook("HTML-CSS mtable Ready",function(){t("mtable"),MathJax.Hub.Startup.signal.Post("Arabic mtable Ready")}),MathJax.Hub.Startup.signal.Post("Arabic Ready")})}),MathJax.Extension.Arabic={version:"1.0.0",config:MathJax.Hub.CombineConfig("Arabic",{dict:{Zero:["zero","Text",["0","\u0635\u0641\u0631"]],Radius:["radius","Text",["r","\u0646\u0642"]],Area:["Area","Text",["A","\u0645"]]},identifiersMap:{a:"\u0623",b:"\u0628",c:"\u062c\u0640",x:"\u0633",y:"\u0635",z:"\u0639",n:"\u0646",f:"\u0642",g:"\u062c\u0640",h:"\u0647\u0640",k:"\u0643",r:"\u0631",t:"\u062a",d:"\u062f",e:"\u0647\u0640",m:"\u0645",l:"\u0644",sin:"\u062c\u0627",cos:"\u062c\u062a\u0627",tan:"\u0638\u0627",cot:"\u0638\u062a\u0627",sec:"\u0642\u0627",csc:"\u0642\u062a\u0627",log:"\u0644\u0648"},numbersMap:{0:"\u0660",1:"\u0661",2:"\u0662",3:"\u0663",4:"\u0664",5:"\u0665",6:"\u0666",7:"\u0667",8:"\u0668",9:"\u0669"},operatorsMap:{",":"\u060c",";":"\u061b",lim:"\u0646\u0647\u0640\u0640\u0627"},isArabicPage:"ar"===document.documentElement.lang}),arabicLanguageRegExp:/([\u0600-\u06FF]+)/g,TeX:function(a,t){return function(r){var n,e=MathJax.InputJax.TeX;n="ar"===this.stack.env.lang?t:a,this.Push(e.Parse(n).mml())}},Text:function(a,t){return MathJax.Extension.Arabic.TeX(a,"\\fliph{\\text{"+t+"}}")},Symbols:function(a,t){var r=t.replace(MathJax.Extension.Arabic.arabicLanguageRegExp,"\\fliph{\\text{$1}}");return MathJax.Extension.Arabic.TeX(a,r)}},MathJax.Hub.Startup.signal.Post("Arabic TeX Startup"),MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var a=MathJax.InputJax.TeX,t=MathJax.Extension.Arabic,r=a.Parse.prototype.mmlToken,n=MathJax.Hub.config.Arabic.dict,e=function(){var a=/[\\^$.*+?()[\]{}|]/g;return function(t){return t.replace(a,"\\$&")}}(),i=function(a){var t=Object.keys(a).sort(function(a,t){return t.length-a.length});return new RegExp(t.map(e).join("|"),"gi")};a.Definitions.Add({macros:{ar:"HandleArabic",alwaysar:"MarkAsArabic",fliph:"HandleFlipHorizontal",transx:"TranslateTeX",transt:"TranslateText",transs:"TranslateSymbols"}});var o=a.Stack.Item.array,s=o.prototype.clearEnv;o.Augment({clearEnv:function(){var a=this.env.lang;s.apply(this,arguments),a&&(this.env.lang=a)}}),a.Definitions.Add({macros:function(){var a={};return Object.keys(n).forEach(function(t){var r=n[t][0];a[r]=t}),a}()}),a.Parse.Augment(function(){var a={};return Object.keys(n).forEach(function(r){var e=n[r][1],i=n[r][2];a[r]=t[e].apply(null,i)}),a}()),a.Parse.Augment({flipHorizontal:function(a){return a.arabicFlipH=!a.arabicFlipH,a},arabicNumber:function(){var a=/[0-9]/g,t=MathJax.Hub.config.Arabic.numbersMap,r=function(a){return t[a]};return function(t){var n=t.data[0].data[0],e=n.replace(a,r);return e!==n&&(t.data[0].data[0]=e,t.arabicFontLang="ar"),this.flipHorizontal(t)}}(),arabicIdentifier:function(){var a=MathJax.Hub.config.Arabic.identifiersMap,t=i(a),r=function(t){return a[t.toLowerCase()]};return function(a){var n=a.data[0].data[0];if("chars"===a.data[0].type){var e=n.replace(t,r);e!==n&&(a.data[0].data[0]=e,a.arabicFontLang="ar")}return this.flipHorizontal(a)}}(),arabicOperator:function(){var a=MathJax.Hub.config.Arabic.operatorsMap,t=i(a),r=function(t){return a[t]};return function(a){var n=a.data[0].data[0],e=n.replace(t,r);return e!==n&&(a=this.flipHorizontal(a),a.arabicFontLang="ar",a.data[0].data[0]=e),a}}(),_getArgumentMML:function(a){var t=this.ParseArg(a);return t.inferred&&1===t.data.length?t=t.data[0]:delete t.inferred,t},mmlToken:function(a){var t=r.call(this,a);return"ar"===this.stack.env.lang&&this.markArabicToken(t),t},markArabicToken:function(a){return"mn"===a.type?this.arabicNumber(a):"mi"===a.type?this.arabicIdentifier(a):"mo"===a.type?this.arabicOperator(a):a},HandleArabic:function(a){MathJax.Hub.config.Arabic.isArabicPage&&this.MarkAsArabic(a)},TranslateTeX:function(a){var r=this.GetArgument(a),n=this.GetArgument(a),e=t.TeX(r,n);return e.call(this,a)},TranslateText:function(a){var r=this.GetArgument(a),n=this.GetArgument(a),e=t.Text(r,n);return e.call(this,a)},TranslateSymbols:function(a){var r=this.GetArgument(a),n=this.GetArgument(a),e=t.Symbols(r,n);return e.call(this,a)},MarkAsArabic:function(a){var t=this.stack.env.lang;this.stack.env.lang="ar";var r=this._getArgumentMML(a);this.stack.env.lang=t,this.Push(this.flipHorizontal(r))},HandleFlipHorizontal:function(a){var t=this._getArgumentMML(a);this.Push(this.flipHorizontal(t))}}),MathJax.Hub.Startup.signal.Post("Arabic TeX Ready")}),MathJax.Ajax.loadComplete("[arabic]/arabic.js"); \ No newline at end of file +MathJax.Hub.Register.StartupHook("HTML-CSS Jax Require",function(){MathJax.Hub.Config({"HTML-CSS":{styles:{".MathJax .mfliph":{display:"inline-block !important","-moz-transform":"scaleX(-1)","-webkit-transform":"scaleX(-1)","-o-transform":"scaleX(-1)",transform:"scaleX(-1)","-ms-filter":"fliph",filter:"fliph"},".MathJax .mar":{"font-style":"normal !important"},".MathJax .mar > span":{"font-style":"normal !important"}}}})}),MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function(){MathJax.Hub.Register.StartupHook("Arabic TeX Ready",function(){var a=MathJax.ElementJax.mml,t=function(t){var r=a[t].prototype.toHTML;a[t].Augment({toHTML:function(){var a=r.apply(this,arguments);if(this.arabicFlipH){var t=document.createElement("span");for(t.className="mfliph","ar"===this.arabicFontLang&&(t.className+=" mar");a.firstChild;)t.appendChild(a.firstChild);a.appendChild(t)}return a}})};["mfrac","mi","mn","mo","mrow","ms","msqrt","msubsup","mroot","mtext"].forEach(t),MathJax.Hub.Register.StartupHook("HTML-CSS mtable Ready",function(){t("mtable"),MathJax.Hub.Startup.signal.Post("Arabic mtable Ready")}),MathJax.Hub.Startup.signal.Post("Arabic Ready")})}),MathJax.Extension.Arabic={version:"1.0.0",config:MathJax.Hub.CombineConfig("Arabic",{dict:{Zero:["zero","Text",["0","\u0635\u0641\u0631"]],Radius:["radius","Text",["r","\u0646\u0642"]],Area:["Area","Text",["A","\u0645"]]},identifiersMap:{a:"\u0623",b:"\u0628",c:"\u062c\u0640",x:"\u0633",y:"\u0635",z:"\u0639",n:"\u0646",f:"\u0642",g:"\u062c\u0640",h:"\u0647\u0640",k:"\u0643",r:"\u0631",t:"\u062a",d:"\u062f",e:"\u0647\u0640",m:"\u0645",l:"\u0644",sin:"\u062c\u0627",cos:"\u062c\u062a\u0627",tan:"\u0638\u0627",cot:"\u0638\u062a\u0627",sec:"\u0642\u0627",csc:"\u0642\u062a\u0627",log:"\u0644\u0648"},numbersMap:{0:"\u0660",1:"\u0661",2:"\u0662",3:"\u0663",4:"\u0664",5:"\u0665",6:"\u0666",7:"\u0667",8:"\u0668",9:"\u0669"},operatorsMap:{",":"\u060c",";":"\u061b",lim:"\u0646\u0647\u0640\u0640\u0627"},isArabicPage:"ar"===document.documentElement.lang}),arabicLanguageRegExp:/([\u0600-\u06FF]+)/g,TeX:function(a,t){return function(r){var n,e=MathJax.InputJax.TeX;n="ar"===this.stack.env.lang?t:a,this.Push(e.Parse(n).mml())}},Text:function(a,t){return MathJax.Extension.Arabic.TeX(a,"\\fliph{\\text{"+t+"}}")},Symbols:function(a,t){var r=t.replace(MathJax.Extension.Arabic.arabicLanguageRegExp,"\\fliph{\\text{$1}}");return MathJax.Extension.Arabic.TeX(a,r)}},MathJax.Hub.Startup.signal.Post("Arabic TeX Startup"),MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var a=MathJax.InputJax.TeX,t=MathJax.Extension.Arabic,r=a.Parse.prototype.mmlToken,n=MathJax.Hub.config.Arabic.dict,e=function(){var a=/[\\^$.*+?()[\]{}|]/g;return function(t){return t.replace(a,"\\$&")}}(),i=function(a){var t=Object.keys(a).sort(function(a,t){return t.length-a.length});return new RegExp(t.map(e).join("|"),"gi")};a.Definitions.Add({macros:{ar:"HandleArabic",alwaysar:"MarkAsArabic",fliph:"HandleFlipHorizontal",transx:"TranslateTeX",transt:"TranslateText",transs:"TranslateSymbols"}});var o=a.Stack.Item.array,s=o.prototype.clearEnv,c=o.prototype.Init;o.Augment({Init:function(){c.apply(this,arguments),this.copyEnv=!0},clearEnv:function(){var a=this.env.lang;s.apply(this,arguments),a&&(this.env.lang=a)}}),a.Definitions.Add({macros:function(){var a={};return Object.keys(n).forEach(function(t){var r=n[t][0];a[r]=t}),a}()}),a.Parse.Augment(function(){var a={};return Object.keys(n).forEach(function(r){var e=n[r][1],i=n[r][2];a[r]=t[e].apply(null,i)}),a}()),a.Parse.Augment({flipHorizontal:function(a){return a.arabicFlipH=!a.arabicFlipH,a},arabicNumber:function(){var a=/[0-9]/g,t=MathJax.Hub.config.Arabic.numbersMap,r=function(a){return t[a]};return function(t){var n=t.data[0].data[0],e=n.replace(a,r);return e!==n&&(t.data[0].data[0]=e,t.arabicFontLang="ar"),this.flipHorizontal(t)}}(),arabicIdentifier:function(){var a=MathJax.Hub.config.Arabic.identifiersMap,t=i(a),r=function(t){return a[t.toLowerCase()]};return function(a){var n=a.data[0].data[0];if("chars"===a.data[0].type){var e=n.replace(t,r);e!==n&&(a.data[0].data[0]=e,a.arabicFontLang="ar")}return this.flipHorizontal(a)}}(),arabicOperator:function(){var a=MathJax.Hub.config.Arabic.operatorsMap,t=i(a),r=function(t){return a[t]};return function(a){var n=a.data[0].data[0],e=n.replace(t,r);return e!==n&&(a=this.flipHorizontal(a),a.arabicFontLang="ar",a.data[0].data[0]=e),a}}(),_getArgumentMML:function(a){var t=this.ParseArg(a);return t.inferred&&1===t.data.length?t=t.data[0]:delete t.inferred,t},mmlToken:function(a){var t=r.call(this,a);return"ar"===this.stack.env.lang&&this.markArabicToken(t),t},markArabicToken:function(a){return"mn"===a.type?this.arabicNumber(a):"mi"===a.type?this.arabicIdentifier(a):"mo"===a.type?this.arabicOperator(a):a},HandleArabic:function(a){MathJax.Hub.config.Arabic.isArabicPage&&this.MarkAsArabic(a)},TranslateTeX:function(a){var r=this.GetArgument(a),n=this.GetArgument(a),e=t.TeX(r,n);return e.call(this,a)},TranslateText:function(a){var r=this.GetArgument(a),n=this.GetArgument(a),e=t.Text(r,n);return e.call(this,a)},TranslateSymbols:function(a){var r=this.GetArgument(a),n=this.GetArgument(a),e=t.Symbols(r,n);return e.call(this,a)},MarkAsArabic:function(a){var t=this.stack.env.lang;this.stack.env.lang="ar";var r=this._getArgumentMML(a);this.stack.env.lang=t,this.Push(this.flipHorizontal(r))},HandleFlipHorizontal:function(a){var t=this._getArgumentMML(a);this.Push(this.flipHorizontal(t))}}),MathJax.Hub.Startup.signal.Post("Arabic TeX Ready")}),MathJax.Ajax.loadComplete("[arabic]/arabic.js"); \ No newline at end of file diff --git a/dist/unpacked/arabic.js b/dist/unpacked/arabic.js index c85e4da..6f1dce9 100644 --- a/dist/unpacked/arabic.js +++ b/dist/unpacked/arabic.js @@ -244,11 +244,23 @@ MathJax.Hub.Register.StartupHook('TeX Jax Ready', function () { var array = TEX.Stack.Item.array; var arrayClearEnv = array.prototype.clearEnv; + var arrayInit = array.prototype.Init; array.Augment({ + Init: function () { + // Overcome the copyEnv issue that has been introduced in: + // - Pull Request: https://github.com/mathjax/MathJax/pull/1523 + // + // Otherwise arrays won't be Arabized. + // - Bug Report: https://groups.google.com/forum/#!topic/mathjax-dev/cWoTKcwMqmY + arrayInit.apply(this, arguments); + this.copyEnv = true; + }, clearEnv: function () { // Propagate `lang` from Arrays to their children fractions and others. // This is a bug in the MathJax itself, so this code should be removed once the bug is fixed. + // Follow up on https://github.com/mathjax/MathJax/pull/1523 + // It's still not clear how/when a proper solution is possible. var lang = this.env.lang; arrayClearEnv.apply(this, arguments); diff --git a/src/tex.js b/src/tex.js index 95d5444..ce6fa8b 100644 --- a/src/tex.js +++ b/src/tex.js @@ -136,11 +136,23 @@ MathJax.Hub.Register.StartupHook('TeX Jax Ready', function () { var array = TEX.Stack.Item.array; var arrayClearEnv = array.prototype.clearEnv; + var arrayInit = array.prototype.Init; array.Augment({ + Init: function () { + // Overcome the copyEnv issue that has been introduced in: + // - Pull Request: https://github.com/mathjax/MathJax/pull/1523 + // + // Otherwise arrays won't be Arabized. + // - Bug Report: https://groups.google.com/forum/#!topic/mathjax-dev/cWoTKcwMqmY + arrayInit.apply(this, arguments); + this.copyEnv = true; + }, clearEnv: function () { // Propagate `lang` from Arrays to their children fractions and others. // This is a bug in the MathJax itself, so this code should be removed once the bug is fixed. + // Follow up on https://github.com/mathjax/MathJax/pull/1523 + // It's still not clear how/when a proper solution is possible. var lang = this.env.lang; arrayClearEnv.apply(this, arguments); diff --git a/testcases/index.html b/testcases/index.html index 1fe7875..d3ff6b8 100644 --- a/testcases/index.html +++ b/testcases/index.html @@ -26,7 +26,7 @@ if (isLocalDevelopment) { mathjaxScript = '/mathjax/unpacked/MathJax.js?config=' + mathjaxConfigs; } else { - mathjaxScript = '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.6.1/MathJax.js?config=' + mathjaxConfigs; + mathjaxScript = '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=' + mathjaxConfigs; } var script = document.createElement("script");