@khanacademy/perseus-editor 2.3.7 → 2.3.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Perseus editors",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "2.3.7",
6
+ "version": "2.3.9",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@khanacademy/kas": "^0.3.1",
25
25
  "@khanacademy/kmath": "^0.1.1",
26
- "@khanacademy/perseus": "^6.4.3"
26
+ "@khanacademy/perseus": "^6.5.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@khanacademy/wonder-blocks-button": "^4.0.8",
package/src/editor.tsx CHANGED
@@ -10,6 +10,12 @@ import {
10
10
  import $ from "jquery";
11
11
  // eslint-disable-next-line import/no-unresolved, import/no-extraneous-dependencies
12
12
  import katex from "katex";
13
+ // ./katex-mhchem is imported for side effects. It adds the mhchem extension
14
+ // to KaTeX, which is needed to render chemistry expressions. This prevents
15
+ // spurious KaTeX errors from displaying in the editor for every chemistry
16
+ // expression.
17
+ // eslint-disable-next-line import/no-unassigned-import
18
+ import "./katex-mhchem";
13
19
  import * as React from "react";
14
20
  import * as ReactDOM from "react-dom";
15
21
  import _ from "underscore";
@@ -0,0 +1,73 @@
1
+ /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
2
+ /* vim: set ts=2 et sw=2 tw=80: */
3
+
4
+ /*************************************************************
5
+ *
6
+ * KaTeX mhchem.js
7
+ *
8
+ * This file implements a KaTeX version of mhchem version 3.3.0.
9
+ * It is adapted from MathJax/extensions/TeX/mhchem.js
10
+ * It differs from the MathJax version as follows:
11
+ * 1. The interface is changed so that it can be called from KaTeX, not MathJax.
12
+ * 2. \rlap and \llap are replaced with \mathrlap and \mathllap.
13
+ * 3. Four lines of code are edited in order to use \raisebox instead of \raise.
14
+ * 4. The reaction arrow code is simplified. All reaction arrows are rendered
15
+ * using KaTeX extensible arrows instead of building non-extensible arrows.
16
+ * 5. \tripledash vertical alignment is slightly adjusted.
17
+ *
18
+ * This code, as other KaTeX code, is released under the MIT license.
19
+ *
20
+ * /*************************************************************
21
+ *
22
+ * MathJax/extensions/TeX/mhchem.js
23
+ *
24
+ * Implements the \ce command for handling chemical formulas
25
+ * from the mhchem LaTeX package.
26
+ *
27
+ * ---------------------------------------------------------------------
28
+ *
29
+ * Copyright (c) 2011-2015 The MathJax Consortium
30
+ * Copyright (c) 2015-2018 Martin Hensel
31
+ *
32
+ * Licensed under the Apache License, Version 2.0 (the "License");
33
+ * you may not use this file except in compliance with the License.
34
+ * You may obtain a copy of the License at
35
+ *
36
+ * http://www.apache.org/licenses/LICENSE-2.0
37
+ *
38
+ * Unless required by applicable law or agreed to in writing, software
39
+ * distributed under the License is distributed on an "AS IS" BASIS,
40
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41
+ * See the License for the specific language governing permissions and
42
+ * limitations under the License.
43
+ */
44
+
45
+ //
46
+ // Coding Style
47
+ // - use '' for identifiers that can by minified/uglified
48
+ // - use "" for strings that need to stay untouched
49
+
50
+ // version: "3.3.0" for MathJax and KaTeX
51
+
52
+ import katex from "katex";
53
+
54
+ import {chemParse} from "./parser";
55
+
56
+ // Add \ce, \pu, and \tripledash to the KaTeX macros.
57
+
58
+ katex.__defineMacro("\\ce", function (context) {
59
+ return chemParse(context.consumeArgs(1)[0], "ce");
60
+ });
61
+
62
+ katex.__defineMacro("\\pu", function (context) {
63
+ return chemParse(context.consumeArgs(1)[0], "pu");
64
+ });
65
+
66
+ // Needed for \bond for the ~ forms
67
+ // Raise by 2.56mu, not 2mu. We're raising a hyphen-minus, U+002D, not
68
+ // a mathematical minus, U+2212. So we need that extra 0.56.
69
+ katex.__defineMacro(
70
+ "\\tripledash",
71
+ "{\\vphantom{-}\\raisebox{2.56mu}{$\\mkern2mu" +
72
+ "\\tiny\\text{-}\\mkern1mu\\text{-}\\mkern1mu\\text{-}\\mkern2mu$}}",
73
+ );