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 17.1 kB
(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})}};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,{Package:()=>x,PackageError:()=>m});var n={};e.r(n),e.d(n,{CONFIG:()=>M,Loader:()=>w,MathJax:()=>O,PathFilters:()=>b});var o={};e.r(o),e.d(o,{CONFIG:()=>E,MathJax:()=>k,Startup:()=>j});const s="4.1.0",a={},i="undefined"!=typeof window?window:void 0!==e.g?e.g:"undefined"!=typeof globalThis?globalThis:a;function r(e){return"object"==typeof e&&null!==e}function d(e,t,n=!1){var o;for(const s of Object.keys(t))"__esModule"!==s&&e[s]!==t[s]&&null!==t[s]&&void 0!==t[s]&&(r(e[s])&&r(t[s])?d(e[s],t[s],n||"_"===s):n&&(null===(o=Object.getOwnPropertyDescriptor(e,s))||void 0===o?void 0:o.get)||(e[s]=t[s]));return e}function c(e,t,n){e[t]||(e[t]={}),e=e[t];for(const t of Object.keys(n))r(e[t])&&r(n[t])?c(e,t,n[t]):null==e[t]&&null!=n[t]&&(e[t]=n[t]);return e}function u(e){return d(l,e)}void 0!==i.MathJax&&i.MathJax.constructor==={}.constructor||(i.MathJax={}),i.MathJax.version||(i.MathJax={version:s,_:{},config:i.MathJax});const l=i.MathJax;!Object.hasOwn&&l.config.startup.polyfillHasOwn&&(Object.hasOwn=function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(Object(e),t)});const p="undefined"!=typeof window,h={window:p?window:null,document:p?window.document:null,os:(()=>{if(p&&window.navigator){const e=window.navigator.appVersion,t=[["Win","Windows"],["Mac","MacOS"],["X11","Unix"],["Linux","Unix"]];for(const[n,o]of t)if(e.includes(n))return o;if(window.navigator.userAgent.includes("Android"))return"Unix"}else if("undefined"!=typeof process)return{linux:"Unix",android:"Unix",aix:"Unix",freebsd:"Unix",netbsd:"Unix",openbsd:"Unix",sunos:"Unix",darwin:"MacOS",win32:"Windows",cygwin:"Windows"}[process.platform]||process.platform;return"unknown"})(),path:e=>e};"Windows"===h.os&&(h.path=e=>e.match(/^[/\\]?[a-zA-Z]:[/\\]/)?e.replace(/\\/g,"/").replace(/^\//,""):e);class m extends Error{constructor(e,t){super(e),this.package=t}}class x{get canLoad(){return 0===this.dependencyCount&&!this.noLoad&&!this.isLoading&&!this.hasFailed}static loadPromise(e){const t=M[e]||{},n=t.extraLoads?w.load(...t.extraLoads):Promise.resolve(),o=t.checkReady||(()=>Promise.resolve());return n.then((()=>o()))}static resolvePath(e,t=!0){const n={name:e,original:e,addExtension:t};return w.pathFilters.execute(n),n.name}static loadAll(){for(const e of this.packages.values())e.canLoad&&e.load()}constructor(e,t=!1){this.isLoaded=!1,this.result={},this.isLoading=!1,this.hasFailed=!1,this.dependents=[],this.dependencies=[],this.dependencyCount=0,this.provided=[],this.name=e,this.noLoad=t,x.packages.set(e,this),this.promise=this.makePromise(this.makeDependencies())}makeDependencies(){const e=[],t=x.packages,n=this.noLoad,o=this.name,s=[];Object.hasOwn(M.dependencies,o)?s.push(...M.dependencies[o]):"core"!==o&&s.push("core");for(const o of s){const s=t.get(o)||new x(o,n);this.dependencies.includes(s)||(s.addDependent(this,n),this.dependencies.push(s),s.isLoaded||(this.dependencyCount++,e.push(s.promise)))}return e}makePromise(e){let t=new Promise(((e,t)=>{this.resolve=e,this.reject=t}));const n=M[this.name]||{};return n.ready&&(t=t.then((e=>n.ready(this.name)))),e.length&&(e.push(t),t=Promise.all(e).then((e=>e.join(", ")))),n.failed&&t.catch((e=>n.failed(new m(e,this.name)))),t}load(){if(!this.isLoaded&&!this.isLoading&&!this.noLoad){this.isLoading=!0;const e=x.resolvePath(this.name);M.require?this.loadCustom(e):this.loadScript(e)}}loadCustom(e){try{const t=M.require(e);t instanceof Promise?t.then((e=>this.result=e)).then((()=>this.checkLoad())).catch((t=>this.failed("Can't load \""+e+'"\n'+t.message.trim()))):(this.result=t,this.checkLoad())}catch(e){this.failed(e.message)}}loadScript(e){const t=h.document.createElement("script");t.src=e,t.charset="UTF-8",t.onload=e=>this.checkLoad(),t.onerror=t=>this.failed("Can't load \""+e+'"'),h.document.head.appendChild(t)}loaded(){this.isLoaded=!0,this.isLoading=!1;for(const e of this.dependents)e.requirementSatisfied();for(const e of this.provided)e.loaded();this.resolve(this.name)}failed(e){this.hasFailed=!0,this.isLoading=!1,this.reject(new m(e,this.name))}checkLoad(){x.loadPromise(this.name).then((()=>this.loaded())).catch((e=>this.failed(e)))}requirementSatisfied(){this.dependencyCount&&(this.dependencyCount--,this.canLoad&&this.load())}provides(e=[]){for(const t of e){let e=x.packages.get(t);e||(M.dependencies[t]||(M.dependencies[t]=[]),M.dependencies[t].push(t),e=new x(t,!0),e.isLoading=!0),this.provided.push(e)}}addDependent(e,t){this.dependents.push(e),t||this.checkNoLoad()}checkNoLoad(){if(this.noLoad){this.noLoad=!1;for(const e of this.dependencies)e.checkNoLoad()}}}x.packages=new Map;class f{constructor(){this.items=[],this.items=[]}[Symbol.iterator](){let e=0;const t=this.items;return{next:()=>({value:t[e++],done:e>t.length})}}add(e,t=f.DEFAULTPRIORITY){let n=this.items.length;do{n--}while(n>=0&&t<this.items[n].priority);return this.items.splice(n+1,0,{item:e,priority:t}),e}remove(e){let t=this.items.length;do{t--}while(t>=0&&this.items[t].item!==e);return t>=0&&this.items.splice(t,1),this}}f.DEFAULTPRIORITY=5;const g=l.config||{};var y=function(e,t,n,o){return new(n||(n=Promise))((function(s,a){function i(e){try{d(o.next(e))}catch(e){a(e)}}function r(e){try{d(o.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,r)}d((o=o.apply(e,t||[])).next())}))};const b={source:e=>(Object.hasOwn(M.source,e.name)&&(e.name=M.source[e.name]),!0),normalize:e=>{const t=e.name;return t.match(/^(?:[a-z]+:\/)?\/|[a-z]:[/\\]|\[/i)||(e.name="[mathjax]/"+t.replace(/^\.\//,"")),!0},prefix:e=>{let t;for(;(t=e.name.match(/^\[([^\]]*)\]/))&&Object.hasOwn(M.paths,t[1]);)e.name=M.paths[t[1]]+e.name.substring(t[0].length);return!0},addExtension:e=>(e.addExtension&&!e.name.match(/\.[^/]+$/)&&(e.name+=".js"),!0)},v=l.version,w={versions:new Map,nestedLoads:[],ready(...e){0===e.length&&(e=Array.from(x.packages.keys()));const t=[];for(const n of e){const e=x.packages.get(n)||new x(n,!0);t.push(e.promise)}return Promise.all(t)},load(...e){if(0===e.length)return Promise.resolve([]);let t=[];this.nestedLoads.unshift(t);const n=Promise.resolve().then((()=>y(this,void 0,void 0,(function*(){const n=[];for(const t of e){let e=x.packages.get(t);e||(e=new x(t),e.provides(M.provides[t])),e.checkNoLoad(),n.push(e.promise.then((()=>(M.versionWarnings&&e.isLoaded&&!w.versions.has(x.resolvePath(t))&&console.warn(`No version information available for component ${t}`),e.result))))}x.loadAll();const o=yield Promise.all(n);for(;t.length;){const e=Promise.all(t);t=this.nestedLoads[this.nestedLoads.indexOf(t)]=[],yield e}return this.nestedLoads.splice(this.nestedLoads.indexOf(t),1),o}))));return this.nestedLoads.slice(1).forEach((e=>e.push(n))),n},preLoaded(...e){for(const t of e){let e=x.packages.get(t);e||(e=new x(t,!0),e.provides(M.provides[t])),e.loaded()}},addPackageData(e,t){let n=M[e];n||(n=M[e]={});for(const[e,o]of Object.entries(t))if(Array.isArray(o)){n[e]||(n[e]=[]);const t=new Set([...n[e],...o]);n[e]=[...t]}else n[e]=o},defaultReady(){void 0!==O.startup&&O.config.startup.ready()},getRoot(){if(h.document){const e=h.document.currentScript||h.document.getElementById("MathJax-script");if(e&&e instanceof HTMLScriptElement)return e.src.replace(/\/[^/]*$/,"")}return g?.loader?.paths?.mathjax||g?.__dirname||"/"},checkVersion(e,t,n){return this.saveVersion(e),!(!M.versionWarnings||t===v)&&(console.warn(`Component ${e} uses ${t} of MathJax; version in use is ${v}`),!0)},saveVersion(e){w.versions.set(x.resolvePath(e),v)},pathFilters:new class extends f{constructor(e=null){super(),e&&this.addList(e)}addList(e){for(const t of e)Array.isArray(t)?this.add(t[0],t[1]):this.add(t)}execute(...e){for(const t of this){if(!1===t.item(...e))return!1}return!0}asyncExecute(...e){let t=-1;const n=this.items;return new Promise(((o,s)=>{!function a(){for(;++t<n.length;){const i=n[t].item(...e);if(i instanceof Promise)return void i.then(a).catch((e=>s(e)));if(!1===i)return void o(!1)}o(!0)}()}))}}};w.pathFilters.add(b.source,0),w.pathFilters.add(b.normalize,10),w.pathFilters.add(b.prefix,20),w.pathFilters.add(b.addExtension,30);const O=l;if(void 0===O.loader){c(O.config,"loader",{paths:{mathjax:w.getRoot(),fonts:h.window?"https://cdn.jsdelivr.net/npm/@mathjax":"@mathjax"},source:{},dependencies:{},provides:{},load:[],ready:w.defaultReady.bind(w),failed:e=>console.log(`MathJax(${e.package||"?"}): ${e.message}`),require:null,pathFilters:[],versionWarnings:!0}),u({loader:w});for(const e of O.config.loader.pathFilters)Array.isArray(e)?w.pathFilters.add(e[0],e[1]):w.pathFilters.add(e)}const M=O.config.loader;const L={invalidOption:"warn",optionError:(e,t)=>{if("fatal"===L.invalidOption)throw new Error(e);console.warn("MathJax: "+e)}};var P=function(e,t,n,o){return new(n||(n=Promise))((function(s,a){function i(e){try{d(o.next(e))}catch(e){a(e)}}function r(e){try{d(o.throw(e))}catch(e){a(e)}}function d(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,r)}d((o=o.apply(e,t||[])).next())}))};class j{static toMML(e){return j.visitor.visitTree(e,this.document)}static registerConstructor(e,t){j.constructors[e]=t}static useHandler(e,t=!1){E.handler&&!t||(E.handler=e)}static useAdaptor(e,t=!1){E.adaptor&&!t||(E.adaptor=e)}static useInput(e,t=!1){R&&!t||E.input.push(e)}static useOutput(e,t=!1){E.output&&!t||(E.output=e)}static extendHandler(e,t=10){j.extensions.add(e,t)}static defaultReady(){j.getComponents(),j.makeMethods(),j.pagePromise.then((()=>E.pageReady())).then((()=>j.promiseResolve())).catch((e=>j.promiseReject(e)))}static defaultPageReady(){return(E.loadAllFontFiles&&j.output.font?j.output.font.loadDynamicFiles():Promise.resolve()).then((()=>{var e;return null===(e=j.document.menu)||void 0===e?void 0:e.loadingPromise})).then(E.typeset&&k.typesetPromise?()=>j.typesetPromise(E.elements):Promise.resolve()).then((()=>j.promiseResolve()))}static typesetPromise(e){return this.hasTypeset=!0,j.document.whenReady((()=>P(this,void 0,void 0,(function*(){j.document.options.elements=e,j.document.reset(),yield j.document.renderPromise()}))))}static getComponents(){j.visitor=new k._.core.MmlTree.SerializedMmlVisitor.SerializedMmlVisitor,j.mathjax=k._.mathjax.mathjax,j.input=j.getInputJax(),j.output=j.getOutputJax(),j.adaptor=j.getAdaptor(),j.handler&&j.mathjax.handlers.unregister(j.handler),j.handler=j.getHandler(),j.handler&&(j.mathjax.handlers.register(j.handler),j.document=j.getDocument())}static makeMethods(){j.input&&j.output&&j.makeTypesetMethods();const e=j.output?j.output.name.toLowerCase():"";for(const t of j.input){const n=t.name.toLowerCase();j.makeMmlMethods(n,t),j.makeResetMethod(n,t),j.output&&j.makeOutputMethods(n,e,t)}k.done=()=>j.document.done(),k.whenReady=e=>j.document.whenReady(e)}static makeTypesetMethods(){k.typeset=(e=null)=>{this.hasTypeset=!0,j.document.options.elements=e,j.document.reset(),j.document.render()},k.typesetPromise=(e=null)=>j.typesetPromise(e),k.typesetClear=(e=null)=>{e?j.document.clearMathItemsWithin(e):j.document.clear()}}static makeOutputMethods(e,t,n){const o=e+"2"+t;k[o]=(e,t={})=>(t=Object.assign(Object.assign({},t),{format:n.name}),j.document.convert(e,t)),k[o+"Promise"]=(e,t={})=>(t=Object.assign(Object.assign({},t),{format:n.name}),j.document.convertPromise(e,t)),k[t+"Stylesheet"]=()=>j.output.styleSheet(j.document),"getMetricsFor"in j.output&&(k.getMetricsFor=(e,t)=>j.output.getMetricsFor(e,t))}static makeMmlMethods(e,t){const n=k._.core.MathItem.STATE;k[e+"2mml"]=(e,o={})=>(o=Object.assign(Object.assign({},o),{end:n.CONVERT,format:t.name}),j.toMML(j.document.convert(e,o))),k[e+"2mmlPromise"]=(e,...o)=>P(this,[e,...o],void 0,(function*(e,o={}){o=Object.assign(Object.assign({},o),{end:n.CONVERT,format:t.name});const s=yield j.document.convertPromise(e,o);return j.toMML(s)}))}static makeResetMethod(e,t){k[e+"Reset"]=(...e)=>t.reset(...e)}static getInputJax(){const e=[];for(const t of E.input){const n=j.constructors[t];if(!n)throw Error('Input Jax "'+t+'" is not defined (has it been loaded?)');e[t]=new n(k.config[t]),e.push(e[t])}return e}static getOutputJax(){const e=E.output;if(!e)return null;const t=j.constructors[e];if(!t)throw Error('Output Jax "'+e+'" is not defined (has it been loaded?)');return new t(k.config[e])}static getAdaptor(){const e=E.adaptor;if(!e||"none"===e)return null;const t=j.constructors[e];if(!t)throw Error('DOMAdaptor "'+e+'" is not defined (has it been loaded?)');return t(k.config[e])}static getHandler(){const e=E.handler;if(!e||"none"===e||!j.adaptor)return null;const t=j.constructors[e];if(!t)throw Error('Handler "'+e+'" is not defined (has it been loaded?)');let n=new t(j.adaptor,5);for(const e of j.extensions)n=e.item(n);return n}static getDocument(e=null){return j.mathjax.document(e||E.document,Object.assign(Object.assign({},k.config.options),{InputJax:j.input,OutputJax:j.output}))}}j.extensions=new f,j.constructors={},j.input=[],j.output=null,j.handler=null,j.adaptor=null,j.elements=null,j.document=null,j.promise=new Promise(((e,t)=>{j.promiseResolve=e,j.promiseReject=t})),j.pagePromise=new Promise(((e,t)=>{const n=i.document;if(n&&n.readyState&&"complete"!==n.readyState&&"interactive"!==n.readyState){const t=()=>e();n.defaultView.addEventListener("load",t,!0),n.defaultView.addEventListener("DOMContentLoaded",t,!0)}else e()})),j.hasTypeset=!1,j.defaultOptionError=L.optionError;const k=l;void 0===k._.startup&&(c(k.config,"startup",{input:[],output:"",handler:null,adaptor:null,document:h.document||"",elements:null,typeset:!0,ready:j.defaultReady.bind(j),pageReady:j.defaultPageReady.bind(j),polyfillHasOwn:!0}),u({startup:j,options:{}}),k.config.startup.invalidOption&&(L.invalidOption=k.config.startup.invalidOption),k.config.startup.optionError&&(L.optionError=k.config.startup.optionError));const E=k.config.startup,R=0!==E.input.length;MathJax.loader&&MathJax.loader.checkVersion("startup",s,"startup"),u({_:{components:{loader:n,package:t,startup:o}}});var F;w.preLoaded("loader","startup"),c(MathJax.config.loader,"dependencies",{"a11y/semantic-enrich":["input/mml","a11y/sre"],"a11y/speech":["a11y/semantic-enrich"],"a11y/complexity":["a11y/semantic-enrich"],"a11y/explorer":["a11y/speech"],"[mml]/mml3":["input/mml"],"[tex]/action":["input/tex-base"],"[tex]/ams":["input/tex-base","[tex]/newcommand"],"[tex]/amscd":["input/tex-base"],"[tex]/autoload":["input/tex-base","[tex]/require"],"[tex]/bbm":["input/tex-base"],"[tex]/bboldx":["input/tex-base","[tex]/textmacros"],"[tex]/bbox":["input/tex-base"],"[tex]/begingroup":["input/tex-base","[tex]/newcommand"],"[tex]/boldsymbol":["input/tex-base"],"[tex]/braket":["input/tex-base"],"[tex]/bussproofs":["input/tex-base"],"[tex]/cancel":["input/tex-base","[tex]/enclose"],"[tex]/cases":["[tex]/empheq"],"[tex]/centernot":["input/tex-base"],"[tex]/color":["input/tex-base"],"[tex]/colortbl":["input/tex-base","[tex]/color"],"[tex]/colorv2":["input/tex-base"],"[tex]/configmacros":["input/tex-base","[tex]/newcommand"],"[tex]/dsfont":["input/tex-base"],"[tex]/empheq":["input/tex-base","[tex]/ams"],"[tex]/enclose":["input/tex-base"],"[tex]/extpfeil":["input/tex-base","[tex]/newcommand","[tex]/ams"],"[tex]/gensymb":["input/tex-base"],"[tex]/html":["input/tex-base"],"[tex]/mathtools":["input/tex-base","[tex]/newcommand","[tex]/ams","[tex]/boldsymbol"],"[tex]/mhchem":["input/tex-base","[tex]/ams"],"[tex]/newcommand":["input/tex-base"],"[tex]/noerrors":["input/tex-base"],"[tex]/noundefined":["input/tex-base"],"[tex]/physics":["input/tex-base"],"[tex]/require":["input/tex-base"],"[tex]/setoptions":["input/tex-base"],"[tex]/tagformat":["input/tex-base"],"[tex]/texhtml":["input/tex-base"],"[tex]/textcomp":["input/tex-base","[tex]/textmacros"],"[tex]/textmacros":["input/tex-base"],"[tex]/unicode":["input/tex-base"],"[tex]/units":["input/tex-base"],"[tex]/upgreek":["input/tex-base"],"[tex]/verb":["input/tex-base"],"ui/menu":["a11y/sre"]}),c(MathJax.config.loader,"paths",{tex:"[mathjax]/input/tex/extensions",mml:"[mathjax]/input/mml/extensions",sre:"[mathjax]/sre",mathmaps:"[sre]/mathmaps"}),c(MathJax.config.loader,"provides",{startup:["loader"],"input/tex":["input/tex-base","[tex]/ams","[tex]/newcommand","[tex]/textmacros","[tex]/noundefined","[tex]/require","[tex]/autoload","[tex]/configmacros"]}),c(MathJax.config.loader,"source",{"[tex]/amsCd":"[tex]/amscd","[tex]/colorV2":"[tex]/colorv2","[tex]/configMacros":"[tex]/configmacros","[tex]/tagFormat":"[tex]/tagformat"}),w.load(...M.load).then((()=>(F||function(){})())).then((()=>M.ready())).catch((e=>M.failed(e)))})();