katex 0.16.15 → 0.16.17
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/README.md +3 -3
- package/contrib/copy-tex/README.md +2 -2
- package/contrib/mathtex-script-type/README.md +5 -5
- package/contrib/mhchem/README.md +1 -1
- package/dist/README.md +3 -3
- package/dist/katex.css +1 -1
- package/dist/katex.js +65 -18
- package/dist/katex.min.css +1 -1
- package/dist/katex.min.js +1 -1
- package/dist/katex.mjs +67 -22
- package/katex.js +33 -11
- package/package.json +9 -3
- package/src/buildMathML.js +42 -6
- package/src/mathMLTree.js +12 -1
package/dist/katex.mjs
CHANGED
|
@@ -6677,7 +6677,19 @@ class MathNode {
|
|
|
6677
6677
|
}
|
|
6678
6678
|
|
|
6679
6679
|
for (var i = 0; i < this.children.length; i++) {
|
|
6680
|
-
|
|
6680
|
+
// Combine multiple TextNodes into one TextNode, to prevent
|
|
6681
|
+
// screen readers from reading each as a separate word [#3995]
|
|
6682
|
+
if (this.children[i] instanceof TextNode && this.children[i + 1] instanceof TextNode) {
|
|
6683
|
+
var text = this.children[i].toText() + this.children[++i].toText();
|
|
6684
|
+
|
|
6685
|
+
while (this.children[i + 1] instanceof TextNode) {
|
|
6686
|
+
text += this.children[++i].toText();
|
|
6687
|
+
}
|
|
6688
|
+
|
|
6689
|
+
node.appendChild(new TextNode(text).toNode());
|
|
6690
|
+
} else {
|
|
6691
|
+
node.appendChild(this.children[i].toNode());
|
|
6692
|
+
}
|
|
6681
6693
|
}
|
|
6682
6694
|
|
|
6683
6695
|
return node;
|
|
@@ -6947,12 +6959,34 @@ var getVariant = function getVariant(group, options) {
|
|
|
6947
6959
|
|
|
6948
6960
|
return null;
|
|
6949
6961
|
};
|
|
6962
|
+
/**
|
|
6963
|
+
* Check for <mi>.</mi> which is how a dot renders in MathML,
|
|
6964
|
+
* or <mo separator="true" lspace="0em" rspace="0em">,</mo>
|
|
6965
|
+
* which is how a braced comma {,} renders in MathML
|
|
6966
|
+
*/
|
|
6967
|
+
|
|
6968
|
+
function isNumberPunctuation(group) {
|
|
6969
|
+
if (!group) {
|
|
6970
|
+
return false;
|
|
6971
|
+
}
|
|
6972
|
+
|
|
6973
|
+
if (group.type === 'mi' && group.children.length === 1) {
|
|
6974
|
+
var child = group.children[0];
|
|
6975
|
+
return child instanceof TextNode && child.text === '.';
|
|
6976
|
+
} else if (group.type === 'mo' && group.children.length === 1 && group.getAttribute('separator') === 'true' && group.getAttribute('lspace') === '0em' && group.getAttribute('rspace') === '0em') {
|
|
6977
|
+
var _child = group.children[0];
|
|
6978
|
+
return _child instanceof TextNode && _child.text === ',';
|
|
6979
|
+
} else {
|
|
6980
|
+
return false;
|
|
6981
|
+
}
|
|
6982
|
+
}
|
|
6950
6983
|
/**
|
|
6951
6984
|
* Takes a list of nodes, builds them, and returns a list of the generated
|
|
6952
6985
|
* MathML nodes. Also combine consecutive <mtext> outputs into a single
|
|
6953
6986
|
* <mtext> tag.
|
|
6954
6987
|
*/
|
|
6955
6988
|
|
|
6989
|
+
|
|
6956
6990
|
var buildExpression = function buildExpression(expression, options, isOrdgroup) {
|
|
6957
6991
|
if (expression.length === 1) {
|
|
6958
6992
|
var group = buildGroup(expression[0], options);
|
|
@@ -6981,22 +7015,30 @@ var buildExpression = function buildExpression(expression, options, isOrdgroup)
|
|
|
6981
7015
|
} else if (_group.type === 'mn' && lastGroup.type === 'mn') {
|
|
6982
7016
|
lastGroup.children.push(..._group.children);
|
|
6983
7017
|
continue; // Concatenate <mn>...</mn> followed by <mi>.</mi>
|
|
6984
|
-
} else if (_group
|
|
6985
|
-
|
|
7018
|
+
} else if (isNumberPunctuation(_group) && lastGroup.type === 'mn') {
|
|
7019
|
+
lastGroup.children.push(..._group.children);
|
|
7020
|
+
continue; // Concatenate <mi>.</mi> followed by <mn>...</mn>
|
|
7021
|
+
} else if (_group.type === 'mn' && isNumberPunctuation(lastGroup)) {
|
|
7022
|
+
_group.children = [...lastGroup.children, ..._group.children];
|
|
7023
|
+
groups.pop(); // Put preceding <mn>...</mn> or <mi>.</mi> inside base of
|
|
7024
|
+
// <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
|
|
7025
|
+
} else if ((_group.type === 'msup' || _group.type === 'msub') && _group.children.length >= 1 && (lastGroup.type === 'mn' || isNumberPunctuation(lastGroup))) {
|
|
7026
|
+
var base = _group.children[0];
|
|
7027
|
+
|
|
7028
|
+
if (base instanceof MathNode && base.type === 'mn') {
|
|
7029
|
+
base.children = [...lastGroup.children, ...base.children];
|
|
7030
|
+
groups.pop();
|
|
7031
|
+
} // \not
|
|
6986
7032
|
|
|
6987
|
-
if (child instanceof TextNode && child.text === '.') {
|
|
6988
|
-
lastGroup.children.push(..._group.children);
|
|
6989
|
-
continue;
|
|
6990
|
-
}
|
|
6991
7033
|
} else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
|
|
6992
7034
|
var lastChild = lastGroup.children[0];
|
|
6993
7035
|
|
|
6994
7036
|
if (lastChild instanceof TextNode && lastChild.text === '\u0338' && (_group.type === 'mo' || _group.type === 'mi' || _group.type === 'mn')) {
|
|
6995
|
-
var
|
|
7037
|
+
var child = _group.children[0];
|
|
6996
7038
|
|
|
6997
|
-
if (
|
|
7039
|
+
if (child instanceof TextNode && child.text.length > 0) {
|
|
6998
7040
|
// Overlay with combining character long solidus
|
|
6999
|
-
|
|
7041
|
+
child.text = child.text.slice(0, 1) + "\u0338" + child.text.slice(1);
|
|
7000
7042
|
groups.pop();
|
|
7001
7043
|
}
|
|
7002
7044
|
}
|
|
@@ -18371,11 +18413,21 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
|
|
|
18371
18413
|
}
|
|
18372
18414
|
};
|
|
18373
18415
|
|
|
18416
|
+
var version = "0.16.17";
|
|
18417
|
+
var __domTree = {
|
|
18418
|
+
Span,
|
|
18419
|
+
Anchor,
|
|
18420
|
+
SymbolNode,
|
|
18421
|
+
SvgNode,
|
|
18422
|
+
PathNode,
|
|
18423
|
+
LineNode
|
|
18424
|
+
}; // ESM exports
|
|
18425
|
+
|
|
18374
18426
|
var katex = {
|
|
18375
18427
|
/**
|
|
18376
18428
|
* Current KaTeX version
|
|
18377
18429
|
*/
|
|
18378
|
-
version
|
|
18430
|
+
version,
|
|
18379
18431
|
|
|
18380
18432
|
/**
|
|
18381
18433
|
* Renders the given LaTeX into an HTML+MathML combination, and adds
|
|
@@ -18395,7 +18447,7 @@ var katex = {
|
|
|
18395
18447
|
ParseError,
|
|
18396
18448
|
|
|
18397
18449
|
/**
|
|
18398
|
-
* The
|
|
18450
|
+
* The schema of Settings
|
|
18399
18451
|
*/
|
|
18400
18452
|
SETTINGS_SCHEMA,
|
|
18401
18453
|
|
|
@@ -18455,18 +18507,11 @@ var katex = {
|
|
|
18455
18507
|
/**
|
|
18456
18508
|
* Expose the dom tree node types, which can be useful for type checking nodes.
|
|
18457
18509
|
*
|
|
18458
|
-
* NOTE:
|
|
18510
|
+
* NOTE: These methods are not currently recommended for public use.
|
|
18459
18511
|
* The internal tree representation is unstable and is very likely
|
|
18460
18512
|
* to change. Use at your own risk.
|
|
18461
18513
|
*/
|
|
18462
|
-
__domTree
|
|
18463
|
-
Span,
|
|
18464
|
-
Anchor,
|
|
18465
|
-
SymbolNode,
|
|
18466
|
-
SvgNode,
|
|
18467
|
-
PathNode,
|
|
18468
|
-
LineNode
|
|
18469
|
-
}
|
|
18514
|
+
__domTree
|
|
18470
18515
|
};
|
|
18471
18516
|
|
|
18472
|
-
export { katex as default };
|
|
18517
|
+
export { ParseError, SETTINGS_SCHEMA, defineFunction as __defineFunction, defineMacro as __defineMacro, defineSymbol as __defineSymbol, __domTree, generateParseTree as __parse, renderToDomTree as __renderToDomTree, renderToHTMLTree as __renderToHTMLTree, setFontMetrics as __setFontMetrics, katex as default, render, renderToString, version };
|
package/katex.js
CHANGED
|
@@ -138,11 +138,40 @@ const renderToHTMLTree = function(
|
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
+
const version = __VERSION__;
|
|
142
|
+
|
|
143
|
+
const __domTree = {
|
|
144
|
+
Span,
|
|
145
|
+
Anchor,
|
|
146
|
+
SymbolNode,
|
|
147
|
+
SvgNode,
|
|
148
|
+
PathNode,
|
|
149
|
+
LineNode,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// ESM exports
|
|
153
|
+
export {
|
|
154
|
+
version,
|
|
155
|
+
render,
|
|
156
|
+
renderToString,
|
|
157
|
+
ParseError,
|
|
158
|
+
SETTINGS_SCHEMA,
|
|
159
|
+
generateParseTree as __parse,
|
|
160
|
+
renderToDomTree as __renderToDomTree,
|
|
161
|
+
renderToHTMLTree as __renderToHTMLTree,
|
|
162
|
+
setFontMetrics as __setFontMetrics,
|
|
163
|
+
defineSymbol as __defineSymbol,
|
|
164
|
+
defineFunction as __defineFunction,
|
|
165
|
+
defineMacro as __defineMacro,
|
|
166
|
+
__domTree,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// CJS exports and ESM default export
|
|
141
170
|
export default {
|
|
142
171
|
/**
|
|
143
172
|
* Current KaTeX version
|
|
144
173
|
*/
|
|
145
|
-
version
|
|
174
|
+
version,
|
|
146
175
|
/**
|
|
147
176
|
* Renders the given LaTeX into an HTML+MathML combination, and adds
|
|
148
177
|
* it as a child to the specified DOM node.
|
|
@@ -158,7 +187,7 @@ export default {
|
|
|
158
187
|
*/
|
|
159
188
|
ParseError,
|
|
160
189
|
/**
|
|
161
|
-
* The
|
|
190
|
+
* The schema of Settings
|
|
162
191
|
*/
|
|
163
192
|
SETTINGS_SCHEMA,
|
|
164
193
|
/**
|
|
@@ -210,16 +239,9 @@ export default {
|
|
|
210
239
|
/**
|
|
211
240
|
* Expose the dom tree node types, which can be useful for type checking nodes.
|
|
212
241
|
*
|
|
213
|
-
* NOTE:
|
|
242
|
+
* NOTE: These methods are not currently recommended for public use.
|
|
214
243
|
* The internal tree representation is unstable and is very likely
|
|
215
244
|
* to change. Use at your own risk.
|
|
216
245
|
*/
|
|
217
|
-
__domTree
|
|
218
|
-
Span,
|
|
219
|
-
Anchor,
|
|
220
|
-
SymbolNode,
|
|
221
|
-
SvgNode,
|
|
222
|
-
PathNode,
|
|
223
|
-
LineNode,
|
|
224
|
-
},
|
|
246
|
+
__domTree,
|
|
225
247
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "katex",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.17",
|
|
4
4
|
"description": "Fast math typesetting for the web.",
|
|
5
5
|
"main": "dist/katex.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
|
-
"require":
|
|
9
|
-
|
|
8
|
+
"require": {
|
|
9
|
+
"types": "./types/katex.d.ts",
|
|
10
|
+
"default": "./dist/katex.js"
|
|
11
|
+
},
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./types/katex.d.ts",
|
|
14
|
+
"default": "./dist/katex.mjs"
|
|
15
|
+
}
|
|
10
16
|
},
|
|
11
17
|
"./contrib/auto-render": {
|
|
12
18
|
"require": "./dist/contrib/auto-render.js",
|
package/src/buildMathML.js
CHANGED
|
@@ -128,6 +128,30 @@ export const getVariant = function(
|
|
|
128
128
|
return null;
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Check for <mi>.</mi> which is how a dot renders in MathML,
|
|
133
|
+
* or <mo separator="true" lspace="0em" rspace="0em">,</mo>
|
|
134
|
+
* which is how a braced comma {,} renders in MathML
|
|
135
|
+
*/
|
|
136
|
+
function isNumberPunctuation(group: ?MathNode): boolean {
|
|
137
|
+
if (!group) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (group.type === 'mi' && group.children.length === 1) {
|
|
141
|
+
const child = group.children[0];
|
|
142
|
+
return child instanceof TextNode && child.text === '.';
|
|
143
|
+
} else if (group.type === 'mo' && group.children.length === 1 &&
|
|
144
|
+
group.getAttribute('separator') === 'true' &&
|
|
145
|
+
group.getAttribute('lspace') === '0em' &&
|
|
146
|
+
group.getAttribute('rspace') === '0em'
|
|
147
|
+
) {
|
|
148
|
+
const child = group.children[0];
|
|
149
|
+
return child instanceof TextNode && child.text === ',';
|
|
150
|
+
} else {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
131
155
|
/**
|
|
132
156
|
* Takes a list of nodes, builds them, and returns a list of the generated
|
|
133
157
|
* MathML nodes. Also combine consecutive <mtext> outputs into a single
|
|
@@ -165,13 +189,25 @@ export const buildExpression = function(
|
|
|
165
189
|
lastGroup.children.push(...group.children);
|
|
166
190
|
continue;
|
|
167
191
|
// Concatenate <mn>...</mn> followed by <mi>.</mi>
|
|
168
|
-
} else if (group.type === '
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
192
|
+
} else if (isNumberPunctuation(group) && lastGroup.type === 'mn') {
|
|
193
|
+
lastGroup.children.push(...group.children);
|
|
194
|
+
continue;
|
|
195
|
+
// Concatenate <mi>.</mi> followed by <mn>...</mn>
|
|
196
|
+
} else if (group.type === 'mn' && isNumberPunctuation(lastGroup)) {
|
|
197
|
+
group.children = [...lastGroup.children, ...group.children];
|
|
198
|
+
groups.pop();
|
|
199
|
+
// Put preceding <mn>...</mn> or <mi>.</mi> inside base of
|
|
200
|
+
// <msup><mn>...base...</mn>...exponent...</msup> (or <msub>)
|
|
201
|
+
} else if ((group.type === 'msup' || group.type === 'msub') &&
|
|
202
|
+
group.children.length >= 1 &&
|
|
203
|
+
(lastGroup.type === 'mn' || isNumberPunctuation(lastGroup))
|
|
204
|
+
) {
|
|
205
|
+
const base = group.children[0];
|
|
206
|
+
if (base instanceof MathNode && base.type === 'mn') {
|
|
207
|
+
base.children = [...lastGroup.children, ...base.children];
|
|
208
|
+
groups.pop();
|
|
174
209
|
}
|
|
210
|
+
// \not
|
|
175
211
|
} else if (lastGroup.type === 'mi' && lastGroup.children.length === 1) {
|
|
176
212
|
const lastChild = lastGroup.children[0];
|
|
177
213
|
if (lastChild instanceof TextNode && lastChild.text === '\u0338' &&
|
package/src/mathMLTree.js
CHANGED
|
@@ -95,7 +95,18 @@ export class MathNode implements MathDomNode {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
for (let i = 0; i < this.children.length; i++) {
|
|
98
|
-
|
|
98
|
+
// Combine multiple TextNodes into one TextNode, to prevent
|
|
99
|
+
// screen readers from reading each as a separate word [#3995]
|
|
100
|
+
if (this.children[i] instanceof TextNode &&
|
|
101
|
+
this.children[i + 1] instanceof TextNode) {
|
|
102
|
+
let text = this.children[i].toText() + this.children[++i].toText();
|
|
103
|
+
while (this.children[i + 1] instanceof TextNode) {
|
|
104
|
+
text += this.children[++i].toText();
|
|
105
|
+
}
|
|
106
|
+
node.appendChild(new TextNode(text).toNode());
|
|
107
|
+
} else {
|
|
108
|
+
node.appendChild(this.children[i].toNode());
|
|
109
|
+
}
|
|
99
110
|
}
|
|
100
111
|
|
|
101
112
|
return node;
|