@khanacademy/perseus-editor 2.3.7 → 2.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/index.js CHANGED
@@ -17656,6 +17656,2825 @@ var katex$1 = {exports: {}};
17656
17656
 
17657
17657
  var katex = /*@__PURE__*/getDefaultExportFromCjs(katex$1.exports);
17658
17658
 
17659
+ /* eslint-disable */
17660
+
17661
+ //
17662
+ // NOTE(kevinb): This file was originally part of mhchem.js, but
17663
+ // was extracted so that it could be mocked for testing purposes.
17664
+ //
17665
+
17666
+ //
17667
+ // This is the main function for handing the \ce and \pu commands.
17668
+ // It takes the argument to \ce or \pu and returns the corresponding TeX string.
17669
+ //
17670
+
17671
+ const chemParse = function chemParse(tokens, stateMachine) {
17672
+ // Recreate the argument string from KaTeX's array of tokens.
17673
+ let str = "";
17674
+ let expectedLoc = tokens[tokens.length - 1].loc.start;
17675
+ for (let i = tokens.length - 1; i >= 0; i--) {
17676
+ if (tokens[i].loc.start > expectedLoc) {
17677
+ // context.consumeArgs has eaten a space.
17678
+ str += " ";
17679
+ expectedLoc = tokens[i].loc.start;
17680
+ }
17681
+ str += tokens[i].text;
17682
+ expectedLoc += tokens[i].text.length;
17683
+ }
17684
+ const tex = texify.go(mhchemParser.go(str, stateMachine));
17685
+ return tex;
17686
+ };
17687
+
17688
+ //
17689
+ // Core parser for mhchem syntax (recursive)
17690
+ //
17691
+ /** @type {MhchemParser} */
17692
+ var mhchemParser = {
17693
+ //
17694
+ // Parses mchem \ce syntax
17695
+ //
17696
+ // Call like
17697
+ // go("H2O");
17698
+ //
17699
+ go: function (input, stateMachine) {
17700
+ if (!input) {
17701
+ return [];
17702
+ }
17703
+ if (stateMachine === undefined) {
17704
+ stateMachine = "ce";
17705
+ }
17706
+ let state = "0";
17707
+
17708
+ //
17709
+ // String buffers for parsing:
17710
+ //
17711
+ // buffer.a == amount
17712
+ // buffer.o == element
17713
+ // buffer.b == left-side superscript
17714
+ // buffer.p == left-side subscript
17715
+ // buffer.q == right-side subscript
17716
+ // buffer.d == right-side superscript
17717
+ //
17718
+ // buffer.r == arrow
17719
+ // buffer.rdt == arrow, script above, type
17720
+ // buffer.rd == arrow, script above, content
17721
+ // buffer.rqt == arrow, script below, type
17722
+ // buffer.rq == arrow, script below, content
17723
+ //
17724
+ // buffer.text_
17725
+ // buffer.rm
17726
+ // etc.
17727
+ //
17728
+ // buffer.parenthesisLevel == int, starting at 0
17729
+ // buffer.sb == bool, space before
17730
+ // buffer.beginsWithBond == bool
17731
+ //
17732
+ // These letters are also used as state names.
17733
+ //
17734
+ // Other states:
17735
+ // 0 == begin of main part (arrow/operator unlikely)
17736
+ // 1 == next entity
17737
+ // 2 == next entity (arrow/operator unlikely)
17738
+ // 3 == next atom
17739
+ // c == macro
17740
+ //
17741
+ /** @type {Buffer} */
17742
+ const buffer = {};
17743
+ buffer["parenthesisLevel"] = 0;
17744
+ input = input.replace(/\n/g, " ");
17745
+ input = input.replace(/[\u2212\u2013\u2014\u2010]/g, "-");
17746
+ input = input.replace(/[\u2026]/g, "...");
17747
+
17748
+ //
17749
+ // Looks through mhchemParser.transitions, to execute a matching action
17750
+ // (recursive)
17751
+ //
17752
+ let lastInput;
17753
+ let watchdog = 10;
17754
+ /** @type {ParserOutput[]} */
17755
+ const output = [];
17756
+ while (true) {
17757
+ if (lastInput !== input) {
17758
+ watchdog = 10;
17759
+ lastInput = input;
17760
+ } else {
17761
+ watchdog--;
17762
+ }
17763
+ //
17764
+ // Find actions in transition table
17765
+ //
17766
+ const machine = mhchemParser.stateMachines[stateMachine];
17767
+ const t = machine.transitions[state] || machine.transitions["*"];
17768
+ iterateTransitions: for (let i = 0; i < t.length; i++) {
17769
+ const matches = mhchemParser.patterns.match_(t[i].pattern, input);
17770
+ if (matches) {
17771
+ //
17772
+ // Execute actions
17773
+ //
17774
+ const task = t[i].task;
17775
+ for (let iA = 0; iA < task.action_.length; iA++) {
17776
+ var o;
17777
+ //
17778
+ // Find and execute action
17779
+ //
17780
+ if (machine.actions[task.action_[iA].type_]) {
17781
+ o = machine.actions[task.action_[iA].type_](buffer, matches.match_, task.action_[iA].option);
17782
+ } else if (mhchemParser.actions[task.action_[iA].type_]) {
17783
+ o = mhchemParser.actions[task.action_[iA].type_](buffer, matches.match_, task.action_[iA].option);
17784
+ } else {
17785
+ throw ["MhchemBugA", "mhchem bug A. Please report. (" + task.action_[iA].type_ + ")"]; // Trying to use non-existing action
17786
+ }
17787
+ //
17788
+ // Add output
17789
+ //
17790
+ mhchemParser.concatArray(output, o);
17791
+ }
17792
+ //
17793
+ // Set next state,
17794
+ // Shorten input,
17795
+ // Continue with next character
17796
+ // (= apply only one transition per position)
17797
+ //
17798
+ state = task.nextState || state;
17799
+ if (input.length > 0) {
17800
+ if (!task.revisit) {
17801
+ input = matches.remainder;
17802
+ }
17803
+ if (!task.toContinue) {
17804
+ break iterateTransitions;
17805
+ }
17806
+ } else {
17807
+ return output;
17808
+ }
17809
+ }
17810
+ }
17811
+ //
17812
+ // Prevent infinite loop
17813
+ //
17814
+ if (watchdog <= 0) {
17815
+ throw ["MhchemBugU", "mhchem bug U. Please report."]; // Unexpected character
17816
+ }
17817
+ }
17818
+ },
17819
+
17820
+ concatArray: function (a, b) {
17821
+ if (b) {
17822
+ if (Array.isArray(b)) {
17823
+ for (let iB = 0; iB < b.length; iB++) {
17824
+ a.push(b[iB]);
17825
+ }
17826
+ } else {
17827
+ a.push(b);
17828
+ }
17829
+ }
17830
+ },
17831
+ patterns: {
17832
+ //
17833
+ // Matching patterns
17834
+ // either regexps or function that return null or {match_:"a", remainder:"bc"}
17835
+ //
17836
+ patterns: {
17837
+ // property names must not look like integers ("2") for correct property traversal order, later on
17838
+ empty: /^$/,
17839
+ else: /^./,
17840
+ else2: /^./,
17841
+ space: /^\s/,
17842
+ "space A": /^\s(?=[A-Z\\$])/,
17843
+ space$: /^\s$/,
17844
+ "a-z": /^[a-z]/,
17845
+ x: /^x/,
17846
+ x$: /^x$/,
17847
+ i$: /^i$/,
17848
+ 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]))))+/,
17849
+ "\\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]))/,
17850
+ "one lowercase latin letter $": /^(?:([a-z])(?:$|[^a-zA-Z]))$/,
17851
+ "$one lowercase latin letter$ $": /^\$(?:([a-z])(?:$|[^a-zA-Z]))\$$/,
17852
+ "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]))$/,
17853
+ digits: /^[0-9]+/,
17854
+ "-9.,9": /^[+\-]?(?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))/,
17855
+ "-9.,9 no missing 0": /^[+\-]?[0-9]+(?:[.,][0-9]+)?/,
17856
+ "(-)(9.,9)(e)(99)": function (input) {
17857
+ const 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]+\}))?/);
17858
+ if (m && m[0]) {
17859
+ return {
17860
+ match_: m.splice(1),
17861
+ remainder: input.substr(m[0].length)
17862
+ };
17863
+ }
17864
+ return null;
17865
+ },
17866
+ "(-)(9)^(-9)": function (input) {
17867
+ const m = input.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+)?)\^([+\-]?[0-9]+|\{[+\-]?[0-9]+\})/);
17868
+ if (m && m[0]) {
17869
+ return {
17870
+ match_: m.splice(1),
17871
+ remainder: input.substr(m[0].length)
17872
+ };
17873
+ }
17874
+ return null;
17875
+ },
17876
+ "state of aggregation $": function (input) {
17877
+ // ... or crystal system
17878
+ const a = mhchemParser.patterns.findObserveGroups(input, "", /^\([a-z]{1,3}(?=[\),])/, ")", ""); // (aq), (aq,$\infty$), (aq, sat)
17879
+ if (a && a.remainder.match(/^($|[\s,;\)\]\}])/)) {
17880
+ return a;
17881
+ } // AND end of 'phrase'
17882
+ const m = input.match(/^(?:\((?:\\ca\s?)?\$[amothc]\$\))/); // OR crystal system ($o$) (\ca$c$)
17883
+ if (m) {
17884
+ return {
17885
+ match_: m[0],
17886
+ remainder: input.substr(m[0].length)
17887
+ };
17888
+ }
17889
+ return null;
17890
+ },
17891
+ "_{(state of aggregation)}$": /^_\{(\([a-z]{1,3}\))\}/,
17892
+ "{[(": /^(?:\\\{|\[|\()/,
17893
+ ")]}": /^(?:\)|\]|\\\})/,
17894
+ ", ": /^[,;]\s*/,
17895
+ ",": /^[,;]/,
17896
+ ".": /^[.]/,
17897
+ ". ": /^([.\u22C5\u00B7\u2022])\s*/,
17898
+ "...": /^\.\.\.(?=$|[^.])/,
17899
+ "* ": /^([*])\s*/,
17900
+ "^{(...)}": function (input) {
17901
+ return mhchemParser.patterns.findObserveGroups(input, "^{", "", "", "}");
17902
+ },
17903
+ "^($...$)": function (input) {
17904
+ return mhchemParser.patterns.findObserveGroups(input, "^", "$", "$", "");
17905
+ },
17906
+ "^a": /^\^([0-9]+|[^\\_])/,
17907
+ "^\\x{}{}": function (input) {
17908
+ return mhchemParser.patterns.findObserveGroups(input, "^", /^\\[a-zA-Z]+\{/, "}", "", "", "{", "}", "", true);
17909
+ },
17910
+ "^\\x{}": function (input) {
17911
+ return mhchemParser.patterns.findObserveGroups(input, "^", /^\\[a-zA-Z]+\{/, "}", "");
17912
+ },
17913
+ "^\\x": /^\^(\\[a-zA-Z]+)\s*/,
17914
+ "^(-1)": /^\^(-?\d+)/,
17915
+ "'": /^'/,
17916
+ "_{(...)}": function (input) {
17917
+ return mhchemParser.patterns.findObserveGroups(input, "_{", "", "", "}");
17918
+ },
17919
+ "_($...$)": function (input) {
17920
+ return mhchemParser.patterns.findObserveGroups(input, "_", "$", "$", "");
17921
+ },
17922
+ _9: /^_([+\-]?[0-9]+|[^\\])/,
17923
+ "_\\x{}{}": function (input) {
17924
+ return mhchemParser.patterns.findObserveGroups(input, "_", /^\\[a-zA-Z]+\{/, "}", "", "", "{", "}", "", true);
17925
+ },
17926
+ "_\\x{}": function (input) {
17927
+ return mhchemParser.patterns.findObserveGroups(input, "_", /^\\[a-zA-Z]+\{/, "}", "");
17928
+ },
17929
+ "_\\x": /^_(\\[a-zA-Z]+)\s*/,
17930
+ "^_": /^(?:\^(?=_)|\_(?=\^)|[\^_]$)/,
17931
+ "{}": /^\{\}/,
17932
+ "{...}": function (input) {
17933
+ return mhchemParser.patterns.findObserveGroups(input, "", "{", "}", "");
17934
+ },
17935
+ "{(...)}": function (input) {
17936
+ return mhchemParser.patterns.findObserveGroups(input, "{", "", "", "}");
17937
+ },
17938
+ "$...$": function (input) {
17939
+ return mhchemParser.patterns.findObserveGroups(input, "", "$", "$", "");
17940
+ },
17941
+ "${(...)}$": function (input) {
17942
+ return mhchemParser.patterns.findObserveGroups(input, "${", "", "", "}$");
17943
+ },
17944
+ "$(...)$": function (input) {
17945
+ return mhchemParser.patterns.findObserveGroups(input, "$", "", "", "$");
17946
+ },
17947
+ "=<>": /^[=<>]/,
17948
+ "#": /^[#\u2261]/,
17949
+ "+": /^\+/,
17950
+ "-$": /^-(?=[\s_},;\]/]|$|\([a-z]+\))/,
17951
+ // -space -, -; -] -/ -$ -state-of-aggregation
17952
+ "-9": /^-(?=[0-9])/,
17953
+ "- orbital overlap": /^-(?=(?:[spd]|sp)(?:$|[\s,;\)\]\}]))/,
17954
+ "-": /^-/,
17955
+ "pm-operator": /^(?:\\pm|\$\\pm\$|\+-|\+\/-)/,
17956
+ operator: /^(?:\+|(?:[\-=<>]|<<|>>|\\approx|\$\\approx\$)(?=\s|$|-?[0-9]))/,
17957
+ arrowUpDown: /^(?:v|\(v\)|\^|\(\^\))(?=$|[\s,;\)\]\}])/,
17958
+ "\\bond{(...)}": function (input) {
17959
+ return mhchemParser.patterns.findObserveGroups(input, "\\bond{", "", "", "}");
17960
+ },
17961
+ "->": /^(?:<->|<-->|->|<-|<=>>|<<=>|<=>|[\u2192\u27F6\u21CC])/,
17962
+ CMT: /^[CMT](?=\[)/,
17963
+ "[(...)]": function (input) {
17964
+ return mhchemParser.patterns.findObserveGroups(input, "[", "", "", "]");
17965
+ },
17966
+ "1st-level escape": /^(&|\\\\|\\hline)\s*/,
17967
+ "\\,": /^(?:\\[,\ ;:])/,
17968
+ // \\x - but output no space before
17969
+ "\\x{}{}": function (input) {
17970
+ return mhchemParser.patterns.findObserveGroups(input, "", /^\\[a-zA-Z]+\{/, "}", "", "", "{", "}", "", true);
17971
+ },
17972
+ "\\x{}": function (input) {
17973
+ return mhchemParser.patterns.findObserveGroups(input, "", /^\\[a-zA-Z]+\{/, "}", "");
17974
+ },
17975
+ "\\ca": /^\\ca(?:\s+|(?![a-zA-Z]))/,
17976
+ "\\x": /^(?:\\[a-zA-Z]+\s*|\\[_&{}%])/,
17977
+ orbital: /^(?:[0-9]{1,2}[spdfgh]|[0-9]{0,2}sp)(?=$|[^a-zA-Z])/,
17978
+ // only those with numbers in front, because the others will be formatted correctly anyway
17979
+ others: /^[\/~|]/,
17980
+ "\\frac{(...)}": function (input) {
17981
+ return mhchemParser.patterns.findObserveGroups(input, "\\frac{", "", "", "}", "{", "", "", "}");
17982
+ },
17983
+ "\\overset{(...)}": function (input) {
17984
+ return mhchemParser.patterns.findObserveGroups(input, "\\overset{", "", "", "}", "{", "", "", "}");
17985
+ },
17986
+ "\\underset{(...)}": function (input) {
17987
+ return mhchemParser.patterns.findObserveGroups(input, "\\underset{", "", "", "}", "{", "", "", "}");
17988
+ },
17989
+ "\\underbrace{(...)}": function (input) {
17990
+ return mhchemParser.patterns.findObserveGroups(input, "\\underbrace{", "", "", "}_", "{", "", "", "}");
17991
+ },
17992
+ "\\color{(...)}0": function (input) {
17993
+ return mhchemParser.patterns.findObserveGroups(input, "\\color{", "", "", "}");
17994
+ },
17995
+ "\\color{(...)}{(...)}1": function (input) {
17996
+ return mhchemParser.patterns.findObserveGroups(input, "\\color{", "", "", "}", "{", "", "", "}");
17997
+ },
17998
+ "\\color(...){(...)}2": function (input) {
17999
+ return mhchemParser.patterns.findObserveGroups(input, "\\color", "\\", "", /^(?=\{)/, "{", "", "", "}");
18000
+ },
18001
+ "\\ce{(...)}": function (input) {
18002
+ return mhchemParser.patterns.findObserveGroups(input, "\\ce{", "", "", "}");
18003
+ },
18004
+ oxidation$: /^(?:[+-][IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,
18005
+ "d-oxidation$": /^(?:[+-]?\s?[IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,
18006
+ // 0 could be oxidation or charge
18007
+ "roman numeral": /^[IVX]+/,
18008
+ "1/2$": /^[+\-]?(?:[0-9]+|\$[a-z]\$|[a-z])\/[0-9]+(?:\$[a-z]\$|[a-z])?$/,
18009
+ amount: function (input) {
18010
+ let match;
18011
+ // e.g. 2, 0.5, 1/2, -2, n/2, +; $a$ could be added later in parsing
18012
+ 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))/);
18013
+ if (match) {
18014
+ return {
18015
+ match_: match[0],
18016
+ remainder: input.substr(match[0].length)
18017
+ };
18018
+ }
18019
+ const a = mhchemParser.patterns.findObserveGroups(input, "", "$", "$", "");
18020
+ if (a) {
18021
+ // e.g. $2n-1$, $-$
18022
+ match = a.match_.match(/^\$(?:\(?[+\-]?(?:[0-9]*[a-z]?[+\-])?[0-9]*[a-z](?:[+\-][0-9]*[a-z]?)?\)?|\+|-)\$$/);
18023
+ if (match) {
18024
+ return {
18025
+ match_: match[0],
18026
+ remainder: input.substr(match[0].length)
18027
+ };
18028
+ }
18029
+ }
18030
+ return null;
18031
+ },
18032
+ amount2: function (input) {
18033
+ return this["amount"](input);
18034
+ },
18035
+ "(KV letters),": /^(?:[A-Z][a-z]{0,2}|i)(?=,)/,
18036
+ formula$: function (input) {
18037
+ if (input.match(/^\([a-z]+\)$/)) {
18038
+ return null;
18039
+ } // state of aggregation = no formula
18040
+ const match = input.match(/^(?:[a-z]|(?:[0-9\ \+\-\,\.\(\)]+[a-z])+[0-9\ \+\-\,\.\(\)]*|(?:[a-z][0-9\ \+\-\,\.\(\)]+)+[a-z]?)$/);
18041
+ if (match) {
18042
+ return {
18043
+ match_: match[0],
18044
+ remainder: input.substr(match[0].length)
18045
+ };
18046
+ }
18047
+ return null;
18048
+ },
18049
+ uprightEntities: /^(?:pH|pOH|pC|pK|iPr|iBu)(?=$|[^a-zA-Z])/,
18050
+ "/": /^\s*(\/)\s*/,
18051
+ "//": /^\s*(\/\/)\s*/,
18052
+ "*": /^\s*[*.]\s*/
18053
+ },
18054
+ findObserveGroups: function (input, begExcl, begIncl, endIncl, endExcl, beg2Excl, beg2Incl, end2Incl, end2Excl, combine) {
18055
+ /** @type {{(input: string, pattern: string | RegExp): string | string[] | null;}} */
18056
+ const _match = function _match(input, pattern) {
18057
+ if (typeof pattern === "string") {
18058
+ if (input.indexOf(pattern) !== 0) {
18059
+ return null;
18060
+ }
18061
+ return pattern;
18062
+ }
18063
+ const match = input.match(pattern);
18064
+ if (!match) {
18065
+ return null;
18066
+ }
18067
+ return match[0];
18068
+ };
18069
+ /** @type {{(input: string, i: number, endChars: string | RegExp): {endMatchBegin: number, endMatchEnd: number} | null;}} */
18070
+ const _findObserveGroups = function _findObserveGroups(input, i, endChars) {
18071
+ let braces = 0;
18072
+ while (i < input.length) {
18073
+ const a = input.charAt(i);
18074
+ const match = _match(input.substr(i), endChars);
18075
+ if (match !== null && braces === 0) {
18076
+ return {
18077
+ endMatchBegin: i,
18078
+ endMatchEnd: i + match.length
18079
+ };
18080
+ }
18081
+ if (a === "{") {
18082
+ braces++;
18083
+ } else if (a === "}") {
18084
+ if (braces === 0) {
18085
+ throw ["ExtraCloseMissingOpen", "Extra close brace or missing open brace"];
18086
+ } else {
18087
+ braces--;
18088
+ }
18089
+ }
18090
+ i++;
18091
+ }
18092
+ if (braces > 0) {
18093
+ return null;
18094
+ }
18095
+ return null;
18096
+ };
18097
+ let match = _match(input, begExcl);
18098
+ if (match === null) {
18099
+ return null;
18100
+ }
18101
+ input = input.substr(match.length);
18102
+ match = _match(input, begIncl);
18103
+ if (match === null) {
18104
+ return null;
18105
+ }
18106
+ const e = _findObserveGroups(input, match.length, endIncl || endExcl);
18107
+ if (e === null) {
18108
+ return null;
18109
+ }
18110
+ const match1 = input.substring(0, endIncl ? e.endMatchEnd : e.endMatchBegin);
18111
+ if (!(beg2Excl || beg2Incl)) {
18112
+ return {
18113
+ match_: match1,
18114
+ remainder: input.substr(e.endMatchEnd)
18115
+ };
18116
+ }
18117
+ const group2 = this.findObserveGroups(input.substr(e.endMatchEnd), beg2Excl, beg2Incl, end2Incl, end2Excl);
18118
+ if (group2 === null) {
18119
+ return null;
18120
+ }
18121
+ /** @type {string[]} */
18122
+ const matchRet = [match1, group2.match_];
18123
+ return {
18124
+ match_: combine ? matchRet.join("") : matchRet,
18125
+ remainder: group2.remainder
18126
+ };
18127
+ },
18128
+ //
18129
+ // Matching function
18130
+ // e.g. match("a", input) will look for the regexp called "a" and see if it matches
18131
+ // returns null or {match_:"a", remainder:"bc"}
18132
+ //
18133
+ match_: function (m, input) {
18134
+ const pattern = mhchemParser.patterns.patterns[m];
18135
+ if (pattern === undefined) {
18136
+ throw ["MhchemBugP", "mhchem bug P. Please report. (" + m + ")"]; // Trying to use non-existing pattern
18137
+ } else if (typeof pattern === "function") {
18138
+ return mhchemParser.patterns.patterns[m](input); // cannot use cached var pattern here, because some pattern functions need this===mhchemParser
18139
+ } else {
18140
+ // RegExp
18141
+ const match = input.match(pattern);
18142
+ if (match) {
18143
+ let mm;
18144
+ if (match[2]) {
18145
+ mm = [match[1], match[2]];
18146
+ } else if (match[1]) {
18147
+ mm = match[1];
18148
+ } else {
18149
+ mm = match[0];
18150
+ }
18151
+ return {
18152
+ match_: mm,
18153
+ remainder: input.substr(match[0].length)
18154
+ };
18155
+ }
18156
+ return null;
18157
+ }
18158
+ }
18159
+ },
18160
+ //
18161
+ // Generic state machine actions
18162
+ //
18163
+ actions: {
18164
+ "a=": function (buffer, m) {
18165
+ buffer.a = (buffer.a || "") + m;
18166
+ },
18167
+ "b=": function (buffer, m) {
18168
+ buffer.b = (buffer.b || "") + m;
18169
+ },
18170
+ "p=": function (buffer, m) {
18171
+ buffer.p = (buffer.p || "") + m;
18172
+ },
18173
+ "o=": function (buffer, m) {
18174
+ buffer.o = (buffer.o || "") + m;
18175
+ },
18176
+ "q=": function (buffer, m) {
18177
+ buffer.q = (buffer.q || "") + m;
18178
+ },
18179
+ "d=": function (buffer, m) {
18180
+ buffer.d = (buffer.d || "") + m;
18181
+ },
18182
+ "rm=": function (buffer, m) {
18183
+ buffer.rm = (buffer.rm || "") + m;
18184
+ },
18185
+ "text=": function (buffer, m) {
18186
+ buffer.text_ = (buffer.text_ || "") + m;
18187
+ },
18188
+ insert: function (buffer, m, a) {
18189
+ return {
18190
+ type_: a
18191
+ };
18192
+ },
18193
+ "insert+p1": function (buffer, m, a) {
18194
+ return {
18195
+ type_: a,
18196
+ p1: m
18197
+ };
18198
+ },
18199
+ "insert+p1+p2": function (buffer, m, a) {
18200
+ return {
18201
+ type_: a,
18202
+ p1: m[0],
18203
+ p2: m[1]
18204
+ };
18205
+ },
18206
+ copy: function (buffer, m) {
18207
+ return m;
18208
+ },
18209
+ rm: function (buffer, m) {
18210
+ return {
18211
+ type_: "rm",
18212
+ p1: m || ""
18213
+ };
18214
+ },
18215
+ text: function (buffer, m) {
18216
+ return mhchemParser.go(m, "text");
18217
+ },
18218
+ "{text}": function (buffer, m) {
18219
+ const ret = ["{"];
18220
+ mhchemParser.concatArray(ret, mhchemParser.go(m, "text"));
18221
+ ret.push("}");
18222
+ return ret;
18223
+ },
18224
+ "tex-math": function (buffer, m) {
18225
+ return mhchemParser.go(m, "tex-math");
18226
+ },
18227
+ "tex-math tight": function (buffer, m) {
18228
+ return mhchemParser.go(m, "tex-math tight");
18229
+ },
18230
+ bond: function (buffer, m, k) {
18231
+ return {
18232
+ type_: "bond",
18233
+ kind_: k || m
18234
+ };
18235
+ },
18236
+ "color0-output": function (buffer, m) {
18237
+ return {
18238
+ type_: "color0",
18239
+ color: m[0]
18240
+ };
18241
+ },
18242
+ ce: function (buffer, m) {
18243
+ return mhchemParser.go(m);
18244
+ },
18245
+ "1/2": function (buffer, m) {
18246
+ /** @type {ParserOutput[]} */
18247
+ const ret = [];
18248
+ if (m.match(/^[+\-]/)) {
18249
+ ret.push(m.substr(0, 1));
18250
+ m = m.substr(1);
18251
+ }
18252
+ const n = m.match(/^([0-9]+|\$[a-z]\$|[a-z])\/([0-9]+)(\$[a-z]\$|[a-z])?$/);
18253
+ n[1] = n[1].replace(/\$/g, "");
18254
+ ret.push({
18255
+ type_: "frac",
18256
+ p1: n[1],
18257
+ p2: n[2]
18258
+ });
18259
+ if (n[3]) {
18260
+ n[3] = n[3].replace(/\$/g, "");
18261
+ ret.push({
18262
+ type_: "tex-math",
18263
+ p1: n[3]
18264
+ });
18265
+ }
18266
+ return ret;
18267
+ },
18268
+ "9,9": function (buffer, m) {
18269
+ return mhchemParser.go(m, "9,9");
18270
+ }
18271
+ },
18272
+ //
18273
+ // createTransitions
18274
+ // convert { 'letter': { 'state': { action_: 'output' } } } to { 'state' => [ { pattern: 'letter', task: { action_: [{type_: 'output'}] } } ] }
18275
+ // with expansion of 'a|b' to 'a' and 'b' (at 2 places)
18276
+ //
18277
+ createTransitions: function (o) {
18278
+ let pattern;
18279
+ let state;
18280
+ /** @type {string[]} */
18281
+ let stateArray;
18282
+ let i;
18283
+ //
18284
+ // 1. Collect all states
18285
+ //
18286
+ /** @type {Transitions} */
18287
+ const transitions = {};
18288
+ for (pattern in o) {
18289
+ for (state in o[pattern]) {
18290
+ stateArray = state.split("|");
18291
+ o[pattern][state].stateArray = stateArray;
18292
+ for (i = 0; i < stateArray.length; i++) {
18293
+ transitions[stateArray[i]] = [];
18294
+ }
18295
+ }
18296
+ }
18297
+ //
18298
+ // 2. Fill states
18299
+ //
18300
+ for (pattern in o) {
18301
+ for (state in o[pattern]) {
18302
+ stateArray = o[pattern][state].stateArray || [];
18303
+ for (i = 0; i < stateArray.length; i++) {
18304
+ //
18305
+ // 2a. Normalize actions into array: 'text=' ==> [{type_:'text='}]
18306
+ // (Note to myself: Resolving the function here would be problematic. It would need .bind (for *this*) and currying (for *option*).)
18307
+ //
18308
+ /** @type {any} */
18309
+ const p = o[pattern][state];
18310
+ if (p.action_) {
18311
+ p.action_ = [].concat(p.action_);
18312
+ for (let k = 0; k < p.action_.length; k++) {
18313
+ if (typeof p.action_[k] === "string") {
18314
+ p.action_[k] = {
18315
+ type_: p.action_[k]
18316
+ };
18317
+ }
18318
+ }
18319
+ } else {
18320
+ p.action_ = [];
18321
+ }
18322
+ //
18323
+ // 2.b Multi-insert
18324
+ //
18325
+ const patternArray = pattern.split("|");
18326
+ for (let j = 0; j < patternArray.length; j++) {
18327
+ if (stateArray[i] === "*") {
18328
+ // insert into all
18329
+ for (const t in transitions) {
18330
+ transitions[t].push({
18331
+ pattern: patternArray[j],
18332
+ task: p
18333
+ });
18334
+ }
18335
+ } else {
18336
+ transitions[stateArray[i]].push({
18337
+ pattern: patternArray[j],
18338
+ task: p
18339
+ });
18340
+ }
18341
+ }
18342
+ }
18343
+ }
18344
+ }
18345
+ return transitions;
18346
+ },
18347
+ stateMachines: {}
18348
+ };
18349
+
18350
+ //
18351
+ // Definition of state machines
18352
+ //
18353
+ mhchemParser.stateMachines = {
18354
+ //
18355
+ // \ce state machines
18356
+ //
18357
+ //#region ce
18358
+ ce: {
18359
+ // main parser
18360
+ transitions: mhchemParser.createTransitions({
18361
+ empty: {
18362
+ "*": {
18363
+ action_: "output"
18364
+ }
18365
+ },
18366
+ else: {
18367
+ "0|1|2": {
18368
+ action_: "beginsWithBond=false",
18369
+ revisit: true,
18370
+ toContinue: true
18371
+ }
18372
+ },
18373
+ oxidation$: {
18374
+ "0": {
18375
+ action_: "oxidation-output"
18376
+ }
18377
+ },
18378
+ CMT: {
18379
+ r: {
18380
+ action_: "rdt=",
18381
+ nextState: "rt"
18382
+ },
18383
+ rd: {
18384
+ action_: "rqt=",
18385
+ nextState: "rdt"
18386
+ }
18387
+ },
18388
+ arrowUpDown: {
18389
+ "0|1|2|as": {
18390
+ action_: ["sb=false", "output", "operator"],
18391
+ nextState: "1"
18392
+ }
18393
+ },
18394
+ uprightEntities: {
18395
+ "0|1|2": {
18396
+ action_: ["o=", "output"],
18397
+ nextState: "1"
18398
+ }
18399
+ },
18400
+ orbital: {
18401
+ "0|1|2|3": {
18402
+ action_: "o=",
18403
+ nextState: "o"
18404
+ }
18405
+ },
18406
+ "->": {
18407
+ "0|1|2|3": {
18408
+ action_: "r=",
18409
+ nextState: "r"
18410
+ },
18411
+ "a|as": {
18412
+ action_: ["output", "r="],
18413
+ nextState: "r"
18414
+ },
18415
+ "*": {
18416
+ action_: ["output", "r="],
18417
+ nextState: "r"
18418
+ }
18419
+ },
18420
+ "+": {
18421
+ o: {
18422
+ action_: "d= kv",
18423
+ nextState: "d"
18424
+ },
18425
+ "d|D": {
18426
+ action_: "d=",
18427
+ nextState: "d"
18428
+ },
18429
+ q: {
18430
+ action_: "d=",
18431
+ nextState: "qd"
18432
+ },
18433
+ "qd|qD": {
18434
+ action_: "d=",
18435
+ nextState: "qd"
18436
+ },
18437
+ dq: {
18438
+ action_: ["output", "d="],
18439
+ nextState: "d"
18440
+ },
18441
+ "3": {
18442
+ action_: ["sb=false", "output", "operator"],
18443
+ nextState: "0"
18444
+ }
18445
+ },
18446
+ amount: {
18447
+ "0|2": {
18448
+ action_: "a=",
18449
+ nextState: "a"
18450
+ }
18451
+ },
18452
+ "pm-operator": {
18453
+ "0|1|2|a|as": {
18454
+ action_: ["sb=false", "output", {
18455
+ type_: "operator",
18456
+ option: "\\pm"
18457
+ }],
18458
+ nextState: "0"
18459
+ }
18460
+ },
18461
+ operator: {
18462
+ "0|1|2|a|as": {
18463
+ action_: ["sb=false", "output", "operator"],
18464
+ nextState: "0"
18465
+ }
18466
+ },
18467
+ "-$": {
18468
+ "o|q": {
18469
+ action_: ["charge or bond", "output"],
18470
+ nextState: "qd"
18471
+ },
18472
+ d: {
18473
+ action_: "d=",
18474
+ nextState: "d"
18475
+ },
18476
+ D: {
18477
+ action_: ["output", {
18478
+ type_: "bond",
18479
+ option: "-"
18480
+ }],
18481
+ nextState: "3"
18482
+ },
18483
+ q: {
18484
+ action_: "d=",
18485
+ nextState: "qd"
18486
+ },
18487
+ qd: {
18488
+ action_: "d=",
18489
+ nextState: "qd"
18490
+ },
18491
+ "qD|dq": {
18492
+ action_: ["output", {
18493
+ type_: "bond",
18494
+ option: "-"
18495
+ }],
18496
+ nextState: "3"
18497
+ }
18498
+ },
18499
+ "-9": {
18500
+ "3|o": {
18501
+ action_: ["output", {
18502
+ type_: "insert",
18503
+ option: "hyphen"
18504
+ }],
18505
+ nextState: "3"
18506
+ }
18507
+ },
18508
+ "- orbital overlap": {
18509
+ o: {
18510
+ action_: ["output", {
18511
+ type_: "insert",
18512
+ option: "hyphen"
18513
+ }],
18514
+ nextState: "2"
18515
+ },
18516
+ d: {
18517
+ action_: ["output", {
18518
+ type_: "insert",
18519
+ option: "hyphen"
18520
+ }],
18521
+ nextState: "2"
18522
+ }
18523
+ },
18524
+ "-": {
18525
+ "0|1|2": {
18526
+ action_: [{
18527
+ type_: "output",
18528
+ option: 1
18529
+ }, "beginsWithBond=true", {
18530
+ type_: "bond",
18531
+ option: "-"
18532
+ }],
18533
+ nextState: "3"
18534
+ },
18535
+ "3": {
18536
+ action_: {
18537
+ type_: "bond",
18538
+ option: "-"
18539
+ }
18540
+ },
18541
+ a: {
18542
+ action_: ["output", {
18543
+ type_: "insert",
18544
+ option: "hyphen"
18545
+ }],
18546
+ nextState: "2"
18547
+ },
18548
+ as: {
18549
+ action_: [{
18550
+ type_: "output",
18551
+ option: 2
18552
+ }, {
18553
+ type_: "bond",
18554
+ option: "-"
18555
+ }],
18556
+ nextState: "3"
18557
+ },
18558
+ b: {
18559
+ action_: "b="
18560
+ },
18561
+ o: {
18562
+ action_: {
18563
+ type_: "- after o/d",
18564
+ option: false
18565
+ },
18566
+ nextState: "2"
18567
+ },
18568
+ q: {
18569
+ action_: {
18570
+ type_: "- after o/d",
18571
+ option: false
18572
+ },
18573
+ nextState: "2"
18574
+ },
18575
+ "d|qd|dq": {
18576
+ action_: {
18577
+ type_: "- after o/d",
18578
+ option: true
18579
+ },
18580
+ nextState: "2"
18581
+ },
18582
+ "D|qD|p": {
18583
+ action_: ["output", {
18584
+ type_: "bond",
18585
+ option: "-"
18586
+ }],
18587
+ nextState: "3"
18588
+ }
18589
+ },
18590
+ amount2: {
18591
+ "1|3": {
18592
+ action_: "a=",
18593
+ nextState: "a"
18594
+ }
18595
+ },
18596
+ letters: {
18597
+ "0|1|2|3|a|as|b|p|bp|o": {
18598
+ action_: "o=",
18599
+ nextState: "o"
18600
+ },
18601
+ "q|dq": {
18602
+ action_: ["output", "o="],
18603
+ nextState: "o"
18604
+ },
18605
+ "d|D|qd|qD": {
18606
+ action_: "o after d",
18607
+ nextState: "o"
18608
+ }
18609
+ },
18610
+ digits: {
18611
+ o: {
18612
+ action_: "q=",
18613
+ nextState: "q"
18614
+ },
18615
+ "d|D": {
18616
+ action_: "q=",
18617
+ nextState: "dq"
18618
+ },
18619
+ q: {
18620
+ action_: ["output", "o="],
18621
+ nextState: "o"
18622
+ },
18623
+ a: {
18624
+ action_: "o=",
18625
+ nextState: "o"
18626
+ }
18627
+ },
18628
+ "space A": {
18629
+ "b|p|bp": {}
18630
+ },
18631
+ space: {
18632
+ a: {
18633
+ nextState: "as"
18634
+ },
18635
+ "0": {
18636
+ action_: "sb=false"
18637
+ },
18638
+ "1|2": {
18639
+ action_: "sb=true"
18640
+ },
18641
+ "r|rt|rd|rdt|rdq": {
18642
+ action_: "output",
18643
+ nextState: "0"
18644
+ },
18645
+ "*": {
18646
+ action_: ["output", "sb=true"],
18647
+ nextState: "1"
18648
+ }
18649
+ },
18650
+ "1st-level escape": {
18651
+ "1|2": {
18652
+ action_: ["output", {
18653
+ type_: "insert+p1",
18654
+ option: "1st-level escape"
18655
+ }]
18656
+ },
18657
+ "*": {
18658
+ action_: ["output", {
18659
+ type_: "insert+p1",
18660
+ option: "1st-level escape"
18661
+ }],
18662
+ nextState: "0"
18663
+ }
18664
+ },
18665
+ "[(...)]": {
18666
+ "r|rt": {
18667
+ action_: "rd=",
18668
+ nextState: "rd"
18669
+ },
18670
+ "rd|rdt": {
18671
+ action_: "rq=",
18672
+ nextState: "rdq"
18673
+ }
18674
+ },
18675
+ "...": {
18676
+ "o|d|D|dq|qd|qD": {
18677
+ action_: ["output", {
18678
+ type_: "bond",
18679
+ option: "..."
18680
+ }],
18681
+ nextState: "3"
18682
+ },
18683
+ "*": {
18684
+ action_: [{
18685
+ type_: "output",
18686
+ option: 1
18687
+ }, {
18688
+ type_: "insert",
18689
+ option: "ellipsis"
18690
+ }],
18691
+ nextState: "1"
18692
+ }
18693
+ },
18694
+ ". |* ": {
18695
+ "*": {
18696
+ action_: ["output", {
18697
+ type_: "insert",
18698
+ option: "addition compound"
18699
+ }],
18700
+ nextState: "1"
18701
+ }
18702
+ },
18703
+ "state of aggregation $": {
18704
+ "*": {
18705
+ action_: ["output", "state of aggregation"],
18706
+ nextState: "1"
18707
+ }
18708
+ },
18709
+ "{[(": {
18710
+ "a|as|o": {
18711
+ action_: ["o=", "output", "parenthesisLevel++"],
18712
+ nextState: "2"
18713
+ },
18714
+ "0|1|2|3": {
18715
+ action_: ["o=", "output", "parenthesisLevel++"],
18716
+ nextState: "2"
18717
+ },
18718
+ "*": {
18719
+ action_: ["output", "o=", "output", "parenthesisLevel++"],
18720
+ nextState: "2"
18721
+ }
18722
+ },
18723
+ ")]}": {
18724
+ "0|1|2|3|b|p|bp|o": {
18725
+ action_: ["o=", "parenthesisLevel--"],
18726
+ nextState: "o"
18727
+ },
18728
+ "a|as|d|D|q|qd|qD|dq": {
18729
+ action_: ["output", "o=", "parenthesisLevel--"],
18730
+ nextState: "o"
18731
+ }
18732
+ },
18733
+ ", ": {
18734
+ "*": {
18735
+ action_: ["output", "comma"],
18736
+ nextState: "0"
18737
+ }
18738
+ },
18739
+ "^_": {
18740
+ // ^ and _ without a sensible argument
18741
+ "*": {}
18742
+ },
18743
+ "^{(...)}|^($...$)": {
18744
+ "0|1|2|as": {
18745
+ action_: "b=",
18746
+ nextState: "b"
18747
+ },
18748
+ p: {
18749
+ action_: "b=",
18750
+ nextState: "bp"
18751
+ },
18752
+ "3|o": {
18753
+ action_: "d= kv",
18754
+ nextState: "D"
18755
+ },
18756
+ q: {
18757
+ action_: "d=",
18758
+ nextState: "qD"
18759
+ },
18760
+ "d|D|qd|qD|dq": {
18761
+ action_: ["output", "d="],
18762
+ nextState: "D"
18763
+ }
18764
+ },
18765
+ "^a|^\\x{}{}|^\\x{}|^\\x|'": {
18766
+ "0|1|2|as": {
18767
+ action_: "b=",
18768
+ nextState: "b"
18769
+ },
18770
+ p: {
18771
+ action_: "b=",
18772
+ nextState: "bp"
18773
+ },
18774
+ "3|o": {
18775
+ action_: "d= kv",
18776
+ nextState: "d"
18777
+ },
18778
+ q: {
18779
+ action_: "d=",
18780
+ nextState: "qd"
18781
+ },
18782
+ "d|qd|D|qD": {
18783
+ action_: "d="
18784
+ },
18785
+ dq: {
18786
+ action_: ["output", "d="],
18787
+ nextState: "d"
18788
+ }
18789
+ },
18790
+ "_{(state of aggregation)}$": {
18791
+ "d|D|q|qd|qD|dq": {
18792
+ action_: ["output", "q="],
18793
+ nextState: "q"
18794
+ }
18795
+ },
18796
+ "_{(...)}|_($...$)|_9|_\\x{}{}|_\\x{}|_\\x": {
18797
+ "0|1|2|as": {
18798
+ action_: "p=",
18799
+ nextState: "p"
18800
+ },
18801
+ b: {
18802
+ action_: "p=",
18803
+ nextState: "bp"
18804
+ },
18805
+ "3|o": {
18806
+ action_: "q=",
18807
+ nextState: "q"
18808
+ },
18809
+ "d|D": {
18810
+ action_: "q=",
18811
+ nextState: "dq"
18812
+ },
18813
+ "q|qd|qD|dq": {
18814
+ action_: ["output", "q="],
18815
+ nextState: "q"
18816
+ }
18817
+ },
18818
+ "=<>": {
18819
+ "0|1|2|3|a|as|o|q|d|D|qd|qD|dq": {
18820
+ action_: [{
18821
+ type_: "output",
18822
+ option: 2
18823
+ }, "bond"],
18824
+ nextState: "3"
18825
+ }
18826
+ },
18827
+ "#": {
18828
+ "0|1|2|3|a|as|o": {
18829
+ action_: [{
18830
+ type_: "output",
18831
+ option: 2
18832
+ }, {
18833
+ type_: "bond",
18834
+ option: "#"
18835
+ }],
18836
+ nextState: "3"
18837
+ }
18838
+ },
18839
+ "{}": {
18840
+ "*": {
18841
+ action_: {
18842
+ type_: "output",
18843
+ option: 1
18844
+ },
18845
+ nextState: "1"
18846
+ }
18847
+ },
18848
+ "{...}": {
18849
+ "0|1|2|3|a|as|b|p|bp": {
18850
+ action_: "o=",
18851
+ nextState: "o"
18852
+ },
18853
+ "o|d|D|q|qd|qD|dq": {
18854
+ action_: ["output", "o="],
18855
+ nextState: "o"
18856
+ }
18857
+ },
18858
+ "$...$": {
18859
+ a: {
18860
+ action_: "a="
18861
+ },
18862
+ // 2$n$
18863
+ "0|1|2|3|as|b|p|bp|o": {
18864
+ action_: "o=",
18865
+ nextState: "o"
18866
+ },
18867
+ // not 'amount'
18868
+ "as|o": {
18869
+ action_: "o="
18870
+ },
18871
+ "q|d|D|qd|qD|dq": {
18872
+ action_: ["output", "o="],
18873
+ nextState: "o"
18874
+ }
18875
+ },
18876
+ "\\bond{(...)}": {
18877
+ "*": {
18878
+ action_: [{
18879
+ type_: "output",
18880
+ option: 2
18881
+ }, "bond"],
18882
+ nextState: "3"
18883
+ }
18884
+ },
18885
+ "\\frac{(...)}": {
18886
+ "*": {
18887
+ action_: [{
18888
+ type_: "output",
18889
+ option: 1
18890
+ }, "frac-output"],
18891
+ nextState: "3"
18892
+ }
18893
+ },
18894
+ "\\overset{(...)}": {
18895
+ "*": {
18896
+ action_: [{
18897
+ type_: "output",
18898
+ option: 2
18899
+ }, "overset-output"],
18900
+ nextState: "3"
18901
+ }
18902
+ },
18903
+ "\\underset{(...)}": {
18904
+ "*": {
18905
+ action_: [{
18906
+ type_: "output",
18907
+ option: 2
18908
+ }, "underset-output"],
18909
+ nextState: "3"
18910
+ }
18911
+ },
18912
+ "\\underbrace{(...)}": {
18913
+ "*": {
18914
+ action_: [{
18915
+ type_: "output",
18916
+ option: 2
18917
+ }, "underbrace-output"],
18918
+ nextState: "3"
18919
+ }
18920
+ },
18921
+ "\\color{(...)}{(...)}1|\\color(...){(...)}2": {
18922
+ "*": {
18923
+ action_: [{
18924
+ type_: "output",
18925
+ option: 2
18926
+ }, "color-output"],
18927
+ nextState: "3"
18928
+ }
18929
+ },
18930
+ "\\color{(...)}0": {
18931
+ "*": {
18932
+ action_: [{
18933
+ type_: "output",
18934
+ option: 2
18935
+ }, "color0-output"]
18936
+ }
18937
+ },
18938
+ "\\ce{(...)}": {
18939
+ "*": {
18940
+ action_: [{
18941
+ type_: "output",
18942
+ option: 2
18943
+ }, "ce"],
18944
+ nextState: "3"
18945
+ }
18946
+ },
18947
+ "\\,": {
18948
+ "*": {
18949
+ action_: [{
18950
+ type_: "output",
18951
+ option: 1
18952
+ }, "copy"],
18953
+ nextState: "1"
18954
+ }
18955
+ },
18956
+ "\\x{}{}|\\x{}|\\x": {
18957
+ "0|1|2|3|a|as|b|p|bp|o|c0": {
18958
+ action_: ["o=", "output"],
18959
+ nextState: "3"
18960
+ },
18961
+ "*": {
18962
+ action_: ["output", "o=", "output"],
18963
+ nextState: "3"
18964
+ }
18965
+ },
18966
+ others: {
18967
+ "*": {
18968
+ action_: [{
18969
+ type_: "output",
18970
+ option: 1
18971
+ }, "copy"],
18972
+ nextState: "3"
18973
+ }
18974
+ },
18975
+ else2: {
18976
+ a: {
18977
+ action_: "a to o",
18978
+ nextState: "o",
18979
+ revisit: true
18980
+ },
18981
+ as: {
18982
+ action_: ["output", "sb=true"],
18983
+ nextState: "1",
18984
+ revisit: true
18985
+ },
18986
+ "r|rt|rd|rdt|rdq": {
18987
+ action_: ["output"],
18988
+ nextState: "0",
18989
+ revisit: true
18990
+ },
18991
+ "*": {
18992
+ action_: ["output", "copy"],
18993
+ nextState: "3"
18994
+ }
18995
+ }
18996
+ }),
18997
+ actions: {
18998
+ "o after d": function (buffer, m) {
18999
+ let ret;
19000
+ if ((buffer.d || "").match(/^[0-9]+$/)) {
19001
+ const tmp = buffer.d;
19002
+ buffer.d = undefined;
19003
+ ret = this["output"](buffer);
19004
+ buffer.b = tmp;
19005
+ } else {
19006
+ ret = this["output"](buffer);
19007
+ }
19008
+ mhchemParser.actions["o="](buffer, m);
19009
+ return ret;
19010
+ },
19011
+ "d= kv": function (buffer, m) {
19012
+ buffer.d = m;
19013
+ buffer.dType = "kv";
19014
+ },
19015
+ "charge or bond": function (buffer, m) {
19016
+ if (buffer["beginsWithBond"]) {
19017
+ /** @type {ParserOutput[]} */
19018
+ const ret = [];
19019
+ mhchemParser.concatArray(ret, this["output"](buffer));
19020
+ mhchemParser.concatArray(ret, mhchemParser.actions["bond"](buffer, m, "-"));
19021
+ return ret;
19022
+ }
19023
+ buffer.d = m;
19024
+ },
19025
+ "- after o/d": function (buffer, m, isAfterD) {
19026
+ let c1 = mhchemParser.patterns.match_("orbital", buffer.o || "");
19027
+ const c2 = mhchemParser.patterns.match_("one lowercase greek letter $", buffer.o || "");
19028
+ const c3 = mhchemParser.patterns.match_("one lowercase latin letter $", buffer.o || "");
19029
+ const c4 = mhchemParser.patterns.match_("$one lowercase latin letter$ $", buffer.o || "");
19030
+ const hyphenFollows = m === "-" && (c1 && c1.remainder === "" || c2 || c3 || c4);
19031
+ if (hyphenFollows && !buffer.a && !buffer.b && !buffer.p && !buffer.d && !buffer.q && !c1 && c3) {
19032
+ buffer.o = "$" + buffer.o + "$";
19033
+ }
19034
+ /** @type {ParserOutput[]} */
19035
+ const ret = [];
19036
+ if (hyphenFollows) {
19037
+ mhchemParser.concatArray(ret, this["output"](buffer));
19038
+ ret.push({
19039
+ type_: "hyphen"
19040
+ });
19041
+ } else {
19042
+ c1 = mhchemParser.patterns.match_("digits", buffer.d || "");
19043
+ if (isAfterD && c1 && c1.remainder === "") {
19044
+ mhchemParser.concatArray(ret, mhchemParser.actions["d="](buffer, m));
19045
+ mhchemParser.concatArray(ret, this["output"](buffer));
19046
+ } else {
19047
+ mhchemParser.concatArray(ret, this["output"](buffer));
19048
+ mhchemParser.concatArray(ret, mhchemParser.actions["bond"](buffer, m, "-"));
19049
+ }
19050
+ }
19051
+ return ret;
19052
+ },
19053
+ "a to o": function (buffer) {
19054
+ buffer.o = buffer.a;
19055
+ buffer.a = undefined;
19056
+ },
19057
+ "sb=true": function (buffer) {
19058
+ buffer.sb = true;
19059
+ },
19060
+ "sb=false": function (buffer) {
19061
+ buffer.sb = false;
19062
+ },
19063
+ "beginsWithBond=true": function (buffer) {
19064
+ buffer["beginsWithBond"] = true;
19065
+ },
19066
+ "beginsWithBond=false": function (buffer) {
19067
+ buffer["beginsWithBond"] = false;
19068
+ },
19069
+ "parenthesisLevel++": function (buffer) {
19070
+ buffer["parenthesisLevel"]++;
19071
+ },
19072
+ "parenthesisLevel--": function (buffer) {
19073
+ buffer["parenthesisLevel"]--;
19074
+ },
19075
+ "state of aggregation": function (buffer, m) {
19076
+ return {
19077
+ type_: "state of aggregation",
19078
+ p1: mhchemParser.go(m, "o")
19079
+ };
19080
+ },
19081
+ comma: function (buffer, m) {
19082
+ const a = m.replace(/\s*$/, "");
19083
+ const withSpace = a !== m;
19084
+ if (withSpace && buffer["parenthesisLevel"] === 0) {
19085
+ return {
19086
+ type_: "comma enumeration L",
19087
+ p1: a
19088
+ };
19089
+ }
19090
+ return {
19091
+ type_: "comma enumeration M",
19092
+ p1: a
19093
+ };
19094
+ },
19095
+ output: function (buffer, m, entityFollows) {
19096
+ // entityFollows:
19097
+ // undefined = if we have nothing else to output, also ignore the just read space (buffer.sb)
19098
+ // 1 = an entity follows, never omit the space if there was one just read before (can only apply to state 1)
19099
+ // 2 = 1 + the entity can have an amount, so output a\, instead of converting it to o (can only apply to states a|as)
19100
+ /** @type {ParserOutput | ParserOutput[]} */
19101
+ let ret;
19102
+ if (!buffer.r) {
19103
+ ret = [];
19104
+ if (!buffer.a && !buffer.b && !buffer.p && !buffer.o && !buffer.q && !buffer.d && !entityFollows) ; else {
19105
+ if (buffer.sb) {
19106
+ ret.push({
19107
+ type_: "entitySkip"
19108
+ });
19109
+ }
19110
+ if (!buffer.o && !buffer.q && !buffer.d && !buffer.b && !buffer.p && entityFollows !== 2) {
19111
+ buffer.o = buffer.a;
19112
+ buffer.a = undefined;
19113
+ } else if (!buffer.o && !buffer.q && !buffer.d && (buffer.b || buffer.p)) {
19114
+ buffer.o = buffer.a;
19115
+ buffer.d = buffer.b;
19116
+ buffer.q = buffer.p;
19117
+ buffer.a = buffer.b = buffer.p = undefined;
19118
+ } else {
19119
+ if (buffer.o && buffer.dType === "kv" && mhchemParser.patterns.match_("d-oxidation$", buffer.d || "")) {
19120
+ buffer.dType = "oxidation";
19121
+ } else if (buffer.o && buffer.dType === "kv" && !buffer.q) {
19122
+ buffer.dType = undefined;
19123
+ }
19124
+ }
19125
+ ret.push({
19126
+ type_: "chemfive",
19127
+ a: mhchemParser.go(buffer.a, "a"),
19128
+ b: mhchemParser.go(buffer.b, "bd"),
19129
+ p: mhchemParser.go(buffer.p, "pq"),
19130
+ o: mhchemParser.go(buffer.o, "o"),
19131
+ q: mhchemParser.go(buffer.q, "pq"),
19132
+ d: mhchemParser.go(buffer.d, buffer.dType === "oxidation" ? "oxidation" : "bd"),
19133
+ dType: buffer.dType
19134
+ });
19135
+ }
19136
+ } else {
19137
+ // r
19138
+ /** @type {ParserOutput[]} */
19139
+ let rd;
19140
+ if (buffer.rdt === "M") {
19141
+ rd = mhchemParser.go(buffer.rd, "tex-math");
19142
+ } else if (buffer.rdt === "T") {
19143
+ rd = [{
19144
+ type_: "text",
19145
+ p1: buffer.rd || ""
19146
+ }];
19147
+ } else {
19148
+ rd = mhchemParser.go(buffer.rd);
19149
+ }
19150
+ /** @type {ParserOutput[]} */
19151
+ let rq;
19152
+ if (buffer.rqt === "M") {
19153
+ rq = mhchemParser.go(buffer.rq, "tex-math");
19154
+ } else if (buffer.rqt === "T") {
19155
+ rq = [{
19156
+ type_: "text",
19157
+ p1: buffer.rq || ""
19158
+ }];
19159
+ } else {
19160
+ rq = mhchemParser.go(buffer.rq);
19161
+ }
19162
+ ret = {
19163
+ type_: "arrow",
19164
+ r: buffer.r,
19165
+ rd: rd,
19166
+ rq: rq
19167
+ };
19168
+ }
19169
+ for (const p in buffer) {
19170
+ if (p !== "parenthesisLevel" && p !== "beginsWithBond") {
19171
+ delete buffer[p];
19172
+ }
19173
+ }
19174
+ return ret;
19175
+ },
19176
+ "oxidation-output": function (buffer, m) {
19177
+ const ret = ["{"];
19178
+ mhchemParser.concatArray(ret, mhchemParser.go(m, "oxidation"));
19179
+ ret.push("}");
19180
+ return ret;
19181
+ },
19182
+ "frac-output": function (buffer, m) {
19183
+ return {
19184
+ type_: "frac-ce",
19185
+ p1: mhchemParser.go(m[0]),
19186
+ p2: mhchemParser.go(m[1])
19187
+ };
19188
+ },
19189
+ "overset-output": function (buffer, m) {
19190
+ return {
19191
+ type_: "overset",
19192
+ p1: mhchemParser.go(m[0]),
19193
+ p2: mhchemParser.go(m[1])
19194
+ };
19195
+ },
19196
+ "underset-output": function (buffer, m) {
19197
+ return {
19198
+ type_: "underset",
19199
+ p1: mhchemParser.go(m[0]),
19200
+ p2: mhchemParser.go(m[1])
19201
+ };
19202
+ },
19203
+ "underbrace-output": function (buffer, m) {
19204
+ return {
19205
+ type_: "underbrace",
19206
+ p1: mhchemParser.go(m[0]),
19207
+ p2: mhchemParser.go(m[1])
19208
+ };
19209
+ },
19210
+ "color-output": function (buffer, m) {
19211
+ return {
19212
+ type_: "color",
19213
+ color1: m[0],
19214
+ color2: mhchemParser.go(m[1])
19215
+ };
19216
+ },
19217
+ "r=": function (buffer, m) {
19218
+ buffer.r = m;
19219
+ },
19220
+ "rdt=": function (buffer, m) {
19221
+ buffer.rdt = m;
19222
+ },
19223
+ "rd=": function (buffer, m) {
19224
+ buffer.rd = m;
19225
+ },
19226
+ "rqt=": function (buffer, m) {
19227
+ buffer.rqt = m;
19228
+ },
19229
+ "rq=": function (buffer, m) {
19230
+ buffer.rq = m;
19231
+ },
19232
+ operator: function (buffer, m, p1) {
19233
+ return {
19234
+ type_: "operator",
19235
+ kind_: p1 || m
19236
+ };
19237
+ }
19238
+ }
19239
+ },
19240
+ a: {
19241
+ transitions: mhchemParser.createTransitions({
19242
+ empty: {
19243
+ "*": {}
19244
+ },
19245
+ "1/2$": {
19246
+ "0": {
19247
+ action_: "1/2"
19248
+ }
19249
+ },
19250
+ else: {
19251
+ "0": {
19252
+ nextState: "1",
19253
+ revisit: true
19254
+ }
19255
+ },
19256
+ "$(...)$": {
19257
+ "*": {
19258
+ action_: "tex-math tight",
19259
+ nextState: "1"
19260
+ }
19261
+ },
19262
+ ",": {
19263
+ "*": {
19264
+ action_: {
19265
+ type_: "insert",
19266
+ option: "commaDecimal"
19267
+ }
19268
+ }
19269
+ },
19270
+ else2: {
19271
+ "*": {
19272
+ action_: "copy"
19273
+ }
19274
+ }
19275
+ }),
19276
+ actions: {}
19277
+ },
19278
+ o: {
19279
+ transitions: mhchemParser.createTransitions({
19280
+ empty: {
19281
+ "*": {}
19282
+ },
19283
+ "1/2$": {
19284
+ "0": {
19285
+ action_: "1/2"
19286
+ }
19287
+ },
19288
+ else: {
19289
+ "0": {
19290
+ nextState: "1",
19291
+ revisit: true
19292
+ }
19293
+ },
19294
+ letters: {
19295
+ "*": {
19296
+ action_: "rm"
19297
+ }
19298
+ },
19299
+ "\\ca": {
19300
+ "*": {
19301
+ action_: {
19302
+ type_: "insert",
19303
+ option: "circa"
19304
+ }
19305
+ }
19306
+ },
19307
+ "\\x{}{}|\\x{}|\\x": {
19308
+ "*": {
19309
+ action_: "copy"
19310
+ }
19311
+ },
19312
+ "${(...)}$|$(...)$": {
19313
+ "*": {
19314
+ action_: "tex-math"
19315
+ }
19316
+ },
19317
+ "{(...)}": {
19318
+ "*": {
19319
+ action_: "{text}"
19320
+ }
19321
+ },
19322
+ else2: {
19323
+ "*": {
19324
+ action_: "copy"
19325
+ }
19326
+ }
19327
+ }),
19328
+ actions: {}
19329
+ },
19330
+ text: {
19331
+ transitions: mhchemParser.createTransitions({
19332
+ empty: {
19333
+ "*": {
19334
+ action_: "output"
19335
+ }
19336
+ },
19337
+ "{...}": {
19338
+ "*": {
19339
+ action_: "text="
19340
+ }
19341
+ },
19342
+ "${(...)}$|$(...)$": {
19343
+ "*": {
19344
+ action_: "tex-math"
19345
+ }
19346
+ },
19347
+ "\\greek": {
19348
+ "*": {
19349
+ action_: ["output", "rm"]
19350
+ }
19351
+ },
19352
+ "\\,|\\x{}{}|\\x{}|\\x": {
19353
+ "*": {
19354
+ action_: ["output", "copy"]
19355
+ }
19356
+ },
19357
+ else: {
19358
+ "*": {
19359
+ action_: "text="
19360
+ }
19361
+ }
19362
+ }),
19363
+ actions: {
19364
+ output: function (buffer) {
19365
+ if (buffer.text_) {
19366
+ /** @type {ParserOutput} */
19367
+ const ret = {
19368
+ type_: "text",
19369
+ p1: buffer.text_
19370
+ };
19371
+ for (const p in buffer) {
19372
+ delete buffer[p];
19373
+ }
19374
+ return ret;
19375
+ }
19376
+ }
19377
+ }
19378
+ },
19379
+ pq: {
19380
+ transitions: mhchemParser.createTransitions({
19381
+ empty: {
19382
+ "*": {}
19383
+ },
19384
+ "state of aggregation $": {
19385
+ "*": {
19386
+ action_: "state of aggregation"
19387
+ }
19388
+ },
19389
+ i$: {
19390
+ "0": {
19391
+ nextState: "!f",
19392
+ revisit: true
19393
+ }
19394
+ },
19395
+ "(KV letters),": {
19396
+ "0": {
19397
+ action_: "rm",
19398
+ nextState: "0"
19399
+ }
19400
+ },
19401
+ formula$: {
19402
+ "0": {
19403
+ nextState: "f",
19404
+ revisit: true
19405
+ }
19406
+ },
19407
+ "1/2$": {
19408
+ "0": {
19409
+ action_: "1/2"
19410
+ }
19411
+ },
19412
+ else: {
19413
+ "0": {
19414
+ nextState: "!f",
19415
+ revisit: true
19416
+ }
19417
+ },
19418
+ "${(...)}$|$(...)$": {
19419
+ "*": {
19420
+ action_: "tex-math"
19421
+ }
19422
+ },
19423
+ "{(...)}": {
19424
+ "*": {
19425
+ action_: "text"
19426
+ }
19427
+ },
19428
+ "a-z": {
19429
+ f: {
19430
+ action_: "tex-math"
19431
+ }
19432
+ },
19433
+ letters: {
19434
+ "*": {
19435
+ action_: "rm"
19436
+ }
19437
+ },
19438
+ "-9.,9": {
19439
+ "*": {
19440
+ action_: "9,9"
19441
+ }
19442
+ },
19443
+ ",": {
19444
+ "*": {
19445
+ action_: {
19446
+ type_: "insert+p1",
19447
+ option: "comma enumeration S"
19448
+ }
19449
+ }
19450
+ },
19451
+ "\\color{(...)}{(...)}1|\\color(...){(...)}2": {
19452
+ "*": {
19453
+ action_: "color-output"
19454
+ }
19455
+ },
19456
+ "\\color{(...)}0": {
19457
+ "*": {
19458
+ action_: "color0-output"
19459
+ }
19460
+ },
19461
+ "\\ce{(...)}": {
19462
+ "*": {
19463
+ action_: "ce"
19464
+ }
19465
+ },
19466
+ "\\,|\\x{}{}|\\x{}|\\x": {
19467
+ "*": {
19468
+ action_: "copy"
19469
+ }
19470
+ },
19471
+ else2: {
19472
+ "*": {
19473
+ action_: "copy"
19474
+ }
19475
+ }
19476
+ }),
19477
+ actions: {
19478
+ "state of aggregation": function (buffer, m) {
19479
+ return {
19480
+ type_: "state of aggregation subscript",
19481
+ p1: mhchemParser.go(m, "o")
19482
+ };
19483
+ },
19484
+ "color-output": function (buffer, m) {
19485
+ return {
19486
+ type_: "color",
19487
+ color1: m[0],
19488
+ color2: mhchemParser.go(m[1], "pq")
19489
+ };
19490
+ }
19491
+ }
19492
+ },
19493
+ bd: {
19494
+ transitions: mhchemParser.createTransitions({
19495
+ empty: {
19496
+ "*": {}
19497
+ },
19498
+ x$: {
19499
+ "0": {
19500
+ nextState: "!f",
19501
+ revisit: true
19502
+ }
19503
+ },
19504
+ formula$: {
19505
+ "0": {
19506
+ nextState: "f",
19507
+ revisit: true
19508
+ }
19509
+ },
19510
+ else: {
19511
+ "0": {
19512
+ nextState: "!f",
19513
+ revisit: true
19514
+ }
19515
+ },
19516
+ "-9.,9 no missing 0": {
19517
+ "*": {
19518
+ action_: "9,9"
19519
+ }
19520
+ },
19521
+ ".": {
19522
+ "*": {
19523
+ action_: {
19524
+ type_: "insert",
19525
+ option: "electron dot"
19526
+ }
19527
+ }
19528
+ },
19529
+ "a-z": {
19530
+ f: {
19531
+ action_: "tex-math"
19532
+ }
19533
+ },
19534
+ x: {
19535
+ "*": {
19536
+ action_: {
19537
+ type_: "insert",
19538
+ option: "KV x"
19539
+ }
19540
+ }
19541
+ },
19542
+ letters: {
19543
+ "*": {
19544
+ action_: "rm"
19545
+ }
19546
+ },
19547
+ "'": {
19548
+ "*": {
19549
+ action_: {
19550
+ type_: "insert",
19551
+ option: "prime"
19552
+ }
19553
+ }
19554
+ },
19555
+ "${(...)}$|$(...)$": {
19556
+ "*": {
19557
+ action_: "tex-math"
19558
+ }
19559
+ },
19560
+ "{(...)}": {
19561
+ "*": {
19562
+ action_: "text"
19563
+ }
19564
+ },
19565
+ "\\color{(...)}{(...)}1|\\color(...){(...)}2": {
19566
+ "*": {
19567
+ action_: "color-output"
19568
+ }
19569
+ },
19570
+ "\\color{(...)}0": {
19571
+ "*": {
19572
+ action_: "color0-output"
19573
+ }
19574
+ },
19575
+ "\\ce{(...)}": {
19576
+ "*": {
19577
+ action_: "ce"
19578
+ }
19579
+ },
19580
+ "\\,|\\x{}{}|\\x{}|\\x": {
19581
+ "*": {
19582
+ action_: "copy"
19583
+ }
19584
+ },
19585
+ else2: {
19586
+ "*": {
19587
+ action_: "copy"
19588
+ }
19589
+ }
19590
+ }),
19591
+ actions: {
19592
+ "color-output": function (buffer, m) {
19593
+ return {
19594
+ type_: "color",
19595
+ color1: m[0],
19596
+ color2: mhchemParser.go(m[1], "bd")
19597
+ };
19598
+ }
19599
+ }
19600
+ },
19601
+ oxidation: {
19602
+ transitions: mhchemParser.createTransitions({
19603
+ empty: {
19604
+ "*": {}
19605
+ },
19606
+ "roman numeral": {
19607
+ "*": {
19608
+ action_: "roman-numeral"
19609
+ }
19610
+ },
19611
+ "${(...)}$|$(...)$": {
19612
+ "*": {
19613
+ action_: "tex-math"
19614
+ }
19615
+ },
19616
+ else: {
19617
+ "*": {
19618
+ action_: "copy"
19619
+ }
19620
+ }
19621
+ }),
19622
+ actions: {
19623
+ "roman-numeral": function (buffer, m) {
19624
+ return {
19625
+ type_: "roman numeral",
19626
+ p1: m || ""
19627
+ };
19628
+ }
19629
+ }
19630
+ },
19631
+ "tex-math": {
19632
+ transitions: mhchemParser.createTransitions({
19633
+ empty: {
19634
+ "*": {
19635
+ action_: "output"
19636
+ }
19637
+ },
19638
+ "\\ce{(...)}": {
19639
+ "*": {
19640
+ action_: ["output", "ce"]
19641
+ }
19642
+ },
19643
+ "{...}|\\,|\\x{}{}|\\x{}|\\x": {
19644
+ "*": {
19645
+ action_: "o="
19646
+ }
19647
+ },
19648
+ else: {
19649
+ "*": {
19650
+ action_: "o="
19651
+ }
19652
+ }
19653
+ }),
19654
+ actions: {
19655
+ output: function (buffer) {
19656
+ if (buffer.o) {
19657
+ /** @type {ParserOutput} */
19658
+ const ret = {
19659
+ type_: "tex-math",
19660
+ p1: buffer.o
19661
+ };
19662
+ for (const p in buffer) {
19663
+ delete buffer[p];
19664
+ }
19665
+ return ret;
19666
+ }
19667
+ }
19668
+ }
19669
+ },
19670
+ "tex-math tight": {
19671
+ transitions: mhchemParser.createTransitions({
19672
+ empty: {
19673
+ "*": {
19674
+ action_: "output"
19675
+ }
19676
+ },
19677
+ "\\ce{(...)}": {
19678
+ "*": {
19679
+ action_: ["output", "ce"]
19680
+ }
19681
+ },
19682
+ "{...}|\\,|\\x{}{}|\\x{}|\\x": {
19683
+ "*": {
19684
+ action_: "o="
19685
+ }
19686
+ },
19687
+ "-|+": {
19688
+ "*": {
19689
+ action_: "tight operator"
19690
+ }
19691
+ },
19692
+ else: {
19693
+ "*": {
19694
+ action_: "o="
19695
+ }
19696
+ }
19697
+ }),
19698
+ actions: {
19699
+ "tight operator": function (buffer, m) {
19700
+ buffer.o = (buffer.o || "") + "{" + m + "}";
19701
+ },
19702
+ output: function (buffer) {
19703
+ if (buffer.o) {
19704
+ /** @type {ParserOutput} */
19705
+ const ret = {
19706
+ type_: "tex-math",
19707
+ p1: buffer.o
19708
+ };
19709
+ for (const p in buffer) {
19710
+ delete buffer[p];
19711
+ }
19712
+ return ret;
19713
+ }
19714
+ }
19715
+ }
19716
+ },
19717
+ "9,9": {
19718
+ transitions: mhchemParser.createTransitions({
19719
+ empty: {
19720
+ "*": {}
19721
+ },
19722
+ ",": {
19723
+ "*": {
19724
+ action_: "comma"
19725
+ }
19726
+ },
19727
+ else: {
19728
+ "*": {
19729
+ action_: "copy"
19730
+ }
19731
+ }
19732
+ }),
19733
+ actions: {
19734
+ comma: function () {
19735
+ return {
19736
+ type_: "commaDecimal"
19737
+ };
19738
+ }
19739
+ }
19740
+ },
19741
+ //#endregion
19742
+ //
19743
+ // \pu state machines
19744
+ //
19745
+ //#region pu
19746
+ pu: {
19747
+ transitions: mhchemParser.createTransitions({
19748
+ empty: {
19749
+ "*": {
19750
+ action_: "output"
19751
+ }
19752
+ },
19753
+ space$: {
19754
+ "*": {
19755
+ action_: ["output", "space"]
19756
+ }
19757
+ },
19758
+ "{[(|)]}": {
19759
+ "0|a": {
19760
+ action_: "copy"
19761
+ }
19762
+ },
19763
+ "(-)(9)^(-9)": {
19764
+ "0": {
19765
+ action_: "number^",
19766
+ nextState: "a"
19767
+ }
19768
+ },
19769
+ "(-)(9.,9)(e)(99)": {
19770
+ "0": {
19771
+ action_: "enumber",
19772
+ nextState: "a"
19773
+ }
19774
+ },
19775
+ space: {
19776
+ "0|a": {}
19777
+ },
19778
+ "pm-operator": {
19779
+ "0|a": {
19780
+ action_: {
19781
+ type_: "operator",
19782
+ option: "\\pm"
19783
+ },
19784
+ nextState: "0"
19785
+ }
19786
+ },
19787
+ operator: {
19788
+ "0|a": {
19789
+ action_: "copy",
19790
+ nextState: "0"
19791
+ }
19792
+ },
19793
+ "//": {
19794
+ d: {
19795
+ action_: "o=",
19796
+ nextState: "/"
19797
+ }
19798
+ },
19799
+ "/": {
19800
+ d: {
19801
+ action_: "o=",
19802
+ nextState: "/"
19803
+ }
19804
+ },
19805
+ "{...}|else": {
19806
+ "0|d": {
19807
+ action_: "d=",
19808
+ nextState: "d"
19809
+ },
19810
+ a: {
19811
+ action_: ["space", "d="],
19812
+ nextState: "d"
19813
+ },
19814
+ "/|q": {
19815
+ action_: "q=",
19816
+ nextState: "q"
19817
+ }
19818
+ }
19819
+ }),
19820
+ actions: {
19821
+ enumber: function (buffer, m) {
19822
+ /** @type {ParserOutput[]} */
19823
+ const ret = [];
19824
+ if (m[0] === "+-" || m[0] === "+/-") {
19825
+ ret.push("\\pm ");
19826
+ } else if (m[0]) {
19827
+ ret.push(m[0]);
19828
+ }
19829
+ if (m[1]) {
19830
+ mhchemParser.concatArray(ret, mhchemParser.go(m[1], "pu-9,9"));
19831
+ if (m[2]) {
19832
+ if (m[2].match(/[,.]/)) {
19833
+ mhchemParser.concatArray(ret, mhchemParser.go(m[2], "pu-9,9"));
19834
+ } else {
19835
+ ret.push(m[2]);
19836
+ }
19837
+ }
19838
+ m[3] = m[4] || m[3];
19839
+ if (m[3]) {
19840
+ m[3] = m[3].trim();
19841
+ if (m[3] === "e" || m[3].substr(0, 1) === "*") {
19842
+ ret.push({
19843
+ type_: "cdot"
19844
+ });
19845
+ } else {
19846
+ ret.push({
19847
+ type_: "times"
19848
+ });
19849
+ }
19850
+ }
19851
+ }
19852
+ if (m[3]) {
19853
+ ret.push("10^{" + m[5] + "}");
19854
+ }
19855
+ return ret;
19856
+ },
19857
+ "number^": function (buffer, m) {
19858
+ /** @type {ParserOutput[]} */
19859
+ const ret = [];
19860
+ if (m[0] === "+-" || m[0] === "+/-") {
19861
+ ret.push("\\pm ");
19862
+ } else if (m[0]) {
19863
+ ret.push(m[0]);
19864
+ }
19865
+ mhchemParser.concatArray(ret, mhchemParser.go(m[1], "pu-9,9"));
19866
+ ret.push("^{" + m[2] + "}");
19867
+ return ret;
19868
+ },
19869
+ operator: function (buffer, m, p1) {
19870
+ return {
19871
+ type_: "operator",
19872
+ kind_: p1 || m
19873
+ };
19874
+ },
19875
+ space: function () {
19876
+ return {
19877
+ type_: "pu-space-1"
19878
+ };
19879
+ },
19880
+ output: function (buffer) {
19881
+ /** @type {ParserOutput | ParserOutput[]} */
19882
+ let ret;
19883
+ const md = mhchemParser.patterns.match_("{(...)}", buffer.d || "");
19884
+ if (md && md.remainder === "") {
19885
+ buffer.d = md.match_;
19886
+ }
19887
+ const mq = mhchemParser.patterns.match_("{(...)}", buffer.q || "");
19888
+ if (mq && mq.remainder === "") {
19889
+ buffer.q = mq.match_;
19890
+ }
19891
+ if (buffer.d) {
19892
+ buffer.d = buffer.d.replace(/\u00B0C|\^oC|\^{o}C/g, "{}^{\\circ}C");
19893
+ buffer.d = buffer.d.replace(/\u00B0F|\^oF|\^{o}F/g, "{}^{\\circ}F");
19894
+ }
19895
+ if (buffer.q) {
19896
+ // fraction
19897
+ buffer.q = buffer.q.replace(/\u00B0C|\^oC|\^{o}C/g, "{}^{\\circ}C");
19898
+ buffer.q = buffer.q.replace(/\u00B0F|\^oF|\^{o}F/g, "{}^{\\circ}F");
19899
+ const b5 = {
19900
+ d: mhchemParser.go(buffer.d, "pu"),
19901
+ q: mhchemParser.go(buffer.q, "pu")
19902
+ };
19903
+ if (buffer.o === "//") {
19904
+ ret = {
19905
+ type_: "pu-frac",
19906
+ p1: b5.d,
19907
+ p2: b5.q
19908
+ };
19909
+ } else {
19910
+ ret = b5.d;
19911
+ if (b5.d.length > 1 || b5.q.length > 1) {
19912
+ ret.push({
19913
+ type_: " / "
19914
+ });
19915
+ } else {
19916
+ ret.push({
19917
+ type_: "/"
19918
+ });
19919
+ }
19920
+ mhchemParser.concatArray(ret, b5.q);
19921
+ }
19922
+ } else {
19923
+ // no fraction
19924
+ ret = mhchemParser.go(buffer.d, "pu-2");
19925
+ }
19926
+ for (const p in buffer) {
19927
+ delete buffer[p];
19928
+ }
19929
+ return ret;
19930
+ }
19931
+ }
19932
+ },
19933
+ "pu-2": {
19934
+ transitions: mhchemParser.createTransitions({
19935
+ empty: {
19936
+ "*": {
19937
+ action_: "output"
19938
+ }
19939
+ },
19940
+ "*": {
19941
+ "*": {
19942
+ action_: ["output", "cdot"],
19943
+ nextState: "0"
19944
+ }
19945
+ },
19946
+ "\\x": {
19947
+ "*": {
19948
+ action_: "rm="
19949
+ }
19950
+ },
19951
+ space: {
19952
+ "*": {
19953
+ action_: ["output", "space"],
19954
+ nextState: "0"
19955
+ }
19956
+ },
19957
+ "^{(...)}|^(-1)": {
19958
+ "1": {
19959
+ action_: "^(-1)"
19960
+ }
19961
+ },
19962
+ "-9.,9": {
19963
+ "0": {
19964
+ action_: "rm=",
19965
+ nextState: "0"
19966
+ },
19967
+ "1": {
19968
+ action_: "^(-1)",
19969
+ nextState: "0"
19970
+ }
19971
+ },
19972
+ "{...}|else": {
19973
+ "*": {
19974
+ action_: "rm=",
19975
+ nextState: "1"
19976
+ }
19977
+ }
19978
+ }),
19979
+ actions: {
19980
+ cdot: function () {
19981
+ return {
19982
+ type_: "tight cdot"
19983
+ };
19984
+ },
19985
+ "^(-1)": function (buffer, m) {
19986
+ buffer.rm += "^{" + m + "}";
19987
+ },
19988
+ space: function () {
19989
+ return {
19990
+ type_: "pu-space-2"
19991
+ };
19992
+ },
19993
+ output: function (buffer) {
19994
+ /** @type {ParserOutput | ParserOutput[]} */
19995
+ let ret = [];
19996
+ if (buffer.rm) {
19997
+ const mrm = mhchemParser.patterns.match_("{(...)}", buffer.rm || "");
19998
+ if (mrm && mrm.remainder === "") {
19999
+ ret = mhchemParser.go(mrm.match_, "pu");
20000
+ } else {
20001
+ ret = {
20002
+ type_: "rm",
20003
+ p1: buffer.rm
20004
+ };
20005
+ }
20006
+ }
20007
+ for (const p in buffer) {
20008
+ delete buffer[p];
20009
+ }
20010
+ return ret;
20011
+ }
20012
+ }
20013
+ },
20014
+ "pu-9,9": {
20015
+ transitions: mhchemParser.createTransitions({
20016
+ empty: {
20017
+ "0": {
20018
+ action_: "output-0"
20019
+ },
20020
+ o: {
20021
+ action_: "output-o"
20022
+ }
20023
+ },
20024
+ ",": {
20025
+ "0": {
20026
+ action_: ["output-0", "comma"],
20027
+ nextState: "o"
20028
+ }
20029
+ },
20030
+ ".": {
20031
+ "0": {
20032
+ action_: ["output-0", "copy"],
20033
+ nextState: "o"
20034
+ }
20035
+ },
20036
+ else: {
20037
+ "*": {
20038
+ action_: "text="
20039
+ }
20040
+ }
20041
+ }),
20042
+ actions: {
20043
+ comma: function () {
20044
+ return {
20045
+ type_: "commaDecimal"
20046
+ };
20047
+ },
20048
+ "output-0": function (buffer) {
20049
+ /** @type {ParserOutput[]} */
20050
+ const ret = [];
20051
+ buffer.text_ = buffer.text_ || "";
20052
+ if (buffer.text_.length > 4) {
20053
+ let a = buffer.text_.length % 3;
20054
+ if (a === 0) {
20055
+ a = 3;
20056
+ }
20057
+ for (let i = buffer.text_.length - 3; i > 0; i -= 3) {
20058
+ ret.push(buffer.text_.substr(i, 3));
20059
+ ret.push({
20060
+ type_: "1000 separator"
20061
+ });
20062
+ }
20063
+ ret.push(buffer.text_.substr(0, a));
20064
+ ret.reverse();
20065
+ } else {
20066
+ ret.push(buffer.text_);
20067
+ }
20068
+ for (const p in buffer) {
20069
+ delete buffer[p];
20070
+ }
20071
+ return ret;
20072
+ },
20073
+ "output-o": function (buffer) {
20074
+ /** @type {ParserOutput[]} */
20075
+ const ret = [];
20076
+ buffer.text_ = buffer.text_ || "";
20077
+ if (buffer.text_.length > 4) {
20078
+ const a = buffer.text_.length - 3;
20079
+ for (var i = 0; i < a; i += 3) {
20080
+ ret.push(buffer.text_.substr(i, 3));
20081
+ ret.push({
20082
+ type_: "1000 separator"
20083
+ });
20084
+ }
20085
+ ret.push(buffer.text_.substr(i));
20086
+ } else {
20087
+ ret.push(buffer.text_);
20088
+ }
20089
+ for (const p in buffer) {
20090
+ delete buffer[p];
20091
+ }
20092
+ return ret;
20093
+ }
20094
+ }
20095
+ }
20096
+ //#endregion
20097
+ };
20098
+
20099
+ //
20100
+ // texify: Take MhchemParser output and convert it to TeX
20101
+ //
20102
+ /** @type {Texify} */
20103
+ var texify = {
20104
+ go: function (input, isInner) {
20105
+ // (recursive, max 4 levels)
20106
+ if (!input) {
20107
+ return "";
20108
+ }
20109
+ let res = "";
20110
+ let cee = false;
20111
+ for (let i = 0; i < input.length; i++) {
20112
+ const inputi = input[i];
20113
+ if (typeof inputi === "string") {
20114
+ res += inputi;
20115
+ } else {
20116
+ res += texify._go2(inputi);
20117
+ if (inputi.type_ === "1st-level escape") {
20118
+ cee = true;
20119
+ }
20120
+ }
20121
+ }
20122
+ if (!isInner && !cee && res) {
20123
+ res = "{" + res + "}";
20124
+ }
20125
+ return res;
20126
+ },
20127
+ _goInner: function (input) {
20128
+ if (!input) {
20129
+ return input;
20130
+ }
20131
+ return texify.go(input, true);
20132
+ },
20133
+ _go2: function (buf) {
20134
+ /** @type {undefined | string} */
20135
+ let res;
20136
+ switch (buf.type_) {
20137
+ case "chemfive":
20138
+ res = "";
20139
+ var b5 = {
20140
+ a: texify._goInner(buf.a),
20141
+ b: texify._goInner(buf.b),
20142
+ p: texify._goInner(buf.p),
20143
+ o: texify._goInner(buf.o),
20144
+ q: texify._goInner(buf.q),
20145
+ d: texify._goInner(buf.d)
20146
+ };
20147
+ //
20148
+ // a
20149
+ //
20150
+ if (b5.a) {
20151
+ if (b5.a.match(/^[+\-]/)) {
20152
+ b5.a = "{" + b5.a + "}";
20153
+ }
20154
+ res += b5.a + "\\,";
20155
+ }
20156
+ //
20157
+ // b and p
20158
+ //
20159
+ if (b5.b || b5.p) {
20160
+ res += "{\\vphantom{X}}";
20161
+ res += "^{\\hphantom{" + (b5.b || "") + "}}_{\\hphantom{" + (b5.p || "") + "}}";
20162
+ res += "{\\vphantom{X}}";
20163
+ res += "^{\\smash[t]{\\vphantom{2}}\\mathllap{" + (b5.b || "") + "}}";
20164
+ res += "_{\\vphantom{2}\\mathllap{\\smash[t]{" + (b5.p || "") + "}}}";
20165
+ }
20166
+ //
20167
+ // o
20168
+ //
20169
+ if (b5.o) {
20170
+ if (b5.o.match(/^[+\-]/)) {
20171
+ b5.o = "{" + b5.o + "}";
20172
+ }
20173
+ res += b5.o;
20174
+ }
20175
+ //
20176
+ // q and d
20177
+ //
20178
+ if (buf.dType === "kv") {
20179
+ if (b5.d || b5.q) {
20180
+ res += "{\\vphantom{X}}";
20181
+ }
20182
+ if (b5.d) {
20183
+ res += "^{" + b5.d + "}";
20184
+ }
20185
+ if (b5.q) {
20186
+ res += "_{\\smash[t]{" + b5.q + "}}";
20187
+ }
20188
+ } else if (buf.dType === "oxidation") {
20189
+ if (b5.d) {
20190
+ res += "{\\vphantom{X}}";
20191
+ res += "^{" + b5.d + "}";
20192
+ }
20193
+ if (b5.q) {
20194
+ res += "{\\vphantom{X}}";
20195
+ res += "_{\\smash[t]{" + b5.q + "}}";
20196
+ }
20197
+ } else {
20198
+ if (b5.q) {
20199
+ res += "{\\vphantom{X}}";
20200
+ res += "_{\\smash[t]{" + b5.q + "}}";
20201
+ }
20202
+ if (b5.d) {
20203
+ res += "{\\vphantom{X}}";
20204
+ res += "^{" + b5.d + "}";
20205
+ }
20206
+ }
20207
+ break;
20208
+ case "rm":
20209
+ res = "\\mathrm{" + buf.p1 + "}";
20210
+ break;
20211
+ case "text":
20212
+ if (buf.p1.match(/[\^_]/)) {
20213
+ buf.p1 = buf.p1.replace(" ", "~").replace("-", "\\text{-}");
20214
+ res = "\\mathrm{" + buf.p1 + "}";
20215
+ } else {
20216
+ res = "\\text{" + buf.p1 + "}";
20217
+ }
20218
+ break;
20219
+ case "roman numeral":
20220
+ res = "\\mathrm{" + buf.p1 + "}";
20221
+ break;
20222
+ case "state of aggregation":
20223
+ res = "\\mskip2mu " + texify._goInner(buf.p1);
20224
+ break;
20225
+ case "state of aggregation subscript":
20226
+ res = "\\mskip1mu " + texify._goInner(buf.p1);
20227
+ break;
20228
+ case "bond":
20229
+ res = texify._getBond(buf.kind_);
20230
+ if (!res) {
20231
+ throw ["MhchemErrorBond", "mhchem Error. Unknown bond type (" + buf.kind_ + ")"];
20232
+ }
20233
+ break;
20234
+ case "frac":
20235
+ var c = "\\frac{" + buf.p1 + "}{" + buf.p2 + "}";
20236
+ res = "\\mathchoice{\\textstyle" + c + "}{" + c + "}{" + c + "}{" + c + "}";
20237
+ break;
20238
+ case "pu-frac":
20239
+ var d = "\\frac{" + texify._goInner(buf.p1) + "}{" + texify._goInner(buf.p2) + "}";
20240
+ res = "\\mathchoice{\\textstyle" + d + "}{" + d + "}{" + d + "}{" + d + "}";
20241
+ break;
20242
+ case "tex-math":
20243
+ res = buf.p1 + " ";
20244
+ break;
20245
+ case "frac-ce":
20246
+ res = "\\frac{" + texify._goInner(buf.p1) + "}{" + texify._goInner(buf.p2) + "}";
20247
+ break;
20248
+ case "overset":
20249
+ res = "\\overset{" + texify._goInner(buf.p1) + "}{" + texify._goInner(buf.p2) + "}";
20250
+ break;
20251
+ case "underset":
20252
+ res = "\\underset{" + texify._goInner(buf.p1) + "}{" + texify._goInner(buf.p2) + "}";
20253
+ break;
20254
+ case "underbrace":
20255
+ res = "\\underbrace{" + texify._goInner(buf.p1) + "}_{" + texify._goInner(buf.p2) + "}";
20256
+ break;
20257
+ case "color":
20258
+ res = "{\\color{" + buf.color1 + "}{" + texify._goInner(buf.color2) + "}}";
20259
+ break;
20260
+ case "color0":
20261
+ res = "\\color{" + buf.color + "}";
20262
+ break;
20263
+ case "arrow":
20264
+ var b6 = {
20265
+ rd: texify._goInner(buf.rd),
20266
+ rq: texify._goInner(buf.rq)
20267
+ };
20268
+ var arrow = "\\x" + texify._getArrow(buf.r);
20269
+ if (b6.rq) {
20270
+ arrow += "[{" + b6.rq + "}]";
20271
+ }
20272
+ if (b6.rd) {
20273
+ arrow += "{" + b6.rd + "}";
20274
+ } else {
20275
+ arrow += "{}";
20276
+ }
20277
+ res = arrow;
20278
+ break;
20279
+ case "operator":
20280
+ res = texify._getOperator(buf.kind_);
20281
+ break;
20282
+ case "1st-level escape":
20283
+ res = buf.p1 + " "; // &, \\\\, \\hlin
20284
+ break;
20285
+ case "space":
20286
+ res = " ";
20287
+ break;
20288
+ case "entitySkip":
20289
+ res = "~";
20290
+ break;
20291
+ case "pu-space-1":
20292
+ res = "~";
20293
+ break;
20294
+ case "pu-space-2":
20295
+ res = "\\mkern3mu ";
20296
+ break;
20297
+ case "1000 separator":
20298
+ res = "\\mkern2mu ";
20299
+ break;
20300
+ case "commaDecimal":
20301
+ res = "{,}";
20302
+ break;
20303
+ case "comma enumeration L":
20304
+ res = "{" + buf.p1 + "}\\mkern6mu ";
20305
+ break;
20306
+ case "comma enumeration M":
20307
+ res = "{" + buf.p1 + "}\\mkern3mu ";
20308
+ break;
20309
+ case "comma enumeration S":
20310
+ res = "{" + buf.p1 + "}\\mkern1mu ";
20311
+ break;
20312
+ case "hyphen":
20313
+ res = "\\text{-}";
20314
+ break;
20315
+ case "addition compound":
20316
+ res = "\\,{\\cdot}\\,";
20317
+ break;
20318
+ case "electron dot":
20319
+ res = "\\mkern1mu \\bullet\\mkern1mu ";
20320
+ break;
20321
+ case "KV x":
20322
+ res = "{\\times}";
20323
+ break;
20324
+ case "prime":
20325
+ res = "\\prime ";
20326
+ break;
20327
+ case "cdot":
20328
+ res = "\\cdot ";
20329
+ break;
20330
+ case "tight cdot":
20331
+ res = "\\mkern1mu{\\cdot}\\mkern1mu ";
20332
+ break;
20333
+ case "times":
20334
+ res = "\\times ";
20335
+ break;
20336
+ case "circa":
20337
+ res = "{\\sim}";
20338
+ break;
20339
+ case "^":
20340
+ res = "uparrow";
20341
+ break;
20342
+ case "v":
20343
+ res = "downarrow";
20344
+ break;
20345
+ case "ellipsis":
20346
+ res = "\\ldots ";
20347
+ break;
20348
+ case "/":
20349
+ res = "/";
20350
+ break;
20351
+ case " / ":
20352
+ res = "\\,/\\,";
20353
+ break;
20354
+ default:
20355
+ throw ["MhchemBugT", "mhchem bug T. Please report."];
20356
+ // Missing texify rule or unknown MhchemParser output
20357
+ }
20358
+ return res;
20359
+ },
20360
+ _getArrow: function (a) {
20361
+ switch (a) {
20362
+ case "->":
20363
+ return "rightarrow";
20364
+ case "\u2192":
20365
+ return "rightarrow";
20366
+ case "\u27F6":
20367
+ return "rightarrow";
20368
+ case "<-":
20369
+ return "leftarrow";
20370
+ case "<->":
20371
+ return "leftrightarrow";
20372
+ case "<-->":
20373
+ return "rightleftarrows";
20374
+ case "<=>":
20375
+ return "rightleftharpoons";
20376
+ case "\u21CC":
20377
+ return "rightleftharpoons";
20378
+ case "<=>>":
20379
+ return "rightequilibrium";
20380
+ case "<<=>":
20381
+ return "leftequilibrium";
20382
+ default:
20383
+ throw ["MhchemBugT", "mhchem bug T. Please report."];
20384
+ }
20385
+ },
20386
+ _getBond: function (a) {
20387
+ switch (a) {
20388
+ case "-":
20389
+ return "{-}";
20390
+ case "1":
20391
+ return "{-}";
20392
+ case "=":
20393
+ return "{=}";
20394
+ case "2":
20395
+ return "{=}";
20396
+ case "#":
20397
+ return "{\\equiv}";
20398
+ case "3":
20399
+ return "{\\equiv}";
20400
+ case "~":
20401
+ return "{\\tripledash}";
20402
+ case "~-":
20403
+ return "{\\mathrlap{\\raisebox{-.1em}{$-$}}\\raisebox{.1em}{$\\tripledash$}}";
20404
+ case "~=":
20405
+ return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$\\tripledash$}}-}";
20406
+ case "~--":
20407
+ return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$\\tripledash$}}-}";
20408
+ case "-~-":
20409
+ return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$-$}}\\tripledash}";
20410
+ case "...":
20411
+ return "{{\\cdot}{\\cdot}{\\cdot}}";
20412
+ case "....":
20413
+ return "{{\\cdot}{\\cdot}{\\cdot}{\\cdot}}";
20414
+ case "->":
20415
+ return "{\\rightarrow}";
20416
+ case "<-":
20417
+ return "{\\leftarrow}";
20418
+ case "<":
20419
+ return "{<}";
20420
+ case ">":
20421
+ return "{>}";
20422
+ default:
20423
+ throw ["MhchemBugT", "mhchem bug T. Please report."];
20424
+ }
20425
+ },
20426
+ _getOperator: function (a) {
20427
+ switch (a) {
20428
+ case "+":
20429
+ return " {}+{} ";
20430
+ case "-":
20431
+ return " {}-{} ";
20432
+ case "=":
20433
+ return " {}={} ";
20434
+ case "<":
20435
+ return " {}<{} ";
20436
+ case ">":
20437
+ return " {}>{} ";
20438
+ case "<<":
20439
+ return " {}\\ll{} ";
20440
+ case ">>":
20441
+ return " {}\\gg{} ";
20442
+ case "\\pm":
20443
+ return " {}\\pm{} ";
20444
+ case "\\approx":
20445
+ return " {}\\approx{} ";
20446
+ case "$\\approx$":
20447
+ return " {}\\approx{} ";
20448
+ case "v":
20449
+ return " \\downarrow{} ";
20450
+ case "(v)":
20451
+ return " \\downarrow{} ";
20452
+ case "^":
20453
+ return " \\uparrow{} ";
20454
+ case "(^)":
20455
+ return " \\uparrow{} ";
20456
+ default:
20457
+ throw ["MhchemBugT", "mhchem bug T. Please report."];
20458
+ }
20459
+ }
20460
+ };
20461
+
20462
+ /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
20463
+
20464
+ // Add \ce, \pu, and \tripledash to the KaTeX macros.
20465
+
20466
+ katex.__defineMacro("\\ce", function (context) {
20467
+ return chemParse(context.consumeArgs(1)[0], "ce");
20468
+ });
20469
+ katex.__defineMacro("\\pu", function (context) {
20470
+ return chemParse(context.consumeArgs(1)[0], "pu");
20471
+ });
20472
+
20473
+ // Needed for \bond for the ~ forms
20474
+ // Raise by 2.56mu, not 2mu. We're raising a hyphen-minus, U+002D, not
20475
+ // a mathematical minus, U+2212. So we need that extra 0.56.
20476
+ katex.__defineMacro("\\tripledash", "{\\vphantom{-}\\raisebox{2.56mu}{$\\mkern2mu" + "\\tiny\\text{-}\\mkern1mu\\text{-}\\mkern1mu\\text{-}\\mkern2mu$}}");
20477
+
17659
20478
  const DragTarget = createReactClass({
17660
20479
  displayName: "DragTarget",
17661
20480
  propTypes: {