katex 0.15.4 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/katex.mjs CHANGED
@@ -15789,7 +15789,67 @@ defineMacro("\\bra", "\\mathinner{\\langle{#1}|}");
15789
15789
  defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
15790
15790
  defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
15791
15791
  defineMacro("\\Bra", "\\left\\langle#1\\right|");
15792
- defineMacro("\\Ket", "\\left|#1\\right\\rangle"); //////////////////////////////////////////////////////////////////////
15792
+ defineMacro("\\Ket", "\\left|#1\\right\\rangle");
15793
+
15794
+ var braketHelper = one => context => {
15795
+ var left = context.consumeArg().tokens;
15796
+ var middle = context.consumeArg().tokens;
15797
+ var middleDouble = context.consumeArg().tokens;
15798
+ var right = context.consumeArg().tokens;
15799
+ var oldMiddle = context.macros.get("|");
15800
+ var oldMiddleDouble = context.macros.get("\\|");
15801
+ context.macros.beginGroup();
15802
+
15803
+ var midMacro = double => context => {
15804
+ if (one) {
15805
+ // Only modify the first instance of | or \|
15806
+ context.macros.set("|", oldMiddle);
15807
+
15808
+ if (middleDouble.length) {
15809
+ context.macros.set("\\|", oldMiddleDouble);
15810
+ }
15811
+ }
15812
+
15813
+ var doubled = double;
15814
+
15815
+ if (!double && middleDouble.length) {
15816
+ // Mimic \@ifnextchar
15817
+ var nextToken = context.future();
15818
+
15819
+ if (nextToken.text === "|") {
15820
+ context.popToken();
15821
+ doubled = true;
15822
+ }
15823
+ }
15824
+
15825
+ return {
15826
+ tokens: doubled ? middleDouble : middle,
15827
+ numArgs: 0
15828
+ };
15829
+ };
15830
+
15831
+ context.macros.set("|", midMacro(false));
15832
+
15833
+ if (middleDouble.length) {
15834
+ context.macros.set("\\|", midMacro(true));
15835
+ }
15836
+
15837
+ var arg = context.consumeArg().tokens;
15838
+ var expanded = context.expandTokens([...right, ...arg, ...left // reversed
15839
+ ]);
15840
+ context.macros.endGroup();
15841
+ return {
15842
+ tokens: expanded.reverse(),
15843
+ numArgs: 0
15844
+ };
15845
+ };
15846
+
15847
+ defineMacro("\\bra@ket", braketHelper(false));
15848
+ defineMacro("\\bra@set", braketHelper(true));
15849
+ defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" + "{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
15850
+ defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" + "{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
15851
+ defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}"); // has no support for special || or \|
15852
+ //////////////////////////////////////////////////////////////////////
15793
15853
  // actuarialangle.dtx
15794
15854
 
15795
15855
  defineMacro("\\angln", "{\\angl n}"); // Custom Khan Academy colors, should be moved to an optional package
@@ -16245,7 +16305,9 @@ class MacroExpander {
16245
16305
  return this.macros.has(name) ? this.expandTokens([new Token(name)]) : undefined;
16246
16306
  }
16247
16307
  /**
16248
- * Fully expand the given token stream and return the resulting list of tokens
16308
+ * Fully expand the given token stream and return the resulting list of
16309
+ * tokens. Note that the input tokens are in reverse order, but the
16310
+ * output tokens are in forward order.
16249
16311
  */
16250
16312
 
16251
16313
 
@@ -18106,7 +18168,7 @@ var katex = {
18106
18168
  /**
18107
18169
  * Current KaTeX version
18108
18170
  */
18109
- version: "0.15.4",
18171
+ version: "0.16.0",
18110
18172
 
18111
18173
  /**
18112
18174
  * Renders the given LaTeX into an HTML+MathML combination, and adds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.15.4",
3
+ "version": "0.16.0",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "exports": {
@@ -127,7 +127,7 @@
127
127
  "test": "yarn test:lint && yarn test:flow && yarn test:jest",
128
128
  "test:lint": "yarn test:lint:js && yarn test:lint:css",
129
129
  "test:lint:js": "eslint .",
130
- "test:lint:css": "stylelint src/katex.less static/main.css contrib/**/*.css website/static/**/*.css",
130
+ "test:lint:css": "stylelint src/katex.less static/main.css website/static/**/*.css",
131
131
  "test:flow": "flow",
132
132
  "test:jest": "jest",
133
133
  "test:jest:watch": "jest --watch",
@@ -356,7 +356,9 @@ export default class MacroExpander implements MacroContextInterface {
356
356
  }
357
357
 
358
358
  /**
359
- * Fully expand the given token stream and return the resulting list of tokens
359
+ * Fully expand the given token stream and return the resulting list of
360
+ * tokens. Note that the input tokens are in reverse order, but the
361
+ * output tokens are in forward order.
360
362
  */
361
363
  expandTokens(tokens: Token[]): Token[] {
362
364
  const output = [];
@@ -61,6 +61,13 @@ export interface MacroContextInterface {
61
61
  */
62
62
  expandMacroAsText(name: string): string | void;
63
63
 
64
+ /**
65
+ * Fully expand the given token stream and return the resulting list of
66
+ * tokens. Note that the input tokens are in reverse order, but the
67
+ * output tokens are in forward order.
68
+ */
69
+ expandTokens(tokens: Token[]): Token[];
70
+
64
71
  /**
65
72
  * Consume an argument from the token stream, and return the resulting array
66
73
  * of tokens and start/end token.
package/src/macros.js CHANGED
@@ -912,6 +912,58 @@ defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
912
912
  defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
913
913
  defineMacro("\\Bra", "\\left\\langle#1\\right|");
914
914
  defineMacro("\\Ket", "\\left|#1\\right\\rangle");
915
+ const braketHelper = (one) => (context) => {
916
+ const left = context.consumeArg().tokens;
917
+ const middle = context.consumeArg().tokens;
918
+ const middleDouble = context.consumeArg().tokens;
919
+ const right = context.consumeArg().tokens;
920
+ const oldMiddle = context.macros.get("|");
921
+ const oldMiddleDouble = context.macros.get("\\|");
922
+ context.macros.beginGroup();
923
+ const midMacro = (double) => (context) => {
924
+ if (one) {
925
+ // Only modify the first instance of | or \|
926
+ context.macros.set("|", oldMiddle);
927
+ if (middleDouble.length) {
928
+ context.macros.set("\\|", oldMiddleDouble);
929
+ }
930
+ }
931
+ let doubled = double;
932
+ if (!double && middleDouble.length) {
933
+ // Mimic \@ifnextchar
934
+ const nextToken = context.future();
935
+ if (nextToken.text === "|") {
936
+ context.popToken();
937
+ doubled = true;
938
+ }
939
+ }
940
+ return {
941
+ tokens: doubled ? middleDouble : middle,
942
+ numArgs: 0,
943
+ };
944
+ };
945
+ context.macros.set("|", midMacro(false));
946
+ if (middleDouble.length) {
947
+ context.macros.set("\\|", midMacro(true));
948
+ }
949
+ const arg = context.consumeArg().tokens;
950
+ const expanded = context.expandTokens([
951
+ ...right, ...arg, ...left, // reversed
952
+ ]);
953
+ context.macros.endGroup();
954
+ return {
955
+ tokens: expanded.reverse(),
956
+ numArgs: 0,
957
+ };
958
+ };
959
+ defineMacro("\\bra@ket", braketHelper(false));
960
+ defineMacro("\\bra@set", braketHelper(true));
961
+ defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" +
962
+ "{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
963
+ defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" +
964
+ "{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
965
+ defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}");
966
+ // has no support for special || or \|
915
967
 
916
968
  //////////////////////////////////////////////////////////////////////
917
969
  // actuarialangle.dtx
@@ -1,10 +0,0 @@
1
- /* Force selection of entire .katex/.katex-display blocks, so that we can
2
- * copy/paste the entire source code. If you omit this CSS, partial
3
- * selections of a formula will work, but will copy the ugly HTML
4
- * representation instead of the LaTeX source code. (Full selections will
5
- * still produce the LaTeX source code.)
6
- */
7
- .katex,
8
- .katex-display {
9
- user-select: all;
10
- }
@@ -1,6 +0,0 @@
1
- /**
2
- * This is the webpack entry point for KaTeX. As ECMAScript doesn't support
3
- * CSS modules natively, a separate entry point is used.
4
- */
5
- import './copy-tex.css';
6
- import './copy-tex.js';
@@ -1,235 +0,0 @@
1
- 0a1
2
- > /* eslint-disable */
3
- 5a7,22
4
- > * KaTeX mhchem.js
5
- > *
6
- > * This file implements a KaTeX version of mhchem version 3.3.0.
7
- > * It is adapted from MathJax/extensions/TeX/mhchem.js
8
- > * It differs from the MathJax version as follows:
9
- > * 1. The interface is changed so that it can be called from KaTeX, not MathJax.
10
- > * 2. \rlap and \llap are replaced with \mathrlap and \mathllap.
11
- > * 3. Four lines of code are edited in order to use \raisebox instead of \raise.
12
- > * 4. The reaction arrow code is simplified. All reaction arrows are rendered
13
- > * using KaTeX extensible arrows instead of building non-extensible arrows.
14
- > * 5. \tripledash vertical alignment is slightly adjusted.
15
- > *
16
- > * This code, as other KaTeX code, is released under the MIT license.
17
- > *
18
- > * /*************************************************************
19
- > *
20
- 33a51
21
- > // version: "3.3.0" for MathJax and KaTeX
22
- 35,37d52
23
- < MathJax.Extension["TeX/mhchem"] = {
24
- < version: "3.3.0"
25
- < };
26
- 39c54
27
- < MathJax.Hub.Register.StartupHook("TeX Jax Ready", function () {
28
- ---
29
- > // Add \ce, \pu, and \tripledash to the KaTeX macros.
30
- 41c56,58
31
- < var TEX = MathJax.InputJax.TeX;
32
- ---
33
- > katex.__defineMacro("\\ce", function(context) {
34
- > return chemParse(context.consumeArgs(1)[0], "ce")
35
- > });
36
- 43,47c60,62
37
- < //
38
- < // This is the main class for handing the \ce and related commands.
39
- < // Its main method is Parse() which takes the argument to \ce and
40
- < // returns the corresponding TeX string.
41
- < //
42
- ---
43
- > katex.__defineMacro("\\pu", function(context) {
44
- > return chemParse(context.consumeArgs(1)[0], "pu");
45
- > });
46
- 49,50c64,68
47
- < var CE = MathJax.Object.Subclass({
48
- < string: "", // the \ce string being parsed
49
- ---
50
- > // Needed for \bond for the ~ forms
51
- > // Raise by 2.56mu, not 2mu. We're raising a hyphen-minus, U+002D, not
52
- > // a mathematical minus, U+2212. So we need that extra 0.56.
53
- > katex.__defineMacro("\\tripledash", "{\\vphantom{-}\\raisebox{2.56mu}{$\\mkern2mu"
54
- > + "\\tiny\\text{-}\\mkern1mu\\text{-}\\mkern1mu\\text{-}\\mkern2mu$}}");
55
- 52,55c70
56
- < //
57
- < // Store the string when a CE object is created
58
- < //
59
- < Init: function (string) { this.string = string; },
60
- ---
61
- > import katex from "katex";
62
- 57,64c72,85
63
- < //
64
- < // This converts the CE string to a TeX string.
65
- < //
66
- < Parse: function (stateMachine) {
67
- < try {
68
- < return texify.go(mhchemParser.go(this.string, stateMachine));
69
- < } catch (ex) {
70
- < TEX.Error(ex);
71
- ---
72
- > //
73
- > // This is the main function for handing the \ce and \pu commands.
74
- > // It takes the argument to \ce or \pu and returns the corresponding TeX string.
75
- > //
76
- >
77
- > var chemParse = function (tokens, stateMachine) {
78
- > // Recreate the argument string from KaTeX's array of tokens.
79
- > var str = "";
80
- > var expectedLoc = tokens[tokens.length - 1].loc.start
81
- > for (var i = tokens.length - 1; i >= 0; i--) {
82
- > if(tokens[i].loc.start > expectedLoc) {
83
- > // context.consumeArgs has eaten a space.
84
- > str += " ";
85
- > expectedLoc = tokens[i].loc.start;
86
- 65a87,88
87
- > str += tokens[i].text;
88
- > expectedLoc += tokens[i].text.length;
89
- 67c90,92
90
- < });
91
- ---
92
- > var tex = texify.go(mhchemParser.go(str, stateMachine));
93
- > return tex;
94
- > };
95
- 1405,1406c1430,1431
96
- < res += "^{\\smash[t]{\\vphantom{2}}\\llap{"+(b5.b||"")+"}}";
97
- < res += "_{\\vphantom{2}\\llap{\\smash[t]{"+(b5.p||"")+"}}}";
98
- ---
99
- > res += "^{\\smash[t]{\\vphantom{2}}\\mathllap{"+(b5.b||"")+"}}";
100
- > res += "_{\\vphantom{2}\\mathllap{\\smash[t]{"+(b5.p||"")+"}}}";
101
- 1508,1520c1533,1536
102
- < var arrow = texify._getArrow(buf.r);
103
- < if (b6.rd || b6.rq) {
104
- < if (buf.r === "<=>" || buf.r === "<=>>" || buf.r === "<<=>" || buf.r === "<-->") {
105
- < // arrows that cannot stretch correctly yet, https://github.com/mathjax/MathJax/issues/1491
106
- < arrow = "\\long"+arrow;
107
- < if (b6.rd) { arrow = "\\overset{"+b6.rd+"}{"+arrow+"}"; }
108
- < if (b6.rq) { arrow = "\\underset{\\lower7mu{"+b6.rq+"}}{"+arrow+"}"; }
109
- < arrow = " {}\\mathrel{"+arrow+"}{} ";
110
- < } else {
111
- < if (b6.rq) { arrow += "[{"+b6.rq+"}]"; }
112
- < arrow += "{"+b6.rd+"}";
113
- < arrow = " {}\\mathrel{\\x"+arrow+"}{} ";
114
- < }
115
- ---
116
- > var arrow = "\\x" + texify._getArrow(buf.r);
117
- > if (b6.rq) { arrow += "[{" + b6.rq + "}]"; }
118
- > if (b6.rd) {
119
- > arrow += "{" + b6.rd + "}";
120
- 1522c1538
121
- < arrow = " {}\\mathrel{\\long"+arrow+"}{} ";
122
- ---
123
- > arrow += "{}";
124
- 1615c1631
125
- < case "<-->": return "leftrightarrows";
126
- ---
127
- > case "<-->": return "rightleftarrows";
128
- 1618,1619c1634,1635
129
- < case "<=>>": return "Rightleftharpoons";
130
- < case "<<=>": return "Leftrightharpoons";
131
- ---
132
- > case "<=>>": return "rightequilibrium";
133
- > case "<<=>": return "leftequilibrium";
134
- 1634,1637c1650,1653
135
- < case "~-": return "{\\rlap{\\lower.1em{-}}\\raise.1em{\\tripledash}}";
136
- < case "~=": return "{\\rlap{\\lower.2em{-}}\\rlap{\\raise.2em{\\tripledash}}-}";
137
- < case "~--": return "{\\rlap{\\lower.2em{-}}\\rlap{\\raise.2em{\\tripledash}}-}";
138
- < case "-~-": return "{\\rlap{\\lower.2em{-}}\\rlap{\\raise.2em{-}}\\tripledash}";
139
- ---
140
- > case "~-": return "{\\mathrlap{\\raisebox{-.1em}{$-$}}\\raisebox{.1em}{$\\tripledash$}}";
141
- > case "~=": return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$\\tripledash$}}-}";
142
- > case "~--": return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$\\tripledash$}}-}";
143
- > case "-~-": return "{\\mathrlap{\\raisebox{-.2em}{$-$}}\\mathrlap{\\raisebox{.2em}{$-$}}\\tripledash}";
144
- 1680,1770d1695
145
- <
146
- < //
147
- < // MathJax definitions
148
- < //
149
- < MathJax.Extension["TeX/mhchem"].CE = CE;
150
- <
151
- < /***************************************************************************/
152
- <
153
- < TEX.Definitions.Add({
154
- < macros: {
155
- < //
156
- < // Set up the macros for chemistry
157
- < //
158
- < ce: "CE",
159
- < pu: "PU",
160
- <
161
- < //
162
- < // Make these load AMSmath package (redefined below when loaded)
163
- < //
164
- < xleftrightarrow: ["Extension", "AMSmath"],
165
- < xrightleftharpoons: ["Extension", "AMSmath"],
166
- < xRightleftharpoons: ["Extension", "AMSmath"],
167
- < xLeftrightharpoons: ["Extension", "AMSmath"],
168
- <
169
- < // FIXME: These don't work well in FF NativeMML mode
170
- < longrightleftharpoons: ["Macro", "\\stackrel{\\textstyle{-}\\!\\!{\\rightharpoonup}}{\\smash{{\\leftharpoondown}\\!\\!{-}}}"],
171
- < longRightleftharpoons: ["Macro", "\\stackrel{\\textstyle{-}\\!\\!{\\rightharpoonup}}{\\smash{\\leftharpoondown}}"],
172
- < longLeftrightharpoons: ["Macro", "\\stackrel{\\textstyle\\vphantom{{-}}{\\rightharpoonup}}{\\smash{{\\leftharpoondown}\\!\\!{-}}}"],
173
- < longleftrightarrows: ["Macro", "\\stackrel{\\longrightarrow}{\\smash{\\longleftarrow}\\Rule{0px}{.25em}{0px}}"],
174
- <
175
- < //
176
- < // Needed for \bond for the ~ forms
177
- < // Not perfectly aligned when zoomed in, but on 100%
178
- < //
179
- < tripledash: ["Macro", "\\vphantom{-}\\raise2mu{\\kern2mu\\tiny\\text{-}\\kern1mu\\text{-}\\kern1mu\\text{-}\\kern2mu}"]
180
- < },
181
- < }, null, true);
182
- <
183
- < if (!MathJax.Extension["TeX/AMSmath"]) {
184
- < TEX.Definitions.Add({
185
- < macros: {
186
- < xrightarrow: ["Extension", "AMSmath"],
187
- < xleftarrow: ["Extension", "AMSmath"]
188
- < }
189
- < }, null, true);
190
- < }
191
- <
192
- < //
193
- < // These arrows need to wait until AMSmath is loaded
194
- < //
195
- < MathJax.Hub.Register.StartupHook("TeX AMSmath Ready", function () {
196
- < TEX.Definitions.Add({
197
- < macros: {
198
- < //
199
- < // Some of these are hacks for now
200
- < //
201
- < xleftrightarrow: ["xArrow", 0x2194, 6, 6],
202
- < xrightleftharpoons: ["xArrow", 0x21CC, 5, 7], // FIXME: doesn't stretch in HTML-CSS output
203
- < xRightleftharpoons: ["xArrow", 0x21CC, 5, 7], // FIXME: how should this be handled?
204
- < xLeftrightharpoons: ["xArrow", 0x21CC, 5, 7]
205
- < }
206
- < }, null, true);
207
- < });
208
- <
209
- < TEX.Parse.Augment({
210
- <
211
- < //
212
- < // Implements \ce and friends
213
- < //
214
- < CE: function (name) {
215
- < var arg = this.GetArgument(name);
216
- < var tex = CE(arg).Parse();
217
- < this.string = tex + this.string.substr(this.i); this.i = 0;
218
- < },
219
- <
220
- < PU: function (name) {
221
- < var arg = this.GetArgument(name);
222
- < var tex = CE(arg).Parse('pu');
223
- < this.string = tex + this.string.substr(this.i); this.i = 0;
224
- < }
225
- <
226
- < });
227
- <
228
- < //
229
- < // Indicate that the extension is ready
230
- < //
231
- < MathJax.Hub.Startup.signal.Post("TeX mhchem Ready");
232
- <
233
- < });
234
- <
235
- < MathJax.Ajax.loadComplete("[mhchem]/unpacked/mhchem.js");
@@ -1,13 +0,0 @@
1
- /* Force selection of entire .katex/.katex-display blocks, so that we can
2
- * copy/paste the entire source code. If you omit this CSS, partial
3
- * selections of a formula will work, but will copy the ugly HTML
4
- * representation instead of the LaTeX source code. (Full selections will
5
- * still produce the LaTeX source code.)
6
- */
7
- .katex,
8
- .katex-display {
9
- -webkit-user-select: all;
10
- -moz-user-select: all;
11
- user-select: all;
12
- }
13
-
@@ -1 +0,0 @@
1
- .katex,.katex-display{-webkit-user-select:all;-moz-user-select:all;user-select:all}