17 lines
3.5 KiB
JavaScript
17 lines
3.5 KiB
JavaScript
/*
|
|
* /MathJax/extensions/TeX/begingroup.js
|
|
*
|
|
* Copyright (c) 2010 Design Science, Inc.
|
|
*
|
|
* Part of the MathJax library.
|
|
* See http://www.mathjax.org for details.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0;
|
|
* you may not use this file except in compliance with the License.
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*/
|
|
|
|
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function(){var d="1.1.1";var e=MathJax.InputJax.TeX,b=e.Definitions;var a=MathJax.Object.Subclass({macros:null,environments:null,Init:function(f,g){this.macros=(f||{});this.environments=(g||{})},Find:function(f,g){if(this[g][f]){return this[g][f]}},Def:function(f,h,g){this[g][f]=h},Undef:function(f,g){delete this[g][f]},Merge:function(f){MathJax.Hub.Insert(this.macros,f.macros);MathJax.Hub.Insert(this.environments,f.environments)},MergeGlobals:function(f){var g=this.macros;for(var h in g){if(g.hasOwnProperty(h)&&g[h].global){f.Def(h,g[h],"macros",true);delete g[h].global;delete g[h]}}},Clear:function(h){this.environments={};if(h){this.macros={}}else{var f=this.macros;for(var g in f){if(f.hasOwnProperty(g)&&!f[g].global){delete f[g]}}}return this}});var c=e.nsStack=MathJax.Object.Subclass({stack:null,top:0,isEqn:false,Init:function(f){this.isEqn=f;this.stack=[];if(!f){this.Push(a(b.macros,b.environments))}else{this.Push(a())}},Def:function(f,i,g,h){var j=this.top-1;if(h){while(j>0){this.stack[j].Undef(f,g);j--}if(!(i instanceof Array)){i=[i]}if(this.isEqn){i.global=true}}this.stack[j].Def(f,i,g)},Push:function(f){this.stack.push(f);this.top=this.stack.length},Pop:function(){var f;if(this.top>1){f=this.stack[--this.top];if(this.isEqn){this.stack.pop()}}else{if(this.isEqn){this.Clear()}}return f},Find:function(f,h){for(var g=this.top-1;g>=0;g--){var j=this.stack[g].Find(f,h);if(j){return j}}return null},Merge:function(f){f.stack[0].MergeGlobals(this);this.stack[this.top-1].Merge(f.stack[0]);var g=[this.top,this.stack.length-this.top].concat(f.stack.slice(1));this.stack.splice.apply(this.stack,g);this.top=this.stack.length},Reset:function(){this.top=this.stack.length},Clear:function(f){this.stack=[this.stack[0].Clear()];this.top=this.stack.length}},{nsFrame:a});b.macros.begingroup="BeginGroup";b.macros.endgroup="EndGroup";b.macros.global=["Extension","newcommand"];b.macros.gdef=["Extension","newcommand"];e.Parse.Augment({BeginGroup:function(f){e.eqnStack.Push(a())},EndGroup:function(f){if(e.eqnStack.top>1){e.eqnStack.Pop()}else{if(e.rootStack.top===1){e.Error("Extra "+f+" or missing \\begingroup")}else{e.eqnStack.Clear();e.rootStack.Pop()}}},csFindMacro:function(f){return(e.eqnStack.Find(f,"macros")||e.rootStack.Find(f,"macros"))},envFindName:function(f){return(e.eqnStack.Find(f,"environments")||e.rootStack.Find(f,"environments"))}});e.rootStack=c();e.eqnStack=c(true);e.prefilterHooks.Add(function(){e.rootStack.Reset();e.eqnStack.Clear(true)});e.postfilterHooks.Add(function(){e.rootStack.Merge(e.eqnStack)});MathJax.Hub.Register.StartupHook("TeX newcommand Ready",function(){b.macros.global="Global";b.macros.gdef=["Macro","\\global\\def"];e.Parse.Augment({setDef:function(f,g){g.isUser=true;e.eqnStack.Def(f,g,"macros",this.stack.env.isGlobal);delete this.stack.env.isGlobal},setEnv:function(f,g){g.isUser=true;e.eqnStack.Def(f,g,"environments")},Global:function(f){var g=this.i;var h=this.GetCSname(f);this.i=g;if(h!=="let"&&h!=="def"&&h!=="newcommand"){e.Error(f+" not followed by \\let, \\def, or \\newcommand")}this.stack.env.isGlobal=true}})});MathJax.Hub.Startup.signal.Post("TeX begingroup Ready")});MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/begingroup.js");
|
|
|