You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3215 lines
78 KiB

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