katex 0.15.3 → 0.15.4

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
@@ -16366,6 +16366,113 @@ class MacroExpander {
16366
16366
 
16367
16367
  }
16368
16368
 
16369
+ // Helpers for Parser.js handling of Unicode (sub|super)script characters.
16370
+ var unicodeSubRegEx = /^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/;
16371
+ var uSubsAndSups = Object.freeze({
16372
+ '₊': '+',
16373
+ '₋': '-',
16374
+ '₌': '=',
16375
+ '₍': '(',
16376
+ '₎': ')',
16377
+ '₀': '0',
16378
+ '₁': '1',
16379
+ '₂': '2',
16380
+ '₃': '3',
16381
+ '₄': '4',
16382
+ '₅': '5',
16383
+ '₆': '6',
16384
+ '₇': '7',
16385
+ '₈': '8',
16386
+ '₉': '9',
16387
+ '\u2090': 'a',
16388
+ '\u2091': 'e',
16389
+ '\u2095': 'h',
16390
+ '\u1D62': 'i',
16391
+ '\u2C7C': 'j',
16392
+ '\u2096': 'k',
16393
+ '\u2097': 'l',
16394
+ '\u2098': 'm',
16395
+ '\u2099': 'n',
16396
+ '\u2092': 'o',
16397
+ '\u209A': 'p',
16398
+ '\u1D63': 'r',
16399
+ '\u209B': 's',
16400
+ '\u209C': 't',
16401
+ '\u1D64': 'u',
16402
+ '\u1D65': 'v',
16403
+ '\u2093': 'x',
16404
+ '\u1D66': 'β',
16405
+ '\u1D67': 'γ',
16406
+ '\u1D68': 'ρ',
16407
+ '\u1D69': '\u03d5',
16408
+ '\u1D6A': 'χ',
16409
+ '⁺': '+',
16410
+ '⁻': '-',
16411
+ '⁼': '=',
16412
+ '⁽': '(',
16413
+ '⁾': ')',
16414
+ '⁰': '0',
16415
+ '¹': '1',
16416
+ '²': '2',
16417
+ '³': '3',
16418
+ '⁴': '4',
16419
+ '⁵': '5',
16420
+ '⁶': '6',
16421
+ '⁷': '7',
16422
+ '⁸': '8',
16423
+ '⁹': '9',
16424
+ '\u1D2C': 'A',
16425
+ '\u1D2E': 'B',
16426
+ '\u1D30': 'D',
16427
+ '\u1D31': 'E',
16428
+ '\u1D33': 'G',
16429
+ '\u1D34': 'H',
16430
+ '\u1D35': 'I',
16431
+ '\u1D36': 'J',
16432
+ '\u1D37': 'K',
16433
+ '\u1D38': 'L',
16434
+ '\u1D39': 'M',
16435
+ '\u1D3A': 'N',
16436
+ '\u1D3C': 'O',
16437
+ '\u1D3E': 'P',
16438
+ '\u1D3F': 'R',
16439
+ '\u1D40': 'T',
16440
+ '\u1D41': 'U',
16441
+ '\u2C7D': 'V',
16442
+ '\u1D42': 'W',
16443
+ '\u1D43': 'a',
16444
+ '\u1D47': 'b',
16445
+ '\u1D9C': 'c',
16446
+ '\u1D48': 'd',
16447
+ '\u1D49': 'e',
16448
+ '\u1DA0': 'f',
16449
+ '\u1D4D': 'g',
16450
+ '\u02B0': 'h',
16451
+ '\u2071': 'i',
16452
+ '\u02B2': 'j',
16453
+ '\u1D4F': 'k',
16454
+ '\u02E1': 'l',
16455
+ '\u1D50': 'm',
16456
+ '\u207F': 'n',
16457
+ '\u1D52': 'o',
16458
+ '\u1D56': 'p',
16459
+ '\u02B3': 'r',
16460
+ '\u02E2': 's',
16461
+ '\u1D57': 't',
16462
+ '\u1D58': 'u',
16463
+ '\u1D5B': 'v',
16464
+ '\u02B7': 'w',
16465
+ '\u02E3': 'x',
16466
+ '\u02B8': 'y',
16467
+ '\u1DBB': 'z',
16468
+ '\u1D5D': 'β',
16469
+ '\u1D5E': 'γ',
16470
+ '\u1D5F': 'δ',
16471
+ '\u1D60': '\u03d5',
16472
+ '\u1D61': 'χ',
16473
+ '\u1DBF': 'θ'
16474
+ });
16475
+
16369
16476
  /* eslint no-constant-condition:0 */
