Skip to content

Instantly share code, notes, and snippets.

@dpvc
Created October 20, 2019 13:53
Show Gist options
  • Save dpvc/f35d953b669aebeb38fe2289e8709a4b to your computer and use it in GitHub Desktop.
Save dpvc/f35d953b669aebeb38fe2289e8709a4b to your computer and use it in GitHub Desktop.
Persian numbers in MathJax
{
"component": "mhchem",
"targets": ["input/tex/mhchem"],
"exclude": ["input/tex/mhchem/mhchem_parser.d.ts"]
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
MathJax = {
loader: {
load: ['[tex]/mhchem'],
source: {'[tex]/mhchem': '[persian]/mhchem.min.js'},
paths: {persian: '.'}
},
tex: {
packages: {'[+]': ['mhchem']},
digits: /^(?:[\d۰-۹]+(?:[,٬'][\d۰-۹]{3})*(?:[\.٫][\d۰-۹]*)?|[\.٫][\d۰-۹]+)/,
tags:"ams"
},
svg: {
mtextInheritFont: true,
},
startup: {
ready() {
var ParseMethods = MathJax._.input.tex.ParseMethods.default;
var RegExpMap = MathJax._.input.tex.SymbolMap.RegExpMap;
new RegExpMap('digit', ParseMethods.digit, /[\d.٫۰-۹]/);
MathJax.startup.defaultReady();
}
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js"></script>
</head>
<body>
<textarea id="source" autofocus style="width:100%; height:30vh;">
\begin{align}
۱۲٬۳۴۵٬۶۷۸٫۳\qquad&,\qquad12,345,678.3\\
\ce{H۲O <=> H۲ + ۱/۲ O۲}\qquad&,\qquad\ce{H2O <=> H2 + 1/2 O2}
\end{align}
</textarea>
<br><button type="button" onclick="compile()">compile</button><br>
<div id="result" style="width:100%; height:55vh;"></div>
<script>
function compile(){
var source=document.getElementById("source");
var result=document.getElementById("result");
result.innerHTML = source.value;
MathJax.texReset();
MathJax.typesetClear();
MathJax.typeset();
}
</script>
</body>
</html>
import './lib/mhchem.js';
import {mhchemParser, texify} from '../node_modules/mathjax-full/js/input/tex/mhchem/mhchem_parser.js';
MathJax._.input.tex.mhchem.mhchem_parser = {mhchemParser, texify};
Object.assign(mhchemParser.patterns.patterns, {
'digits': /^[0-9۰-۹]+/,
'-9.,9': /^[+\-]?(?:[0-9۰-۹]+(?:[,.٫][0-9۰-۹]+)?|[0-9۰-۹]*(?:[.٫][0-9۰-۹]+))/,
'-9.,9 no missing 0': /^[+\-]?[0-9۰-۹]+(?:[.,٫][0-9۰-۹]+)?/,
'(-)(9.,9)(e)(99)': function (input) {
var m = input.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9۰-۹]+(?:[,.٫][0-9۰-۹]+)?|[0-9۰-۹]*(?:[.٫][0-9۰-۹]+))?(\((?:[0-9۰-۹]+(?:[,.][0-9۰-۹]+)?|[0-9۰-۹]*(?:[.٫][0-9۰-۹]+))\))?(?:([eE]|\s*(\*|x|\\times|\u00D7)\s*(?:10|۱۰)\^)([+\-]?[0-9۰-۹]+|\{[+\-]?[0-9۰-۹]+\}))?/);
if (m && m[0]) {
return { match_: m.splice(1), remainder: input.substr(m[0].length) };
}
return null;
},
'(-)(9)^(-9)': function (input) {
var m = input.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9۰-۹]+(?:[,.٫][0-9۰-۹]+)?|[0-9۰-۹]*(?:[.٫][0-9۰-۹]+)?)\^([+\-]?[0-9۰-۹]+|\{[+\-]?[0-9۰-۹]+\})/);
if (m && m[0]) {
return { match_: m.splice(1), remainder: input.substr(m[0].length) };
}
return null;
},
'^a': /^\^([0-9۰-۹]+|[^\\_])/,
'_9': /^_([+\-]?[0-9۰-۹]+|[^\\])/,
'-9': /^-(?=[0-9۰-۹])/,
'operator': /^(?:\+|(?:[\-=<>]|<<|>>|\\approx|\$\\approx\$)(?=\s|$|-?[0-9۰-۹]))/,
'orbital': /^(?:[0-9۰-۹]{1,2}[spdfgh]|[0-9۰-۹]{0,2}sp)(?=$|[^a-zA-Z])/,
'1/2$': /^[+\-]?(?:[0-9۰-۹]+|\$[a-z]\$|[a-z])\/[0-9۰-۹]+(?:\$[a-z]\$|[a-z])?$/,
'amount': function (input) {
var match;
// e.g. 2, 0.5, 1/2, -2, n/2, +; $a$ could be added later in parsing
match = input.match(/^(?:(?:(?:\([+\-]?[0-9۰-۹]+\/[0-9۰-۹]+\)|[+\-]?(?:[0-9۰-۹]+|\$[a-z]\$|[a-z])\/[0-9۰-۹]+|[+\-]?[0-9۰-۹]+[.,٫][0-9۰-۹]+|[+\-]?[.٫][0-9۰-۹]+|[+\-]?[0-9۰-۹]+)(?:[a-z](?=\s*[A-Z]))?)|[+\-]?[a-z](?=\s*[A-Z])|\+(?!\s))/);
if (match) {
return { match_: match[0], remainder: input.substr(match[0].length) };
}
var a = mhchemParser.patterns.findObserveGroups(input, "", "$", "$", "");
if (a) { // e.g. $2n-1$, $-$
match = a.match_.match(/^\$(?:\(?[+\-]?(?:[0-9۰-۹]*[a-z]?[+\-])?[0-9۰-۹]*[a-z](?:[+\-][0-9۰-۹]*[a-z]?)?\)?|\+|-)\$$/);
if (match) {
return { match_: match[0], remainder: input.substr(match[0].length) };
}
}
return null;
},
'formula$': function (input) {
if (input.match(/^\([a-z]+\)$/)) { return null; } // state of aggregation = no formula
var match = input.match(/^(?:[a-z]|(?:[0-9۰-۹\ \+\-\,\.\(\)٫]+[a-z])+[0-9۰-۹\ \+\-\,\.\(\)٫]*|(?:[a-z][0-9۰-۹\ \+\-\,\.\(\)٫]+)+[a-z]?)$/);
if (match) {
return { match_: match[0], remainder: input.substr(match[0].length) };
}
return null;
}
});
Object.assign(mhchemParser.actions, {
'1/2': function (buffer, m) {
/** @type {ParserOutput[]} */
var ret = [];
if (m.match(/^[+\-]/)) {
ret.push(m.substr(0, 1));
m = m.substr(1);
}
var n = m.match(/^([0-9۰-۹]+|\$[a-z]\$|[a-z])\/([0-9۰-۹]+)(\$[a-z]\$|[a-z])?$/);
n[1] = n[1].replace(/\$/g, "");
ret.push({ type_: 'frac', p1: n[1], p2: n[2] });
if (n[3]) {
n[3] = n[3].replace(/\$/g, "");
ret.push({ type_: 'tex-math', p1: n[3] });
}
return ret;
}
});
!function(a){var n={};function o(t){if(n[t])return n[t].exports;var e=n[t]={i:t,l:!1,exports:{}};return a[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}o.m=a,o.c=n,o.d=function(t,e,a){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(o.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(a,n,function(t){return e[t]}.bind(null,n));return a},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var h={go:function(t,e){if(!t)return[];void 0===e&&(e="ce");var a,n="0",o={};o.parenthesisLevel=0,t=(t=(t=t.replace(/\n/g," ")).replace(/[\u2212\u2013\u2014\u2010]/g,"-")).replace(/[\u2026]/g,"...");for(var r=10,i=[];;){a!==t?(r=10,a=t):r--;var c=h.stateMachines[e],u=c.transitions[n]||c.transitions["*"];t:for(var s=0;s<u.length;s++){var p=h.patterns.match_(u[s].pattern,t);if(p){for(var _=u[s].task,l=0;l<_.action_.length;l++){var m;if(c.actions[_.action_[l].type_])m=c.actions[_.action_[l].type_](o,p.match_,_.action_[l].option);else{if(!h.actions[_.action_[l].type_])throw["MhchemBugA","mhchem bug A. Please report. ("+_.action_[l].type_+")"];m=h.actions[_.action_[l].type_](o,p.match_,_.action_[l].option)}h.concatArray(i,m)}if(n=_.nextState||n,!(0<t.length))return i;if(_.revisit||(t=p.remainder),!_.toContinue)break t}}if(r<=0)throw["MhchemBugU","mhchem bug U. Please report."]}},concatArray:function(t,e){if(e)if(Array.isArray(e))for(var a=0;a<e.length;a++)t.push(e[a]);else t.push(e)},patterns:{patterns:{empty:/^$/,else:/^./,else2:/^./,space:/^\s/,"space A":/^\s(?=[A-Z\\$])/,space$:/^\s$/,"a-z":/^[a-z]/,x:/^x/,x$:/^x$/,i$:/^i$/,letters:/^(?:[a-zA-Z\u03B1-\u03C9\u0391-\u03A9?@]|(?:\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega)(?:\s+|\{\}|(?![a-zA-Z]))))+/,"\\greek":/^\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega)(?:\s+|\{\}|(?![a-zA-Z]))/,"one lowercase latin letter $":/^(?:([a-z])(?:$|[^a-zA-Z]))$/,"$one lowercase latin letter$ $":/^\$(?:([a-z])(?:$|[^a-zA-Z]))\$$/,"one lowercase greek letter $":/^(?:\$?[\u03B1-\u03C9]\$?|\$?\\(?:alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega)\s*\$?)(?:\s+|\{\}|(?![a-zA-Z]))$/,digits:/^[0-9]+/,"-9.,9":/^[+\-]?(?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))/,"-9.,9 no missing 0":/^[+\-]?[0-9]+(?:[.,][0-9]+)?/,"(-)(9.,9)(e)(99)":function(t){var e=t.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))?(\((?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))\))?(?:([eE]|\s*(\*|x|\\times|\u00D7)\s*10\^)([+\-]?[0-9]+|\{[+\-]?[0-9]+\}))?/);return e&&e[0]?{match_:e.splice(1),remainder:t.substr(e[0].length)}:null},"(-)(9)^(-9)":function(t){var e=t.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+)?)\^([+\-]?[0-9]+|\{[+\-]?[0-9]+\})/);return e&&e[0]?{match_:e.splice(1),remainder:t.substr(e[0].length)}:null},"state of aggregation $":function(t){var e=h.patterns.findObserveGroups(t,"",/^\([a-z]{1,3}(?=[\),])/,")","");if(e&&e.remainder.match(/^($|[\s,;\)\]\}])/))return e;var a=t.match(/^(?:\((?:\\ca\s?)?\$[amothc]\$\))/);return a?{match_:a[0],remainder:t.substr(a[0].length)}:null},"_{(state of aggregation)}$":/^_\{(\([a-z]{1,3}\))\}/,"{[(":/^(?:\\\{|\[|\()/,")]}":/^(?:\)|\]|\\\})/,", ":/^[,;]\s*/,",":/^[,;]/,".":/^[.]/,". ":/^([.\u22C5\u00B7\u2022])\s*/,"...":/^\.\.\.(?=$|[^.])/,"* ":/^([*])\s*/,"^{(...)}":function(t){return h.patterns.findObserveGroups(t,"^{","","","}")},"^($...$)":function(t){return h.patterns.findObserveGroups(t,"^","$","$","")},"^a":/^\^([0-9]+|[^\\_])/,"^\\x{}{}":function(t){return h.patterns.findObserveGroups(t,"^",/^\\[a-zA-Z]+\{/,"}","","","{","}","",!0)},"^\\x{}":function(t){return h.patterns.findObserveGroups(t,"^",/^\\[a-zA-Z]+\{/,"}","")},"^\\x":/^\^(\\[a-zA-Z]+)\s*/,"^(-1)":/^\^(-?\d+)/,"'":/^'/,"_{(...)}":function(t){return h.patterns.findObserveGroups(t,"_{","","","}")},"_($...$)":function(t){return h.patterns.findObserveGroups(t,"_","$","$","")},_9:/^_([+\-]?[0-9]+|[^\\])/,"_\\x{}{}":function(t){return h.patterns.findObserveGroups(t,"_",/^\\[a-zA-Z]+\{/,"}","","","{","}","",!0)},"_\\x{}":function(t){return h.patterns.findObserveGroups(t,"_",/^\\[a-zA-Z]+\{/,"}","")},"_\\x":/^_(\\[a-zA-Z]+)\s*/,"^_":/^(?:\^(?=_)|\_(?=\^)|[\^_]$)/,"{}":/^\{\}/,"{...}":function(t){return h.patterns.findObserveGroups(t,"","{","}","")},"{(...)}":function(t){return h.patterns.findObserveGroups(t,"{","","","}")},"$...$":function(t){return h.patterns.findObserveGroups(t,"","$","$","")},"${(...)}$":function(t){return h.patterns.findObserveGroups(t,"${","","","}$")},"$(...)$":function(t){return h.patterns.findObserveGroups(t,"$","","","$")},"=<>":/^[=<>]/,"#":/^[#\u2261]/,"+":/^\+/,"-$":/^-(?=[\s_},;\]/]|$|\([a-z]+\))/,"-9":/^-(?=[0-9])/,"- orbital overlap":/^-(?=(?:[spd]|sp)(?:$|[\s,;\)\]\}]))/,"-":/^-/,"pm-operator":/^(?:\\pm|\$\\pm\$|\+-|\+\/-)/,operator:/^(?:\+|(?:[\-=<>]|<<|>>|\\approx|\$\\approx\$)(?=\s|$|-?[0-9]))/,arrowUpDown:/^(?:v|\(v\)|\^|\(\^\))(?=$|[\s,;\)\]\}])/,"\\bond{(...)}":function(t){return h.patterns.findObserveGroups(t,"\\bond{","","","}")},"->":/^(?:<->|<-->|->|<-|<=>>|<<=>|<=>|[\u2192\u27F6\u21CC])/,CMT:/^[CMT](?=\[)/,"[(...)]":function(t){return h.patterns.findObserveGroups(t,"[","","","]")},"1st-level escape":/^(&|\\\\|\\hline)\s*/,"\\,":/^(?:\\[,\ ;:])/,"\\x{}{}":function(t){return h.patterns.findObserveGroups(t,"",/^\\[a-zA-Z]+\{/,"}","","","{","}","",!0)},"\\x{}":function(t){return h.patterns.findObserveGroups(t,"",/^\\[a-zA-Z]+\{/,"}","")},"\\ca":/^\\ca(?:\s+|(?![a-zA-Z]))/,"\\x":/^(?:\\[a-zA-Z]+\s*|\\[_&{}%])/,orbital:/^(?:[0-9]{1,2}[spdfgh]|[0-9]{0,2}sp)(?=$|[^a-zA-Z])/,others:/^[\/~|]/,"\\frac{(...)}":function(t){return h.patterns.findObserveGroups(t,"\\frac{","","","}","{","","","}")},"\\overset{(...)}":function(t){return h.patterns.findObserveGroups(t,"\\overset{","","","}","{","","","}")},"\\underset{(...)}":function(t){return h.patterns.findObserveGroups(t,"\\underset{","","","}","{","","","}")},"\\underbrace{(...)}":function(t){return h.patterns.findObserveGroups(t,"\\underbrace{","","","}_","{","","","}")},"\\color{(...)}0":function(t){return h.patterns.findObserveGroups(t,"\\color{","","","}")},"\\color{(...)}{(...)}1":function(t){return h.patterns.findObserveGroups(t,"\\color{","","","}","{","","","}")},"\\color(...){(...)}2":function(t){return h.patterns.findObserveGroups(t,"\\color","\\","",/^(?=\{)/,"{","","","}")},"\\ce{(...)}":function(t){return h.patterns.findObserveGroups(t,"\\ce{","","","}")},oxidation$:/^(?:[+-][IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,"d-oxidation$":/^(?:[+-]?\s?[IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,"roman numeral":/^[IVX]+/,"1/2$":/^[+\-]?(?:[0-9]+|\$[a-z]\$|[a-z])\/[0-9]+(?:\$[a-z]\$|[a-z])?$/,amount:function(t){var e;if(e=t.match(/^(?:(?:(?:\([+\-]?[0-9]+\/[0-9]+\)|[+\-]?(?:[0-9]+|\$[a-z]\$|[a-z])\/[0-9]+|[+\-]?[0-9]+[.,][0-9]+|[+\-]?\.[0-9]+|[+\-]?[0-9]+)(?:[a-z](?=\s*[A-Z]))?)|[+\-]?[a-z](?=\s*[A-Z])|\+(?!\s))/))return{match_:e[0],remainder:t.substr(e[0].length)};var a=h.patterns.findObserveGroups(t,"","$","$","");return a&&(e=a.match_.match(/^\$(?:\(?[+\-]?(?:[0-9]*[a-z]?[+\-])?[0-9]*[a-z](?:[+\-][0-9]*[a-z]?)?\)?|\+|-)\$$/))?{match_:e[0],remainder:t.substr(e[0].length)}:null},amount2:function(t){return this.amount(t)},"(KV letters),":/^(?:[A-Z][a-z]{0,2}|i)(?=,)/,formula$:function(t){if(t.match(/^\([a-z]+\)$/))return null;var e=t.match(/^(?:[a-z]|(?:[0-9\ \+\-\,\.\(\)]+[a-z])+[0-9\ \+\-\,\.\(\)]*|(?:[a-z][0-9\ \+\-\,\.\(\)]+)+[a-z]?)$/);return e?{match_:e[0],remainder:t.substr(e[0].length)}:null},uprightEntities:/^(?:pH|pOH|pC|pK|iPr|iBu)(?=$|[^a-zA-Z])/,"/":/^\s*(\/)\s*/,"//":/^\s*(\/\/)\s*/,"*":/^\s*[*.]\s*/},findObserveGroups:function(t,e,a,n,o,r,i,c,u,s){function p(t,e){if("string"==typeof e)return 0!==t.indexOf(e)?null:e;var a=t.match(e);return a?a[0]:null}var _=p(t,e);if(null===_)return null;if(t=t.substr(_.length),null===(_=p(t,a)))return null;var l=function(t,e,a){for(var n=0;e<t.length;){var o=t.charAt(e),r=p(t.substr(e),a);if(null!==r&&0===n)return{endMatchBegin:e,endMatchEnd:e+r.length};if("{"===o)n++;else if("}"===o){if(0===n)throw["ExtraCloseMissingOpen","Extra close brace or missing open brace"];n--}e++}return null}(t,_.length,n||o);if(null===l)return null;var m=t.substring(0,n?l.endMatchEnd:l.endMatchBegin);if(r||i){var h=this.findObserveGroups(t.substr(l.endMatchEnd),r,i,c,u);if(null===h)return null;var d=[m,h.match_];return{match_:s?d.join(""):d,remainder:h.remainder}}return{match_:m,remainder:t.substr(l.endMatchEnd)}},match_:function(t,e){var a=h.patterns.patterns[t];if(void 0===a)throw["MhchemBugP","mhchem bug P. Please report. ("+t+")"];if("function"==typeof a)return h.patterns.patterns[t](e);var n=e.match(a);return n?{match_:n[2]?[n[1],n[2]]:n[1]?n[1]:n[0],remainder:e.substr(n[0].length)}:null}},actions:{"a=":function(t,e){t.a=(t.a||"")+e},"b=":function(t,e){t.b=(t.b||"")+e},"p=":function(t,e){t.p=(t.p||"")+e},"o=":function(t,e){t.o=(t.o||"")+e},"q=":function(t,e){t.q=(t.q||"")+e},"d=":function(t,e){t.d=(t.d||"")+e},"rm=":function(t,e){t.rm=(t.rm||"")+e},"text=":function(t,e){t.text_=(t.text_||"")+e},insert:function(t,e,a){return{type_:a}},"insert+p1":function(t,e,a){return{type_:a,p1:e}},"insert+p1+p2":function(t,e,a){return{type_:a,p1:e[0],p2:e[1]}},copy:function(t,e){return e},rm:function(t,e){return{type_:"rm",p1:e||""}},text:function(t,e){return h.go(e,"text")},"{text}":function(t,e){var a=["{"];return h.concatArray(a,h.go(e,"text")),a.push("}"),a},"tex-math":function(t,e){return h.go(e,"tex-math")},"tex-math tight":function(t,e){return h.go(e,"tex-math tight")},bond:function(t,e,a){return{type_:"bond",kind_:a||e}},"color0-output":function(t,e){return{type_:"color0",color:e[0]}},ce:function(t,e){return h.go(e)},"1/2":function(t,e){var a=[];e.match(/^[+\-]/)&&(a.push(e.substr(0,1)),e=e.substr(1));var n=e.match(/^([0-9]+|\$[a-z]\$|[a-z])\/([0-9]+)(\$[a-z]\$|[a-z])?$/);return n[1]=n[1].replace(/\$/g,""),a.push({type_:"frac",p1:n[1],p2:n[2]}),n[3]&&(n[3]=n[3].replace(/\$/g,""),a.push({type_:"tex-math",p1:n[3]})),a},"9,9":function(t,e){return h.go(e,"9,9")}},createTransitions:function(t){var e,a,n,o,r={};for(e in t)for(a in t[e])for(n=a.split("|"),t[e][a].stateArray=n,o=0;o<n.length;o++)r[n[o]]=[];for(e in t)for(a in t[e])for(n=t[e][a].stateArray||[],o=0;o<n.length;o++){var i=t[e][a];if(i.action_){i.action_=[].concat(i.action_);for(var c=0;c<i.action_.length;c++)"string"==typeof i.action_[c]&&(i.action_[c]={type_:i.action_[c]})}else i.action_=[];for(var u=e.split("|"),s=0;s<u.length;s++)if("*"===n[o])for(var p in r)r[p].push({pattern:u[s],task:i});else r[n[o]].push({pattern:u[s],task:i})}return r},stateMachines:{}};h.stateMachines={ce:{transitions:h.createTransitions({empty:{"*":{action_:"output"}},else:{"0|1|2":{action_:"beginsWithBond=false",revisit:!0,toContinue:!0}},oxidation$:{0:{action_:"oxidation-output"}},CMT:{r:{action_:"rdt=",nextState:"rt"},rd:{action_:"rqt=",nextState:"rdt"}},arrowUpDown:{"0|1|2|as":{action_:["sb=false","output","operator"],nextState:"1"}},uprightEntities:{"0|1|2":{action_:["o=","output"],nextState:"1"}},orbital:{"0|1|2|3":{action_:"o=",nextState:"o"}},"->":{"0|1|2|3":{action_:"r=",nextState:"r"},"a|as":{action_:["output","r="],nextState:"r"},"*":{action_:["output","r="],nextState:"r"}},"+":{o:{action_:"d= kv",nextState:"d"},"d|D":{action_:"d=",nextState:"d"},q:{action_:"d=",nextState:"qd"},"qd|qD":{action_:"d=",nextState:"qd"},dq:{action_:["output","d="],nextState:"d"},3:{action_:["sb=false","output","operator"],nextState:"0"}},amount:{"0|2":{action_:"a=",nextState:"a"}},"pm-operator":{"0|1|2|a|as":{action_:["sb=false","output",{type_:"operator",option:"\\pm"}],nextState:"0"}},operator:{"0|1|2|a|as":{action_:["sb=false","output","operator"],nextState:"0"}},"-$":{"o|q":{action_:["charge or bond","output"],nextState:"qd"},d:{action_:"d=",nextState:"d"},D:{action_:["output",{type_:"bond",option:"-"}],nextState:"3"},q:{action_:"d=",nextState:"qd"},qd:{action_:"d=",nextState:"qd"},"qD|dq":{action_:["output",{type_:"bond",option:"-"}],nextState:"3"}},"-9":{"3|o":{action_:["output",{type_:"insert",option:"hyphen"}],nextState:"3"}},"- orbital overlap":{o:{action_:["output",{type_:"insert",option:"hyphen"}],nextState:"2"},d:{action_:["output",{type_:"insert",option:"hyphen"}],nextState:"2"}},"-":{"0|1|2":{action_:[{type_:"output",option:1},"beginsWithBond=true",{type_:"bond",option:"-"}],nextState:"3"},3:{action_:{type_:"bond",option:"-"}},a:{action_:["output",{type_:"insert",option:"hyphen"}],nextState:"2"},as:{action_:[{type_:"output",option:2},{type_:"bond",option:"-"}],nextState:"3"},b:{action_:"b="},o:{action_:{type_:"- after o/d",option:!1},nextState:"2"},q:{action_:{type_:"- after o/d",option:!1},nextState:"2"},"d|qd|dq":{action_:{type_:"- after o/d",option:!0},nextState:"2"},"D|qD|p":{action_:["output",{type_:"bond",option:"-"}],nextState:"3"}},amount2:{"1|3":{action_:"a=",nextState:"a"}},letters:{"0|1|2|3|a|as|b|p|bp|o":{action_:"o=",nextState:"o"},"q|dq":{action_:["output","o="],nextState:"o"},"d|D|qd|qD":{action_:"o after d",nextState:"o"}},digits:{o:{action_:"q=",nextState:"q"},"d|D":{action_:"q=",nextState:"dq"},q:{action_:["output","o="],nextState:"o"},a:{action_:"o=",nextState:"o"}},"space A":{"b|p|bp":{}},space:{a:{nextState:"as"},0:{action_:"sb=false"},"1|2":{action_:"sb=true"},"r|rt|rd|rdt|rdq":{action_:"output",nextState:"0"},"*":{action_:["output","sb=true"],nextState:"1"}},"1st-level escape":{"1|2":{action_:["output",{type_:"insert+p1",option:"1st-level escape"}]},"*":{action_:["output",{type_:"insert+p1",option:"1st-level escape"}],nextState:"0"}},"[(...)]":{"r|rt":{action_:"rd=",nextState:"rd"},"rd|rdt":{action_:"rq=",nextState:"rdq"}},"...":{"o|d|D|dq|qd|qD":{action_:["output",{type_:"bond",option:"..."}],nextState:"3"},"*":{action_:[{type_:"output",option:1},{type_:"insert",option:"ellipsis"}],nextState:"1"}},". |* ":{"*":{action_:["output",{type_:"insert",option:"addition compound"}],nextState:"1"}},"state of aggregation $":{"*":{action_:["output","state of aggregation"],nextState:"1"}},"{[(":{"a|as|o":{action_:["o=","output","parenthesisLevel++"],nextState:"2"},"0|1|2|3":{action_:["o=","output","parenthesisLevel++"],nextState:"2"},"*":{action_:["output","o=","output","parenthesisLevel++"],nextState:"2"}},")]}":{"0|1|2|3|b|p|bp|o":{action_:["o=","parenthesisLevel--"],nextState:"o"},"a|as|d|D|q|qd|qD|dq":{action_:["output","o=","parenthesisLevel--"],nextState:"o"}},", ":{"*":{action_:["output","comma"],nextState:"0"}},"^_":{"*":{}},"^{(...)}|^($...$)":{"0|1|2|as":{action_:"b=",nextState:"b"},p:{action_:"b=",nextState:"bp"},"3|o":{action_:"d= kv",nextState:"D"},q:{action_:"d=",nextState:"qD"},"d|D|qd|qD|dq":{action_:["output","d="],nextState:"D"}},"^a|^\\x{}{}|^\\x{}|^\\x|'":{"0|1|2|as":{action_:"b=",nextState:"b"},p:{action_:"b=",nextState:"bp"},"3|o":{action_:"d= kv",nextState:"d"},q:{action_:"d=",nextState:"qd"},"d|qd|D|qD":{action_:"d="},dq:{action_:["output","d="],nextState:"d"}},"_{(state of aggregation)}$":{"d|D|q|qd|qD|dq":{action_:["output","q="],nextState:"q"}},"_{(...)}|_($...$)|_9|_\\x{}{}|_\\x{}|_\\x":{"0|1|2|as":{action_:"p=",nextState:"p"},b:{action_:"p=",nextState:"bp"},"3|o":{action_:"q=",nextState:"q"},"d|D":{action_:"q=",nextState:"dq"},"q|qd|qD|dq":{action_:["output","q="],nextState:"q"}},"=<>":{"0|1|2|3|a|as|o|q|d|D|qd|qD|dq":{action_:[{type_:"output",option:2},"bond"],nextState:"3"}},"#":{"0|1|2|3|a|as|o":{action_:[{type_:"output",option:2},{type_:"bond",option:"#"}],nextState:"3"}},"{}":{"*":{action_:{type_:"output",option:1},nextState:"1"}},"{...}":{"0|1|2|3|a|as|b|p|bp":{action_:"o=",nextState:"o"},"o|d|D|q|qd|qD|dq":{action_:["output","o="],nextState:"o"}},"$...$":{a:{action_:"a="},"0|1|2|3|as|b|p|bp|o":{action_:"o=",nextState:"o"},"as|o":{action_:"o="},"q|d|D|qd|qD|dq":{action_:["output","o="],nextState:"o"}},"\\bond{(...)}":{"*":{action_:[{type_:"output",option:2},"bond"],nextState:"3"}},"\\frac{(...)}":{"*":{action_:[{type_:"output",option:1},"frac-output"],nextState:"3"}},"\\overset{(...)}":{"*":{action_:[{type_:"output",option:2},"overset-output"],nextState:"3"}},"\\underset{(...)}":{"*":{action_:[{type_:"output",option:2},"underset-output"],nextState:"3"}},"\\underbrace{(...)}":{"*":{action_:[{type_:"output",option:2},"underbrace-output"],nextState:"3"}},"\\color{(...)}{(...)}1|\\color(...){(...)}2":{"*":{action_:[{type_:"output",option:2},"color-output"],nextState:"3"}},"\\color{(...)}0":{"*":{action_:[{type_:"output",option:2},"color0-output"]}},"\\ce{(...)}":{"*":{action_:[{type_:"output",option:2},"ce"],nextState:"3"}},"\\,":{"*":{action_:[{type_:"output",option:1},"copy"],nextState:"1"}},"\\x{}{}|\\x{}|\\x":{"0|1|2|3|a|as|b|p|bp|o|c0":{action_:["o=","output"],nextState:"3"},"*":{action_:["output","o=","output"],nextState:"3"}},others:{"*":{action_:[{type_:"output",option:1},"copy"],nextState:"3"}},else2:{a:{action_:"a to o",nextState:"o",revisit:!0},as:{action_:["output","sb=true"],nextState:"1",revisit:!0},"r|rt|rd|rdt|rdq":{action_:["output"],nextState:"0",revisit:!0},"*":{action_:["output","copy"],nextState:"3"}}}),actions:{"o after d":function(t,e){var a;if((t.d||"").match(/^[0-9]+$/)){var n=t.d;t.d=void 0,a=this.output(t),t.b=n}else a=this.output(t);return h.actions["o="](t,e),a},"d= kv":function(t,e){t.d=e,t.dType="kv"},"charge or bond":function(t,e){if(t.beginsWithBond){var a=[];return h.concatArray(a,this.output(t)),h.concatArray(a,h.actions.bond(t,e,"-")),a}t.d=e},"- after o/d":function(t,e,a){var n=h.patterns.match_("orbital",t.o||""),o=h.patterns.match_("one lowercase greek letter $",t.o||""),r=h.patterns.match_("one lowercase latin letter $",t.o||""),i=h.patterns.match_("$one lowercase latin letter$ $",t.o||""),c="-"===e&&(n&&""===n.remainder||o||r||i);!c||t.a||t.b||t.p||t.d||t.q||n||!r||(t.o="$"+t.o+"$");var u=[];return c?(h.concatArray(u,this.output(t)),u.push({type_:"hyphen"})):(n=h.patterns.match_("digits",t.d||""),a&&n&&""===n.remainder?(h.concatArray(u,h.actions["d="](t,e)),h.concatArray(u,this.output(t))):(h.concatArray(u,this.output(t)),h.concatArray(u,h.actions.bond(t,e,"-")))),u},"a to o":function(t){t.o=t.a,t.a=void 0},"sb=true":function(t){t.sb=!0},"sb=false":function(t){t.sb=!1},"beginsWithBond=true":function(t){t.beginsWithBond=!0},"beginsWithBond=false":function(t){t.beginsWithBond=!1},"parenthesisLevel++":function(t){t.parenthesisLevel++},"parenthesisLevel--":function(t){t.parenthesisLevel--},"state of aggregation":function(t,e){return{type_:"state of aggregation",p1:h.go(e,"o")}},comma:function(t,e){var a=e.replace(/\s*$/,"");return a!==e&&0===t.parenthesisLevel?{type_:"comma enumeration L",p1:a}:{type_:"comma enumeration M",p1:a}},output:function(t,e,a){var n,o,r;t.r?(o="M"===t.rdt?h.go(t.rd,"tex-math"):"T"===t.rdt?[{type_:"text",p1:t.rd||""}]:h.go(t.rd),r="M"===t.rqt?h.go(t.rq,"tex-math"):"T"===t.rqt?[{type_:"text",p1:t.rq||""}]:h.go(t.rq),n={type_:"arrow",r:t.r,rd:o,rq:r}):(n=[],(t.a||t.b||t.p||t.o||t.q||t.d||a)&&(t.sb&&n.push({type_:"entitySkip"}),t.o||t.q||t.d||t.b||t.p||2===a?t.o||t.q||t.d||!t.b&&!t.p?t.o&&"kv"===t.dType&&h.patterns.match_("d-oxidation$",t.d||"")?t.dType="oxidation":t.o&&"kv"===t.dType&&!t.q&&(t.dType=void 0):(t.o=t.a,t.d=t.b,t.q=t.p,t.a=t.b=t.p=void 0):(t.o=t.a,t.a=void 0),n.push({type_:"chemfive",a:h.go(t.a,"a"),b:h.go(t.b,"bd"),p:h.go(t.p,"pq"),o:h.go(t.o,"o"),q:h.go(t.q,"pq"),d:h.go(t.d,"oxidation"===t.dType?"oxidation":"bd"),dType:t.dType})));for(var i in t)"parenthesisLevel"!==i&&"beginsWithBond"!==i&&delete t[i];return n},"oxidation-output":function(t,e){var a=["{"];return h.concatArray(a,h.go(e,"oxidation")),a.push("}"),a},"frac-output":function(t,e){return{type_:"frac-ce",p1:h.go(e[0]),p2:h.go(e[1])}},"overset-output":function(t,e){return{type_:"overset",p1:h.go(e[0]),p2:h.go(e[1])}},"underset-output":function(t,e){return{type_:"underset",p1:h.go(e[0]),p2:h.go(e[1])}},"underbrace-output":function(t,e){return{type_:"underbrace",p1:h.go(e[0]),p2:h.go(e[1])}},"color-output":function(t,e){return{type_:"color",color1:e[0],color2:h.go(e[1])}},"r=":function(t,e){t.r=e},"rdt=":function(t,e){t.rdt=e},"rd=":function(t,e){t.rd=e},"rqt=":function(t,e){t.rqt=e},"rq=":function(t,e){t.rq=e},operator:function(t,e,a){return{type_:"operator",kind_:a||e}}}},a:{transitions:h.createTransitions({empty:{"*":{}},"1/2$":{0:{action_:"1/2"}},else:{0:{nextState:"1",revisit:!0}},"$(...)$":{"*":{action_:"tex-math tight",nextState:"1"}},",":{"*":{action_:{type_:"insert",option:"commaDecimal"}}},else2:{"*":{action_:"copy"}}}),actions:{}},o:{transitions:h.createTransitions({empty:{"*":{}},"1/2$":{0:{action_:"1/2"}},else:{0:{nextState:"1",revisit:!0}},letters:{"*":{action_:"rm"}},"\\ca":{"*":{action_:{type_:"insert",option:"circa"}}},"\\x{}{}|\\x{}|\\x":{"*":{action_:"copy"}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},"{(...)}":{"*":{action_:"{text}"}},else2:{"*":{action_:"copy"}}}),actions:{}},text:{transitions:h.createTransitions({empty:{"*":{action_:"output"}},"{...}":{"*":{action_:"text="}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},"\\greek":{"*":{action_:["output","rm"]}},"\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:["output","copy"]}},else:{"*":{action_:"text="}}}),actions:{output:function(t){if(t.text_){var e={type_:"text",p1:t.text_};for(var a in t)delete t[a];return e}}}},pq:{transitions:h.createTransitions({empty:{"*":{}},"state of aggregation $":{"*":{action_:"state of aggregation"}},i$:{0:{nextState:"!f",revisit:!0}},"(KV letters),":{0:{action_:"rm",nextState:"0"}},formula$:{0:{nextState:"f",revisit:!0}},"1/2$":{0:{action_:"1/2"}},else:{0:{nextState:"!f",revisit:!0}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},"{(...)}":{"*":{action_:"text"}},"a-z":{f:{action_:"tex-math"}},letters:{"*":{action_:"rm"}},"-9.,9":{"*":{action_:"9,9"}},",":{"*":{action_:{type_:"insert+p1",option:"comma enumeration S"}}},"\\color{(...)}{(...)}1|\\color(...){(...)}2":{"*":{action_:"color-output"}},"\\color{(...)}0":{"*":{action_:"color0-output"}},"\\ce{(...)}":{"*":{action_:"ce"}},"\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:"copy"}},else2:{"*":{action_:"copy"}}}),actions:{"state of aggregation":function(t,e){return{type_:"state of aggregation subscript",p1:h.go(e,"o")}},"color-output":function(t,e){return{type_:"color",color1:e[0],color2:h.go(e[1],"pq")}}}},bd:{transitions:h.createTransitions({empty:{"*":{}},x$:{0:{nextState:"!f",revisit:!0}},formula$:{0:{nextState:"f",revisit:!0}},else:{0:{nextState:"!f",revisit:!0}},"-9.,9 no missing 0":{"*":{action_:"9,9"}},".":{"*":{action_:{type_:"insert",option:"electron dot"}}},"a-z":{f:{action_:"tex-math"}},x:{"*":{action_:{type_:"insert",option:"KV x"}}},letters:{"*":{action_:"rm"}},"'":{"*":{action_:{type_:"insert",option:"prime"}}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},"{(...)}":{"*":{action_:"text"}},"\\color{(...)}{(...)}1|\\color(...){(...)}2":{"*":{action_:"color-output"}},"\\color{(...)}0":{"*":{action_:"color0-output"}},"\\ce{(...)}":{"*":{action_:"ce"}},"\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:"copy"}},else2:{"*":{action_:"copy"}}}),actions:{"color-output":function(t,e){return{type_:"color",color1:e[0],color2:h.go(e[1],"bd")}}}},oxidation:{transitions:h.createTransitions({empty:{"*":{}},"roman numeral":{"*":{action_:"roman-numeral"}},"${(...)}$|$(...)$":{"*":{action_:"tex-math"}},else:{"*":{action_:"copy"}}}),actions:{"roman-numeral":function(t,e){return{type_:"roman numeral",p1:e||""}}}},"tex-math":{transitions:h.createTransitions({empty:{"*":{action_:"output"}},"\\ce{(...)}":{"*":{action_:["output","ce"]}},"{...}|\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:"o="}},else:{"*":{action_:"o="}}}),actions:{output:function(t){if(t.o){var e={type_:"tex-math",p1:t.o};for(var a in t)delete t[a];return e}}}},"tex-math tight":{transitions:h.createTransitions({empty:{"*":{action_:"output"}},"\\ce{(...)}":{"*":{action_:["output","ce"]}},"{...}|\\,|\\x{}{}|\\x{}|\\x":{"*":{action_:"o="}},"-|+":{"*":{action_:"tight operator"}},else:{"*":{action_:"o="}}}),actions:{"tight operator":function(t,e){t.o=(t.o||"")+"{"+e+"}"},output:function(t){if(t.o){var e={type_:"tex-math",p1:t.o};for(var a in t)delete t[a];return e}}}},"9,9":{transitions:h.createTransitions({empty:{"*":{}},",":{"*":{action_:"comma"}},else:{"*":{action_:"copy"}}}),actions:{comma:function(){return{type_:"commaDecimal"}}}},pu:{transitions:h.createTransitions({empty:{"*":{action_:"output"}},space$:{"*":{action_:["output","space"]}},"{[(|)]}":{"0|a":{action_:"copy"}},"(-)(9)^(-9)":{0:{action_:"number^",nextState:"a"}},"(-)(9.,9)(e)(99)":{0:{action_:"enumber",nextState:"a"}},space:{"0|a":{}},"pm-operator":{"0|a":{action_:{type_:"operator",option:"\\pm"},nextState:"0"}},operator:{"0|a":{action_:"copy",nextState:"0"}},"//":{d:{action_:"o=",nextState:"/"}},"/":{d:{action_:"o=",nextState:"/"}},"{...}|else":{"0|d":{action_:"d=",nextState:"d"},a:{action_:["space","d="],nextState:"d"},"/|q":{action_:"q=",nextState:"q"}}}),actions:{enumber:function(t,e){var a=[];return"+-"===e[0]||"+/-"===e[0]?a.push("\\pm "):e[0]&&a.push(e[0]),e[1]&&(h.concatArray(a,h.go(e[1],"pu-9,9")),e[2]&&(e[2].match(/[,.]/)?h.concatArray(a,h.go(e[2],"pu-9,9")):a.push(e[2])),e[3]=e[4]||e[3],e[3]&&(e[3]=e[3].trim(),"e"===e[3]||"*"===e[3].substr(0,1)?a.push({type_:"cdot"}):a.push({type_:"times"}))),e[3]&&a.push("10^{"+e[5]+"}"),a},"number^":function(t,e){var a=[];return"+-"===e[0]||"+/-"===e[0]?a.push("\\pm "):e[0]&&a.push(e[0]),h.concatArray(a,h.go(e[1],"pu-9,9")),a.push("^{"+e[2]+"}"),a},operator:function(t,e,a){return{type_:"operator",kind_:a||e}},space:function(){return{type_:"pu-space-1"}},output:function(t){var e,a=h.patterns.match_("{(...)}",t.d||"");a&&""===a.remainder&&(t.d=a.match_);var n=h.patterns.match_("{(...)}",t.q||"");if(n&&""===n.remainder&&(t.q=n.match_),t.d&&(t.d=t.d.replace(/\u00B0C|\^oC|\^{o}C/g,"{}^{\\circ}C"),t.d=t.d.replace(/\u00B0F|\^oF|\^{o}F/g,"{}^{\\circ}F")),t.q){t.q=t.q.replace(/\u00B0C|\^oC|\^{o}C/g,"{}^{\\circ}C"),t.q=t.q.replace(/\u00B0F|\^oF|\^{o}F/g,"{}^{\\circ}F");var o={d:h.go(t.d,"pu"),q:h.go(t.q,"pu")};"//"===t.o?e={type_:"pu-frac",p1:o.d,p2:o.q}:(1<(e=o.d).length||1<o.q.length?e.push({type_:" / "}):e.push({type_:"/"}),h.concatArray(e,o.q))}else e=h.go(t.d,"pu-2");for(var r in t)delete t[r];return e}}},"pu-2":{transitions:h.createTransitions({empty:{"*":{action_:"output"}},"*":{"*":{action_:["output","cdot"],nextState:"0"}},"\\x":{"*":{action_:"rm="}},space:{"*":{action_:["output","space"],nextState:"0"}},"^{(...)}|^(-1)":{1:{action_:"^(-1)"}},"-9.,9":{0:{action_:"rm=",nextState:"0"},1:{action_:"^(-1)",nextState:"0"}},"{...}|else":{"*":{action_:"rm=",nextState:"1"}}}),actions:{cdot:function(){return{type_:"tight cdot"}},"^(-1)":function(t,e){t.rm+="^{"+e+"}"},space:function(){return{type_:"pu-space-2"}},output:function(t){var e=[];if(t.rm){var a=h.patterns.match_("{(...)}",t.rm||"");e=a&&""===a.remainder?h.go(a.match_,"pu"):{type_:"rm",p1:t.rm}}for(var n in t)delete t[n];return e}}},"pu-9,9":{transitions:h.createTransitions({empty:{0:{action_:"output-0"},o:{action_:"output-o"}},",":{0:{action_:["output-0","comma"],nextState:"o"}},".":{0:{action_:["output-0","copy"],nextState:"o"}},else:{"*":{action_:"text="}}}),actions:{comma:function(){return{type_:"commaDecimal"}},"output-0":function(t){var e=[];if(t.text_=t.text_||"",4<t.text_.length){var a=t.text_.length%3;0===a&&(a=3);for(var n=t.text_.length-3;0<n;n-=3)e.push(t.text_.substr(n,3)),e.push({type_:"1000 separator"});e.push(t.text_.substr(0,a)),e.reverse()}else e.push(t.text_);for(var o in t)delete t[o];return e},"output-o":function(t){var e=[];if(t.text_=t.text_||"",4<t.text_.length){for(var a=t.text_.length-3,n=0;n<a;n+=3)e.push(t.text_.substr(n,3)),e.push({type_:"1000 separator"});e.push(t.text_.substr(n))}else e.push(t.text_);for(var o in t)delete t[o];return e}}}};var u={go:function(t,e){if(!t)return"";for(var a="",n=!1,o=0;o<t.length;o++){var r=t[o];"string"==typeof r?a+=r:(a+=u._go2(r),"1st-level escape"===r.type_&&(n=!0))}return e||n||!a||(a="{"+a+"}"),a},_goInner:function(t){return t?u.go(t,!0):t},_go2:function(t){var e;switch(t.type_){case"chemfive":e="";var a={a:u._goInner(t.a),b:u._goInner(t.b),p:u._goInner(t.p),o:u._goInner(t.o),q:u._goInner(t.q),d:u._goInner(t.d)};a.a&&(a.a.match(/^[+\-]/)&&(a.a="{"+a.a+"}"),e+=a.a+"\\,"),(a.b||a.p)&&(e+="{\\vphantom{X}}",e+="^{\\hphantom{"+(a.b||"")+"}}_{\\hphantom{"+(a.p||"")+"}}",e+="{\\vphantom{X}}",e+="^{\\smash[t]{\\vphantom{2}}\\llap{"+(a.b||"")+"}}",e+="_{\\vphantom{2}\\llap{\\smash[t]{"+(a.p||"")+"}}}"),a.o&&(a.o.match(/^[+\-]/)&&(a.o="{"+a.o+"}"),e+=a.o),"kv"===t.dType?((a.d||a.q)&&(e+="{\\vphantom{X}}"),a.d&&(e+="^{"+a.d+"}"),a.q&&(e+="_{\\smash[t]{"+a.q+"}}")):"oxidation"===t.dType?(a.d&&(e+="{\\vphantom{X}}",e+="^{"+a.d+"}"),a.q&&(e+="{\\vphantom{X}}",e+="_{\\smash[t]{"+a.q+"}}")):(a.q&&(e+="{\\vphantom{X}}",e+="_{\\smash[t]{"+a.q+"}}"),a.d&&(e+="{\\vphantom{X}}",e+="^{"+a.d+"}"));break;case"rm":e="\\mathrm{"+t.p1+"}";break;case"text":e=t.p1.match(/[\^_]/)?(t.p1=t.p1.replace(" ","~").replace("-","\\text{-}"),"\\mathrm{"+t.p1+"}"):"\\text{"+t.p1+"}";break;case"roman numeral":e="\\mathrm{"+t.p1+"}";break;case"state of aggregation":e="\\mskip2mu "+u._goInner(t.p1);break;case"state of aggregation subscript":e="\\mskip1mu "+u._goInner(t.p1);break;case"bond":if(!(e=u._getBond(t.kind_)))throw["MhchemErrorBond","mhchem Error. Unknown bond type ("+t.kind_+")"];break;case"frac":var n="\\frac{"+t.p1+"}{"+t.p2+"}";e="\\mathchoice{\\textstyle"+n+"}{"+n+"}{"+n+"}{"+n+"}";break;case"pu-frac":var o="\\frac{"+u._goInner(t.p1)+"}{"+u._goInner(t.p2)+"}";e="\\mathchoice{\\textstyle"+o+"}{"+o+"}{"+o+"}{"+o+"}";break;case"tex-math":e=t.p1+" ";break;case"frac-ce":e="\\frac{"+u._goInner(t.p1)+"}{"+u._goInner(t.p2)+"}";break;case"overset":e="\\overset{"+u._goInner(t.p1)+"}{"+u._goInner(t.p2)+"}";break;case"underset":e="\\underset{"+u._goInner(t.p1)+"}{"+u._goInner(t.p2)+"}";break;case"underbrace":e="\\underbrace{"+u._goInner(t.p1)+"}_{"+u._goInner(t.p2)+"}";break;case"color":e="{\\color{"+t.color1+"}{"+u._goInner(t.color2)+"}}";break;case"color0":e="\\color{"+t.color+"}";break;case"arrow":var r=u._goInner(t.rd),i=u._goInner(t.rq),c=u._getArrow(t.r);e=c=r||i?"<=>"===t.r||"<=>>"===t.r||"<<=>"===t.r||"<--\x3e"===t.r?(c="\\long"+c,r&&(c="\\overset{"+r+"}{"+c+"}"),i&&(c="\\underset{\\lower7mu{"+i+"}}{"+c+"}")," {}\\mathrel{"+c+"}{} "):(i&&(c+="[{"+i+"}]")," {}\\mathrel{\\x"+(c+="{"+r+"}")+"}{} "):" {}\\mathrel{\\long"+c+"}{} ";break;case"operator":e=u._getOperator(t.kind_);break;case"1st-level escape":e=t.p1+" ";break;case"space":e=" ";break;case"entitySkip":case"pu-space-1":e="~";break;case"pu-space-2":e="\\mkern3mu ";break;case"1000 separator":e="\\mkern2mu ";break;case"commaDecimal":e="{,}";break;case"comma enumeration L":e="{"+t.p1+"}\\mkern6mu ";break;case"comma enumeration M":e="{"+t.p1+"}\\mkern3mu ";break;case"comma enumeration S":e="{"+t.p1+"}\\mkern1mu ";break;case"hyphen":e="\\text{-}";break;case"addition compound":e="\\,{\\cdot}\\,";break;case"electron dot":e="\\mkern1mu \\bullet\\mkern1mu ";break;case"KV x":e="{\\times}";break;case"prime":e="\\prime ";break;case"cdot":e="\\cdot ";break;case"tight cdot":e="\\mkern1mu{\\cdot}\\mkern1mu ";break;case"times":e="\\times ";break;case"circa":e="{\\sim}";break;case"^":e="uparrow";break;case"v":e="downarrow";break;case"ellipsis":e="\\ldots ";break;case"/":e="/";break;case" / ":e="\\,/\\,";break;default:throw["MhchemBugT","mhchem bug T. Please report."]}return e},_getArrow:function(t){switch(t){case"->":case"\u2192":case"\u27f6":return"rightarrow";case"<-":return"leftarrow";case"<->":return"leftrightarrow";case"<--\x3e":return"leftrightarrows";case"<=>":case"\u21cc":return"rightleftharpoons";case"<=>>":return"Rightleftharpoons";case"<<=>":return"Leftrightharpoons";default:throw["MhchemBugT","mhchem bug T. Please report."]}},_getBond:function(t){switch(t){case"-":case"1":return"{-}";case"=":case"2":return"{=}";case"#":case"3":return"{\\equiv}";case"~":return"{\\tripledash}";case"~-":return"{\\rlap{\\lower.1em{-}}\\raise.1em{\\tripledash}}";case"~=":case"~--":return"{\\rlap{\\lower.2em{-}}\\rlap{\\raise.2em{\\tripledash}}-}";case"-~-":return"{\\rlap{\\lower.2em{-}}\\rlap{\\raise.2em{-}}\\tripledash}";case"...":return"{{\\cdot}{\\cdot}{\\cdot}}";case"....":return"{{\\cdot}{\\cdot}{\\cdot}{\\cdot}}";case"->":return"{\\rightarrow}";case"<-":return"{\\leftarrow}";case"<":return"{<}";case">":return"{>}";default:throw["MhchemBugT","mhchem bug T. Please report."]}},_getOperator:function(t){switch(t){case"+":return" {}+{} ";case"-":return" {}-{} ";case"=":return" {}={} ";case"<":return" {}<{} ";case">":return" {}>{} ";case"<<":return" {}\\ll{} ";case">>":return" {}\\gg{} ";case"\\pm":return" {}\\pm{} ";case"\\approx":case"$\\approx$":return" {}\\approx{} ";case"v":case"(v)":return" \\downarrow{} ";case"^":case"(^)":return" \\uparrow{} ";default:throw["MhchemBugT","mhchem bug T. Please report."]}}};function n(t){}function o(t){}e.mhchemParser=h,e.texify=u,e.assertNever=n,e.assertString=o},function(t,e,a){"use strict";a(2);var n=a(0);MathJax._.input.tex.mhchem.mhchem_parser={mhchemParser:n.mhchemParser,texify:n.texify},Object.assign(n.mhchemParser.patterns.patterns,{digits:/^[0-9\u06f0-\u06f9]+/,"-9.,9":/^[+\-]?(?:[0-9\u06f0-\u06f9]+(?:[,.\u066b][0-9\u06f0-\u06f9]+)?|[0-9\u06f0-\u06f9]*(?:[.\u066b][0-9\u06f0-\u06f9]+))/,"-9.,9 no missing 0":/^[+\-]?[0-9\u06f0-\u06f9]+(?:[.,\u066b][0-9\u06f0-\u06f9]+)?/,"(-)(9.,9)(e)(99)":function(t){var e=t.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9\u06f0-\u06f9]+(?:[,.\u066b][0-9\u06f0-\u06f9]+)?|[0-9\u06f0-\u06f9]*(?:[.\u066b][0-9\u06f0-\u06f9]+))?(\((?:[0-9\u06f0-\u06f9]+(?:[,.][0-9\u06f0-\u06f9]+)?|[0-9\u06f0-\u06f9]*(?:[.\u066b][0-9\u06f0-\u06f9]+))\))?(?:([eE]|\s*(\*|x|\\times|\u00D7)\s*(?:10|\u06f1\u06f0)\^)([+\-]?[0-9\u06f0-\u06f9]+|\{[+\-]?[0-9\u06f0-\u06f9]+\}))?/);return e&&e[0]?{match_:e.splice(1),remainder:t.substr(e[0].length)}:null},"(-)(9)^(-9)":function(t){var e=t.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9\u06f0-\u06f9]+(?:[,.\u066b][0-9\u06f0-\u06f9]+)?|[0-9\u06f0-\u06f9]*(?:[.\u066b][0-9\u06f0-\u06f9]+)?)\^([+\-]?[0-9\u06f0-\u06f9]+|\{[+\-]?[0-9\u06f0-\u06f9]+\})/);return e&&e[0]?{match_:e.splice(1),remainder:t.substr(e[0].length)}:null},"^a":/^\^([0-9\u06f0-\u06f9]+|[^\\_])/,_9:/^_([+\-]?[0-9\u06f0-\u06f9]+|[^\\])/,"-9":/^-(?=[0-9\u06f0-\u06f9])/,operator:/^(?:\+|(?:[\-=<>]|<<|>>|\\approx|\$\\approx\$)(?=\s|$|-?[0-9\u06f0-\u06f9]))/,orbital:/^(?:[0-9\u06f0-\u06f9]{1,2}[spdfgh]|[0-9\u06f0-\u06f9]{0,2}sp)(?=$|[^a-zA-Z])/,"1/2$":/^[+\-]?(?:[0-9\u06f0-\u06f9]+|\$[a-z]\$|[a-z])\/[0-9\u06f0-\u06f9]+(?:\$[a-z]\$|[a-z])?$/,amount:function(t){var e;if(e=t.match(/^(?:(?:(?:\([+\-]?[0-9\u06f0-\u06f9]+\/[0-9\u06f0-\u06f9]+\)|[+\-]?(?:[0-9\u06f0-\u06f9]+|\$[a-z]\$|[a-z])\/[0-9\u06f0-\u06f9]+|[+\-]?[0-9\u06f0-\u06f9]+[.,\u066b][0-9\u06f0-\u06f9]+|[+\-]?[.\u066b][0-9\u06f0-\u06f9]+|[+\-]?[0-9\u06f0-\u06f9]+)(?:[a-z](?=\s*[A-Z]))?)|[+\-]?[a-z](?=\s*[A-Z])|\+(?!\s))/))return{match_:e[0],remainder:t.substr(e[0].length)};var a=n.mhchemParser.patterns.findObserveGroups(t,"","$","$","");return a&&(e=a.match_.match(/^\$(?:\(?[+\-]?(?:[0-9\u06f0-\u06f9]*[a-z]?[+\-])?[0-9\u06f0-\u06f9]*[a-z](?:[+\-][0-9\u06f0-\u06f9]*[a-z]?)?\)?|\+|-)\$$/))?{match_:e[0],remainder:t.substr(e[0].length)}:null},formula$:function(t){if(t.match(/^\([a-z]+\)$/))return null;var e=t.match(/^(?:[a-z]|(?:[0-9\u06f0-\u06f9\ \+\-\,\.\(\)\u066b]+[a-z])+[0-9\u06f0-\u06f9\ \+\-\,\.\(\)\u066b]*|(?:[a-z][0-9\u06f0-\u06f9\ \+\-\,\.\(\)\u066b]+)+[a-z]?)$/);return e?{match_:e[0],remainder:t.substr(e[0].length)}:null}}),Object.assign(n.mhchemParser.actions,{"1/2":function(t,e){var a=[];e.match(/^[+\-]/)&&(a.push(e.substr(0,1)),e=e.substr(1));var n=e.match(/^([0-9\u06f0-\u06f9]+|\$[a-z]\$|[a-z])\/([0-9\u06f0-\u06f9]+)(\$[a-z]\$|[a-z])?$/);return n[1]=n[1].replace(/\$/g,""),a.push({type_:"frac",p1:n[1],p2:n[2]}),n[3]&&(n[3]=n[3].replace(/\$/g,""),a.push({type_:"tex-math",p1:n[3]})),a}})},function(t,e,a){"use strict";var n=a(3),o=function(t){{if(t&&t.__esModule)return t;var e={};if(null!=t)for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e.default=t,e}}(a(4));(0,n.combineWithMathJax)({_:{input:{tex:{mhchem:{MhchemConfiguration:o}}}}})},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.combineConfig=MathJax._.components.global.combineConfig,e.combineDefaults=MathJax._.components.global.combineDefaults,e.combineWithMathJax=MathJax._.components.global.combineWithMathJax,e.MathJax=MathJax._.components.global.MathJax},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=a(5),o=a(6),i=a(7),r=a(8),c=a(9),u=a(0),s={};s.Macro=r.default.Macro,s.xArrow=c.default.xArrow,s.Machine=function(t,e,a){try{var n=t.GetArgument(e),o=u.mhchemParser.go(n,a),r=u.texify.go(o);t.string=r+t.string.substr(t.i),t.i=0}catch(t){throw new i.default(t[0],t[1],t.slice(2))}},new o.CommandMap("mhchem",{ce:["Machine","ce"],pu:["Machine","pu"],longrightleftharpoons:["Macro","\\stackrel{\\textstyle{-}\\!\\!{\\rightharpoonup}}{\\smash{{\\leftharpoondown}\\!\\!{-}}}"],longRightleftharpoons:["Macro","\\stackrel{\\textstyle{-}\\!\\!{\\rightharpoonup}}{\\smash{\\leftharpoondown}}"],longLeftrightharpoons:["Macro","\\stackrel{\\textstyle\\vphantom{{-}}{\\rightharpoonup}}{\\smash{{\\leftharpoondown}\\!\\!{-}}}"],longleftrightarrows:["Macro","\\stackrel{\\longrightarrow}{\\smash{\\longleftarrow}\\Rule{0px}{.25em}{0px}}"],tripledash:["Macro","\\vphantom{-}\\raise2mu{\\kern2mu\\tiny\\text{-}\\kern1mu\\text{-}\\kern1mu\\text{-}\\kern2mu}"],xrightarrow:["xArrow",8594,5,6],xleftarrow:["xArrow",8592,7,3],xleftrightarrow:["xArrow",8596,6,6],xrightleftharpoons:["xArrow",8652,5,7],xRightleftharpoons:["xArrow",8652,5,7],xLeftrightharpoons:["xArrow",8652,5,7]},s),e.MhchemConfiguration=n.Configuration.create("mhchem",{handler:{macro:["mhchem"]}})},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.Configuration=MathJax._.input.tex.Configuration.Configuration,e.ConfigurationHandler=MathJax._.input.tex.Configuration.ConfigurationHandler},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.AbstractSymbolMap=MathJax._.input.tex.SymbolMap.AbstractSymbolMap,e.RegExpMap=MathJax._.input.tex.SymbolMap.RegExpMap,e.AbstractParseMap=MathJax._.input.tex.SymbolMap.AbstractParseMap,e.CharacterMap=MathJax._.input.tex.SymbolMap.CharacterMap,e.DelimiterMap=MathJax._.input.tex.SymbolMap.DelimiterMap,e.MacroMap=MathJax._.input.tex.SymbolMap.MacroMap,e.CommandMap=MathJax._.input.tex.SymbolMap.CommandMap,e.EnvironmentMap=MathJax._.input.tex.SymbolMap.EnvironmentMap},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=MathJax._.input.tex.TexError.default},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=MathJax._.input.tex.base.BaseMethods.default},function(t,e,a){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.default=MathJax._.input.tex.ams.AmsMethods.default}]);
const PACKAGE = require('mathjax-full/components/webpack.common.js');
module.exports = PACKAGE(
'mhchem', // the name of the package to build
'../node_modules/mathjax-full/js', // location of the mathjax library
[ // packages to link to
'components/src/input/tex/extensions/ams/lib',
'components/src/input/tex-base/lib',
'components/src/core/lib'
],
__dirname, // our directory
'.' // where to put the packaged component
);
@dpvc
Copy link
Author

dpvc commented Oct 20, 2019

To recompile this:

mkdir mjx-extensions
cd mjx-extensions
npm install mathjax-full
npm install webpack
npm install webpack-cli
npm install uglifyjs-webpack-plugin
npm install babel-loader@7
npm install babel-core
npm install babel-preset-env
mkdir persian
cd persian
# copy the files from this gist into this directory
../node_modules/mathjax-full/components/bin/makeAll

This should recompile the mhchem.min.js file for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment