UNPKG

mathjax

Version:

Beautiful and accessible math in all browsers. MathJax is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all browsers. This package includes the packaged components (install mathjax-full to get the source

1 lines 8.78 kB
(()=>{"use strict";var e={d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})}};e.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};e.r(t),e.d(t,{BeginEnvItem:()=>M});var n={};e.r(n),e.d(n,{NewcommandPriority:()=>v,NewcommandTables:()=>k,NewcommandUtil:()=>G});var a={};e.r(a),e.d(a,{default:()=>S});var r={};e.r(r),e.d(r,{NewcommandConfig:()=>L,NewcommandConfiguration:()=>J});const i=("undefined"!=typeof window?window:e.g).MathJax._.components.global,o=(i.GLOBAL,i.isObject,i.combineConfig,i.combineDefaults,i.combineWithMathJax),s=(i.MathJax,MathJax._.input.tex.HandlerTypes),c=s.ConfigurationType,l=s.HandlerType,m=MathJax._.input.tex.Configuration,d=m.Configuration,u=(m.ConfigurationHandler,m.ParserConfiguration,MathJax._.input.tex.TexError.default),g=MathJax._.input.tex.StackItem,h=(g.MmlStack,g.BaseItem);class M extends h{get kind(){return"beginEnv"}get isOpen(){return!0}checkItem(e){if(e.isKind("end")){if(e.getName()!==this.getName())throw new u("EnvBadEnd","\\begin{%1} ended with \\end{%2}",this.getName(),e.getName());return[[this.factory.create("mml",this.toMml())],!0]}if(e.isKind("stop"))throw new u("EnvMissingEnd","Missing \\end{%1}",this.getName());return super.checkItem(e)}}const f=MathJax._.input.tex.MapHandler,p=(f.MapHandler,f.SubHandler),b=(f.SubHandlers,MathJax._.input.tex.UnitUtil.UnitUtil),w=MathJax._.input.tex.Token,N=w.Token,E=w.Macro;var k;!function(e){e.NEW_DELIMITER="new-Delimiter",e.NEW_COMMAND="new-Command",e.NEW_ENVIRONMENT="new-Environment"}(k||(k={}));const v=-100,G={GetCSname(e,t){if("\\"!==e.GetNext())throw new u("MissingCS","%1 must be followed by a control sequence",t);const n=b.trimSpaces(e.GetArgument(t)).substring(1);return this.checkProtectedMacros(e,n),n},GetCsNameArgument(e,t){let n=b.trimSpaces(e.GetArgument(t));if("\\"===n.charAt(0)&&(n=n.substring(1)),!n.match(/^(.|[a-z]+)$/i))throw new u("IllegalControlSequenceName","Illegal control sequence name for %1",t);return this.checkProtectedMacros(e,n),n},GetArgCount(e,t){let n=e.GetBrackets(t);if(n&&(n=b.trimSpaces(n),!n.match(/^[0-9]+$/)))throw new u("IllegalParamNumber","Illegal number of parameters specified in %1",t);return n},GetTemplate(e,t,n){let a=e.GetNext();const r=[];let i=0,o=e.i;for(;e.i<e.string.length;){if(a=e.GetNext(),"#"===a){if(o!==e.i&&(r[i]=e.string.substring(o,e.i)),a=e.string.charAt(++e.i),!a.match(/^[1-9]$/))throw new u("CantUseHash2","Illegal use of # in template for %1",n);if(parseInt(a)!==++i)throw new u("SequentialParam","Parameters for %1 must be numbered sequentially",n);o=e.i+1}else if("{"===a)return o!==e.i&&(r[i]=e.string.substring(o,e.i)),r.length>0?[i.toString()].concat(r):i;e.i++}throw new u("MissingReplacementString","Missing replacement string for definition of %1",t)},GetParameter(e,t,n){if(null==n)return e.GetArgument(t);let a=e.i,r=0,i=!1;for(;e.i<e.string.length;){const o=e.string.charAt(e.i);if("{"===o)i=e.i===a,e.GetArgument(t),r=e.i-a;else{if(this.MatchParam(e,n))return i&&(a++,r-=2),e.string.substring(a,a+r);if("\\"===o){e.i++,r++,i=!1;const t=e.string.substring(e.i).match(/[a-z]+|./i);t&&(e.i+=t[0].length,r=e.i-a)}else e.i++,r++,i=!1}}throw new u("RunawayArgument","Runaway argument for %1?",t)},MatchParam:(e,t)=>e.string.substring(e.i,e.i+t.length)!==t||t.match(/\\[a-z]+$/i)&&e.string.charAt(e.i+t.length).match(/[a-z]/i)?0:(e.i+=t.length,1),checkGlobal:(e,t,n)=>e.stack.env.isGlobal?e.configuration.packageData.get("begingroup").stack.checkGlobal(t,n):n.map((t=>e.configuration.handlers.retrieve(t))),checkProtectedMacros(e,t){var n;if(null===(n=e.options.protectedMacros)||void 0===n?void 0:n.includes(t))throw new u("ProtectedMacro","The control sequence %1 can't be redefined",`\\${t}`)},addDelimiter(e,t,n,a){const r=t.substring(1);this.checkProtectedMacros(e,r);const[i,o]=G.checkGlobal(e,[r,t],[k.NEW_COMMAND,k.NEW_DELIMITER]);r!==t&&i.remove(r),o.add(t,new N(t,n,a)),delete e.stack.env.isGlobal},addMacro(e,t,n,a,r=""){this.checkProtectedMacros(e,t);const i=G.checkGlobal(e,[t],[k.NEW_COMMAND])[0];this.undefineDelimiter(e,"\\"+t),i.add(t,new E(r||t,n,a)),delete e.stack.env.isGlobal},addEnvironment(e,t,n,a){G.checkGlobal(e,[t],[k.NEW_ENVIRONMENT])[0].add(t,new E(t,n,a)),delete e.stack.env.isGlobal},undefineMacro(e,t){const n=G.checkGlobal(e,[t],[k.NEW_COMMAND])[0];n.remove(t),e.configuration.handlers.get(l.MACRO).applicable(t)&&(n.add(t,new E(t,(()=>p.FALLBACK),[])),this.undefineDelimiter(e,"\\"+t)),delete e.stack.env.isGlobal},undefineDelimiter(e,t){const n=G.checkGlobal(e,[t],[k.NEW_DELIMITER])[0];n.remove(t),e.configuration.handlers.get(l.DELIMITER).applicable(t)&&n.add(t,new N(t,null,{})),delete e.stack.env.isGlobal}},A=MathJax._.input.tex.TokenMap,x=(A.parseResult,A.AbstractTokenMap,A.RegExpMap,A.AbstractParseMap,A.CharacterMap),I=A.DelimiterMap,C=A.MacroMap,T=A.CommandMap,y=A.EnvironmentMap,D=MathJax._.input.tex.base.BaseMethods,P=(D.splitAlignArray,D.default),_=MathJax._.input.tex.ParseUtil,O=(_.KeyValueDef,_.KeyValueTypes,_.ParseUtil),R={NewCommand(e,t){const n=G.GetCsNameArgument(e,t),a=G.GetArgCount(e,t),r=e.GetBrackets(t),i=e.GetArgument(t);G.addMacro(e,n,R.Macro,[i,a,r]),e.Push(e.itemFactory.create("null"))},NewEnvironment(e,t){const n=b.trimSpaces(e.GetArgument(t)),a=G.GetArgCount(e,t),r=e.GetBrackets(t),i=e.GetArgument(t),o=e.GetArgument(t);G.addEnvironment(e,n,R.BeginEnv,[!0,i,o,a,r]),e.Push(e.itemFactory.create("null"))},MacroDef(e,t){const n=G.GetCSname(e,t),a=G.GetTemplate(e,t,"\\"+n),r=e.GetArgument(t);a instanceof Array?G.addMacro(e,n,R.MacroWithTemplate,[r].concat(a)):G.addMacro(e,n,R.Macro,[r,a]),e.Push(e.itemFactory.create("null"))},Let(e,t){const n=G.GetCSname(e,t);let a=e.GetNext();"="===a&&(e.i++,a=e.GetNext());const r=e.configuration.handlers;if(e.Push(e.itemFactory.create("null")),"\\"===a){if(n===(t=G.GetCSname(e,t)))return;const a=r.get(l.MACRO).applicable(t);if(a instanceof C){const r=a.lookup(t);return void G.addMacro(e,n,r.func,r.args,r.token)}if(a instanceof x&&!(a instanceof I)){const r=a.lookup(t),i=e=>a.parser(e,r);return void G.addMacro(e,n,i,[n,r.char])}const i=r.get(l.DELIMITER).lookup("\\"+t);return i?void G.addDelimiter(e,"\\"+n,i.char,i.attributes):(G.checkProtectedMacros(e,n),G.undefineMacro(e,n),void G.undefineDelimiter(e,"\\"+n))}e.i++;const i=r.get(l.DELIMITER).lookup(a);i?G.addDelimiter(e,"\\"+n,i.char,i.attributes):G.addMacro(e,n,R.Macro,[a])},MacroWithTemplate(e,t,n,a,...r){const i=parseInt(a,10);if(r.length){const a=[];if(e.GetNext(),r[0]&&!G.MatchParam(e,r[0]))throw new u("MismatchUseDef","Use of %1 doesn't match its definition",t);if(i){for(let n=0;n<i;n++)a.push(G.GetParameter(e,t,r[n+1]));n=O.substituteArgs(e,a,n)}}e.string=O.addArgs(e,n,e.string.slice(e.i)),e.i=0,O.checkMaxMacros(e)},BeginEnv(e,t,n,a,r,i){const o=t.getName();if(e.stack.env.closing===o){delete e.stack.env.closing;if(e.stack.global.beginEnv&&(e.stack.global.beginEnv--,a)){const t=e.string.slice(e.i);e.string=O.addArgs(e,e.string.substring(0,e.i),a),e.Parse(),e.string=t,e.i=0}return e.itemFactory.create("end").setProperty("name",o)}if(r){const t=[];if(null!=i){const n=e.GetBrackets(`\\begin{${o}}`);t.push(null==n?i:n)}for(let n=t.length;n<r;n++)t.push(e.GetArgument(`\\begin{${o}}`));n=O.substituteArgs(e,t,n),a=O.substituteArgs(e,[],a)}return e.string=O.addArgs(e,n,e.string.slice(e.i)),e.i=0,e.stack.global.beginEnv=(e.stack.global.beginEnv||0)+1,e.itemFactory.create("beginEnv").setProperty("name",o)},Macro:P.Macro},S=R;new T("Newcommand-macros",{newcommand:S.NewCommand,renewcommand:S.NewCommand,newenvironment:S.NewEnvironment,renewenvironment:S.NewEnvironment,def:S.MacroDef,let:S.Let});const W=MathJax._.input.tex.ParseMethods.default;function L(e,t){t.parseOptions.packageData.has("newcommand")||(t.parseOptions.packageData.set("newcommand",{}),new I(k.NEW_DELIMITER,W.delimiter,{}),new T(k.NEW_COMMAND,{}),new y(k.NEW_ENVIRONMENT,W.environment,{}),t.parseOptions.handlers.add({[l.CHARACTER]:[],[l.DELIMITER]:[k.NEW_DELIMITER],[l.MACRO]:[k.NEW_DELIMITER,k.NEW_COMMAND],[l.ENVIRONMENT]:[k.NEW_ENVIRONMENT]},{},v))}const J=d.create("newcommand",{[c.HANDLER]:{macro:["Newcommand-macros"]},[c.ITEMS]:{[M.prototype.kind]:M},[c.OPTIONS]:{maxMacros:1e3,protectedMacros:["begingroupSandbox"]},[c.CONFIG]:L});MathJax.loader&&MathJax.loader.checkVersion("[tex]/newcommand","4.1.0","tex-extension"),o({_:{input:{tex:{newcommand:{NewcommandConfiguration:r,NewcommandItems:t,NewcommandMethods:a,NewcommandUtil:n}}}}})})();