@khanacademy/perseus-editor 2.3.7 → 2.3.8

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