llms-py 2.0.34__py3-none-any.whl → 3.0.0__py3-none-any.whl

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