res-oqc 1.0.0
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/assets/katex/contrib/mhchem.js +3216 -0
- package/assets/katex/katex.js +17812 -0
- package/package.json +7 -0
- package/views/Sort/components/config.js +21869 -0
|
@@ -0,0 +1,3216 @@
|
|
|
1
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
2
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
3
|
+
{module.exports = factory(require('katex'));}
|
|
4
|
+
else if(typeof define === 'function' && define.amd)
|
|
5
|
+
{define(['katex'], factory);}
|
|
6
|
+
else {
|
|
7
|
+
const a = typeof exports === 'object' ? factory(require('katex')) : factory(root['katex']);
|
|
8
|
+
for(const i in a) {(typeof exports === 'object' ? exports : root)[i] = a[i];}
|
|
9
|
+
}
|
|
10
|
+
})((typeof self !== 'undefined' ? self : this), function(__WEBPACK_EXTERNAL_MODULE__974__) {
|
|
11
|
+
return /******/ (function() { // webpackBootstrap
|
|
12
|
+
/******/
|
|
13
|
+
/******/ const __webpack_modules__ = ({
|
|
14
|
+
|
|
15
|
+
/***/ 974:
|
|
16
|
+
/***/ function(module) {
|
|
17
|
+
|
|
18
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__974__;
|
|
19
|
+
|
|
20
|
+
/***/ }
|
|
21
|
+
|
|
22
|
+
/******/ });
|
|
23
|
+
/************************************************************************/
|
|
24
|
+
/******/ // The module cache
|
|
25
|
+
/******/ const __webpack_module_cache__ = {};
|
|
26
|
+
/******/
|
|
27
|
+
/******/ // The require function
|
|
28
|
+
/******/ function __webpack_require__(moduleId) {
|
|
29
|
+
/******/ // Check if module is in cache
|
|
30
|
+
/******/ const cachedModule = __webpack_module_cache__[moduleId];
|
|
31
|
+
/******/ if (cachedModule !== undefined) {
|
|
32
|
+
/******/ return cachedModule.exports;
|
|
33
|
+
/******/ }
|
|
34
|
+
/******/ // Create a new module (and put it into the cache)
|
|
35
|
+
/******/ const module = __webpack_module_cache__[moduleId] = {
|
|
36
|
+
/******/ // no module.id needed
|
|
37
|
+
/******/ // no module.loaded needed
|
|
38
|
+
/******/ exports: {}
|
|
39
|
+
/******/ };
|
|
40
|
+
/******/
|
|
41
|
+
/******/ // Execute the module function
|
|
42
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
43
|
+
/******/
|
|
44
|
+
/******/ // Return the exports of the module
|
|
45
|
+
/******/ return module.exports;
|
|
46
|
+
/******/ }
|
|
47
|
+
/******/
|
|
48
|
+
/************************************************************************/
|
|
49
|
+
/******/ /* webpack/runtime/compat get default export */
|
|
50
|
+
/******/ !function() {
|
|
51
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
52
|
+
/******/ __webpack_require__.n = function(module) {
|
|
53
|
+
/******/ const getter = module && module.__esModule ?
|
|
54
|
+
/******/ function() { return module['default']; } :
|
|
55
|
+
/******/ function() { return module; };
|
|
56
|
+
/******/ __webpack_require__.d(getter, { a: getter });
|
|
57
|
+
/******/ return getter;
|
|
58
|
+
/******/ };
|
|
59
|
+
/******/ }();
|
|
60
|
+
/******/
|
|
61
|
+
/******/ /* webpack/runtime/define property getters */
|
|
62
|
+
/******/ !function() {
|
|
63
|
+
/******/ // define getter functions for harmony exports
|
|
64
|
+
/******/ __webpack_require__.d = function(exports, definition) {
|
|
65
|
+
/******/ for(const key in definition) {
|
|
66
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
67
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
68
|
+
/******/ }
|
|
69
|
+
/******/ }
|
|
70
|
+
/******/ };
|
|
71
|
+
/******/ }();
|
|
72
|
+
/******/
|
|
73
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
74
|
+
/******/ !function() {
|
|
75
|
+
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); };
|
|
76
|
+
/******/ }();
|
|
77
|
+
/******/
|
|
78
|
+
/************************************************************************/
|
|
79
|
+
let __webpack_exports__ = {};
|
|
80
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
81
|
+
!function() {
|
|
82
|
+
/* harmony import */ const katex__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(974);
|
|
83
|
+
/* harmony import */ const katex__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(katex__WEBPACK_IMPORTED_MODULE_0__);
|
|
84
|
+
/* eslint-disable */
|
|
85
|
+
|
|
86
|
+
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
|
|
87
|
+
|
|
88
|
+
/* vim: set ts=2 et sw=2 tw=80: */
|
|
89
|
+
|
|
90
|
+
/*************************************************************
|
|
91
|
+
*
|
|
92
|
+
* KaTeX mhchem.js
|
|
93
|
+
*
|
|
94
|
+
* This file implements a KaTeX version of mhchem version 3.3.0.
|
|
95
|
+
* It is adapted from MathJax/extensions/TeX/mhchem.js
|
|
96
|
+
* It differs from the MathJax version as follows:
|
|
97
|
+
* 1. The interface is changed so that it can be called from KaTeX, not MathJax.
|
|
98
|
+
* 2. \rlap and \llap are replaced with \mathrlap and \mathllap.
|
|
99
|
+
* 3. Four lines of code are edited in order to use \raisebox instead of \raise.
|
|
100
|
+
* 4. The reaction arrow code is simplified. All reaction arrows are rendered
|
|
101
|
+
* using KaTeX extensible arrows instead of building non-extensible arrows.
|
|
102
|
+
* 5. \tripledash vertical alignment is slightly adjusted.
|
|
103
|
+
*
|
|
104
|
+
* This code, as other KaTeX code, is released under the MIT license.
|
|
105
|
+
*
|
|
106
|
+
* /*************************************************************
|
|
107
|
+
*
|
|
108
|
+
* MathJax/extensions/TeX/mhchem.js
|
|
109
|
+
*
|
|
110
|
+
* Implements the \ce command for handling chemical formulas
|
|
111
|
+
* from the mhchem LaTeX package.
|
|
112
|
+
*
|
|
113
|
+
* ---------------------------------------------------------------------
|
|
114
|
+
*
|
|
115
|
+
* Copyright (c) 2011-2015 The MathJax Consortium
|
|
116
|
+
* Copyright (c) 2015-2018 Martin Hensel
|
|
117
|
+
*
|
|
118
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
119
|
+
* you may not use this file except in compliance with the License.
|
|
120
|
+
* You may obtain a copy of the License at
|
|
121
|
+
*
|
|
122
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
123
|
+
*
|
|
124
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
125
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
126
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
127
|
+
* See the License for the specific language governing permissions and
|
|
128
|
+
* limitations under the License.
|
|
129
|
+
*/
|
|
130
|
+
//
|
|
131
|
+
// Coding Style
|
|
132
|
+
// - use '' for identifiers that can by minified/uglified
|
|
133
|
+
// - use "" for strings that need to stay untouched
|
|
134
|
+
// version: "3.3.0" for MathJax and KaTeX
|
|
135
|
+
// Add \ce, \pu, and \tripledash to the KaTeX macros.
|
|
136
|
+
katex__WEBPACK_IMPORTED_MODULE_0___default().__defineMacro("\\ce", function (context) {
|
|
137
|
+
return chemParse(context.consumeArgs(1)[0], "ce");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
katex__WEBPACK_IMPORTED_MODULE_0___default().__defineMacro("\\pu", function (context) {
|
|
141
|
+
return chemParse(context.consumeArgs(1)[0], "pu");
|
|
142
|
+
}); // Needed for \bond for the ~ forms
|
|
143
|
+
// Raise by 2.56mu, not 2mu. We're raising a hyphen-minus, U+002D, not
|
|
144
|
+
// a mathematical minus, U+2212. So we need that extra 0.56.
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
katex__WEBPACK_IMPORTED_MODULE_0___default().__defineMacro("\\tripledash", "{\\vphantom{-}\\raisebox{2.56mu}{$\\mkern2mu" + "\\tiny\\text{-}\\mkern1mu\\text{-}\\mkern1mu\\text{-}\\mkern2mu$}}");
|
|
148
|
+
|
|
149
|
+
//
|
|
150
|
+
// This is the main function for handing the \ce and \pu commands.
|
|
151
|
+
// It takes the argument to \ce or \pu and returns the corresponding TeX string.
|
|
152
|
+
//
|
|
153
|
+
|
|
154
|
+
var chemParse = function chemParse(tokens, stateMachine) {
|
|
155
|
+
// Recreate the argument string from KaTeX's array of tokens.
|
|
156
|
+
var str = "";
|
|
157
|
+
var expectedLoc = tokens[tokens.length - 1].loc.start;
|
|
158
|
+
|
|
159
|
+
for (var i = tokens.length - 1; i >= 0; i--) {
|
|
160
|
+
if (tokens[i].loc.start > expectedLoc) {
|
|
161
|
+
// context.consumeArgs has eaten a space.
|
|
162
|
+
str += " ";
|
|
163
|
+
expectedLoc = tokens[i].loc.start;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
str += tokens[i].text;
|
|
167
|
+
expectedLoc += tokens[i].text.length;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
var tex = texify.go(mhchemParser.go(str, stateMachine));
|
|
171
|
+
return tex;
|
|
172
|
+
}; //
|
|
173
|
+
// Core parser for mhchem syntax (recursive)
|
|
174
|
+
//
|
|
175
|
+
|
|
176
|
+
/** @type {MhchemParser} */
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
var mhchemParser = {
|
|
180
|
+
//
|
|
181
|
+
// Parses mchem \ce syntax
|
|
182
|
+
//
|
|
183
|
+
// Call like
|
|
184
|
+
// go("H2O");
|
|
185
|
+
//
|
|
186
|
+
go: function go(input, stateMachine) {
|
|
187
|
+
if (!input) {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (stateMachine === undefined) {
|
|
192
|
+
stateMachine = 'ce';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
var state = '0'; //
|
|
196
|
+
// String buffers for parsing:
|
|
197
|
+
//
|
|
198
|
+
// buffer.a == amount
|
|
199
|
+
// buffer.o == element
|
|
200
|
+
// buffer.b == left-side superscript
|
|
201
|
+
// buffer.p == left-side subscript
|
|
202
|
+
// buffer.q == right-side subscript
|
|
203
|
+
// buffer.d == right-side superscript
|
|
204
|
+
//
|
|
205
|
+
// buffer.r == arrow
|
|
206
|
+
// buffer.rdt == arrow, script above, type
|
|
207
|
+
// buffer.rd == arrow, script above, content
|
|
208
|
+
// buffer.rqt == arrow, script below, type
|
|
209
|
+
// buffer.rq == arrow, script below, content
|
|
210
|
+
//
|
|
211
|
+
// buffer.text_
|
|
212
|
+
// buffer.rm
|
|
213
|
+
// etc.
|
|
214
|
+
//
|
|
215
|
+
// buffer.parenthesisLevel == int, starting at 0
|
|
216
|
+
// buffer.sb == bool, space before
|
|
217
|
+
// buffer.beginsWithBond == bool
|
|
218
|
+
//
|
|
219
|
+
// These letters are also used as state names.
|
|
220
|
+
//
|
|
221
|
+
// Other states:
|
|
222
|
+
// 0 == begin of main part (arrow/operator unlikely)
|
|
223
|
+
// 1 == next entity
|
|
224
|
+
// 2 == next entity (arrow/operator unlikely)
|
|
225
|
+
// 3 == next atom
|
|
226
|
+
// c == macro
|
|
227
|
+
//
|
|
228
|
+
|
|
229
|
+
/** @type {Buffer} */
|
|
230
|
+
|
|
231
|
+
var buffer = {};
|
|
232
|
+
buffer['parenthesisLevel'] = 0;
|
|
233
|
+
input = input.replace(/\n/g, " ");
|
|
234
|
+
input = input.replace(/[\u2212\u2013\u2014\u2010]/g, "-");
|
|
235
|
+
input = input.replace(/[\u2026]/g, "..."); //
|
|
236
|
+
// Looks through mhchemParser.transitions, to execute a matching action
|
|
237
|
+
// (recursive)
|
|
238
|
+
//
|
|
239
|
+
|
|
240
|
+
var lastInput;
|
|
241
|
+
var watchdog = 10;
|
|
242
|
+
/** @type {ParserOutput[]} */
|
|
243
|
+
|
|
244
|
+
var output = [];
|
|
245
|
+
|
|
246
|
+
while (true) {
|
|
247
|
+
if (lastInput !== input) {
|
|
248
|
+
watchdog = 10;
|
|
249
|
+
lastInput = input;
|
|
250
|
+
} else {
|
|
251
|
+
watchdog--;
|
|
252
|
+
} //
|
|
253
|
+
// Find actions in transition table
|
|
254
|
+
//
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
var machine = mhchemParser.stateMachines[stateMachine];
|
|
258
|
+
var t = machine.transitions[state] || machine.transitions['*'];
|
|
259
|
+
|
|
260
|
+
iterateTransitions: for (var i = 0; i < t.length; i++) {
|
|
261
|
+
var matches = mhchemParser.patterns.match_(t[i].pattern, input);
|
|
262
|
+
|
|
263
|
+
if (matches) {
|
|
264
|
+
//
|
|
265
|
+
// Execute actions
|
|
266
|
+
//
|
|
267
|
+
var task = t[i].task;
|
|
268
|
+
|
|
269
|
+
for (var iA = 0; iA < task.action_.length; iA++) {
|
|
270
|
+
var o; //
|
|
271
|
+
// Find and execute action
|
|
272
|
+
//
|
|
273
|
+
|
|
274
|
+
if (machine.actions[task.action_[iA].type_]) {
|
|
275
|
+
o = machine.actions[task.action_[iA].type_](buffer, matches.match_, task.action_[iA].option);
|
|
276
|
+
} else if (mhchemParser.actions[task.action_[iA].type_]) {
|
|
277
|
+
o = mhchemParser.actions[task.action_[iA].type_](buffer, matches.match_, task.action_[iA].option);
|
|
278
|
+
} else {
|
|
279
|
+
throw ["MhchemBugA", "mhchem bug A. Please report. (" + task.action_[iA].type_ + ")"]; // Trying to use non-existing action
|
|
280
|
+
} //
|
|
281
|
+
// Add output
|
|
282
|
+
//
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
mhchemParser.concatArray(output, o);
|
|
286
|
+
} //
|
|
287
|
+
// Set next state,
|
|
288
|
+
// Shorten input,
|
|
289
|
+
// Continue with next character
|
|
290
|
+
// (= apply only one transition per position)
|
|
291
|
+
//
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
state = task.nextState || state;
|
|
295
|
+
|
|
296
|
+
if (input.length > 0) {
|
|
297
|
+
if (!task.revisit) {
|
|
298
|
+
input = matches.remainder;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (!task.toContinue) {
|
|
302
|
+
break iterateTransitions;
|
|
303
|
+
}
|
|
304
|
+
} else {
|
|
305
|
+
return output;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
} //
|
|
309
|
+
// Prevent infinite loop
|
|
310
|
+
//
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
if (watchdog <= 0) {
|
|
314
|
+
throw ["MhchemBugU", "mhchem bug U. Please report."]; // Unexpected character
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
concatArray: function concatArray(a, b) {
|
|
319
|
+
if (b) {
|
|
320
|
+
if (Array.isArray(b)) {
|
|
321
|
+
for (var iB = 0; iB < b.length; iB++) {
|
|
322
|
+
a.push(b[iB]);
|
|
323
|
+
}
|
|
324
|
+
} else {
|
|
325
|
+
a.push(b);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
patterns: {
|
|
330
|
+
//
|
|
331
|
+
// Matching patterns
|
|
332
|
+
// either regexps or function that return null or {match_:"a", remainder:"bc"}
|
|
333
|
+
//
|
|
334
|
+
patterns: {
|
|
335
|
+
// property names must not look like integers ("2") for correct property traversal order, later on
|
|
336
|
+
'empty': /^$/,
|
|
337
|
+
'else': /^./,
|
|
338
|
+
'else2': /^./,
|
|
339
|
+
'space': /^\s/,
|
|
340
|
+
'space A': /^\s(?=[A-Z\\$])/,
|
|
341
|
+
'space$': /^\s$/,
|
|
342
|
+
'a-z': /^[a-z]/,
|
|
343
|
+
'x': /^x/,
|
|
344
|
+
'x$': /^x$/,
|
|
345
|
+
'i$': /^i$/,
|
|
346
|
+
'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]))))+/,
|
|
347
|
+
'\\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]))/,
|
|
348
|
+
'one lowercase latin letter $': /^(?:([a-z])(?:$|[^a-zA-Z]))$/,
|
|
349
|
+
'$one lowercase latin letter$ $': /^\$(?:([a-z])(?:$|[^a-zA-Z]))\$$/,
|
|
350
|
+
'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]))$/,
|
|
351
|
+
'digits': /^[0-9]+/,
|
|
352
|
+
'-9.,9': /^[+\-]?(?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))/,
|
|
353
|
+
'-9.,9 no missing 0': /^[+\-]?[0-9]+(?:[.,][0-9]+)?/,
|
|
354
|
+
'(-)(9.,9)(e)(99)': function e99(input) {
|
|
355
|
+
var m = input.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))?(\((?:[0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+))\))?(?:([eE]|\s*(\*|x|\\times|\u00D7)\s*10\^)([+\-]?[0-9]+|\{[+\-]?[0-9]+\}))?/);
|
|
356
|
+
|
|
357
|
+
if (m && m[0]) {
|
|
358
|
+
return {
|
|
359
|
+
match_: m.splice(1),
|
|
360
|
+
remainder: input.substr(m[0].length)
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return null;
|
|
365
|
+
},
|
|
366
|
+
'(-)(9)^(-9)': function _(input) {
|
|
367
|
+
var m = input.match(/^(\+\-|\+\/\-|\+|\-|\\pm\s?)?([0-9]+(?:[,.][0-9]+)?|[0-9]*(?:\.[0-9]+)?)\^([+\-]?[0-9]+|\{[+\-]?[0-9]+\})/);
|
|
368
|
+
|
|
369
|
+
if (m && m[0]) {
|
|
370
|
+
return {
|
|
371
|
+
match_: m.splice(1),
|
|
372
|
+
remainder: input.substr(m[0].length)
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return null;
|
|
377
|
+
},
|
|
378
|
+
'state of aggregation $': function stateOfAggregation$(input) {
|
|
379
|
+
// ... or crystal system
|
|
380
|
+
var a = mhchemParser.patterns.findObserveGroups(input, "", /^\([a-z]{1,3}(?=[\),])/, ")", ""); // (aq), (aq,$\infty$), (aq, sat)
|
|
381
|
+
|
|
382
|
+
if (a && a.remainder.match(/^($|[\s,;\)\]\}])/)) {
|
|
383
|
+
return a;
|
|
384
|
+
} // AND end of 'phrase'
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
var m = input.match(/^(?:\((?:\\ca\s?)?\$[amothc]\$\))/); // OR crystal system ($o$) (\ca$c$)
|
|
388
|
+
|
|
389
|
+
if (m) {
|
|
390
|
+
return {
|
|
391
|
+
match_: m[0],
|
|
392
|
+
remainder: input.substr(m[0].length)
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return null;
|
|
397
|
+
},
|
|
398
|
+
'_{(state of aggregation)}$': /^_\{(\([a-z]{1,3}\))\}/,
|
|
399
|
+
'{[(': /^(?:\\\{|\[|\()/,
|
|
400
|
+
')]}': /^(?:\)|\]|\\\})/,
|
|
401
|
+
', ': /^[,;]\s*/,
|
|
402
|
+
',': /^[,;]/,
|
|
403
|
+
'.': /^[.]/,
|
|
404
|
+
'. ': /^([.\u22C5\u00B7\u2022])\s*/,
|
|
405
|
+
'...': /^\.\.\.(?=$|[^.])/,
|
|
406
|
+
'* ': /^([*])\s*/,
|
|
407
|
+
'^{(...)}': function _(input) {
|
|
408
|
+
return mhchemParser.patterns.findObserveGroups(input, "^{", "", "", "}");
|
|
409
|
+
},
|
|
410
|
+
'^($...$)': function $$(input) {
|
|
411
|
+
return mhchemParser.patterns.findObserveGroups(input, "^", "$", "$", "");
|
|
412
|
+
},
|
|
413
|
+
'^a': /^\^([0-9]+|[^\\_])/,
|
|
414
|
+
'^\\x{}{}': function x(input) {
|
|
415
|
+
return mhchemParser.patterns.findObserveGroups(input, "^", /^\\[a-zA-Z]+\{/, "}", "", "", "{", "}", "", true);
|
|
416
|
+
},
|
|
417
|
+
'^\\x{}': function x(input) {
|
|
418
|
+
return mhchemParser.patterns.findObserveGroups(input, "^", /^\\[a-zA-Z]+\{/, "}", "");
|
|
419
|
+
},
|
|
420
|
+
'^\\x': /^\^(\\[a-zA-Z]+)\s*/,
|
|
421
|
+
'^(-1)': /^\^(-?\d+)/,
|
|
422
|
+
'\'': /^'/,
|
|
423
|
+
'_{(...)}': function _(input) {
|
|
424
|
+
return mhchemParser.patterns.findObserveGroups(input, "_{", "", "", "}");
|
|
425
|
+
},
|
|
426
|
+
'_($...$)': function _$$(input) {
|
|
427
|
+
return mhchemParser.patterns.findObserveGroups(input, "_", "$", "$", "");
|
|
428
|
+
},
|
|
429
|
+
'_9': /^_([+\-]?[0-9]+|[^\\])/,
|
|
430
|
+
'_\\x{}{}': function _X(input) {
|
|
431
|
+
return mhchemParser.patterns.findObserveGroups(input, "_", /^\\[a-zA-Z]+\{/, "}", "", "", "{", "}", "", true);
|
|
432
|
+
},
|
|
433
|
+
'_\\x{}': function _X(input) {
|
|
434
|
+
return mhchemParser.patterns.findObserveGroups(input, "_", /^\\[a-zA-Z]+\{/, "}", "");
|
|
435
|
+
},
|
|
436
|
+
'_\\x': /^_(\\[a-zA-Z]+)\s*/,
|
|
437
|
+
'^_': /^(?:\^(?=_)|\_(?=\^)|[\^_]$)/,
|
|
438
|
+
'{}': /^\{\}/,
|
|
439
|
+
'{...}': function _(input) {
|
|
440
|
+
return mhchemParser.patterns.findObserveGroups(input, "", "{", "}", "");
|
|
441
|
+
},
|
|
442
|
+
'{(...)}': function _(input) {
|
|
443
|
+
return mhchemParser.patterns.findObserveGroups(input, "{", "", "", "}");
|
|
444
|
+
},
|
|
445
|
+
'$...$': function $$(input) {
|
|
446
|
+
return mhchemParser.patterns.findObserveGroups(input, "", "$", "$", "");
|
|
447
|
+
},
|
|
448
|
+
'${(...)}$': function $$(input) {
|
|
449
|
+
return mhchemParser.patterns.findObserveGroups(input, "${", "", "", "}$");
|
|
450
|
+
},
|
|
451
|
+
'$(...)$': function $$(input) {
|
|
452
|
+
return mhchemParser.patterns.findObserveGroups(input, "$", "", "", "$");
|
|
453
|
+
},
|
|
454
|
+
'=<>': /^[=<>]/,
|
|
455
|
+
'#': /^[#\u2261]/,
|
|
456
|
+
'+': /^\+/,
|
|
457
|
+
'-$': /^-(?=[\s_},;\]/]|$|\([a-z]+\))/,
|
|
458
|
+
// -space -, -; -] -/ -$ -state-of-aggregation
|
|
459
|
+
'-9': /^-(?=[0-9])/,
|
|
460
|
+
'- orbital overlap': /^-(?=(?:[spd]|sp)(?:$|[\s,;\)\]\}]))/,
|
|
461
|
+
'-': /^-/,
|
|
462
|
+
'pm-operator': /^(?:\\pm|\$\\pm\$|\+-|\+\/-)/,
|
|
463
|
+
'operator': /^(?:\+|(?:[\-=<>]|<<|>>|\\approx|\$\\approx\$)(?=\s|$|-?[0-9]))/,
|
|
464
|
+
'arrowUpDown': /^(?:v|\(v\)|\^|\(\^\))(?=$|[\s,;\)\]\}])/,
|
|
465
|
+
'\\bond{(...)}': function bond(input) {
|
|
466
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\bond{", "", "", "}");
|
|
467
|
+
},
|
|
468
|
+
'->': /^(?:<->|<-->|->|<-|<=>>|<<=>|<=>|[\u2192\u27F6\u21CC])/,
|
|
469
|
+
'CMT': /^[CMT](?=\[)/,
|
|
470
|
+
'[(...)]': function _(input) {
|
|
471
|
+
return mhchemParser.patterns.findObserveGroups(input, "[", "", "", "]");
|
|
472
|
+
},
|
|
473
|
+
'1st-level escape': /^(&|\\\\|\\hline)\s*/,
|
|
474
|
+
'\\,': /^(?:\\[,\ ;:])/,
|
|
475
|
+
// \\x - but output no space before
|
|
476
|
+
'\\x{}{}': function x(input) {
|
|
477
|
+
return mhchemParser.patterns.findObserveGroups(input, "", /^\\[a-zA-Z]+\{/, "}", "", "", "{", "}", "", true);
|
|
478
|
+
},
|
|
479
|
+
'\\x{}': function x(input) {
|
|
480
|
+
return mhchemParser.patterns.findObserveGroups(input, "", /^\\[a-zA-Z]+\{/, "}", "");
|
|
481
|
+
},
|
|
482
|
+
'\\ca': /^\\ca(?:\s+|(?![a-zA-Z]))/,
|
|
483
|
+
'\\x': /^(?:\\[a-zA-Z]+\s*|\\[_&{}%])/,
|
|
484
|
+
'orbital': /^(?:[0-9]{1,2}[spdfgh]|[0-9]{0,2}sp)(?=$|[^a-zA-Z])/,
|
|
485
|
+
// only those with numbers in front, because the others will be formatted correctly anyway
|
|
486
|
+
'others': /^[\/~|]/,
|
|
487
|
+
'\\frac{(...)}': function frac(input) {
|
|
488
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\frac{", "", "", "}", "{", "", "", "}");
|
|
489
|
+
},
|
|
490
|
+
'\\overset{(...)}': function overset(input) {
|
|
491
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\overset{", "", "", "}", "{", "", "", "}");
|
|
492
|
+
},
|
|
493
|
+
"\\underset{(...)}": function underset(input) {
|
|
494
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\underset{", "", "", "}", "{", "", "", "}");
|
|
495
|
+
},
|
|
496
|
+
"\\underbrace{(...)}": function underbrace(input) {
|
|
497
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\underbrace{", "", "", "}_", "{", "", "", "}");
|
|
498
|
+
},
|
|
499
|
+
'\\color{(...)}0': function color0(input) {
|
|
500
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\color{", "", "", "}");
|
|
501
|
+
},
|
|
502
|
+
'\\color{(...)}{(...)}1': function color1(input) {
|
|
503
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\color{", "", "", "}", "{", "", "", "}");
|
|
504
|
+
},
|
|
505
|
+
'\\color(...){(...)}2': function color2(input) {
|
|
506
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\color", "\\", "", /^(?=\{)/, "{", "", "", "}");
|
|
507
|
+
},
|
|
508
|
+
'\\ce{(...)}': function ce(input) {
|
|
509
|
+
return mhchemParser.patterns.findObserveGroups(input, "\\ce{", "", "", "}");
|
|
510
|
+
},
|
|
511
|
+
'oxidation$': /^(?:[+-][IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,
|
|
512
|
+
'd-oxidation$': /^(?:[+-]?\s?[IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,
|
|
513
|
+
// 0 could be oxidation or charge
|
|
514
|
+
'roman numeral': /^[IVX]+/,
|
|
515
|
+
'1/2$': /^[+\-]?(?:[0-9]+|\$[a-z]\$|[a-z])\/[0-9]+(?:\$[a-z]\$|[a-z])?$/,
|
|
516
|
+
'amount': function amount(input) {
|
|
517
|
+
var match; // e.g. 2, 0.5, 1/2, -2, n/2, +; $a$ could be added later in parsing
|
|
518
|
+
|
|
519
|
+
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))/);
|
|
520
|
+
|
|
521
|
+
if (match) {
|
|
522
|
+
return {
|
|
523
|
+
match_: match[0],
|
|
524
|
+
remainder: input.substr(match[0].length)
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
var a = mhchemParser.patterns.findObserveGroups(input, "", "$", "$", "");
|
|
529
|
+
|
|
530
|
+
if (a) {
|
|
531
|
+
// e.g. $2n-1$, $-$
|
|
532
|
+
match = a.match_.match(/^\$(?:\(?[+\-]?(?:[0-9]*[a-z]?[+\-])?[0-9]*[a-z](?:[+\-][0-9]*[a-z]?)?\)?|\+|-)\$$/);
|
|
533
|
+
|
|
534
|
+
if (match) {
|
|
535
|
+
return {
|
|
536
|
+
match_: match[0],
|
|
537
|
+
remainder: input.substr(match[0].length)
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return null;
|
|
543
|
+
},
|
|
544
|
+
'amount2': function amount2(input) {
|
|
545
|
+
return this['amount'](input);
|
|
546
|
+
},
|
|
547
|
+
'(KV letters),': /^(?:[A-Z][a-z]{0,2}|i)(?=,)/,
|
|
548
|
+
'formula$': function formula$(input) {
|
|
549
|
+
if (input.match(/^\([a-z]+\)$/)) {
|
|
550
|
+
return null;
|
|
551
|
+
} // state of aggregation = no formula
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
var match = input.match(/^(?:[a-z]|(?:[0-9\ \+\-\,\.\(\)]+[a-z])+[0-9\ \+\-\,\.\(\)]*|(?:[a-z][0-9\ \+\-\,\.\(\)]+)+[a-z]?)$/);
|
|
555
|
+
|
|
556
|
+
if (match) {
|
|
557
|
+
return {
|
|
558
|
+
match_: match[0],
|
|
559
|
+
remainder: input.substr(match[0].length)
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return null;
|
|
564
|
+
},
|
|
565
|
+
'uprightEntities': /^(?:pH|pOH|pC|pK|iPr|iBu)(?=$|[^a-zA-Z])/,
|
|
566
|
+
'/': /^\s*(\/)\s*/,
|
|
567
|
+
'//': /^\s*(\/\/)\s*/,
|
|
568
|
+
'*': /^\s*[*.]\s*/
|
|
569
|
+
},
|
|
570
|
+
findObserveGroups: function findObserveGroups(input, begExcl, begIncl, endIncl, endExcl, beg2Excl, beg2Incl, end2Incl, end2Excl, combine) {
|
|
571
|
+
/** @type {{(input: string, pattern: string | RegExp): string | string[] | null;}} */
|
|
572
|
+
var _match = function _match(input, pattern) {
|
|
573
|
+
if (typeof pattern === "string") {
|
|
574
|
+
if (input.indexOf(pattern) !== 0) {
|
|
575
|
+
return null;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
return pattern;
|
|
579
|
+
} else {
|
|
580
|
+
var match = input.match(pattern);
|
|
581
|
+
|
|
582
|
+
if (!match) {
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return match[0];
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
/** @type {{(input: string, i: number, endChars: string | RegExp): {endMatchBegin: number, endMatchEnd: number} | null;}} */
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
var _findObserveGroups = function _findObserveGroups(input, i, endChars) {
|
|
593
|
+
var braces = 0;
|
|
594
|
+
|
|
595
|
+
while (i < input.length) {
|
|
596
|
+
var a = input.charAt(i);
|
|
597
|
+
|
|
598
|
+
var match = _match(input.substr(i), endChars);
|
|
599
|
+
|
|
600
|
+
if (match !== null && braces === 0) {
|
|
601
|
+
return {
|
|
602
|
+
endMatchBegin: i,
|
|
603
|
+
endMatchEnd: i + match.length
|
|
604
|
+
};
|
|
605
|
+
} else if (a === "{") {
|
|
606
|
+
braces++;
|
|
607
|
+
} else if (a === "}") {
|
|
608
|
+
if (braces === 0) {
|
|
609
|
+
throw ["ExtraCloseMissingOpen", "Extra close brace or missing open brace"];
|
|
610
|
+
} else {
|
|
611
|
+
braces--;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
i++;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (braces > 0) {
|
|
619
|
+
return null;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
return null;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
var match = _match(input, begExcl);
|
|
626
|
+
|
|
627
|
+
if (match === null) {
|
|
628
|
+
return null;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
input = input.substr(match.length);
|
|
632
|
+
match = _match(input, begIncl);
|
|
633
|
+
|
|
634
|
+
if (match === null) {
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
var e = _findObserveGroups(input, match.length, endIncl || endExcl);
|
|
639
|
+
|
|
640
|
+
if (e === null) {
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
var match1 = input.substring(0, endIncl ? e.endMatchEnd : e.endMatchBegin);
|
|
645
|
+
|
|
646
|
+
if (!(beg2Excl || beg2Incl)) {
|
|
647
|
+
return {
|
|
648
|
+
match_: match1,
|
|
649
|
+
remainder: input.substr(e.endMatchEnd)
|
|
650
|
+
};
|
|
651
|
+
} else {
|
|
652
|
+
var group2 = this.findObserveGroups(input.substr(e.endMatchEnd), beg2Excl, beg2Incl, end2Incl, end2Excl);
|
|
653
|
+
|
|
654
|
+
if (group2 === null) {
|
|
655
|
+
return null;
|
|
656
|
+
}
|
|
657
|
+
/** @type {string[]} */
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
var matchRet = [match1, group2.match_];
|
|
661
|
+
return {
|
|
662
|
+
match_: combine ? matchRet.join("") : matchRet,
|
|
663
|
+
remainder: group2.remainder
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
//
|
|
668
|
+
// Matching function
|
|
669
|
+
// e.g. match("a", input) will look for the regexp called "a" and see if it matches
|
|
670
|
+
// returns null or {match_:"a", remainder:"bc"}
|
|
671
|
+
//
|
|
672
|
+
match_: function match_(m, input) {
|
|
673
|
+
var pattern = mhchemParser.patterns.patterns[m];
|
|
674
|
+
|
|
675
|
+
if (pattern === undefined) {
|
|
676
|
+
throw ["MhchemBugP", "mhchem bug P. Please report. (" + m + ")"]; // Trying to use non-existing pattern
|
|
677
|
+
} else if (typeof pattern === "function") {
|
|
678
|
+
return mhchemParser.patterns.patterns[m](input); // cannot use cached var pattern here, because some pattern functions need this===mhchemParser
|
|
679
|
+
} else {
|
|
680
|
+
// RegExp
|
|
681
|
+
var match = input.match(pattern);
|
|
682
|
+
|
|
683
|
+
if (match) {
|
|
684
|
+
var mm;
|
|
685
|
+
|
|
686
|
+
if (match[2]) {
|
|
687
|
+
mm = [match[1], match[2]];
|
|
688
|
+
} else if (match[1]) {
|
|
689
|
+
mm = match[1];
|
|
690
|
+
} else {
|
|
691
|
+
mm = match[0];
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
return {
|
|
695
|
+
match_: mm,
|
|
696
|
+
remainder: input.substr(match[0].length)
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
//
|
|
705
|
+
// Generic state machine actions
|
|
706
|
+
//
|
|
707
|
+
actions: {
|
|
708
|
+
'a=': function a(buffer, m) {
|
|
709
|
+
buffer.a = (buffer.a || "") + m;
|
|
710
|
+
},
|
|
711
|
+
'b=': function b(buffer, m) {
|
|
712
|
+
buffer.b = (buffer.b || "") + m;
|
|
713
|
+
},
|
|
714
|
+
'p=': function p(buffer, m) {
|
|
715
|
+
buffer.p = (buffer.p || "") + m;
|
|
716
|
+
},
|
|
717
|
+
'o=': function o(buffer, m) {
|
|
718
|
+
buffer.o = (buffer.o || "") + m;
|
|
719
|
+
},
|
|
720
|
+
'q=': function q(buffer, m) {
|
|
721
|
+
buffer.q = (buffer.q || "") + m;
|
|
722
|
+
},
|
|
723
|
+
'd=': function d(buffer, m) {
|
|
724
|
+
buffer.d = (buffer.d || "") + m;
|
|
725
|
+
},
|
|
726
|
+
'rm=': function rm(buffer, m) {
|
|
727
|
+
buffer.rm = (buffer.rm || "") + m;
|
|
728
|
+
},
|
|
729
|
+
'text=': function text(buffer, m) {
|
|
730
|
+
buffer.text_ = (buffer.text_ || "") + m;
|
|
731
|
+
},
|
|
732
|
+
'insert': function insert(buffer, m, a) {
|
|
733
|
+
return {
|
|
734
|
+
type_: a
|
|
735
|
+
};
|
|
736
|
+
},
|
|
737
|
+
'insert+p1': function insertP1(buffer, m, a) {
|
|
738
|
+
return {
|
|
739
|
+
type_: a,
|
|
740
|
+
p1: m
|
|
741
|
+
};
|
|
742
|
+
},
|
|
743
|
+
'insert+p1+p2': function insertP1P2(buffer, m, a) {
|
|
744
|
+
return {
|
|
745
|
+
type_: a,
|
|
746
|
+
p1: m[0],
|
|
747
|
+
p2: m[1]
|
|
748
|
+
};
|
|
749
|
+
},
|
|
750
|
+
'copy': function copy(buffer, m) {
|
|
751
|
+
return m;
|
|
752
|
+
},
|
|
753
|
+
'rm': function rm(buffer, m) {
|
|
754
|
+
return {
|
|
755
|
+
type_: 'rm',
|
|
756
|
+
p1: m || ""
|
|
757
|
+
};
|
|
758
|
+
},
|
|
759
|
+
'text': function text(buffer, m) {
|
|
760
|
+
return mhchemParser.go(m, 'text');
|
|
761
|
+
},
|
|
762
|
+
'{text}': function text(buffer, m) {
|
|
763
|
+
var ret = ["{"];
|
|
764
|
+
mhchemParser.concatArray(ret, mhchemParser.go(m, 'text'));
|
|
765
|
+
ret.push("}");
|
|
766
|
+
return ret;
|
|
767
|
+
},
|
|
768
|
+
'tex-math': function texMath(buffer, m) {
|
|
769
|
+
return mhchemParser.go(m, 'tex-math');
|
|
770
|
+
},
|
|
771
|
+
'tex-math tight': function texMathTight(buffer, m) {
|
|
772
|
+
return mhchemParser.go(m, 'tex-math tight');
|
|
773
|
+
},
|
|
774
|
+
'bond': function bond(buffer, m, k) {
|
|
775
|
+
return {
|
|
776
|
+
type_: 'bond',
|
|
777
|
+
kind_: k || m
|
|
778
|
+
};
|
|
779
|
+
},
|
|
780
|
+
'color0-output': function color0Output(buffer, m) {
|
|
781
|
+
return {
|
|
782
|
+
type_: 'color0',
|
|
783
|
+
color: m[0]
|
|
784
|
+
};
|
|
785
|
+
},
|
|
786
|
+
'ce': function ce(buffer, m) {
|
|
787
|
+
return mhchemParser.go(m);
|
|
788
|
+
},
|
|
789
|
+
'1/2': function _(buffer, m) {
|
|
790
|
+
/** @type {ParserOutput[]} */
|
|
791
|
+
var ret = [];
|
|
792
|
+
|
|
793
|
+
if (m.match(/^[+\-]/)) {
|
|
794
|
+
ret.push(m.substr(0, 1));
|
|
795
|
+
m = m.substr(1);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
var n = m.match(/^([0-9]+|\$[a-z]\$|[a-z])\/([0-9]+)(\$[a-z]\$|[a-z])?$/);
|
|
799
|
+
n[1] = n[1].replace(/\$/g, "");
|
|
800
|
+
ret.push({
|
|
801
|
+
type_: 'frac',
|
|
802
|
+
p1: n[1],
|
|
803
|
+
p2: n[2]
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
if (n[3]) {
|
|
807
|
+
n[3] = n[3].replace(/\$/g, "");
|
|
808
|
+
ret.push({
|
|
809
|
+
type_: 'tex-math',
|
|
810
|
+
p1: n[3]
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
return ret;
|
|
815
|
+
},
|
|
816
|
+
'9,9': function _(buffer, m) {
|
|
817
|
+
return mhchemParser.go(m, '9,9');
|
|
818
|
+
}
|
|
819
|
+
},
|
|
820
|
+
//
|
|
821
|
+
// createTransitions
|
|
822
|
+
// convert { 'letter': { 'state': { action_: 'output' } } } to { 'state' => [ { pattern: 'letter', task: { action_: [{type_: 'output'}] } } ] }
|
|
823
|
+
// with expansion of 'a|b' to 'a' and 'b' (at 2 places)
|
|
824
|
+
//
|
|
825
|
+
createTransitions: function createTransitions(o) {
|
|
826
|
+
var pattern, state;
|
|
827
|
+
/** @type {string[]} */
|
|
828
|
+
|
|
829
|
+
var stateArray;
|
|
830
|
+
var i; //
|
|
831
|
+
// 1. Collect all states
|
|
832
|
+
//
|
|
833
|
+
|
|
834
|
+
/** @type {Transitions} */
|
|
835
|
+
|
|
836
|
+
var transitions = {};
|
|
837
|
+
|
|
838
|
+
for (pattern in o) {
|
|
839
|
+
for (state in o[pattern]) {
|
|
840
|
+
stateArray = state.split("|");
|
|
841
|
+
o[pattern][state].stateArray = stateArray;
|
|
842
|
+
|
|
843
|
+
for (i = 0; i < stateArray.length; i++) {
|
|
844
|
+
transitions[stateArray[i]] = [];
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
} //
|
|
848
|
+
// 2. Fill states
|
|
849
|
+
//
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
for (pattern in o) {
|
|
853
|
+
for (state in o[pattern]) {
|
|
854
|
+
stateArray = o[pattern][state].stateArray || [];
|
|
855
|
+
|
|
856
|
+
for (i = 0; i < stateArray.length; i++) {
|
|
857
|
+
//
|
|
858
|
+
// 2a. Normalize actions into array: 'text=' ==> [{type_:'text='}]
|
|
859
|
+
// (Note to myself: Resolving the function here would be problematic. It would need .bind (for *this*) and currying (for *option*).)
|
|
860
|
+
//
|
|
861
|
+
|
|
862
|
+
/** @type {any} */
|
|
863
|
+
var p = o[pattern][state];
|
|
864
|
+
|
|
865
|
+
if (p.action_) {
|
|
866
|
+
p.action_ = [].concat(p.action_);
|
|
867
|
+
|
|
868
|
+
for (var k = 0; k < p.action_.length; k++) {
|
|
869
|
+
if (typeof p.action_[k] === "string") {
|
|
870
|
+
p.action_[k] = {
|
|
871
|
+
type_: p.action_[k]
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
} else {
|
|
876
|
+
p.action_ = [];
|
|
877
|
+
} //
|
|
878
|
+
// 2.b Multi-insert
|
|
879
|
+
//
|
|
880
|
+
|
|
881
|
+
|
|
882
|
+
var patternArray = pattern.split("|");
|
|
883
|
+
|
|
884
|
+
for (var j = 0; j < patternArray.length; j++) {
|
|
885
|
+
if (stateArray[i] === '*') {
|
|
886
|
+
// insert into all
|
|
887
|
+
for (var t in transitions) {
|
|
888
|
+
transitions[t].push({
|
|
889
|
+
pattern: patternArray[j],
|
|
890
|
+
task: p
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
} else {
|
|
894
|
+
transitions[stateArray[i]].push({
|
|
895
|
+
pattern: patternArray[j],
|
|
896
|
+
task: p
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
return transitions;
|
|
905
|
+
},
|
|
906
|
+
stateMachines: {}
|
|
907
|
+
}; //
|
|
908
|
+
// Definition of state machines
|
|
909
|
+
//
|
|
910
|
+
|
|
911
|
+
mhchemParser.stateMachines = {
|
|
912
|
+
//
|
|
913
|
+
// \ce state machines
|
|
914
|
+
//
|
|
915
|
+
//#region ce
|
|
916
|
+
'ce': {
|
|
917
|
+
// main parser
|
|
918
|
+
transitions: mhchemParser.createTransitions({
|
|
919
|
+
'empty': {
|
|
920
|
+
'*': {
|
|
921
|
+
action_: 'output'
|
|
922
|
+
}
|
|
923
|
+
},
|
|
924
|
+
'else': {
|
|
925
|
+
'0|1|2': {
|
|
926
|
+
action_: 'beginsWithBond=false',
|
|
927
|
+
revisit: true,
|
|
928
|
+
toContinue: true
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
'oxidation$': {
|
|
932
|
+
'0': {
|
|
933
|
+
action_: 'oxidation-output'
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
'CMT': {
|
|
937
|
+
'r': {
|
|
938
|
+
action_: 'rdt=',
|
|
939
|
+
nextState: 'rt'
|
|
940
|
+
},
|
|
941
|
+
'rd': {
|
|
942
|
+
action_: 'rqt=',
|
|
943
|
+
nextState: 'rdt'
|
|
944
|
+
}
|
|
945
|
+
},
|
|
946
|
+
'arrowUpDown': {
|
|
947
|
+
'0|1|2|as': {
|
|
948
|
+
action_: ['sb=false', 'output', 'operator'],
|
|
949
|
+
nextState: '1'
|
|
950
|
+
}
|
|
951
|
+
},
|
|
952
|
+
'uprightEntities': {
|
|
953
|
+
'0|1|2': {
|
|
954
|
+
action_: ['o=', 'output'],
|
|
955
|
+
nextState: '1'
|
|
956
|
+
}
|
|
957
|
+
},
|
|
958
|
+
'orbital': {
|
|
959
|
+
'0|1|2|3': {
|
|
960
|
+
action_: 'o=',
|
|
961
|
+
nextState: 'o'
|
|
962
|
+
}
|
|
963
|
+
},
|
|
964
|
+
'->': {
|
|
965
|
+
'0|1|2|3': {
|
|
966
|
+
action_: 'r=',
|
|
967
|
+
nextState: 'r'
|
|
968
|
+
},
|
|
969
|
+
'a|as': {
|
|
970
|
+
action_: ['output', 'r='],
|
|
971
|
+
nextState: 'r'
|
|
972
|
+
},
|
|
973
|
+
'*': {
|
|
974
|
+
action_: ['output', 'r='],
|
|
975
|
+
nextState: 'r'
|
|
976
|
+
}
|
|
977
|
+
},
|
|
978
|
+
'+': {
|
|
979
|
+
'o': {
|
|
980
|
+
action_: 'd= kv',
|
|
981
|
+
nextState: 'd'
|
|
982
|
+
},
|
|
983
|
+
'd|D': {
|
|
984
|
+
action_: 'd=',
|
|
985
|
+
nextState: 'd'
|
|
986
|
+
},
|
|
987
|
+
'q': {
|
|
988
|
+
action_: 'd=',
|
|
989
|
+
nextState: 'qd'
|
|
990
|
+
},
|
|
991
|
+
'qd|qD': {
|
|
992
|
+
action_: 'd=',
|
|
993
|
+
nextState: 'qd'
|
|
994
|
+
},
|
|
995
|
+
'dq': {
|
|
996
|
+
action_: ['output', 'd='],
|
|
997
|
+
nextState: 'd'
|
|
998
|
+
},
|
|
999
|
+
'3': {
|
|
1000
|
+
action_: ['sb=false', 'output', 'operator'],
|
|
1001
|
+
nextState: '0'
|
|
1002
|
+
}
|
|
1003
|
+
},
|
|
1004
|
+
'amount': {
|
|
1005
|
+
'0|2': {
|
|
1006
|
+
action_: 'a=',
|
|
1007
|
+
nextState: 'a'
|
|
1008
|
+
}
|
|
1009
|
+
},
|
|
1010
|
+
'pm-operator': {
|
|
1011
|
+
'0|1|2|a|as': {
|
|
1012
|
+
action_: ['sb=false', 'output', {
|
|
1013
|
+
type_: 'operator',
|
|
1014
|
+
option: '\\pm'
|
|
1015
|
+
}],
|
|
1016
|
+
nextState: '0'
|
|
1017
|
+
}
|
|
1018
|
+
},
|
|
1019
|
+
'operator': {
|
|
1020
|
+
'0|1|2|a|as': {
|
|
1021
|
+
action_: ['sb=false', 'output', 'operator'],
|
|
1022
|
+
nextState: '0'
|
|
1023
|
+
}
|
|
1024
|
+
},
|
|
1025
|
+
'-$': {
|
|
1026
|
+
'o|q': {
|
|
1027
|
+
action_: ['charge or bond', 'output'],
|
|
1028
|
+
nextState: 'qd'
|
|
1029
|
+
},
|
|
1030
|
+
'd': {
|
|
1031
|
+
action_: 'd=',
|
|
1032
|
+
nextState: 'd'
|
|
1033
|
+
},
|
|
1034
|
+
'D': {
|
|
1035
|
+
action_: ['output', {
|
|
1036
|
+
type_: 'bond',
|
|
1037
|
+
option: "-"
|
|
1038
|
+
}],
|
|
1039
|
+
nextState: '3'
|
|
1040
|
+
},
|
|
1041
|
+
'q': {
|
|
1042
|
+
action_: 'd=',
|
|
1043
|
+
nextState: 'qd'
|
|
1044
|
+
},
|
|
1045
|
+
'qd': {
|
|
1046
|
+
action_: 'd=',
|
|
1047
|
+
nextState: 'qd'
|
|
1048
|
+
},
|
|
1049
|
+
'qD|dq': {
|
|
1050
|
+
action_: ['output', {
|
|
1051
|
+
type_: 'bond',
|
|
1052
|
+
option: "-"
|
|
1053
|
+
}],
|
|
1054
|
+
nextState: '3'
|
|
1055
|
+
}
|
|
1056
|
+
},
|
|
1057
|
+
'-9': {
|
|
1058
|
+
'3|o': {
|
|
1059
|
+
action_: ['output', {
|
|
1060
|
+
type_: 'insert',
|
|
1061
|
+
option: 'hyphen'
|
|
1062
|
+
}],
|
|
1063
|
+
nextState: '3'
|
|
1064
|
+
}
|
|
1065
|
+
},
|
|
1066
|
+
'- orbital overlap': {
|
|
1067
|
+
'o': {
|
|
1068
|
+
action_: ['output', {
|
|
1069
|
+
type_: 'insert',
|
|
1070
|
+
option: 'hyphen'
|
|
1071
|
+
}],
|
|
1072
|
+
nextState: '2'
|
|
1073
|
+
},
|
|
1074
|
+
'd': {
|
|
1075
|
+
action_: ['output', {
|
|
1076
|
+
type_: 'insert',
|
|
1077
|
+
option: 'hyphen'
|
|
1078
|
+
}],
|
|
1079
|
+
nextState: '2'
|
|
1080
|
+
}
|
|
1081
|
+
},
|
|
1082
|
+
'-': {
|
|
1083
|
+
'0|1|2': {
|
|
1084
|
+
action_: [{
|
|
1085
|
+
type_: 'output',
|
|
1086
|
+
option: 1
|
|
1087
|
+
}, 'beginsWithBond=true', {
|
|
1088
|
+
type_: 'bond',
|
|
1089
|
+
option: "-"
|
|
1090
|
+
}],
|
|
1091
|
+
nextState: '3'
|
|
1092
|
+
},
|
|
1093
|
+
'3': {
|
|
1094
|
+
action_: {
|
|
1095
|
+
type_: 'bond',
|
|
1096
|
+
option: "-"
|
|
1097
|
+
}
|
|
1098
|
+
},
|
|
1099
|
+
'a': {
|
|
1100
|
+
action_: ['output', {
|
|
1101
|
+
type_: 'insert',
|
|
1102
|
+
option: 'hyphen'
|
|
1103
|
+
}],
|
|
1104
|
+
nextState: '2'
|
|
1105
|
+
},
|
|
1106
|
+
'as': {
|
|
1107
|
+
action_: [{
|
|
1108
|
+
type_: 'output',
|
|
1109
|
+
option: 2
|
|
1110
|
+
}, {
|
|
1111
|
+
type_: 'bond',
|
|
1112
|
+
option: "-"
|
|
1113
|
+
}],
|
|
1114
|
+
nextState: '3'
|
|
1115
|
+
},
|
|
1116
|
+
'b': {
|
|
1117
|
+
action_: 'b='
|
|
1118
|
+
},
|
|
1119
|
+
'o': {
|
|
1120
|
+
action_: {
|
|
1121
|
+
type_: '- after o/d',
|
|
1122
|
+
option: false
|
|
1123
|
+
},
|
|
1124
|
+
nextState: '2'
|
|
1125
|
+
},
|
|
1126
|
+
'q': {
|
|
1127
|
+
action_: {
|
|
1128
|
+
type_: '- after o/d',
|
|
1129
|
+
option: false
|
|
1130
|
+
},
|
|
1131
|
+
nextState: '2'
|
|
1132
|
+
},
|
|
1133
|
+
'd|qd|dq': {
|
|
1134
|
+
action_: {
|
|
1135
|
+
type_: '- after o/d',
|
|
1136
|
+
option: true
|
|
1137
|
+
},
|
|
1138
|
+
nextState: '2'
|
|
1139
|
+
},
|
|
1140
|
+
'D|qD|p': {
|
|
1141
|
+
action_: ['output', {
|
|
1142
|
+
type_: 'bond',
|
|
1143
|
+
option: "-"
|
|
1144
|
+
}],
|
|
1145
|
+
nextState: '3'
|
|
1146
|
+
}
|
|
1147
|
+
},
|
|
1148
|
+
'amount2': {
|
|
1149
|
+
'1|3': {
|
|
1150
|
+
action_: 'a=',
|
|
1151
|
+
nextState: 'a'
|
|
1152
|
+
}
|
|
1153
|
+
},
|
|
1154
|
+
'letters': {
|
|
1155
|
+
'0|1|2|3|a|as|b|p|bp|o': {
|
|
1156
|
+
action_: 'o=',
|
|
1157
|
+
nextState: 'o'
|
|
1158
|
+
},
|
|
1159
|
+
'q|dq': {
|
|
1160
|
+
action_: ['output', 'o='],
|
|
1161
|
+
nextState: 'o'
|
|
1162
|
+
},
|
|
1163
|
+
'd|D|qd|qD': {
|
|
1164
|
+
action_: 'o after d',
|
|
1165
|
+
nextState: 'o'
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
'digits': {
|
|
1169
|
+
'o': {
|
|
1170
|
+
action_: 'q=',
|
|
1171
|
+
nextState: 'q'
|
|
1172
|
+
},
|
|
1173
|
+
'd|D': {
|
|
1174
|
+
action_: 'q=',
|
|
1175
|
+
nextState: 'dq'
|
|
1176
|
+
},
|
|
1177
|
+
'q': {
|
|
1178
|
+
action_: ['output', 'o='],
|
|
1179
|
+
nextState: 'o'
|
|
1180
|
+
},
|
|
1181
|
+
'a': {
|
|
1182
|
+
action_: 'o=',
|
|
1183
|
+
nextState: 'o'
|
|
1184
|
+
}
|
|
1185
|
+
},
|
|
1186
|
+
'space A': {
|
|
1187
|
+
'b|p|bp': {}
|
|
1188
|
+
},
|
|
1189
|
+
'space': {
|
|
1190
|
+
'a': {
|
|
1191
|
+
nextState: 'as'
|
|
1192
|
+
},
|
|
1193
|
+
'0': {
|
|
1194
|
+
action_: 'sb=false'
|
|
1195
|
+
},
|
|
1196
|
+
'1|2': {
|
|
1197
|
+
action_: 'sb=true'
|
|
1198
|
+
},
|
|
1199
|
+
'r|rt|rd|rdt|rdq': {
|
|
1200
|
+
action_: 'output',
|
|
1201
|
+
nextState: '0'
|
|
1202
|
+
},
|
|
1203
|
+
'*': {
|
|
1204
|
+
action_: ['output', 'sb=true'],
|
|
1205
|
+
nextState: '1'
|
|
1206
|
+
}
|
|
1207
|
+
},
|
|
1208
|
+
'1st-level escape': {
|
|
1209
|
+
'1|2': {
|
|
1210
|
+
action_: ['output', {
|
|
1211
|
+
type_: 'insert+p1',
|
|
1212
|
+
option: '1st-level escape'
|
|
1213
|
+
}]
|
|
1214
|
+
},
|
|
1215
|
+
'*': {
|
|
1216
|
+
action_: ['output', {
|
|
1217
|
+
type_: 'insert+p1',
|
|
1218
|
+
option: '1st-level escape'
|
|
1219
|
+
}],
|
|
1220
|
+
nextState: '0'
|
|
1221
|
+
}
|
|
1222
|
+
},
|
|
1223
|
+
'[(...)]': {
|
|
1224
|
+
'r|rt': {
|
|
1225
|
+
action_: 'rd=',
|
|
1226
|
+
nextState: 'rd'
|
|
1227
|
+
},
|
|
1228
|
+
'rd|rdt': {
|
|
1229
|
+
action_: 'rq=',
|
|
1230
|
+
nextState: 'rdq'
|
|
1231
|
+
}
|
|
1232
|
+
},
|
|
1233
|
+
'...': {
|
|
1234
|
+
'o|d|D|dq|qd|qD': {
|
|
1235
|
+
action_: ['output', {
|
|
1236
|
+
type_: 'bond',
|
|
1237
|
+
option: "..."
|
|
1238
|
+
}],
|
|
1239
|
+
nextState: '3'
|
|
1240
|
+
},
|
|
1241
|
+
'*': {
|
|
1242
|
+
action_: [{
|
|
1243
|
+
type_: 'output',
|
|
1244
|
+
option: 1
|
|
1245
|
+
}, {
|
|
1246
|
+
type_: 'insert',
|
|
1247
|
+
option: 'ellipsis'
|
|
1248
|
+
}],
|
|
1249
|
+
nextState: '1'
|
|
1250
|
+
}
|
|
1251
|
+
},
|
|
1252
|
+
'. |* ': {
|
|
1253
|
+
'*': {
|
|
1254
|
+
action_: ['output', {
|
|
1255
|
+
type_: 'insert',
|
|
1256
|
+
option: 'addition compound'
|
|
1257
|
+
}],
|
|
1258
|
+
nextState: '1'
|
|
1259
|
+
}
|
|
1260
|
+
},
|
|
1261
|
+
'state of aggregation $': {
|
|
1262
|
+
'*': {
|
|
1263
|
+
action_: ['output', 'state of aggregation'],
|
|
1264
|
+
nextState: '1'
|
|
1265
|
+
}
|
|
1266
|
+
},
|
|
1267
|
+
'{[(': {
|
|
1268
|
+
'a|as|o': {
|
|
1269
|
+
action_: ['o=', 'output', 'parenthesisLevel++'],
|
|
1270
|
+
nextState: '2'
|
|
1271
|
+
},
|
|
1272
|
+
'0|1|2|3': {
|
|
1273
|
+
action_: ['o=', 'output', 'parenthesisLevel++'],
|
|
1274
|
+
nextState: '2'
|
|
1275
|
+
},
|
|
1276
|
+
'*': {
|
|
1277
|
+
action_: ['output', 'o=', 'output', 'parenthesisLevel++'],
|
|
1278
|
+
nextState: '2'
|
|
1279
|
+
}
|
|
1280
|
+
},
|
|
1281
|
+
')]}': {
|
|
1282
|
+
'0|1|2|3|b|p|bp|o': {
|
|
1283
|
+
action_: ['o=', 'parenthesisLevel--'],
|
|
1284
|
+
nextState: 'o'
|
|
1285
|
+
},
|
|
1286
|
+
'a|as|d|D|q|qd|qD|dq': {
|
|
1287
|
+
action_: ['output', 'o=', 'parenthesisLevel--'],
|
|
1288
|
+
nextState: 'o'
|
|
1289
|
+
}
|
|
1290
|
+
},
|
|
1291
|
+
', ': {
|
|
1292
|
+
'*': {
|
|
1293
|
+
action_: ['output', 'comma'],
|
|
1294
|
+
nextState: '0'
|
|
1295
|
+
}
|
|
1296
|
+
},
|
|
1297
|
+
'^_': {
|
|
1298
|
+
// ^ and _ without a sensible argument
|
|
1299
|
+
'*': {}
|
|
1300
|
+
},
|
|
1301
|
+
'^{(...)}|^($...$)': {
|
|
1302
|
+
'0|1|2|as': {
|
|
1303
|
+
action_: 'b=',
|
|
1304
|
+
nextState: 'b'
|
|
1305
|
+
},
|
|
1306
|
+
'p': {
|
|
1307
|
+
action_: 'b=',
|
|
1308
|
+
nextState: 'bp'
|
|
1309
|
+
},
|
|
1310
|
+
'3|o': {
|
|
1311
|
+
action_: 'd= kv',
|
|
1312
|
+
nextState: 'D'
|
|
1313
|
+
},
|
|
1314
|
+
'q': {
|
|
1315
|
+
action_: 'd=',
|
|
1316
|
+
nextState: 'qD'
|
|
1317
|
+
},
|
|
1318
|
+
'd|D|qd|qD|dq': {
|
|
1319
|
+
action_: ['output', 'd='],
|
|
1320
|
+
nextState: 'D'
|
|
1321
|
+
}
|
|
1322
|
+
},
|
|
1323
|
+
'^a|^\\x{}{}|^\\x{}|^\\x|\'': {
|
|
1324
|
+
'0|1|2|as': {
|
|
1325
|
+
action_: 'b=',
|
|
1326
|
+
nextState: 'b'
|
|
1327
|
+
},
|
|
1328
|
+
'p': {
|
|
1329
|
+
action_: 'b=',
|
|
1330
|
+
nextState: 'bp'
|
|
1331
|
+
},
|
|
1332
|
+
'3|o': {
|
|
1333
|
+
action_: 'd= kv',
|
|
1334
|
+
nextState: 'd'
|
|
1335
|
+
},
|
|
1336
|
+
'q': {
|
|
1337
|
+
action_: 'd=',
|
|
1338
|
+
nextState: 'qd'
|
|
1339
|
+
},
|
|
1340
|
+
'd|qd|D|qD': {
|
|
1341
|
+
action_: 'd='
|
|
1342
|
+
},
|
|
1343
|
+
'dq': {
|
|
1344
|
+
action_: ['output', 'd='],
|
|
1345
|
+
nextState: 'd'
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
'_{(state of aggregation)}$': {
|
|
1349
|
+
'd|D|q|qd|qD|dq': {
|
|
1350
|
+
action_: ['output', 'q='],
|
|
1351
|
+
nextState: 'q'
|
|
1352
|
+
}
|
|
1353
|
+
},
|
|
1354
|
+
'_{(...)}|_($...$)|_9|_\\x{}{}|_\\x{}|_\\x': {
|
|
1355
|
+
'0|1|2|as': {
|
|
1356
|
+
action_: 'p=',
|
|
1357
|
+
nextState: 'p'
|
|
1358
|
+
},
|
|
1359
|
+
'b': {
|
|
1360
|
+
action_: 'p=',
|
|
1361
|
+
nextState: 'bp'
|
|
1362
|
+
},
|
|
1363
|
+
'3|o': {
|
|
1364
|
+
action_: 'q=',
|
|
1365
|
+
nextState: 'q'
|
|
1366
|
+
},
|
|
1367
|
+
'd|D': {
|
|
1368
|
+
action_: 'q=',
|
|
1369
|
+
nextState: 'dq'
|
|
1370
|
+
},
|
|
1371
|
+
'q|qd|qD|dq': {
|
|
1372
|
+
action_: ['output', 'q='],
|
|
1373
|
+
nextState: 'q'
|
|
1374
|
+
}
|
|
1375
|
+
},
|
|
1376
|
+
'=<>': {
|
|
1377
|
+
'0|1|2|3|a|as|o|q|d|D|qd|qD|dq': {
|
|
1378
|
+
action_: [{
|
|
1379
|
+
type_: 'output',
|
|
1380
|
+
option: 2
|
|
1381
|
+
}, 'bond'],
|
|
1382
|
+
nextState: '3'
|
|
1383
|
+
}
|
|
1384
|
+
},
|
|
1385
|
+
'#': {
|
|
1386
|
+
'0|1|2|3|a|as|o': {
|
|
1387
|
+
action_: [{
|
|
1388
|
+
type_: 'output',
|
|
1389
|
+
option: 2
|
|
1390
|
+
}, {
|
|
1391
|
+
type_: 'bond',
|
|
1392
|
+
option: "#"
|
|
1393
|
+
}],
|
|
1394
|
+
nextState: '3'
|
|
1395
|
+
}
|
|
1396
|
+
},
|
|
1397
|
+
'{}': {
|
|
1398
|
+
'*': {
|
|
1399
|
+
action_: {
|
|
1400
|
+
type_: 'output',
|
|
1401
|
+
option: 1
|
|
1402
|
+
},
|
|
1403
|
+
nextState: '1'
|
|
1404
|
+
}
|
|
1405
|
+
},
|
|
1406
|
+
'{...}': {
|
|
1407
|
+
'0|1|2|3|a|as|b|p|bp': {
|
|
1408
|
+
action_: 'o=',
|
|
1409
|
+
nextState: 'o'
|
|
1410
|
+
},
|
|
1411
|
+
'o|d|D|q|qd|qD|dq': {
|
|
1412
|
+
action_: ['output', 'o='],
|
|
1413
|
+
nextState: 'o'
|
|
1414
|
+
}
|
|
1415
|
+
},
|
|
1416
|
+
'$...$': {
|
|
1417
|
+
'a': {
|
|
1418
|
+
action_: 'a='
|
|
1419
|
+
},
|
|
1420
|
+
// 2$n$
|
|
1421
|
+
'0|1|2|3|as|b|p|bp|o': {
|
|
1422
|
+
action_: 'o=',
|
|
1423
|
+
nextState: 'o'
|
|
1424
|
+
},
|
|
1425
|
+
// not 'amount'
|
|
1426
|
+
'as|o': {
|
|
1427
|
+
action_: 'o='
|
|
1428
|
+
},
|
|
1429
|
+
'q|d|D|qd|qD|dq': {
|
|
1430
|
+
action_: ['output', 'o='],
|
|
1431
|
+
nextState: 'o'
|
|
1432
|
+
}
|
|
1433
|
+
},
|
|
1434
|
+
'\\bond{(...)}': {
|
|
1435
|
+
'*': {
|
|
1436
|
+
action_: [{
|
|
1437
|
+
type_: 'output',
|
|
1438
|
+
option: 2
|
|
1439
|
+
}, 'bond'],
|
|
1440
|
+
nextState: "3"
|
|
1441
|
+
}
|
|
1442
|
+
},
|
|
1443
|
+
'\\frac{(...)}': {
|
|
1444
|
+
'*': {
|
|
1445
|
+
action_: [{
|
|
1446
|
+
type_: 'output',
|
|
1447
|
+
option: 1
|
|
1448
|
+
}, 'frac-output'],
|
|
1449
|
+
nextState: '3'
|
|
1450
|
+
}
|
|
1451
|
+
},
|
|
1452
|
+
'\\overset{(...)}': {
|
|
1453
|
+
'*': {
|
|
1454
|
+
action_: [{
|
|
1455
|
+
type_: 'output',
|
|
1456
|
+
option: 2
|
|
1457
|
+
}, 'overset-output'],
|
|
1458
|
+
nextState: '3'
|
|
1459
|
+
}
|
|
1460
|
+
},
|
|
1461
|
+
"\\underset{(...)}": {
|
|
1462
|
+
'*': {
|
|
1463
|
+
action_: [{
|
|
1464
|
+
type_: 'output',
|
|
1465
|
+
option: 2
|
|
1466
|
+
}, 'underset-output'],
|
|
1467
|
+
nextState: '3'
|
|
1468
|
+
}
|
|
1469
|
+
},
|
|
1470
|
+
"\\underbrace{(...)}": {
|
|
1471
|
+
'*': {
|
|
1472
|
+
action_: [{
|
|
1473
|
+
type_: 'output',
|
|
1474
|
+
option: 2
|
|
1475
|
+
}, 'underbrace-output'],
|
|
1476
|
+
nextState: '3'
|
|
1477
|
+
}
|
|
1478
|
+
},
|
|
1479
|
+
'\\color{(...)}{(...)}1|\\color(...){(...)}2': {
|
|
1480
|
+
'*': {
|
|
1481
|
+
action_: [{
|
|
1482
|
+
type_: 'output',
|
|
1483
|
+
option: 2
|
|
1484
|
+
}, 'color-output'],
|
|
1485
|
+
nextState: '3'
|
|
1486
|
+
}
|
|
1487
|
+
},
|
|
1488
|
+
'\\color{(...)}0': {
|
|
1489
|
+
'*': {
|
|
1490
|
+
action_: [{
|
|
1491
|
+
type_: 'output',
|
|
1492
|
+
option: 2
|
|
1493
|
+
}, 'color0-output']
|
|
1494
|
+
}
|
|
1495
|
+
},
|
|
1496
|
+
'\\ce{(...)}': {
|
|
1497
|
+
'*': {
|
|
1498
|
+
action_: [{
|
|
1499
|
+
type_: 'output',
|
|
1500
|
+
option: 2
|
|
1501
|
+
}, 'ce'],
|
|
1502
|
+
nextState: '3'
|
|
1503
|
+
}
|
|
1504
|
+
},
|
|
1505
|
+
'\\,': {
|
|
1506
|
+
'*': {
|
|
1507
|
+
action_: [{
|
|
1508
|
+
type_: 'output',
|
|
1509
|
+
option: 1
|
|
1510
|
+
}, 'copy'],
|
|
1511
|
+
nextState: '1'
|
|
1512
|
+
}
|
|
1513
|
+
},
|
|
1514
|
+
'\\x{}{}|\\x{}|\\x': {
|
|
1515
|
+
'0|1|2|3|a|as|b|p|bp|o|c0': {
|
|
1516
|
+
action_: ['o=', 'output'],
|
|
1517
|
+
nextState: '3'
|
|
1518
|
+
},
|
|
1519
|
+
'*': {
|
|
1520
|
+
action_: ['output', 'o=', 'output'],
|
|
1521
|
+
nextState: '3'
|
|
1522
|
+
}
|
|
1523
|
+
},
|
|
1524
|
+
'others': {
|
|
1525
|
+
'*': {
|
|
1526
|
+
action_: [{
|
|
1527
|
+
type_: 'output',
|
|
1528
|
+
option: 1
|
|
1529
|
+
}, 'copy'],
|
|
1530
|
+
nextState: '3'
|
|
1531
|
+
}
|
|
1532
|
+
},
|
|
1533
|
+
'else2': {
|
|
1534
|
+
'a': {
|
|
1535
|
+
action_: 'a to o',
|
|
1536
|
+
nextState: 'o',
|
|
1537
|
+
revisit: true
|
|
1538
|
+
},
|
|
1539
|
+
'as': {
|
|
1540
|
+
action_: ['output', 'sb=true'],
|
|
1541
|
+
nextState: '1',
|
|
1542
|
+
revisit: true
|
|
1543
|
+
},
|
|
1544
|
+
'r|rt|rd|rdt|rdq': {
|
|
1545
|
+
action_: ['output'],
|
|
1546
|
+
nextState: '0',
|
|
1547
|
+
revisit: true
|
|
1548
|
+
},
|
|
1549
|
+
'*': {
|
|
1550
|
+
action_: ['output', 'copy'],
|
|
1551
|
+
nextState: '3'
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
}),
|
|
1555
|
+
actions: {
|
|
1556
|
+
'o after d': function oAfterD(buffer, m) {
|
|
1557
|
+
var ret;
|
|
1558
|
+
|
|
1559
|
+
if ((buffer.d || "").match(/^[0-9]+$/)) {
|
|
1560
|
+
var tmp = buffer.d;
|
|
1561
|
+
buffer.d = undefined;
|
|
1562
|
+
ret = this['output'](buffer);
|
|
1563
|
+
buffer.b = tmp;
|
|
1564
|
+
} else {
|
|
1565
|
+
ret = this['output'](buffer);
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
mhchemParser.actions['o='](buffer, m);
|
|
1569
|
+
return ret;
|
|
1570
|
+
},
|
|
1571
|
+
'd= kv': function dKv(buffer, m) {
|
|
1572
|
+
buffer.d = m;
|
|
1573
|
+
buffer.dType = 'kv';
|
|
1574
|
+
},
|
|
1575
|
+
'charge or bond': function chargeOrBond(buffer, m) {
|
|
1576
|
+
if (buffer['beginsWithBond']) {
|
|
1577
|
+
/** @type {ParserOutput[]} */
|
|
1578
|
+
var ret = [];
|
|
1579
|
+
mhchemParser.concatArray(ret, this['output'](buffer));
|
|
1580
|
+
mhchemParser.concatArray(ret, mhchemParser.actions['bond'](buffer, m, "-"));
|
|
1581
|
+
return ret;
|
|
1582
|
+
} else {
|
|
1583
|
+
buffer.d = m;
|
|
1584
|
+
}
|
|
1585
|
+
},
|
|
1586
|
+
'- after o/d': function afterOD(buffer, m, isAfterD) {
|
|
1587
|
+
var c1 = mhchemParser.patterns.match_('orbital', buffer.o || "");
|
|
1588
|
+
var c2 = mhchemParser.patterns.match_('one lowercase greek letter $', buffer.o || "");
|
|
1589
|
+
var c3 = mhchemParser.patterns.match_('one lowercase latin letter $', buffer.o || "");
|
|
1590
|
+
var c4 = mhchemParser.patterns.match_('$one lowercase latin letter$ $', buffer.o || "");
|
|
1591
|
+
var hyphenFollows = m === "-" && (c1 && c1.remainder === "" || c2 || c3 || c4);
|
|
1592
|
+
|
|
1593
|
+
if (hyphenFollows && !buffer.a && !buffer.b && !buffer.p && !buffer.d && !buffer.q && !c1 && c3) {
|
|
1594
|
+
buffer.o = '$' + buffer.o + '$';
|
|
1595
|
+
}
|
|
1596
|
+
/** @type {ParserOutput[]} */
|
|
1597
|
+
|
|
1598
|
+
|
|
1599
|
+
var ret = [];
|
|
1600
|
+
|
|
1601
|
+
if (hyphenFollows) {
|
|
1602
|
+
mhchemParser.concatArray(ret, this['output'](buffer));
|
|
1603
|
+
ret.push({
|
|
1604
|
+
type_: 'hyphen'
|
|
1605
|
+
});
|
|
1606
|
+
} else {
|
|
1607
|
+
c1 = mhchemParser.patterns.match_('digits', buffer.d || "");
|
|
1608
|
+
|
|
1609
|
+
if (isAfterD && c1 && c1.remainder === '') {
|
|
1610
|
+
mhchemParser.concatArray(ret, mhchemParser.actions['d='](buffer, m));
|
|
1611
|
+
mhchemParser.concatArray(ret, this['output'](buffer));
|
|
1612
|
+
} else {
|
|
1613
|
+
mhchemParser.concatArray(ret, this['output'](buffer));
|
|
1614
|
+
mhchemParser.concatArray(ret, mhchemParser.actions['bond'](buffer, m, "-"));
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
return ret;
|
|
1619
|
+
},
|
|
1620
|
+
'a to o': function aToO(buffer) {
|
|
1621
|
+
buffer.o = buffer.a;
|
|
1622
|
+
buffer.a = undefined;
|
|
1623
|
+
},
|
|
1624
|
+
'sb=true': function sbTrue(buffer) {
|
|
1625
|
+
buffer.sb = true;
|
|
1626
|
+
},
|
|
1627
|
+
'sb=false': function sbFalse(buffer) {
|
|
1628
|
+
buffer.sb = false;
|
|
1629
|
+
},
|
|
1630
|
+
'beginsWithBond=true': function beginsWithBondTrue(buffer) {
|
|
1631
|
+
buffer['beginsWithBond'] = true;
|
|
1632
|
+
},
|
|
1633
|
+
'beginsWithBond=false': function beginsWithBondFalse(buffer) {
|
|
1634
|
+
buffer['beginsWithBond'] = false;
|
|
1635
|
+
},
|
|
1636
|
+
'parenthesisLevel++': function parenthesisLevel(buffer) {
|
|
1637
|
+
buffer['parenthesisLevel']++;
|
|
1638
|
+
},
|
|
1639
|
+
'parenthesisLevel--': function parenthesisLevel(buffer) {
|
|
1640
|
+
buffer['parenthesisLevel']--;
|
|
1641
|
+
},
|
|
1642
|
+
'state of aggregation': function stateOfAggregation(buffer, m) {
|
|
1643
|
+
return {
|
|
1644
|
+
type_: 'state of aggregation',
|
|
1645
|
+
p1: mhchemParser.go(m, 'o')
|
|
1646
|
+
};
|
|
1647
|
+
},
|
|
1648
|
+
'comma': function comma(buffer, m) {
|
|
1649
|
+
var a = m.replace(/\s*$/, '');
|
|
1650
|
+
var withSpace = a !== m;
|
|
1651
|
+
|
|
1652
|
+
if (withSpace && buffer['parenthesisLevel'] === 0) {
|
|
1653
|
+
return {
|
|
1654
|
+
type_: 'comma enumeration L',
|
|
1655
|
+
p1: a
|
|
1656
|
+
};
|
|
1657
|
+
} else {
|
|
1658
|
+
return {
|
|
1659
|
+
type_: 'comma enumeration M',
|
|
1660
|
+
p1: a
|
|
1661
|
+
};
|
|
1662
|
+
}
|
|
1663
|
+
},
|
|
1664
|
+
'output': function output(buffer, m, entityFollows) {
|
|
1665
|
+
// entityFollows:
|
|
1666
|
+
// undefined = if we have nothing else to output, also ignore the just read space (buffer.sb)
|
|
1667
|
+
// 1 = an entity follows, never omit the space if there was one just read before (can only apply to state 1)
|
|
1668
|
+
// 2 = 1 + the entity can have an amount, so output a\, instead of converting it to o (can only apply to states a|as)
|
|
1669
|
+
|
|
1670
|
+
/** @type {ParserOutput | ParserOutput[]} */
|
|
1671
|
+
var ret;
|
|
1672
|
+
|
|
1673
|
+
if (!buffer.r) {
|
|
1674
|
+
ret = [];
|
|
1675
|
+
|
|
1676
|
+
if (!buffer.a && !buffer.b && !buffer.p && !buffer.o && !buffer.q && !buffer.d && !entityFollows) {//ret = [];
|
|
1677
|
+
} else {
|
|
1678
|
+
if (buffer.sb) {
|
|
1679
|
+
ret.push({
|
|
1680
|
+
type_: 'entitySkip'
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
if (!buffer.o && !buffer.q && !buffer.d && !buffer.b && !buffer.p && entityFollows !== 2) {
|
|
1685
|
+
buffer.o = buffer.a;
|
|
1686
|
+
buffer.a = undefined;
|
|
1687
|
+
} else if (!buffer.o && !buffer.q && !buffer.d && (buffer.b || buffer.p)) {
|
|
1688
|
+
buffer.o = buffer.a;
|
|
1689
|
+
buffer.d = buffer.b;
|
|
1690
|
+
buffer.q = buffer.p;
|
|
1691
|
+
buffer.a = buffer.b = buffer.p = undefined;
|
|
1692
|
+
} else {
|
|
1693
|
+
if (buffer.o && buffer.dType === 'kv' && mhchemParser.patterns.match_('d-oxidation$', buffer.d || "")) {
|
|
1694
|
+
buffer.dType = 'oxidation';
|
|
1695
|
+
} else if (buffer.o && buffer.dType === 'kv' && !buffer.q) {
|
|
1696
|
+
buffer.dType = undefined;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
ret.push({
|
|
1701
|
+
type_: 'chemfive',
|
|
1702
|
+
a: mhchemParser.go(buffer.a, 'a'),
|
|
1703
|
+
b: mhchemParser.go(buffer.b, 'bd'),
|
|
1704
|
+
p: mhchemParser.go(buffer.p, 'pq'),
|
|
1705
|
+
o: mhchemParser.go(buffer.o, 'o'),
|
|
1706
|
+
q: mhchemParser.go(buffer.q, 'pq'),
|
|
1707
|
+
d: mhchemParser.go(buffer.d, buffer.dType === 'oxidation' ? 'oxidation' : 'bd'),
|
|
1708
|
+
dType: buffer.dType
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
} else {
|
|
1712
|
+
// r
|
|
1713
|
+
|
|
1714
|
+
/** @type {ParserOutput[]} */
|
|
1715
|
+
var rd;
|
|
1716
|
+
|
|
1717
|
+
if (buffer.rdt === 'M') {
|
|
1718
|
+
rd = mhchemParser.go(buffer.rd, 'tex-math');
|
|
1719
|
+
} else if (buffer.rdt === 'T') {
|
|
1720
|
+
rd = [{
|
|
1721
|
+
type_: 'text',
|
|
1722
|
+
p1: buffer.rd || ""
|
|
1723
|
+
}];
|
|
1724
|
+
} else {
|
|
1725
|
+
rd = mhchemParser.go(buffer.rd);
|
|
1726
|
+
}
|
|
1727
|
+
/** @type {ParserOutput[]} */
|
|
1728
|
+
|
|
1729
|
+
|
|
1730
|
+
var rq;
|
|
1731
|
+
|
|
1732
|
+
if (buffer.rqt === 'M') {
|
|
1733
|
+
rq = mhchemParser.go(buffer.rq, 'tex-math');
|
|
1734
|
+
} else if (buffer.rqt === 'T') {
|
|
1735
|
+
rq = [{
|
|
1736
|
+
type_: 'text',
|
|
1737
|
+
p1: buffer.rq || ""
|
|
1738
|
+
}];
|
|
1739
|
+
} else {
|
|
1740
|
+
rq = mhchemParser.go(buffer.rq);
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
ret = {
|
|
1744
|
+
type_: 'arrow',
|
|
1745
|
+
r: buffer.r,
|
|
1746
|
+
rd: rd,
|
|
1747
|
+
rq: rq
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
for (var p in buffer) {
|
|
1752
|
+
if (p !== 'parenthesisLevel' && p !== 'beginsWithBond') {
|
|
1753
|
+
delete buffer[p];
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
return ret;
|
|
1758
|
+
},
|
|
1759
|
+
'oxidation-output': function oxidationOutput(buffer, m) {
|
|
1760
|
+
var ret = ["{"];
|
|
1761
|
+
mhchemParser.concatArray(ret, mhchemParser.go(m, 'oxidation'));
|
|
1762
|
+
ret.push("}");
|
|
1763
|
+
return ret;
|
|
1764
|
+
},
|
|
1765
|
+
'frac-output': function fracOutput(buffer, m) {
|
|
1766
|
+
return {
|
|
1767
|
+
type_: 'frac-ce',
|
|
1768
|
+
p1: mhchemParser.go(m[0]),
|
|
1769
|
+
p2: mhchemParser.go(m[1])
|
|
1770
|
+
};
|
|
1771
|
+
},
|
|
1772
|
+
'overset-output': function oversetOutput(buffer, m) {
|
|
1773
|
+
return {
|
|
1774
|
+
type_: 'overset',
|
|
1775
|
+
p1: mhchemParser.go(m[0]),
|
|
1776
|
+
p2: mhchemParser.go(m[1])
|
|
1777
|
+
};
|
|
1778
|
+
},
|
|
1779
|
+
'underset-output': function undersetOutput(buffer, m) {
|
|
1780
|
+
return {
|
|
1781
|
+
type_: 'underset',
|
|
1782
|
+
p1: mhchemParser.go(m[0]),
|
|
1783
|
+
p2: mhchemParser.go(m[1])
|
|
1784
|
+
};
|
|
1785
|
+
},
|
|
1786
|
+
'underbrace-output': function underbraceOutput(buffer, m) {
|
|
1787
|
+
return {
|
|
1788
|
+
type_: 'underbrace',
|
|
1789
|
+
p1: mhchemParser.go(m[0]),
|
|
1790
|
+
p2: mhchemParser.go(m[1])
|
|
1791
|
+
};
|
|
1792
|
+
},
|
|
1793
|
+
'color-output': function colorOutput(buffer, m) {
|
|
1794
|
+
return {
|
|
1795
|
+
type_: 'color',
|
|
1796
|
+
color1: m[0],
|
|
1797
|
+
color2: mhchemParser.go(m[1])
|
|
1798
|
+
};
|
|
1799
|
+
},
|
|
1800
|
+
'r=': function r(buffer, m) {
|
|
1801
|
+
buffer.r = m;
|
|
1802
|
+
},
|
|
1803
|
+
'rdt=': function rdt(buffer, m) {
|
|
1804
|
+
buffer.rdt = m;
|
|
1805
|
+
},
|
|
1806
|
+
'rd=': function rd(buffer, m) {
|
|
1807
|
+
buffer.rd = m;
|
|
1808
|
+
},
|
|
1809
|
+
'rqt=': function rqt(buffer, m) {
|
|
1810
|
+
buffer.rqt = m;
|
|
1811
|
+
},
|
|
1812
|
+
'rq=': function rq(buffer, m) {
|
|
1813
|
+
buffer.rq = m;
|
|
1814
|
+
},
|
|
1815
|
+
'operator': function operator(buffer, m, p1) {
|
|
1816
|
+
return {
|
|
1817
|
+
type_: 'operator',
|
|
1818
|
+
kind_: p1 || m
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
},
|
|
1823
|
+
'a': {
|
|
1824
|
+
transitions: mhchemParser.createTransitions({
|
|
1825
|
+
'empty': {
|
|
1826
|
+
'*': {}
|
|
1827
|
+
},
|
|
1828
|
+
'1/2$': {
|
|
1829
|
+
'0': {
|
|
1830
|
+
action_: '1/2'
|
|
1831
|
+
}
|
|
1832
|
+
},
|
|
1833
|
+
'else': {
|
|
1834
|
+
'0': {
|
|
1835
|
+
nextState: '1',
|
|
1836
|
+
revisit: true
|
|
1837
|
+
}
|
|
1838
|
+
},
|
|
1839
|
+
'$(...)$': {
|
|
1840
|
+
'*': {
|
|
1841
|
+
action_: 'tex-math tight',
|
|
1842
|
+
nextState: '1'
|
|
1843
|
+
}
|
|
1844
|
+
},
|
|
1845
|
+
',': {
|
|
1846
|
+
'*': {
|
|
1847
|
+
action_: {
|
|
1848
|
+
type_: 'insert',
|
|
1849
|
+
option: 'commaDecimal'
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
},
|
|
1853
|
+
'else2': {
|
|
1854
|
+
'*': {
|
|
1855
|
+
action_: 'copy'
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
}),
|
|
1859
|
+
actions: {}
|
|
1860
|
+
},
|
|
1861
|
+
'o': {
|
|
1862
|
+
transitions: mhchemParser.createTransitions({
|
|
1863
|
+
'empty': {
|
|
1864
|
+
'*': {}
|
|
1865
|
+
},
|
|
1866
|
+
'1/2$': {
|
|
1867
|
+
'0': {
|
|
1868
|
+
action_: '1/2'
|
|
1869
|
+
}
|
|
1870
|
+
},
|
|
1871
|
+
'else': {
|
|
1872
|
+
'0': {
|
|
1873
|
+
nextState: '1',
|
|
1874
|
+
revisit: true
|
|
1875
|
+
}
|
|
1876
|
+
},
|
|
1877
|
+
'letters': {
|
|
1878
|
+
'*': {
|
|
1879
|
+
action_: 'rm'
|
|
1880
|
+
}
|
|
1881
|
+
},
|
|
1882
|
+
'\\ca': {
|
|
1883
|
+
'*': {
|
|
1884
|
+
action_: {
|
|
1885
|
+
type_: 'insert',
|
|
1886
|
+
option: 'circa'
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
},
|
|
1890
|
+
'\\x{}{}|\\x{}|\\x': {
|
|
1891
|
+
'*': {
|
|
1892
|
+
action_: 'copy'
|
|
1893
|
+
}
|
|
1894
|
+
},
|
|
1895
|
+
'${(...)}$|$(...)$': {
|
|
1896
|
+
'*': {
|
|
1897
|
+
action_: 'tex-math'
|
|
1898
|
+
}
|
|
1899
|
+
},
|
|
1900
|
+
'{(...)}': {
|
|
1901
|
+
'*': {
|
|
1902
|
+
action_: '{text}'
|
|
1903
|
+
}
|
|
1904
|
+
},
|
|
1905
|
+
'else2': {
|
|
1906
|
+
'*': {
|
|
1907
|
+
action_: 'copy'
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}),
|
|
1911
|
+
actions: {}
|
|
1912
|
+
},
|
|
1913
|
+
'text': {
|
|
1914
|
+
transitions: mhchemParser.createTransitions({
|
|
1915
|
+
'empty': {
|
|
1916
|
+
'*': {
|
|
1917
|
+
action_: 'output'
|
|
1918
|
+
}
|
|
1919
|
+
},
|
|
1920
|
+
'{...}': {
|
|
1921
|
+
'*': {
|
|
1922
|
+
action_: 'text='
|
|
1923
|
+
}
|
|
1924
|
+
},
|
|
1925
|
+
'${(...)}$|$(...)$': {
|
|
1926
|
+
'*': {
|
|
1927
|
+
action_: 'tex-math'
|
|
1928
|
+
}
|
|
1929
|
+
},
|
|
1930
|
+
'\\greek': {
|
|
1931
|
+
'*': {
|
|
1932
|
+
action_: ['output', 'rm']
|
|
1933
|
+
}
|
|
1934
|
+
},
|
|
1935
|
+
'\\,|\\x{}{}|\\x{}|\\x': {
|
|
1936
|
+
'*': {
|
|
1937
|
+
action_: ['output', 'copy']
|
|
1938
|
+
}
|
|
1939
|
+
},
|
|
1940
|
+
'else': {
|
|
1941
|
+
'*': {
|
|
1942
|
+
action_: 'text='
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
}),
|
|
1946
|
+
actions: {
|
|
1947
|
+
'output': function output(buffer) {
|
|
1948
|
+
if (buffer.text_) {
|
|
1949
|
+
/** @type {ParserOutput} */
|
|
1950
|
+
var ret = {
|
|
1951
|
+
type_: 'text',
|
|
1952
|
+
p1: buffer.text_
|
|
1953
|
+
};
|
|
1954
|
+
|
|
1955
|
+
for (var p in buffer) {
|
|
1956
|
+
delete buffer[p];
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
return ret;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
},
|
|
1964
|
+
'pq': {
|
|
1965
|
+
transitions: mhchemParser.createTransitions({
|
|
1966
|
+
'empty': {
|
|
1967
|
+
'*': {}
|
|
1968
|
+
},
|
|
1969
|
+
'state of aggregation $': {
|
|
1970
|
+
'*': {
|
|
1971
|
+
action_: 'state of aggregation'
|
|
1972
|
+
}
|
|
1973
|
+
},
|
|
1974
|
+
'i$': {
|
|
1975
|
+
'0': {
|
|
1976
|
+
nextState: '!f',
|
|
1977
|
+
revisit: true
|
|
1978
|
+
}
|
|
1979
|
+
},
|
|
1980
|
+
'(KV letters),': {
|
|
1981
|
+
'0': {
|
|
1982
|
+
action_: 'rm',
|
|
1983
|
+
nextState: '0'
|
|
1984
|
+
}
|
|
1985
|
+
},
|
|
1986
|
+
'formula$': {
|
|
1987
|
+
'0': {
|
|
1988
|
+
nextState: 'f',
|
|
1989
|
+
revisit: true
|
|
1990
|
+
}
|
|
1991
|
+
},
|
|
1992
|
+
'1/2$': {
|
|
1993
|
+
'0': {
|
|
1994
|
+
action_: '1/2'
|
|
1995
|
+
}
|
|
1996
|
+
},
|
|
1997
|
+
'else': {
|
|
1998
|
+
'0': {
|
|
1999
|
+
nextState: '!f',
|
|
2000
|
+
revisit: true
|
|
2001
|
+
}
|
|
2002
|
+
},
|
|
2003
|
+
'${(...)}$|$(...)$': {
|
|
2004
|
+
'*': {
|
|
2005
|
+
action_: 'tex-math'
|
|
2006
|
+
}
|
|
2007
|
+
},
|
|
2008
|
+
'{(...)}': {
|
|
2009
|
+
'*': {
|
|
2010
|
+
action_: 'text'
|
|
2011
|
+
}
|
|
2012
|
+
},
|
|
2013
|
+
'a-z': {
|
|
2014
|
+
'f': {
|
|
2015
|
+
action_: 'tex-math'
|
|
2016
|
+
}
|
|
2017
|
+
},
|
|
2018
|
+
'letters': {
|
|
2019
|
+
'*': {
|
|
2020
|
+
action_: 'rm'
|
|
2021
|
+
}
|
|
2022
|
+
},
|
|
2023
|
+
'-9.,9': {
|
|
2024
|
+
'*': {
|
|
2025
|
+
action_: '9,9'
|
|
2026
|
+
}
|
|
2027
|
+
},
|
|
2028
|
+
',': {
|
|
2029
|
+
'*': {
|
|
2030
|
+
action_: {
|
|
2031
|
+
type_: 'insert+p1',
|
|
2032
|
+
option: 'comma enumeration S'
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
},
|
|
2036
|
+
'\\color{(...)}{(...)}1|\\color(...){(...)}2': {
|
|
2037
|
+
'*': {
|
|
2038
|
+
action_: 'color-output'
|
|
2039
|
+
}
|
|
2040
|
+
},
|
|
2041
|
+
'\\color{(...)}0': {
|
|
2042
|
+
'*': {
|
|
2043
|
+
action_: 'color0-output'
|
|
2044
|
+
}
|
|
2045
|
+
},
|
|
2046
|
+
'\\ce{(...)}': {
|
|
2047
|
+
'*': {
|
|
2048
|
+
action_: 'ce'
|
|
2049
|
+
}
|
|
2050
|
+
},
|
|
2051
|
+
'\\,|\\x{}{}|\\x{}|\\x': {
|
|
2052
|
+
'*': {
|
|
2053
|
+
action_: 'copy'
|
|
2054
|
+
}
|
|
2055
|
+
},
|
|
2056
|
+
'else2': {
|
|
2057
|
+
'*': {
|
|
2058
|
+
action_: 'copy'
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
}),
|
|
2062
|
+
actions: {
|
|
2063
|
+
'state of aggregation': function stateOfAggregation(buffer, m) {
|
|
2064
|
+
return {
|
|
2065
|
+
type_: 'state of aggregation subscript',
|
|
2066
|
+
p1: mhchemParser.go(m, 'o')
|
|
2067
|
+
};
|
|
2068
|
+
},
|
|
2069
|
+
'color-output': function colorOutput(buffer, m) {
|
|
2070
|
+
return {
|
|
2071
|
+
type_: 'color',
|
|
2072
|
+
color1: m[0],
|
|
2073
|
+
color2: mhchemParser.go(m[1], 'pq')
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
},
|
|
2078
|
+
'bd': {
|
|
2079
|
+
transitions: mhchemParser.createTransitions({
|
|
2080
|
+
'empty': {
|
|
2081
|
+
'*': {}
|
|
2082
|
+
},
|
|
2083
|
+
'x$': {
|
|
2084
|
+
'0': {
|
|
2085
|
+
nextState: '!f',
|
|
2086
|
+
revisit: true
|
|
2087
|
+
}
|
|
2088
|
+
},
|
|
2089
|
+
'formula$': {
|
|
2090
|
+
'0': {
|
|
2091
|
+
nextState: 'f',
|
|
2092
|
+
revisit: true
|
|
2093
|
+
}
|
|
2094
|
+
},
|
|
2095
|
+
'else': {
|
|
2096
|
+
'0': {
|
|
2097
|
+
nextState: '!f',
|
|
2098
|
+
revisit: true
|
|
2099
|
+
}
|
|
2100
|
+
},
|
|
2101
|
+
'-9.,9 no missing 0': {
|
|
2102
|
+
'*': {
|
|
2103
|
+
action_: '9,9'
|
|
2104
|
+
}
|
|
2105
|
+
},
|
|
2106
|
+
'.': {
|
|
2107
|
+
'*': {
|
|
2108
|
+
action_: {
|
|
2109
|
+
type_: 'insert',
|
|
2110
|
+
option: 'electron dot'
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
},
|
|
2114
|
+
'a-z': {
|
|
2115
|
+
'f': {
|
|
2116
|
+
action_: 'tex-math'
|
|
2117
|
+
}
|
|
2118
|
+
},
|
|
2119
|
+
'x': {
|
|
2120
|
+
'*': {
|
|
2121
|
+
action_: {
|
|
2122
|
+
type_: 'insert',
|
|
2123
|
+
option: 'KV x'
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
},
|
|
2127
|
+
'letters': {
|
|
2128
|
+
'*': {
|
|
2129
|
+
action_: 'rm'
|
|
2130
|
+
}
|
|
2131
|
+
},
|
|
2132
|
+
'\'': {
|
|
2133
|
+
'*': {
|
|
2134
|
+
action_: {
|
|
2135
|
+
type_: 'insert',
|
|
2136
|
+
option: 'prime'
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
},
|
|
2140
|
+
'${(...)}$|$(...)$': {
|
|
2141
|
+
'*': {
|
|
2142
|
+
action_: 'tex-math'
|
|
2143
|
+
}
|
|
2144
|
+
},
|
|
2145
|
+
'{(...)}': {
|
|
2146
|
+
'*': {
|
|
2147
|
+
action_: 'text'
|
|
2148
|
+
}
|
|
2149
|
+
},
|
|
2150
|
+
'\\color{(...)}{(...)}1|\\color(...){(...)}2': {
|
|
2151
|
+
'*': {
|
|
2152
|
+
action_: 'color-output'
|
|
2153
|
+
}
|
|
2154
|
+
},
|
|
2155
|
+
'\\color{(...)}0': {
|
|
2156
|
+
'*': {
|
|
2157
|
+
action_: 'color0-output'
|
|
2158
|
+
}
|
|
2159
|
+
},
|
|
2160
|
+
'\\ce{(...)}': {
|
|
2161
|
+
'*': {
|
|
2162
|
+
action_: 'ce'
|
|
2163
|
+
}
|
|
2164
|
+
},
|
|
2165
|
+
'\\,|\\x{}{}|\\x{}|\\x': {
|
|
2166
|
+
'*': {
|
|
2167
|
+
action_: 'copy'
|
|
2168
|
+
}
|
|
2169
|
+
},
|
|
2170
|
+
'else2': {
|
|
2171
|
+
'*': {
|
|
2172
|
+
action_: 'copy'
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
}),
|
|
2176
|
+
actions: {
|
|
2177
|
+
'color-output': function colorOutput(buffer, m) {
|
|
2178
|
+
return {
|
|
2179
|
+
type_: 'color',
|
|
2180
|
+
color1: m[0],
|
|
2181
|
+
color2: mhchemParser.go(m[1], 'bd')
|
|
2182
|
+
};
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
},
|
|
2186
|
+
'oxidation': {
|
|
2187
|
+
transitions: mhchemParser.createTransitions({
|
|
2188
|
+
'empty': {
|
|
2189
|
+
'*': {}
|
|
2190
|
+
},
|
|
2191
|
+
'roman numeral': {
|
|
2192
|
+
'*': {
|
|
2193
|
+
action_: 'roman-numeral'
|
|
2194
|
+
}
|
|
2195
|
+
},
|
|
2196
|
+
'${(...)}$|$(...)$': {
|
|
2197
|
+
'*': {
|
|
2198
|
+
action_: 'tex-math'
|
|
2199
|
+
}
|
|
2200
|
+
},
|
|
2201
|
+
'else': {
|
|
2202
|
+
'*': {
|
|
2203
|
+
action_: 'copy'
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
}),
|
|
2207
|
+
actions: {
|
|
2208
|
+
'roman-numeral': function romanNumeral(buffer, m) {
|
|
2209
|
+
return {
|
|
2210
|
+
type_: 'roman numeral',
|
|
2211
|
+
p1: m || ""
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
},
|
|
2216
|
+
'tex-math': {
|
|
2217
|
+
transitions: mhchemParser.createTransitions({
|
|
2218
|
+
'empty': {
|
|
2219
|
+
'*': {
|
|
2220
|
+
action_: 'output'
|
|
2221
|
+
}
|
|
2222
|
+
},
|
|
2223
|
+
'\\ce{(...)}': {
|
|
2224
|
+
'*': {
|
|
2225
|
+
action_: ['output', 'ce']
|
|
2226
|
+
}
|
|
2227
|
+
},
|
|
2228
|
+
'{...}|\\,|\\x{}{}|\\x{}|\\x': {
|
|
2229
|
+
'*': {
|
|
2230
|
+
action_: 'o='
|
|
2231
|
+
}
|
|
2232
|
+
},
|
|
2233
|
+
'else': {
|
|
2234
|
+
'*': {
|
|
2235
|
+
action_: 'o='
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
}),
|
|
2239
|
+
actions: {
|
|
2240
|
+
'output': function output(buffer) {
|
|
2241
|
+
if (buffer.o) {
|
|
2242
|
+
/** @type {ParserOutput} */
|
|
2243
|
+
var ret = {
|
|
2244
|
+
type_: 'tex-math',
|
|
2245
|
+
p1: buffer.o
|
|
2246
|
+
};
|
|
2247
|
+
|
|
2248
|
+
for (var p in buffer) {
|
|
2249
|
+
delete buffer[p];
|
|
2250
|
+
}
|
|
2251
|
+
|
|
2252
|
+
return ret;
|
|
2253
|
+
}
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
},
|
|
2257
|
+
'tex-math tight': {
|
|
2258
|
+
transitions: mhchemParser.createTransitions({
|
|
2259
|
+
'empty': {
|
|
2260
|
+
'*': {
|
|
2261
|
+
action_: 'output'
|
|
2262
|
+
}
|
|
2263
|
+
},
|
|
2264
|
+
'\\ce{(...)}': {
|
|
2265
|
+
'*': {
|
|
2266
|
+
action_: ['output', 'ce']
|
|
2267
|
+
}
|
|
2268
|
+
},
|
|
2269
|
+
'{...}|\\,|\\x{}{}|\\x{}|\\x': {
|
|
2270
|
+
'*': {
|
|
2271
|
+
action_: 'o='
|
|
2272
|
+
}
|
|
2273
|
+
},
|
|
2274
|
+
'-|+': {
|
|
2275
|
+
'*': {
|
|
2276
|
+
action_: 'tight operator'
|
|
2277
|
+
}
|
|
2278
|
+
},
|
|
2279
|
+
'else': {
|
|
2280
|
+
'*': {
|
|
2281
|
+
action_: 'o='
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
}),
|
|
2285
|
+
actions: {
|
|
2286
|
+
'tight operator': function tightOperator(buffer, m) {
|
|
2287
|
+
buffer.o = (buffer.o || "") + "{" + m + "}";
|
|
2288
|
+
},
|
|
2289
|
+
'output': function output(buffer) {
|
|
2290
|
+
if (buffer.o) {
|
|
2291
|
+
/** @type {ParserOutput} */
|
|
2292
|
+
var ret = {
|
|
2293
|
+
type_: 'tex-math',
|
|
2294
|
+
p1: buffer.o
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2297
|
+
for (var p in buffer) {
|
|
2298
|
+
delete buffer[p];
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
return ret;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
},
|
|
2306
|
+
'9,9': {
|
|
2307
|
+
transitions: mhchemParser.createTransitions({
|
|
2308
|
+
'empty': {
|
|
2309
|
+
'*': {}
|
|
2310
|
+
},
|
|
2311
|
+
',': {
|
|
2312
|
+
'*': {
|
|
2313
|
+
action_: 'comma'
|
|
2314
|
+
}
|
|
2315
|
+
},
|
|
2316
|
+
'else': {
|
|
2317
|
+
'*': {
|
|
2318
|
+
action_: 'copy'
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}),
|
|
2322
|
+
actions: {
|
|
2323
|
+
'comma': function comma() {
|
|
2324
|
+
return {
|
|
2325
|
+
type_: 'commaDecimal'
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
},
|
|
2330
|
+
//#endregion
|
|
2331
|
+
//
|
|
2332
|
+
// \pu state machines
|
|
2333
|
+
//
|
|
2334
|
+
//#region pu
|
|
2335
|
+
'pu': {
|
|
2336
|
+
transitions: mhchemParser.createTransitions({
|
|
2337
|
+
'empty': {
|
|
2338
|
+
'*': {
|
|
2339
|
+
action_: 'output'
|
|
2340
|
+
}
|
|
2341
|
+
},
|
|
2342
|
+
'space$': {
|
|
2343
|
+
'*': {
|
|
2344
|
+
action_: ['output', 'space']
|
|
2345
|
+
}
|
|
2346
|
+
},
|
|
2347
|
+
'{[(|)]}': {
|
|
2348
|
+
'0|a': {
|
|
2349
|
+
action_: 'copy'
|
|
2350
|
+
}
|
|
2351
|
+
},
|
|
2352
|
+
'(-)(9)^(-9)': {
|
|
2353
|
+
'0': {
|
|
2354
|
+
action_: 'number^',
|
|
2355
|
+
nextState: 'a'
|
|
2356
|
+
}
|
|
2357
|
+
},
|
|
2358
|
+
'(-)(9.,9)(e)(99)': {
|
|
2359
|
+
'0': {
|
|
2360
|
+
action_: 'enumber',
|
|
2361
|
+
nextState: 'a'
|
|
2362
|
+
}
|
|
2363
|
+
},
|
|
2364
|
+
'space': {
|
|
2365
|
+
'0|a': {}
|
|
2366
|
+
},
|
|
2367
|
+
'pm-operator': {
|
|
2368
|
+
'0|a': {
|
|
2369
|
+
action_: {
|
|
2370
|
+
type_: 'operator',
|
|
2371
|
+
option: '\\pm'
|
|
2372
|
+
},
|
|
2373
|
+
nextState: '0'
|
|
2374
|
+
}
|
|
2375
|
+
},
|
|
2376
|
+
'operator': {
|
|
2377
|
+
'0|a': {
|
|
2378
|
+
action_: 'copy',
|
|
2379
|
+
nextState: '0'
|
|
2380
|
+
}
|
|
2381
|
+
},
|
|
2382
|
+
'//': {
|
|
2383
|
+
'd': {
|
|
2384
|
+
action_: 'o=',
|
|
2385
|
+
nextState: '/'
|
|
2386
|
+
}
|
|
2387
|
+
},
|
|
2388
|
+
'/': {
|
|
2389
|
+
'd': {
|
|
2390
|
+
action_: 'o=',
|
|
2391
|
+
nextState: '/'
|
|
2392
|
+
}
|
|
2393
|
+
},
|
|
2394
|
+
'{...}|else': {
|
|
2395
|
+
'0|d': {
|
|
2396
|
+
action_: 'd=',
|
|
2397
|
+
nextState: 'd'
|
|
2398
|
+
},
|
|
2399
|
+
'a': {
|
|
2400
|
+
action_: ['space', 'd='],
|
|
2401
|
+
nextState: 'd'
|
|
2402
|
+
},
|
|
2403
|
+
'/|q': {
|
|
2404
|
+
action_: 'q=',
|
|
2405
|
+
nextState: 'q'
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
}),
|
|
2409
|
+
actions: {
|
|
2410
|
+
'enumber': function enumber(buffer, m) {
|
|
2411
|
+
/** @type {ParserOutput[]} */
|
|
2412
|
+
var ret = [];
|
|
2413
|
+
|
|
2414
|
+
if (m[0] === "+-" || m[0] === "+/-") {
|
|
2415
|
+
ret.push("\\pm ");
|
|
2416
|
+
} else if (m[0]) {
|
|
2417
|
+
ret.push(m[0]);
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
if (m[1]) {
|
|
2421
|
+
mhchemParser.concatArray(ret, mhchemParser.go(m[1], 'pu-9,9'));
|
|
2422
|
+
|
|
2423
|
+
if (m[2]) {
|
|
2424
|
+
if (m[2].match(/[,.]/)) {
|
|
2425
|
+
mhchemParser.concatArray(ret, mhchemParser.go(m[2], 'pu-9,9'));
|
|
2426
|
+
} else {
|
|
2427
|
+
ret.push(m[2]);
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
m[3] = m[4] || m[3];
|
|
2432
|
+
|
|
2433
|
+
if (m[3]) {
|
|
2434
|
+
m[3] = m[3].trim();
|
|
2435
|
+
|
|
2436
|
+
if (m[3] === "e" || m[3].substr(0, 1) === "*") {
|
|
2437
|
+
ret.push({
|
|
2438
|
+
type_: 'cdot'
|
|
2439
|
+
});
|
|
2440
|
+
} else {
|
|
2441
|
+
ret.push({
|
|
2442
|
+
type_: 'times'
|
|
2443
|
+
});
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
if (m[3]) {
|
|
2449
|
+
ret.push("10^{" + m[5] + "}");
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2452
|
+
return ret;
|
|
2453
|
+
},
|
|
2454
|
+
'number^': function number(buffer, m) {
|
|
2455
|
+
/** @type {ParserOutput[]} */
|
|
2456
|
+
var ret = [];
|
|
2457
|
+
|
|
2458
|
+
if (m[0] === "+-" || m[0] === "+/-") {
|
|
2459
|
+
ret.push("\\pm ");
|
|
2460
|
+
} else if (m[0]) {
|
|
2461
|
+
ret.push(m[0]);
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
mhchemParser.concatArray(ret, mhchemParser.go(m[1], 'pu-9,9'));
|
|
2465
|
+
ret.push("^{" + m[2] + "}");
|
|
2466
|
+
return ret;
|
|
2467
|
+
},
|
|
2468
|
+
'operator': function operator(buffer, m, p1) {
|
|
2469
|
+
return {
|
|
2470
|
+
type_: 'operator',
|
|
2471
|
+
kind_: p1 || m
|
|
2472
|
+
};
|
|
2473
|
+
},
|
|
2474
|
+
'space': function space() {
|
|
2475
|
+
return {
|
|
2476
|
+
type_: 'pu-space-1'
|
|
2477
|
+
};
|
|
2478
|
+
},
|
|
2479
|
+
'output': function output(buffer) {
|
|
2480
|
+
/** @type {ParserOutput | ParserOutput[]} */
|
|
2481
|
+
var ret;
|
|
2482
|
+
var md = mhchemParser.patterns.match_('{(...)}', buffer.d || "");
|
|
2483
|
+
|
|
2484
|
+
if (md && md.remainder === '') {
|
|
2485
|
+
buffer.d = md.match_;
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
var mq = mhchemParser.patterns.match_('{(...)}', buffer.q || "");
|
|
2489
|
+
|
|
2490
|
+
if (mq && mq.remainder === '') {
|
|
2491
|
+
buffer.q = mq.match_;
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
if (buffer.d) {
|
|
2495
|
+
buffer.d = buffer.d.replace(/\u00B0C|\^oC|\^{o}C/g, "{}^{\\circ}C");
|
|
2496
|
+
buffer.d = buffer.d.replace(/\u00B0F|\^oF|\^{o}F/g, "{}^{\\circ}F");
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
if (buffer.q) {
|
|
2500
|
+
// fraction
|
|
2501
|
+
buffer.q = buffer.q.replace(/\u00B0C|\^oC|\^{o}C/g, "{}^{\\circ}C");
|
|
2502
|
+
buffer.q = buffer.q.replace(/\u00B0F|\^oF|\^{o}F/g, "{}^{\\circ}F");
|
|
2503
|
+
var b5 = {
|
|
2504
|
+
d: mhchemParser.go(buffer.d, 'pu'),
|
|
2505
|
+
q: mhchemParser.go(buffer.q, 'pu')
|
|
2506
|
+
};
|
|
2507
|
+
|
|
2508
|
+
if (buffer.o === '//') {
|
|
2509
|
+
ret = {
|
|
2510
|
+
type_: 'pu-frac',
|
|
2511
|
+
p1: b5.d,
|
|
2512
|
+
p2: b5.q
|
|
2513
|
+
};
|
|
2514
|
+
} else {
|
|
2515
|
+
ret = b5.d;
|
|
2516
|
+
|
|
2517
|
+
if (b5.d.length > 1 || b5.q.length > 1) {
|
|
2518
|
+
ret.push({
|
|
2519
|
+
type_: ' / '
|
|
2520
|
+
});
|
|
2521
|
+
} else {
|
|
2522
|
+
ret.push({
|
|
2523
|
+
type_: '/'
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
mhchemParser.concatArray(ret, b5.q);
|
|
2528
|
+
}
|
|
2529
|
+
} else {
|
|
2530
|
+
// no fraction
|
|
2531
|
+
ret = mhchemParser.go(buffer.d, 'pu-2');
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
for (var p in buffer) {
|
|
2535
|
+
delete buffer[p];
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
return ret;
|
|
2539
|
+
}
|
|
2540
|
+
}
|
|
2541
|
+
},
|
|
2542
|
+
'pu-2': {
|
|
2543
|
+
transitions: mhchemParser.createTransitions({
|
|
2544
|
+
'empty': {
|
|
2545
|
+
'*': {
|
|
2546
|
+
action_: 'output'
|
|
2547
|
+
}
|
|
2548
|
+
},
|
|
2549
|
+
'*': {
|
|
2550
|
+
'*': {
|
|
2551
|
+
action_: ['output', 'cdot'],
|
|
2552
|
+
nextState: '0'
|
|
2553
|
+
}
|
|
2554
|
+
},
|
|
2555
|
+
'\\x': {
|
|
2556
|
+
'*': {
|
|
2557
|
+
action_: 'rm='
|
|
2558
|
+
}
|
|
2559
|
+
},
|
|
2560
|
+
'space': {
|
|
2561
|
+
'*': {
|
|
2562
|
+
action_: ['output', 'space'],
|
|
2563
|
+
nextState: '0'
|
|
2564
|
+
}
|
|
2565
|
+
},
|
|
2566
|
+
'^{(...)}|^(-1)': {
|
|
2567
|
+
'1': {
|
|
2568
|
+
action_: '^(-1)'
|
|
2569
|
+
}
|
|
2570
|
+
},
|
|
2571
|
+
'-9.,9': {
|
|
2572
|
+
'0': {
|
|
2573
|
+
action_: 'rm=',
|
|
2574
|
+
nextState: '0'
|
|
2575
|
+
},
|
|
2576
|
+
'1': {
|
|
2577
|
+
action_: '^(-1)',
|
|
2578
|
+
nextState: '0'
|
|
2579
|
+
}
|
|
2580
|
+
},
|
|
2581
|
+
'{...}|else': {
|
|
2582
|
+
'*': {
|
|
2583
|
+
action_: 'rm=',
|
|
2584
|
+
nextState: '1'
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
}),
|
|
2588
|
+
actions: {
|
|
2589
|
+
'cdot': function cdot() {
|
|
2590
|
+
return {
|
|
2591
|
+
type_: 'tight cdot'
|
|
2592
|
+
};
|
|
2593
|
+
},
|
|
2594
|
+
'^(-1)': function _(buffer, m) {
|
|
2595
|
+
buffer.rm += "^{" + m + "}";
|
|
2596
|
+
},
|
|
2597
|
+
'space': function space() {
|
|
2598
|
+
return {
|
|
2599
|
+
type_: 'pu-space-2'
|
|
2600
|
+
};
|
|
2601
|
+
},
|
|
2602
|
+
'output': function output(buffer) {
|
|
2603
|
+
/** @type {ParserOutput | ParserOutput[]} */
|
|
2604
|
+
var ret = [];
|
|
2605
|
+
|
|
2606
|
+
if (buffer.rm) {
|
|
2607
|
+
var mrm = mhchemParser.patterns.match_('{(...)}', buffer.rm || "");
|
|
2608
|
+
|
|
2609
|
+
if (mrm && mrm.remainder === '') {
|
|
2610
|
+
ret = mhchemParser.go(mrm.match_, 'pu');
|
|
2611
|
+
} else {
|
|
2612
|
+
ret = {
|
|
2613
|
+
type_: 'rm',
|
|
2614
|
+
p1: buffer.rm
|
|
2615
|
+
};
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
for (var p in buffer) {
|
|
2620
|
+
delete buffer[p];
|
|
2621
|
+
}
|
|
2622
|
+
|
|
2623
|
+
return ret;
|
|
2624
|
+
}
|
|
2625
|
+
}
|
|
2626
|
+
},
|
|
2627
|
+
'pu-9,9': {
|
|
2628
|
+
transitions: mhchemParser.createTransitions({
|
|
2629
|
+
'empty': {
|
|
2630
|
+
'0': {
|
|
2631
|
+
action_: 'output-0'
|
|
2632
|
+
},
|
|
2633
|
+
'o': {
|
|
2634
|
+
action_: 'output-o'
|
|
2635
|
+
}
|
|
2636
|
+
},
|
|
2637
|
+
',': {
|
|
2638
|
+
'0': {
|
|
2639
|
+
action_: ['output-0', 'comma'],
|
|
2640
|
+
nextState: 'o'
|
|
2641
|
+
}
|
|
2642
|
+
},
|
|
2643
|
+
'.': {
|
|
2644
|
+
'0': {
|
|
2645
|
+
action_: ['output-0', 'copy'],
|
|
2646
|
+
nextState: 'o'
|
|
2647
|
+
}
|
|
2648
|
+
},
|
|
2649
|
+
'else': {
|
|
2650
|
+
'*': {
|
|
2651
|
+
action_: 'text='
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
}),
|
|
2655
|
+
actions: {
|
|
2656
|
+
'comma': function comma() {
|
|
2657
|
+
return {
|
|
2658
|
+
type_: 'commaDecimal'
|
|
2659
|
+
};
|
|
2660
|
+
},
|
|
2661
|
+
'output-0': function output0(buffer) {
|
|
2662
|
+
/** @type {ParserOutput[]} */
|
|
2663
|
+
var ret = [];
|
|
2664
|
+
buffer.text_ = buffer.text_ || "";
|
|
2665
|
+
|
|
2666
|
+
if (buffer.text_.length > 4) {
|
|
2667
|
+
var a = buffer.text_.length % 3;
|
|
2668
|
+
|
|
2669
|
+
if (a === 0) {
|
|
2670
|
+
a = 3;
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
for (var i = buffer.text_.length - 3; i > 0; i -= 3) {
|
|
2674
|
+
ret.push(buffer.text_.substr(i, 3));
|
|
2675
|
+
ret.push({
|
|
2676
|
+
type_: '1000 separator'
|
|
2677
|
+
});
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
ret.push(buffer.text_.substr(0, a));
|
|
2681
|
+
ret.reverse();
|
|
2682
|
+
} else {
|
|
2683
|
+
ret.push(buffer.text_);
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
for (var p in buffer) {
|
|
2687
|
+
delete buffer[p];
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
return ret;
|
|
2691
|
+
},
|
|
2692
|
+
'output-o': function outputO(buffer) {
|
|
2693
|
+
/** @type {ParserOutput[]} */
|
|
2694
|
+
var ret = [];
|
|
2695
|
+
buffer.text_ = buffer.text_ || "";
|
|
2696
|
+
|
|
2697
|
+
if (buffer.text_.length > 4) {
|
|
2698
|
+
var a = buffer.text_.length - 3;
|
|
2699
|
+
|
|
2700
|
+
for (var i = 0; i < a; i += 3) {
|
|
2701
|
+
ret.push(buffer.text_.substr(i, 3));
|
|
2702
|
+
ret.push({
|
|
2703
|
+
type_: '1000 separator'
|
|
2704
|
+
});
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
ret.push(buffer.text_.substr(i));
|
|
2708
|
+
} else {
|
|
2709
|
+
ret.push(buffer.text_);
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
for (var p in buffer) {
|
|
2713
|
+
delete buffer[p];
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
return ret;
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
} //#endregion
|
|
2720
|
+
|
|
2721
|
+
}; //
|
|
2722
|
+
// texify: Take MhchemParser output and convert it to TeX
|
|
2723
|
+
//
|
|
2724
|
+
|
|
2725
|
+
/** @type {Texify} */
|
|
2726
|
+
|
|
2727
|
+
var texify = {
|
|
2728
|
+
go: function go(input, isInner) {
|
|
2729
|
+
// (recursive, max 4 levels)
|
|
2730
|
+
if (!input) {
|
|
2731
|
+
return "";
|
|
2732
|
+
}
|
|
2733
|
+
|
|
2734
|
+
var res = "";
|
|
2735
|
+
var cee = false;
|
|
2736
|
+
|
|
2737
|
+
for (var i = 0; i < input.length; i++) {
|
|
2738
|
+
var inputi = input[i];
|
|
2739
|
+
|
|
2740
|
+
if (typeof inputi === "string") {
|
|
2741
|
+
res += inputi;
|
|
2742
|
+
} else {
|
|
2743
|
+
res += texify._go2(inputi);
|
|
2744
|
+
|
|
2745
|
+
if (inputi.type_ === '1st-level escape') {
|
|
2746
|
+
cee = true;
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
}
|
|
2750
|
+
|
|
2751
|
+
if (!isInner && !cee && res) {
|
|
2752
|
+
res = "{" + res + "}";
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2755
|
+
return res;
|
|
2756
|
+
},
|
|
2757
|
+
_goInner: function _goInner(input) {
|
|
2758
|
+
if (!input) {
|
|
2759
|
+
return input;
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
return texify.go(input, true);
|
|
2763
|
+
},
|
|
2764
|
+
_go2: function _go2(buf) {
|
|
2765
|
+
/** @type {undefined | string} */
|
|
2766
|
+
var res;
|
|
2767
|
+
|
|
2768
|
+
switch (buf.type_) {
|
|
2769
|
+
case 'chemfive':
|
|
2770
|
+
res = "";
|
|
2771
|
+
var b5 = {
|
|
2772
|
+
a: texify._goInner(buf.a),
|
|
2773
|
+
b: texify._goInner(buf.b),
|
|
2774
|
+
p: texify._goInner(buf.p),
|
|
2775
|
+
o: texify._goInner(buf.o),
|
|
2776
|
+
q: texify._goInner(buf.q),
|
|
2777
|
+
d: texify._goInner(buf.d)
|
|
2778
|
+
}; //
|
|
2779
|
+
// a
|
|
2780
|
+
//
|
|
2781
|
+
|
|
2782
|
+
if (b5.a) {
|
|
2783
|
+
if (b5.a.match(/^[+\-]/)) {
|
|
2784
|
+
b5.a = "{" + b5.a + "}";
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
res += b5.a + "\\,";
|
|
2788
|
+
} //
|
|
2789
|
+
// b and p
|
|
2790
|
+
//
|
|
2791
|
+
|
|
2792
|
+
|
|
2793
|
+
if (b5.b || b5.p) {
|
|
2794
|
+
res += "{\\vphantom{X}}";
|
|
2795
|
+
res += "^{\\hphantom{" + (b5.b || "") + "}}_{\\hphantom{" + (b5.p || "") + "}}";
|
|
2796
|
+
res += "{\\vphantom{X}}";
|
|
2797
|
+
res += "^{\\smash[t]{\\vphantom{2}}\\mathllap{" + (b5.b || "") + "}}";
|
|
2798
|
+
res += "_{\\vphantom{2}\\mathllap{\\smash[t]{" + (b5.p || "") + "}}}";
|
|
2799
|
+
} //
|
|
2800
|
+
// o
|
|
2801
|
+
//
|
|
2802
|
+
|
|
2803
|
+
|
|
2804
|
+
if (b5.o) {
|
|
2805
|
+
if (b5.o.match(/^[+\-]/)) {
|
|
2806
|
+
b5.o = "{" + b5.o + "}";
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
res += b5.o;
|
|
2810
|
+
} //
|
|
2811
|
+
// q and d
|
|
2812
|
+
//
|
|
2813
|
+
|
|
2814
|
+
|
|
2815
|
+
if (buf.dType === 'kv') {
|
|
2816
|
+
if (b5.d || b5.q) {
|
|
2817
|
+
res += "{\\vphantom{X}}";
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
if (b5.d) {
|
|
2821
|
+
res += "^{" + b5.d + "}";
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
if (b5.q) {
|
|
2825
|
+
res += "_{\\smash[t]{" + b5.q + "}}";
|
|
2826
|
+
}
|
|
2827
|
+
} else if (buf.dType === 'oxidation') {
|
|
2828
|
+
if (b5.d) {
|
|
2829
|
+
res += "{\\vphantom{X}}";
|
|
2830
|
+
res += "^{" + b5.d + "}";
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
if (b5.q) {
|
|
2834
|
+
res += "{\\vphantom{X}}";
|
|
2835
|
+
res += "_{\\smash[t]{" + b5.q + "}}";
|
|
2836
|
+
}
|
|
2837
|
+
} else {
|
|
2838
|
+
if (b5.q) {
|
|
2839
|
+
res += "{\\vphantom{X}}";
|
|
2840
|
+
res += "_{\\smash[t]{" + b5.q + "}}";
|
|
2841
|
+
}
|
|
2842
|
+
|
|
2843
|
+
if (b5.d) {
|
|
2844
|
+
res += "{\\vphantom{X}}";
|
|
2845
|
+
res += "^{" + b5.d + "}";
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
|
|
2849
|
+
break;
|
|
2850
|
+
|
|
2851
|
+
case 'rm':
|
|
2852
|
+
res = "\\mathrm{" + buf.p1 + "}";
|
|
2853
|
+
break;
|
|
2854
|
+
|
|
2855
|
+
case 'text':
|
|
2856
|
+
if (buf.p1.match(/[\^_]/)) {
|
|
2857
|
+
buf.p1 = buf.p1.replace(" ", "~").replace("-", "\\text{-}");
|
|
2858
|
+
res = "\\mathrm{" + buf.p1 + "}";
|
|
2859
|
+
} else {
|
|
2860
|
+
res = "\\text{" + buf.p1 + "}";
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2863
|
+
break;
|
|
2864
|
+
|
|
2865
|
+
case 'roman numeral':
|
|
2866
|
+
res = "\\mathrm{" + buf.p1 + "}";
|
|
2867
|
+
break;
|
|
2868
|
+
|
|
2869
|
+
case 'state of aggregation':
|
|
2870
|
+
res = "\\mskip2mu " + texify._goInner(buf.p1);
|
|
2871
|
+
break;
|
|
2872
|
+
|
|
2873
|
+
case 'state of aggregation subscript':
|
|
2874
|
+
res = "\\mskip1mu " + texify._goInner(buf.p1);
|
|
2875
|
+
break;
|
|
2876
|
+
|
|
2877
|
+
case 'bond':
|
|
2878
|
+
res = texify._getBond(buf.kind_);
|
|
2879
|
+
|
|
2880
|
+
if (!res) {
|
|
2881
|
+
throw ["MhchemErrorBond", "mhchem Error. Unknown bond type (" + buf.kind_ + ")"];
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
break;
|
|
2885
|
+
|
|
2886
|
+
case 'frac':
|
|
2887
|
+
var c = "\\frac{" + buf.p1 + "}{" + buf.p2 + "}";
|
|
2888
|
+
res = "\\mathchoice{\\textstyle" + c + "}{" + c + "}{" + c + "}{" + c + "}";
|
|
2889
|
+
break;
|
|
2890
|
+
|
|
2891
|
+
case 'pu-frac':
|
|
2892
|
+
var d = "\\frac{" + texify._goInner(buf.p1) + "}{" + texify._goInner(buf.p2) + "}";
|
|
2893
|
+
res = "\\mathchoice{\\textstyle" + d + "}{" + d + "}{" + d + "}{" + d + "}";
|
|
2894
|
+
break;
|
|
2895
|
+
|
|
2896
|
+
case 'tex-math':
|
|
2897
|
+
res = buf.p1 + " ";
|
|
2898
|
+
break;
|
|
2899
|
+
|
|
2900
|
+
case 'frac-ce':
|
|
2901
|
+
res = "\\frac{" + texify._goInner(buf.p1) + "}{" + texify._goInner(buf.p2) + "}";
|
|
2902
|
+
break;
|
|
2903
|
+
|
|
2904
|
+
case 'overset':
|
|
2905
|
+
res = "\\overset{" + texify._goInner(buf.p1) + "}{" + texify._goInner(buf.p2) + "}";
|
|
2906
|
+
break;
|
|
2907
|
+
|
|
2908
|
+
case 'underset':
|
|
2909
|
+
res = "\\underset{" + texify._goInner(buf.p1) + "}{" + texify._goInner(buf.p2) + "}";
|
|
2910
|
+
break;
|
|
2911
|
+
|
|
2912
|
+
case 'underbrace':
|
|
2913
|
+
res = "\\underbrace{" + texify._goInner(buf.p1) + "}_{" + texify._goInner(buf.p2) + "}";
|
|
2914
|
+
break;
|
|
2915
|
+
|
|
2916
|
+
case 'color':
|
|
2917
|
+
res = "{\\color{" + buf.color1 + "}{" + texify._goInner(buf.color2) + "}}";
|
|
2918
|
+
break;
|
|
2919
|
+
|
|
2920
|
+
case 'color0':
|
|
2921
|
+
res = "\\color{" + buf.color + "}";
|
|
2922
|
+
break;
|
|
2923
|
+
|
|
2924
|
+
case 'arrow':
|
|
2925
|
+
var b6 = {
|
|
2926
|
+
rd: texify._goInner(buf.rd),
|
|
2927
|
+
rq: texify._goInner(buf.rq)
|
|
2928
|
+
};
|
|
2929
|
+
|
|
2930
|
+
var arrow = "\\x" + texify._getArrow(buf.r);
|
|
2931
|
+
|
|
2932
|
+
if (b6.rq) {
|
|
2933
|
+
arrow += "[{" + b6.rq + "}]";
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
if (b6.rd) {
|
|
2937
|
+
arrow += "{" + b6.rd + "}";
|
|
2938
|
+
} else {
|
|
2939
|
+
arrow += "{}";
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
res = arrow;
|
|
2943
|
+
break;
|
|
2944
|
+
|
|
2945
|
+
case 'operator':
|
|
2946
|
+
res = texify._getOperator(buf.kind_);
|
|
2947
|
+
break;
|
|
2948
|
+
|
|
2949
|
+
case '1st-level escape':
|
|
2950
|
+
res = buf.p1 + " "; // &, \\\\, \\hlin
|
|
2951
|
+
|
|
2952
|
+
break;
|
|
2953
|
+
|
|
2954
|
+
case 'space':
|
|
2955
|
+
res = " ";
|
|
2956
|
+
break;
|
|
2957
|
+
|
|
2958
|
+
case 'entitySkip':
|
|
2959
|
+
res = "~";
|
|
2960
|
+
break;
|
|
2961
|
+
|
|
2962
|
+
case 'pu-space-1':
|
|
2963
|
+
res = "~";
|
|
2964
|
+
break;
|
|
2965
|
+
|
|
2966
|
+
case 'pu-space-2':
|
|
2967
|
+
res = "\\mkern3mu ";
|
|
2968
|
+
break;
|
|
2969
|
+
|
|
2970
|
+
case '1000 separator':
|
|
2971
|
+
res = "\\mkern2mu ";
|
|
2972
|
+
break;
|
|
2973
|
+
|
|
2974
|
+
case 'commaDecimal':
|
|
2975
|
+
res = "{,}";
|
|
2976
|
+
break;
|
|
2977
|
+
|
|
2978
|
+
case 'comma enumeration L':
|
|
2979
|
+
res = "{" + buf.p1 + "}\\mkern6mu ";
|
|
2980
|
+
break;
|
|
2981
|
+
|
|
2982
|
+
case 'comma enumeration M':
|
|
2983
|
+
res = "{" + buf.p1 + "}\\mkern3mu ";
|
|
2984
|
+
break;
|
|
2985
|
+
|
|
2986
|
+
case 'comma enumeration S':
|
|
2987
|
+
res = "{" + buf.p1 + "}\\mkern1mu ";
|
|
2988
|
+
break;
|
|
2989
|
+
|
|
2990
|
+
case 'hyphen':
|
|
2991
|
+
res = "\\text{-}";
|
|
2992
|
+
break;
|
|
2993
|
+
|
|
2994
|
+
case 'addition compound':
|
|
2995
|
+
res = "\\,{\\cdot}\\,";
|
|
2996
|
+
break;
|
|
2997
|
+
|
|
2998
|
+
case 'electron dot':
|
|
2999
|
+
res = "\\mkern1mu \\bullet\\mkern1mu ";
|
|
3000
|
+
break;
|
|
3001
|
+
|
|
3002
|
+
case 'KV x':
|
|
3003
|
+
res = "{\\times}";
|
|
3004
|
+
break;
|
|
3005
|
+
|
|
3006
|
+
case 'prime':
|
|
3007
|
+
res = "\\prime ";
|
|
3008
|
+
break;
|
|
3009
|
+
|
|
3010
|
+
case 'cdot':
|
|
3011
|
+
res = "\\cdot ";
|
|
3012
|
+
break;
|
|
3013
|
+
|
|
3014
|
+
case 'tight cdot':
|
|
3015
|
+
res = "\\mkern1mu{\\cdot}\\mkern1mu ";
|
|
3016
|
+
break;
|
|
3017
|
+
|
|
3018
|
+
case 'times':
|
|
3019
|
+
res = "\\times ";
|
|
3020
|
+
break;
|
|
3021
|
+
|
|
3022
|
+
case 'circa':
|
|
3023
|
+
res = "{\\sim}";
|
|
3024
|
+
break;
|
|
3025
|
+
|
|
3026
|
+
case '^':
|
|
3027
|
+
res = "uparrow";
|
|
3028
|
+
break;
|
|
3029
|
+
|
|
3030
|
+
case 'v':
|
|
3031
|
+
res = "downarrow";
|
|
3032
|
+
break;
|
|
3033
|
+
|
|
3034
|
+
case 'ellipsis':
|
|
3035
|
+
res = "\\ldots ";
|
|
3036
|
+
break;
|
|
3037
|
+
|
|
3038
|
+
case '/':
|
|
3039
|
+
res = "/";
|
|
3040
|
+
break;
|
|
3041
|
+
|
|
3042
|
+
case ' / ':
|
|
3043
|
+
res = "\\,/\\,";
|
|
3044
|
+
break;
|
|
3045
|
+
|
|
3046
|
+
default:
|
|
3047
|
+
assertNever(buf);
|
|
3048
|
+
throw ["MhchemBugT", "mhchem bug T. Please report."];
|
|
3049
|
+
// Missing texify rule or unknown MhchemParser output
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
assertString(res);
|
|
3053
|
+
return res;
|
|
3054
|
+
},
|
|
3055
|
+
_getArrow: function _getArrow(a) {
|
|
3056
|
+
switch (a) {
|
|
3057
|
+
case "->":
|
|
3058
|
+
return "rightarrow";
|
|
3059
|
+
|
|
3060
|
+
case "\u2192":
|
|
3061
|
+
return "rightarrow";
|
|
3062
|
+
|
|
3063
|
+
case "\u27F6":
|
|
3064
|
+
return "rightarrow";
|
|
3065
|
+
|
|
3066
|
+
case "<-":
|
|
3067
|
+
return "leftarrow";
|
|
3068
|
+
|
|
3069
|
+
case "<->":
|
|
3070
|
+
return "leftrightarrow";
|
|
3071
|
+
|
|
3072
|
+
case "<-->":
|
|
3073
|
+
return "rightleftarrows";
|
|
3074
|
+
|
|
3075
|
+
case "<=>":
|
|
3076
|
+
return "rightleftharpoons";
|
|
3077
|
+
|
|
3078
|
+
case "\u21CC":
|
|
3079
|
+
return "rightleftharpoons";
|
|
3080
|
+
|
|
3081
|
+
case "<=>>":
|
|
3082
|
+
return "rightequilibrium";
|
|
3083
|
+
|
|
3084
|
+
case "<<=>":
|
|
3085
|
+
return "leftequilibrium";
|
|
3086
|
+
|
|
3087
|
+
default:
|
|
3088
|
+
assertNever(a);
|
|
3089
|
+
throw ["MhchemBugT", "mhchem bug T. Please report."];
|
|
3090
|
+
}
|
|
3091
|
+
},
|
|
3092
|
+
_getBond: function _getBond(a) {
|
|
3093
|
+
switch (a) {
|
|
3094
|
+
case "-":
|
|
3095
|
+
return "{-}";
|
|
3096
|
+
|
|
3097
|
+
case "1":
|
|
3098
|
+
return "{-}";
|
|
3099
|
+
|
|
3100
|
+
case "=":
|
|
3101
|
+
return "{=}";
|
|
3102
|
+
|
|
3103
|
+
case "2":
|
|
3104
|
+
return "{=}";
|
|
3105
|
+
|
|
3106
|
+
case "#":
|
|
3107
|
+
return "{\\equiv}";
|
|
3108
|
+
|
|
3109
|
+
case "3":
|
|
3110
|
+
return "{\\equiv}";
|
|
3111
|
+
|
|
3112
|
+
case "~":
|
|
3113
|
+
return "{\\tripledash}";
|
|
3114
|
+
|
|
3115
|
+
case "~-":
|
|
3116
|
+
return "{\\mathrlap{\\raisebox{-.1em}{$-$}}\\raisebox{.1em}{$\\tripledash$}}";
|
|
3117
|
+
|
|
3118
|
+
case "~=":
|
|
3119
|
+
return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$\\tripledash$}}-}";
|
|
3120
|
+
|
|
3121
|
+
case "~--":
|
|
3122
|
+
return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$\\tripledash$}}-}";
|
|
3123
|
+
|
|
3124
|
+
case "-~-":
|
|
3125
|
+
return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$-$}}\\tripledash}";
|
|
3126
|
+
|
|
3127
|
+
case "...":
|
|
3128
|
+
return "{{\\cdot}{\\cdot}{\\cdot}}";
|
|
3129
|
+
|
|
3130
|
+
case "....":
|
|
3131
|
+
return "{{\\cdot}{\\cdot}{\\cdot}{\\cdot}}";
|
|
3132
|
+
|
|
3133
|
+
case "->":
|
|
3134
|
+
return "{\\rightarrow}";
|
|
3135
|
+
|
|
3136
|
+
case "<-":
|
|
3137
|
+
return "{\\leftarrow}";
|
|
3138
|
+
|
|
3139
|
+
case "<":
|
|
3140
|
+
return "{<}";
|
|
3141
|
+
|
|
3142
|
+
case ">":
|
|
3143
|
+
return "{>}";
|
|
3144
|
+
|
|
3145
|
+
default:
|
|
3146
|
+
assertNever(a);
|
|
3147
|
+
throw ["MhchemBugT", "mhchem bug T. Please report."];
|
|
3148
|
+
}
|
|
3149
|
+
},
|
|
3150
|
+
_getOperator: function _getOperator(a) {
|
|
3151
|
+
switch (a) {
|
|
3152
|
+
case "+":
|
|
3153
|
+
return " {}+{} ";
|
|
3154
|
+
|
|
3155
|
+
case "-":
|
|
3156
|
+
return " {}-{} ";
|
|
3157
|
+
|
|
3158
|
+
case "=":
|
|
3159
|
+
return " {}={} ";
|
|
3160
|
+
|
|
3161
|
+
case "<":
|
|
3162
|
+
return " {}<{} ";
|
|
3163
|
+
|
|
3164
|
+
case ">":
|
|
3165
|
+
return " {}>{} ";
|
|
3166
|
+
|
|
3167
|
+
case "<<":
|
|
3168
|
+
return " {}\\ll{} ";
|
|
3169
|
+
|
|
3170
|
+
case ">>":
|
|
3171
|
+
return " {}\\gg{} ";
|
|
3172
|
+
|
|
3173
|
+
case "\\pm":
|
|
3174
|
+
return " {}\\pm{} ";
|
|
3175
|
+
|
|
3176
|
+
case "\\approx":
|
|
3177
|
+
return " {}\\approx{} ";
|
|
3178
|
+
|
|
3179
|
+
case "$\\approx$":
|
|
3180
|
+
return " {}\\approx{} ";
|
|
3181
|
+
|
|
3182
|
+
case "v":
|
|
3183
|
+
return " \\downarrow{} ";
|
|
3184
|
+
|
|
3185
|
+
case "(v)":
|
|
3186
|
+
return " \\downarrow{} ";
|
|
3187
|
+
|
|
3188
|
+
case "^":
|
|
3189
|
+
return " \\uparrow{} ";
|
|
3190
|
+
|
|
3191
|
+
case "(^)":
|
|
3192
|
+
return " \\uparrow{} ";
|
|
3193
|
+
|
|
3194
|
+
default:
|
|
3195
|
+
assertNever(a);
|
|
3196
|
+
throw ["MhchemBugT", "mhchem bug T. Please report."];
|
|
3197
|
+
}
|
|
3198
|
+
}
|
|
3199
|
+
}; //
|
|
3200
|
+
// Helpers for code anaylsis
|
|
3201
|
+
// Will show type error at calling position
|
|
3202
|
+
//
|
|
3203
|
+
|
|
3204
|
+
/** @param {number} a */
|
|
3205
|
+
|
|
3206
|
+
function assertNever(a) {}
|
|
3207
|
+
/** @param {string} a */
|
|
3208
|
+
|
|
3209
|
+
|
|
3210
|
+
function assertString(a) {}
|
|
3211
|
+
}();
|
|
3212
|
+
__webpack_exports__ = __webpack_exports__.default;
|
|
3213
|
+
/******/ return __webpack_exports__;
|
|
3214
|
+
/******/ })()
|
|
3215
|
+
;
|
|
3216
|
+
});
|