16370
16477
 
16371
16478
  var unicodeAccents = {
@@ -17164,6 +17271,46 @@ class Parser {
17164
17271
  mode: this.mode,
17165
17272
  body: primes
17166
17273
  };
17274
+ } else if (uSubsAndSups[lex.text]) {
17275
+ // A Unicode subscript or superscript character.
17276
+ // We treat these similarly to the unicode-math package.
17277
+ // So we render a string of Unicode (sub|super)scripts the
17278
+ // same as a (sub|super)script of regular characters.
17279
+ var str = uSubsAndSups[lex.text];
17280
+ var isSub = unicodeSubRegEx.test(lex.text);
17281
+ this.consume(); // Continue fetching tokens to fill out the string.
17282
+
17283
+ while (true) {
17284
+ var token = this.fetch().text;
17285
+
17286
+ if (!uSubsAndSups[token]) {
17287
+ break;
17288
+ }
17289
+
17290
+ if (unicodeSubRegEx.test(token) !== isSub) {
17291
+ break;
17292
+ }
17293
+
17294
+ this.consume();
17295
+ str += uSubsAndSups[token];
17296
+ } // Now create a (sub|super)script.
17297
+
17298
+
17299
+ var body = new Parser(str, this.settings).parse();
17300
+
17301
+ if (isSub) {
17302
+ subscript = {
17303
+ type: "ordgroup",
17304
+ mode: "math",
17305
+ body
17306
+ };
17307
+ } else {
17308
+ superscript = {
17309
+ type: "ordgroup",
17310
+ mode: "math",
17311
+ body
17312
+ };
17313
+ }
17167
17314
  } else {
17168
17315
  // If it wasn't ^, _, or ', stop parsing super/subscripts
17169
17316
  break;
@@ -17959,7 +18106,7 @@ var katex = {
17959
18106
  /**
17960
18107
  * Current KaTeX version
17961
18108
  */
17962
- version: "0.15.3",
18109
+ version: "0.15.4",
17963
18110
 
17964
18111
  /**
17965
18112
  * 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.3",
3
+ "version": "0.15.4",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "exports": {
package/src/Parser.js CHANGED
@@ -9,6 +9,7 @@ import ParseError from "./ParseError";
9
9
  import {combiningDiacriticalMarksEndRegex} from "./Lexer";
10
10
  import Settings from "./Settings";
11
11
  import SourceLocation from "./SourceLocation";
12
+ import {uSubsAndSups, unicodeSubRegEx} from "./unicodeSupOrSub";
12
13
  import {Token} from "./Token";
13
14
 
14
15
  // Pre-evaluate both modules as unicodeSymbols require String.normalize()
@@ -399,6 +400,29 @@ export default class Parser {
399
400
  }
400
401
  // Put everything into an ordgroup as the superscript
401
402
  superscript = {type: "ordgroup", mode: this.mode, body: primes};
403
+ } else if (uSubsAndSups[lex.text]) {
404
+ // A Unicode subscript or superscript character.
405
+ // We treat these similarly to the unicode-math package.
406
+ // So we render a string of Unicode (sub|super)scripts the
407
+ // same as a (sub|super)script of regular characters.
408
+ let str = uSubsAndSups[lex.text];
409
+ const isSub = unicodeSubRegEx.test(lex.text);
410
+ this.consume();
411
+ // Continue fetching tokens to fill out the string.
412
+ while (true) {
413
+ const token = this.fetch().text;
414
+ if (!(uSubsAndSups[token])) { break; }
415
+ if (unicodeSubRegEx.test(token) !== isSub) { break; }
416
+ this.consume();
417
+ str += uSubsAndSups[token];
418
+ }
419
+ // Now create a (sub|super)script.
420
+ const body = (new Parser(str, this.settings)).parse();
421
+ if (isSub) {
422
+ subscript = {type: "ordgroup", mode: "math", body};
423
+ } else {
424
+ superscript = {type: "ordgroup", mode: "math", body};
425
+ }
402
426
  } else {
403
427
  // If it wasn't ^, _, or ', stop parsing super/subscripts
404
428
  break;
@@ -0,0 +1,108 @@
1
+ // Helpers for Parser.js handling of Unicode (sub|super)script characters.
2
+
3
+ export const unicodeSubRegEx = /^[₊₋₌₍₎₀₁₂₃₄₅₆₇₈₉ₐₑₕᵢⱼₖₗₘₙₒₚᵣₛₜᵤᵥₓᵦᵧᵨᵩᵪ]/;
4
+
5
+ export const uSubsAndSups = Object.freeze({
6
+ '₊': '+',
7
+ '₋': '-',
8
+ '₌': '=',
9
+ '₍': '(',
10
+ '₎': ')',
11
+ '₀': '0',
12
+ '₁': '1',
13
+ '₂': '2',
14
+ '₃': '3',
15
+ '₄': '4',
16
+ '₅': '5',
17
+ '₆': '6',
18
+ '₇': '7',
19
+ '₈': '8',
20
+ '₉': '9',
21
+ '\u2090': 'a',
22
+ '\u2091': 'e',
23
+ '\u2095': 'h',
24
+ '\u1D62': 'i',
25
+ '\u2C7C': 'j',
26
+ '\u2096': 'k',
27
+ '\u2097': 'l',
28
+ '\u2098': 'm',
29
+ '\u2099': 'n',
30
+ '\u2092': 'o',
31
+ '\u209A': 'p',
32
+ '\u1D63': 'r',
33
+ '\u209B': 's',
34
+ '\u209C': 't',
35
+ '\u1D64': 'u',
36
+ '\u1D65': 'v',
37
+ '\u2093': 'x',
38
+ '\u1D66': 'β',
39
+ '\u1D67': 'γ',
40
+ '\u1D68': 'ρ',
41
+ '\u1D69': '\u03d5',
42
+ '\u1D6A': 'χ',
43
+ '⁺': '+',
44
+ '⁻': '-',
45
+ '⁼': '=',
46
+ '⁽': '(',
47
+ '⁾': ')',
48
+ '⁰': '0',
49
+ '¹': '1',
50
+ '²': '2',
51
+ '³': '3',
52
+ '⁴': '4',
53
+ '⁵': '5',
54
+ '⁶': '6',
55
+ '⁷': '7',
56
+ '⁸': '8',
57
+ '⁹': '9',
58
+ '\u1D2C': 'A',
59
+ '\u1D2E': 'B',
60
+ '\u1D30': 'D',
61
+ '\u1D31': 'E',
62
+ '\u1D33': 'G',
63
+ '\u1D34': 'H',
64
+ '\u1D35': 'I',
65
+ '\u1D36': 'J',
66
+ '\u1D37': 'K',
67
+ '\u1D38': 'L',
68
+ '\u1D39': 'M',
69
+ '\u1D3A': 'N',
70
+ '\u1D3C': 'O',
71
+ '\u1D3E': 'P',
72
+ '\u1D3F': 'R',
73
+ '\u1D40': 'T',
74
+ '\u1D41': 'U',
75
+ '\u2C7D': 'V',
76
+ '\u1D42': 'W',
77
+ '\u1D43': 'a',
78
+ '\u1D47': 'b',
79
+ '\u1D9C': 'c',
80
+ '\u1D48': 'd',
81
+ '\u1D49': 'e',
82
+ '\u1DA0': 'f',
83
+ '\u1D4D': 'g',
84
+ '\u02B0': 'h',
85
+ '\u2071': 'i',
86
+ '\u02B2': 'j',
87
+ '\u1D4F': 'k',
88
+ '\u02E1': 'l',
89
+ '\u1D50': 'm',
90
+ '\u207F': 'n',
91
+ '\u1D52': 'o',
92
+ '\u1D56': 'p',
93
+ '\u02B3': 'r',
94
+ '\u02E2': 's',
95
+ '\u1D57': 't',
96
+ '\u1D58': 'u',
97
+ '\u1D5B': 'v',
98
+ '\u02B7': 'w',
99
+ '\u02E3': 'x',
100
+ '\u02B8': 'y',
101
+ '\u1DBB': 'z',
102
+ '\u1D5D': 'β',
103
+ '\u1D5E': 'γ',
104
+ '\u1D5F': 'δ',
105
+ '\u1D60': '\u03d5',
106
+ '\u1D61': 'χ',
107
+ '\u1DBF': 'θ',
108
+ });