katex 0.16.32 → 0.16.34

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 (126) hide show
  1. package/README.md +3 -3
  2. package/contrib/auto-render/{auto-render.js → auto-render.ts} +41 -19
  3. package/contrib/auto-render/{splitAtDelimiters.js → splitAtDelimiters.ts} +18 -4
  4. package/contrib/auto-render/test/{auto-render-spec.js → auto-render-spec.ts} +10 -2
  5. package/contrib/copy-tex/README.md +2 -2
  6. package/contrib/copy-tex/{copy-tex.js → copy-tex.ts} +4 -6
  7. package/contrib/copy-tex/{katex2tex.js → katex2tex.ts} +2 -3
  8. package/contrib/mathtex-script-type/README.md +5 -5
  9. package/contrib/mhchem/README.md +1 -1
  10. package/contrib/render-a11y-string/{render-a11y-string.js → render-a11y-string.ts} +18 -33
  11. package/contrib/render-a11y-string/test/{render-a11y-string-spec.js → render-a11y-string-spec.ts} +0 -1
  12. package/dist/README.md +3 -3
  13. package/dist/contrib/auto-render.js +24 -57
  14. package/dist/contrib/auto-render.min.js +1 -1
  15. package/dist/contrib/auto-render.mjs +16586 -210
  16. package/dist/contrib/copy-tex.js +23 -37
  17. package/dist/contrib/copy-tex.min.js +1 -1
  18. package/dist/contrib/copy-tex.mjs +77 -95
  19. package/dist/contrib/mathtex-script-type.js +0 -3
  20. package/dist/contrib/mathtex-script-type.mjs +16427 -4
  21. package/dist/contrib/mhchem.js +55 -303
  22. package/dist/contrib/mhchem.mjs +12884 -723
  23. package/dist/contrib/render-a11y-string.js +13 -108
  24. package/dist/contrib/render-a11y-string.min.js +1 -1
  25. package/dist/contrib/render-a11y-string.mjs +17020 -760
  26. package/dist/katex-swap.css +2 -1
  27. package/dist/katex-swap.min.css +1 -1
  28. package/dist/katex.css +2 -1
  29. package/dist/katex.js +4547 -5680
  30. package/dist/katex.min.css +1 -1
  31. package/dist/katex.min.js +1 -1
  32. package/dist/katex.mjs +11854 -13828
  33. package/{katex.js → katex.ts} +8 -5
  34. package/package.json +34 -31
  35. package/src/{Lexer.js → Lexer.ts} +1 -2
  36. package/src/{MacroExpander.js → MacroExpander.ts} +11 -15
  37. package/src/{Namespace.js → Namespace.ts} +4 -6
  38. package/src/{Options.js → Options.ts} +7 -12
  39. package/src/{ParseError.js → ParseError.ts} +16 -26
  40. package/src/{Parser.js → Parser.ts} +68 -56
  41. package/src/{Settings.js → Settings.ts} +70 -70
  42. package/src/{SourceLocation.js → SourceLocation.ts} +6 -7
  43. package/src/{Style.js → Style.ts} +4 -5
  44. package/src/{Token.js → Token.ts} +8 -6
  45. package/src/{buildCommon.js → buildCommon.ts} +62 -55
  46. package/src/{buildHTML.js → buildHTML.ts} +29 -25
  47. package/src/{buildMathML.js → buildMathML.ts} +15 -13
  48. package/src/{buildTree.js → buildTree.ts} +1 -2
  49. package/src/{defineEnvironment.js → defineEnvironment.ts} +26 -27
  50. package/src/{defineFunction.js → defineFunction.ts} +54 -56
  51. package/src/{defineMacro.js → defineMacro.ts} +12 -13
  52. package/src/{delimiter.js → delimiter.ts} +19 -17
  53. package/src/{domTree.js → domTree.ts} +94 -103
  54. package/src/environments/{array.js → array.ts} +109 -99
  55. package/src/environments/{cd.js → cd.ts} +9 -11
  56. package/src/{environments.js → environments.ts} +0 -1
  57. package/src/{fontMetrics.js → fontMetrics.ts} +10 -12
  58. package/src/fontMetricsData.d.ts +3 -0
  59. package/src/functions/{accent.js → accent.ts} +1 -2
  60. package/src/functions/{accentunder.js → accentunder.ts} +0 -1
  61. package/src/functions/{arrow.js → arrow.ts} +4 -6
  62. package/src/functions/{char.js → char.ts} +0 -1
  63. package/src/functions/{color.js → color.ts} +5 -6
  64. package/src/functions/{cr.js → cr.ts} +0 -1
  65. package/src/functions/{def.js → def.ts} +9 -7
  66. package/src/functions/{delimsizing.js → delimsizing.ts} +11 -9
  67. package/src/functions/{enclose.js → enclose.ts} +3 -4
  68. package/src/functions/{environment.js → environment.ts} +2 -3
  69. package/src/functions/{font.js → font.ts} +4 -4
  70. package/src/functions/{genfrac.js → genfrac.ts} +14 -15
  71. package/src/functions/{hbox.js → hbox.ts} +0 -1
  72. package/src/functions/{horizBrace.js → horizBrace.ts} +4 -5
  73. package/src/functions/{href.js → href.ts} +4 -4
  74. package/src/functions/{html.js → html.ts} +3 -3
  75. package/src/functions/{htmlmathml.js → htmlmathml.ts} +0 -1
  76. package/src/functions/{includegraphics.js → includegraphics.ts} +0 -1
  77. package/src/functions/{kern.js → kern.ts} +0 -1
  78. package/src/functions/{lap.js → lap.ts} +0 -1
  79. package/src/functions/{math.js → math.ts} +0 -1
  80. package/src/functions/{mathchoice.js → mathchoice.ts} +2 -2
  81. package/src/functions/{mclass.js → mclass.ts} +5 -6
  82. package/src/functions/{op.js → op.ts} +9 -11
  83. package/src/functions/{operatorname.js → operatorname.ts} +4 -7
  84. package/src/functions/{ordgroup.js → ordgroup.ts} +0 -2
  85. package/src/functions/{overline.js → overline.ts} +0 -1
  86. package/src/functions/{phantom.js → phantom.ts} +0 -1
  87. package/src/functions/{pmb.js → pmb.ts} +0 -1
  88. package/src/functions/{raisebox.js → raisebox.ts} +0 -1
  89. package/src/functions/{relax.js → relax.ts} +0 -1
  90. package/src/functions/{rule.js → rule.ts} +0 -1
  91. package/src/functions/{sizing.js → sizing.ts} +0 -1
  92. package/src/functions/{smash.js → smash.ts} +2 -4
  93. package/src/functions/{sqrt.js → sqrt.ts} +0 -1
  94. package/src/functions/{styling.js → styling.ts} +3 -3
  95. package/src/functions/{supsub.js → supsub.ts} +6 -8
  96. package/src/functions/{symbolsOp.js → symbolsOp.ts} +0 -2
  97. package/src/functions/{symbolsOrd.js → symbolsOrd.ts} +1 -2
  98. package/src/functions/{symbolsSpacing.js → symbolsSpacing.ts} +2 -3
  99. package/src/functions/{tag.js → tag.ts} +0 -2
  100. package/src/functions/{text.js → text.ts} +7 -6
  101. package/src/functions/{underline.js → underline.ts} +0 -1
  102. package/src/functions/utils/{assembleSupSub.js → assembleSupSub.ts} +2 -3
  103. package/src/functions/{vcenter.js → vcenter.ts} +0 -2
  104. package/src/functions/{verb.js → verb.ts} +0 -1
  105. package/src/{functions.js → functions.ts} +0 -1
  106. package/src/{macros.js → macros.ts} +10 -8
  107. package/src/{mathMLTree.js → mathMLTree.ts} +5 -6
  108. package/src/parseNode.ts +522 -0
  109. package/src/{parseTree.js → parseTree.ts} +5 -3
  110. package/src/{spacingData.js → spacingData.ts} +11 -12
  111. package/src/{stretchy.js → stretchy.ts} +7 -7
  112. package/src/styles/katex-swap.scss +1 -4
  113. package/src/styles/katex.scss +9 -0
  114. package/src/{svgGeometry.js → svgGeometry.ts} +1 -2
  115. package/src/{symbols.js → symbols.ts} +6 -6
  116. package/src/{tree.js → tree.ts} +5 -7
  117. package/src/{types.js → types.ts} +1 -2
  118. package/src/unicodeAccents.js +4 -1
  119. package/src/{unicodeScripts.js → unicodeScripts.ts} +1 -3
  120. package/src/{unicodeSupOrSub.js → unicodeSupOrSub.ts} +1 -1
  121. package/src/unicodeSymbols.js +4 -3
  122. package/src/{units.js → units.ts} +2 -4
  123. package/src/{utils.js → utils.ts} +2 -3
  124. package/src/{wide-character.js → wide-character.ts} +8 -10
  125. package/types/katex.d.ts +13 -12
  126. package/src/parseNode.js +0 -523
@@ -94,9 +94,10 @@ var __webpack_exports__ = {};
94
94
  * The commas in the string aim to increase ease of understanding
95
95
  * when read by a screenreader.
96
96
  */
97
+
97
98
  // NOTE: since we're importing types here these files won't actually be
98
99
  // included in the build.
99
- // $FlowIgnore: we import the types directly anyways
100
+
100
101
 
101
102
  const stringMap = {
102
103
  "(": "left parenthesis",
@@ -222,14 +223,11 @@ const accentUnderMap = {
222
223
  "\\underlinesegment": "line segment",
223
224
  "\\utilde": "tilde"
224
225
  };
225
-
226
226
  const buildString = (str, type, a11yStrings) => {
227
227
  if (!str) {
228
228
  return;
229
229
  }
230
-
231
230
  let ret;
232
-
233
231
  if (type === "open") {
234
232
  ret = str in openMap ? openMap[str] : stringMap[str] || str;
235
233
  } else if (type === "close") {
@@ -240,28 +238,23 @@ const buildString = (str, type, a11yStrings) => {
240
238
  ret = relMap[str] || str;
241
239
  } else {
242
240
  ret = stringMap[str] || str;
243
- } // If the text to add is a number and there is already a string
241
+ }
242
+
243
+ // If the text to add is a number and there is already a string
244
244
  // in the list and the last string is a number then we should
245
245
  // combine them into a single number
246
-
247
-
248
- if (/^\d+$/.test(ret) && a11yStrings.length > 0 && // TODO(kevinb): check that the last item in a11yStrings is a string
249
- // I think we might be able to drop the nested arrays, which would make
250
- // this easier to type
251
- // $FlowFixMe
252
- /^\d+$/.test(a11yStrings[a11yStrings.length - 1])) {
246
+ const last = a11yStrings[a11yStrings.length - 1];
247
+ if (/^\d+$/.test(ret) && a11yStrings.length > 0 && typeof last === "string" && /^\d+$/.test(last)) {
253
248
  a11yStrings[a11yStrings.length - 1] += ret;
254
249
  } else if (ret) {
255
250
  a11yStrings.push(ret);
256
251
  }
257
252
  };
258
-
259
253
  const buildRegion = (a11yStrings, callback) => {
260
254
  const regionStrings = [];
261
255
  a11yStrings.push(regionStrings);
262
256
  callback(regionStrings);
263
257
  };
264
-
265
258
  const handleObject = (tree, a11yStrings, atomType) => {
266
259
  // Everything else is assumed to be an object...
267
260
  switch (tree.type) {
@@ -275,7 +268,6 @@ const handleObject = (tree, a11yStrings, atomType) => {
275
268
  });
276
269
  break;
277
270
  }
278
-
279
271
  case "accentUnder":
280
272
  {
281
273
  buildRegion(a11yStrings, a11yStrings => {
@@ -286,67 +278,56 @@ const handleObject = (tree, a11yStrings, atomType) => {
286
278
  });
287
279
  break;
288
280
  }
289
-
290
281
  case "accent-token":
291
282
  {
292
283
  // Used internally by accent symbols.
293
284
  break;
294
285
  }
295
-
296
286
  case "atom":
297
287
  {
298
288
  const {
299
289
  text
300
290
  } = tree;
301
-
302
291
  switch (tree.family) {
303
292
  case "bin":
304
293
  {
305
294
  buildString(text, "bin", a11yStrings);
306
295
  break;
307
296
  }
308
-
309
297
  case "close":
310
298
  {
311
299
  buildString(text, "close", a11yStrings);
312
300
  break;
313
301
  }
314
302
  // TODO(kevinb): figure out what should be done for inner
315
-
316
303
  case "inner":
317
304
  {
318
305
  buildString(tree.text, "inner", a11yStrings);
319
306
  break;
320
307
  }
321
-
322
308
  case "open":
323
309
  {
324
310
  buildString(text, "open", a11yStrings);
325
311
  break;
326
312
  }
327
-
328
313
  case "punct":
329
314
  {
330
315
  buildString(text, "punct", a11yStrings);
331
316
  break;
332
317
  }
333
-
334
318
  case "rel":
335
319
  {
336
320
  buildString(text, "rel", a11yStrings);
337
321
  break;
338
322
  }
339
-
340
323
  default:
341
324
  {
342
325
  tree.family;
343
326
  throw new Error("\"" + tree.family + "\" is not a valid atom type");
344
327
  }
345
328
  }
346
-
347
329
  break;
348
330
  }
349
-
350
331
  case "color":
351
332
  {
352
333
  const color = tree.color.replace(/katex-/, "");
@@ -357,23 +338,19 @@ const handleObject = (tree, a11yStrings, atomType) => {
357
338
  });
358
339
  break;
359
340
  }
360
-
361
341
  case "color-token":
362
342
  {
363
343
  // Used by \color, \colorbox, and \fcolorbox but not directly rendered.
364
344
  // It's a leaf node and has no children so just break.
365
345
  break;
366
346
  }
367
-
368
347
  case "delimsizing":
369
348
  {
370
349
  if (tree.delim && tree.delim !== ".") {
371
350
  buildString(tree.delim, "normal", a11yStrings);
372
351
  }
373
-
374
352
  break;
375
353
  }
376
-
377
354
  case "genfrac":
378
355
  {
379
356
  buildRegion(a11yStrings, regionStrings => {
@@ -381,9 +358,10 @@ const handleObject = (tree, a11yStrings, atomType) => {
381
358
  const {
382
359
  leftDelim,
383
360
  rightDelim
384
- } = tree; // NOTE: Not sure if this is a safe assumption
385
- // hasBarLine true -> fraction, false -> binomial
361
+ } = tree;
386
362
 
363
+ // NOTE: Not sure if this is a safe assumption
364
+ // hasBarLine true -> fraction, false -> binomial
387
365
  if (tree.hasBarLine) {
388
366
  regionStrings.push("start fraction");
389
367
  leftDelim && buildString(leftDelim, "open", regionStrings);
@@ -404,20 +382,17 @@ const handleObject = (tree, a11yStrings, atomType) => {
404
382
  });
405
383
  break;
406
384
  }
407
-
408
385
  case "hbox":
409
386
  {
410
387
  buildA11yStrings(tree.body, a11yStrings, atomType);
411
388
  break;
412
389
  }
413
-
414
390
  case "kern":
415
391
  {
416
392
  // No op: we don't attempt to present kerning information
417
393
  // to the screen reader.
418
394
  break;
419
395
  }
420
-
421
396
  case "leftright":
422
397
  {
423
398
  buildRegion(a11yStrings, regionStrings => {
@@ -427,54 +402,45 @@ const handleObject = (tree, a11yStrings, atomType) => {
427
402
  });
428
403
  break;
429
404
  }
430
-
431
405
  case "leftright-right":
432
406
  {
433
407
  // TODO: double check that this is a no-op
434
408
  break;
435
409
  }
436
-
437
410
  case "lap":
438
411
  {
439
412
  buildA11yStrings(tree.body, a11yStrings, atomType);
440
413
  break;
441
414
  }
442
-
443
415
  case "mathord":
444
416
  {
445
417
  buildString(tree.text, "normal", a11yStrings);
446
418
  break;
447
419
  }
448
-
449
420
  case "op":
450
421
  {
451
422
  const {
452
423
  body,
453
424
  name
454
425
  } = tree;
455
-
456
426
  if (body) {
457
427
  buildA11yStrings(body, a11yStrings, atomType);
458
428
  } else if (name) {
459
429
  buildString(name, "normal", a11yStrings);
460
430
  }
461
-
462
431
  break;
463
432
  }
464
-
465
433
  case "op-token":
466
434
  {
467
435
  // Used internally by operator symbols.
468
436
  buildString(tree.text, atomType, a11yStrings);
469
437
  break;
470
438
  }
471
-
472
439
  case "ordgroup":
473
440
  {
474
441
  buildA11yStrings(tree.body, a11yStrings, atomType);
475
442
  break;
476
443
  }
477
-
478
444
  case "overline":
479
445
  {
480
446
  buildRegion(a11yStrings, function (a11yStrings) {
@@ -484,50 +450,42 @@ const handleObject = (tree, a11yStrings, atomType) => {
484
450
  });
485
451
  break;
486
452
  }
487
-
488
453
  case "pmb":
489
454
  {
490
455
  a11yStrings.push("bold");
491
456
  break;
492
457
  }
493
-
494
458
  case "phantom":
495
459
  {
496
460
  a11yStrings.push("empty space");
497
461
  break;
498
462
  }
499
-
500
463
  case "raisebox":
501
464
  {
502
465
  buildA11yStrings(tree.body, a11yStrings, atomType);
503
466
  break;
504
467
  }
505
-
506
468
  case "rule":
507
469
  {
508
470
  a11yStrings.push("rectangle");
509
471
  break;
510
472
  }
511
-
512
473
  case "sizing":
513
474
  {
514
475
  buildA11yStrings(tree.body, a11yStrings, atomType);
515
476
  break;
516
477
  }
517
-
518
478
  case "spacing":
519
479
  {
520
480
  a11yStrings.push("space");
521
481
  break;
522
482
  }
523
-
524
483
  case "styling":
525
484
  {
526
485
  // We ignore the styling and just pass through the contents
527
486
  buildA11yStrings(tree.body, a11yStrings, atomType);
528
487
  break;
529
488
  }
530
-
531
489
  case "sqrt":
532
490
  {
533
491
  buildRegion(a11yStrings, regionStrings => {
@@ -535,31 +493,26 @@ const handleObject = (tree, a11yStrings, atomType) => {
535
493
  body,
536
494
  index
537
495
  } = tree;
538
-
539
496
  if (index) {
540
497
  const indexString = flatten(buildA11yStrings(index, [], atomType)).join(",");
541
-
542
498
  if (indexString === "3") {
543
499
  regionStrings.push("cube root of");
544
500
  buildA11yStrings(body, regionStrings, atomType);
545
501
  regionStrings.push("end cube root");
546
502
  return;
547
503
  }
548
-
549
504
  regionStrings.push("root");
550
505
  regionStrings.push("start index");
551
506
  buildA11yStrings(index, regionStrings, atomType);
552
507
  regionStrings.push("end index");
553
508
  return;
554
509
  }
555
-
556
510
  regionStrings.push("square root of");
557
511
  buildA11yStrings(body, regionStrings, atomType);
558
512
  regionStrings.push("end square root");
559
513
  });
560
514
  break;
561
515
  }
562
-
563
516
  case "supsub":
564
517
  {
565
518
  const {
@@ -568,12 +521,10 @@ const handleObject = (tree, a11yStrings, atomType) => {
568
521
  sup
569
522
  } = tree;
570
523
  let isLog = false;
571
-
572
524
  if (base) {
573
525
  buildA11yStrings(base, a11yStrings, atomType);
574
526
  isLog = base.type === "op" && base.name === "\\log";
575
527
  }
576
-
577
528
  if (sub) {
578
529
  const regionName = isLog ? "base" : "subscript";
579
530
  buildRegion(a11yStrings, function (regionStrings) {
@@ -582,25 +533,20 @@ const handleObject = (tree, a11yStrings, atomType) => {
582
533
  regionStrings.push("end " + regionName);
583
534
  });
584
535
  }
585
-
586
536
  if (sup) {
587
537
  buildRegion(a11yStrings, function (regionStrings) {
588
538
  const supString = flatten(buildA11yStrings(sup, [], atomType)).join(",");
589
-
590
539
  if (supString in powerMap) {
591
540
  regionStrings.push(powerMap[supString]);
592
541
  return;
593
542
  }
594
-
595
543
  regionStrings.push("start superscript");
596
544
  buildA11yStrings(sup, regionStrings, atomType);
597
545
  regionStrings.push("end superscript");
598
546
  });
599
547
  }
600
-
601
548
  break;
602
549
  }
603
-
604
550
  case "text":
605
551
  {
606
552
  // TODO: handle other fonts
@@ -612,7 +558,6 @@ const handleObject = (tree, a11yStrings, atomType) => {
612
558
  });
613
559
  break;
614
560
  }
615
-
616
561
  buildRegion(a11yStrings, function (regionStrings) {
617
562
  regionStrings.push("start text");
618
563
  buildA11yStrings(tree.body, regionStrings, atomType);
@@ -620,19 +565,16 @@ const handleObject = (tree, a11yStrings, atomType) => {
620
565
  });
621
566
  break;
622
567
  }
623
-
624
568
  case "textord":
625
569
  {
626
570
  buildString(tree.text, atomType, a11yStrings);
627
571
  break;
628
572
  }
629
-
630
573
  case "smash":
631
574
  {
632
575
  buildA11yStrings(tree.body, a11yStrings, atomType);
633
576
  break;
634
577
  }
635
-
636
578
  case "enclose":
637
579
  {
638
580
  // TODO: create a map for these.
@@ -667,59 +609,48 @@ const handleObject = (tree, a11yStrings, atomType) => {
667
609
  });
668
610
  break;
669
611
  }
670
-
671
612
  throw new Error("KaTeX-a11y: enclose node with " + tree.label + " not supported yet");
672
613
  }
673
-
674
614
  case "vcenter":
675
615
  {
676
616
  buildA11yStrings(tree.body, a11yStrings, atomType);
677
617
  break;
678
618
  }
679
-
680
619
  case "vphantom":
681
620
  {
682
621
  throw new Error("KaTeX-a11y: vphantom not implemented yet");
683
622
  }
684
-
685
623
  case "hphantom":
686
624
  {
687
625
  throw new Error("KaTeX-a11y: hphantom not implemented yet");
688
626
  }
689
-
690
627
  case "operatorname":
691
628
  {
692
629
  buildA11yStrings(tree.body, a11yStrings, atomType);
693
630
  break;
694
631
  }
695
-
696
632
  case "array":
697
633
  {
698
634
  throw new Error("KaTeX-a11y: array not implemented yet");
699
635
  }
700
-
701
636
  case "raw":
702
637
  {
703
638
  throw new Error("KaTeX-a11y: raw not implemented yet");
704
639
  }
705
-
706
640
  case "size":
707
641
  {
708
642
  // Although there are nodes of type "size" in the parse tree, they have
709
643
  // no semantic meaning and should be ignored.
710
644
  break;
711
645
  }
712
-
713
646
  case "url":
714
647
  {
715
648
  throw new Error("KaTeX-a11y: url not implemented yet");
716
649
  }
717
-
718
650
  case "tag":
719
651
  {
720
652
  throw new Error("KaTeX-a11y: tag not implemented yet");
721
653
  }
722
-
723
654
  case "verb":
724
655
  {
725
656
  buildString("start verbatim", "normal", a11yStrings);
@@ -727,12 +658,10 @@ const handleObject = (tree, a11yStrings, atomType) => {
727
658
  buildString("end verbatim", "normal", a11yStrings);
728
659
  break;
729
660
  }
730
-
731
661
  case "environment":
732
662
  {
733
663
  throw new Error("KaTeX-a11y: environment not implemented yet");
734
664
  }
735
-
736
665
  case "horizBrace":
737
666
  {
738
667
  buildString("start " + tree.label.slice(1), "normal", a11yStrings);
@@ -740,18 +669,15 @@ const handleObject = (tree, a11yStrings, atomType) => {
740
669
  buildString("end " + tree.label.slice(1), "normal", a11yStrings);
741
670
  break;
742
671
  }
743
-
744
672
  case "infix":
745
673
  {
746
674
  // All infix nodes are replace with other nodes.
747
675
  break;
748
676
  }
749
-
750
677
  case "includegraphics":
751
678
  {
752
679
  throw new Error("KaTeX-a11y: includegraphics not implemented yet");
753
680
  }
754
-
755
681
  case "font":
756
682
  {
757
683
  // TODO: callout the start/end of specific fonts
@@ -759,18 +685,15 @@ const handleObject = (tree, a11yStrings, atomType) => {
759
685
  buildA11yStrings(tree.body, a11yStrings, atomType);
760
686
  break;
761
687
  }
762
-
763
688
  case "href":
764
689
  {
765
690
  throw new Error("KaTeX-a11y: href not implemented yet");
766
691
  }
767
-
768
692
  case "cr":
769
693
  {
770
694
  // This is used by environments.
771
695
  throw new Error("KaTeX-a11y: cr not implemented yet");
772
696
  }
773
-
774
697
  case "underline":
775
698
  {
776
699
  buildRegion(a11yStrings, function (a11yStrings) {
@@ -780,32 +703,27 @@ const handleObject = (tree, a11yStrings, atomType) => {
780
703
  });
781
704
  break;
782
705
  }
783
-
784
706
  case "xArrow":
785
707
  {
786
708
  throw new Error("KaTeX-a11y: xArrow not implemented yet");
787
709
  }
788
-
789
710
  case "cdlabel":
790
711
  {
791
712
  throw new Error("KaTeX-a11y: cdlabel not implemented yet");
792
713
  }
793
-
794
714
  case "cdlabelparent":
795
715
  {
796
716
  throw new Error("KaTeX-a11y: cdlabelparent not implemented yet");
797
717
  }
798
-
799
718
  case "mclass":
800
719
  {
801
720
  // \neq and \ne are macros so we let "htmlmathml" render the mathmal
802
721
  // side of things and extract the text from that.
803
- const atomType = tree.mclass.slice(1); // $FlowFixMe: drop the leading "m" from the values in mclass
804
-
722
+ const atomType = tree.mclass.slice(1);
723
+ // TODO(ts): drop the leading "m" from the values in mclass
805
724
  buildA11yStrings(tree.body, a11yStrings, atomType);
806
725
  break;
807
726
  }
808
-
809
727
  case "mathchoice":
810
728
  {
811
729
  // TODO: track which style we're using, e.g. display, text, etc.
@@ -813,42 +731,34 @@ const handleObject = (tree, a11yStrings, atomType) => {
813
731
  buildA11yStrings(tree.text, a11yStrings, atomType);
814
732
  break;
815
733
  }
816
-
817
734
  case "htmlmathml":
818
735
  {
819
736
  buildA11yStrings(tree.mathml, a11yStrings, atomType);
820
737
  break;
821
738
  }
822
-
823
739
  case "middle":
824
740
  {
825
741
  buildString(tree.delim, atomType, a11yStrings);
826
742
  break;
827
743
  }
828
-
829
744
  case "internal":
830
745
  {
831
746
  // internal nodes are never included in the parse tree
832
747
  break;
833
748
  }
834
-
835
749
  case "html":
836
750
  {
837
751
  buildA11yStrings(tree.body, a11yStrings, atomType);
838
752
  break;
839
753
  }
840
-
841
754
  default:
842
- tree.type;
843
755
  throw new Error("KaTeX a11y un-recognized type: " + tree.type);
844
756
  }
845
757
  };
846
-
847
758
  const buildA11yStrings = function (tree, a11yStrings, atomType) {
848
759
  if (a11yStrings === void 0) {
849
760
  a11yStrings = [];
850
761
  }
851
-
852
762
  if (tree instanceof Array) {
853
763
  for (let i = 0; i < tree.length; i++) {
854
764
  buildA11yStrings(tree[i], a11yStrings, atomType);
@@ -856,14 +766,12 @@ const buildA11yStrings = function (tree, a11yStrings, atomType) {
856
766
  } else {
857
767
  handleObject(tree, a11yStrings, atomType);
858
768
  }
859
-
860
769
  return a11yStrings;
861
770
  };
862
-
863
771
  const flatten = function (array) {
864
772
  let result = [];
865
773
  array.forEach(function (item) {
866
- if (item instanceof Array) {
774
+ if (Array.isArray(item)) {
867
775
  result = result.concat(flatten(item));
868
776
  } else {
869
777
  result.push(item);
@@ -871,14 +779,11 @@ const flatten = function (array) {
871
779
  });
872
780
  return result;
873
781
  };
874
-
875
782
  const renderA11yString = function (text, settings) {
876
783
  const tree = katex__WEBPACK_IMPORTED_MODULE_0___default().__parse(text, settings);
877
-
878
784
  const a11yStrings = buildA11yStrings(tree, [], "normal");
879
785
  return flatten(a11yStrings).join(", ");
880
786
  };
881
-
882
787
  /* harmony default export */ __webpack_exports__["default"] = (renderA11yString);
883
788
  __webpack_exports__ = __webpack_exports__["default"];
884
789
  /******/ return __webpack_exports__;
@@ -1 +1 @@
1
- !function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r(require("katex"));else if("function"==typeof define&&define.amd)define(["katex"],r);else{var t="object"==typeof exports?r(require("katex")):r(e.katex);for(var a in t)("object"==typeof exports?exports:e)[a]=t[a]}}("undefined"!=typeof self?self:this,function(e){return function(){"use strict";var r={757:function(r){r.exports=e}},t={};function a(e){var o=t[e];if(void 0!==o)return o.exports;var n=t[e]={exports:{}};return r[e](n,n.exports,a),n.exports}a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,{a:r}),r},a.d=function(e,r){for(var t in r)a.o(r,t)&&!a.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)};var o={},n=a(757),s=a.n(n);const l={"(":"left parenthesis",")":"right parenthesis","[":"open bracket","]":"close bracket","\\{":"left brace","\\}":"right brace","\\lvert":"open vertical bar","\\rvert":"close vertical bar","|":"vertical bar","\\uparrow":"up arrow","\\Uparrow":"up arrow","\\downarrow":"down arrow","\\Downarrow":"down arrow","\\updownarrow":"up down arrow","\\leftarrow":"left arrow","\\Leftarrow":"left arrow","\\rightarrow":"right arrow","\\Rightarrow":"right arrow","\\langle":"open angle","\\rangle":"close angle","\\lfloor":"open floor","\\rfloor":"close floor","\\int":"integral","\\intop":"integral","\\lim":"limit","\\ln":"natural log","\\log":"log","\\sin":"sine","\\cos":"cosine","\\tan":"tangent","\\cot":"cotangent","\\sum":"sum","/":"slash",",":"comma",".":"point","-":"negative","+":"plus","~":"tilde",":":"colon","?":"question mark","'":"apostrophe","\\%":"percent"," ":"space","\\ ":"space","\\$":"dollar sign","\\angle":"angle","\\degree":"degree","\\circ":"circle","\\vec":"vector","\\triangle":"triangle","\\pi":"pi","\\prime":"prime","\\infty":"infinity","\\alpha":"alpha","\\beta":"beta","\\gamma":"gamma","\\omega":"omega","\\theta":"theta","\\sigma":"sigma","\\lambda":"lambda","\\tau":"tau","\\Delta":"delta","\\delta":"delta","\\mu":"mu","\\rho":"rho","\\nabla":"del","\\ell":"ell","\\ldots":"dots","\\hat":"hat","\\acute":"acute"},i={prime:"prime",degree:"degrees",circle:"degrees",2:"squared",3:"cubed"},c={"|":"open vertical bar",".":""},p={"|":"close vertical bar",".":""},u={"+":"plus","-":"minus","\\pm":"plus minus","\\cdot":"dot","*":"times","/":"divided by","\\times":"times","\\div":"divided by","\\circ":"circle","\\bullet":"bullet"},d={"=":"equals","\\approx":"approximately equals","\u2260":"does not equal","\\geq":"is greater than or equal to","\\ge":"is greater than or equal to","\\leq":"is less than or equal to","\\le":"is less than or equal to",">":"is greater than","<":"is less than","\\leftarrow":"left arrow","\\Leftarrow":"left arrow","\\rightarrow":"right arrow","\\Rightarrow":"right arrow",":":"colon"},h={"\\underleftarrow":"left arrow","\\underrightarrow":"right arrow","\\underleftrightarrow":"left-right arrow","\\undergroup":"group","\\underlinesegment":"line segment","\\utilde":"tilde"},b=(e,r,t)=>{if(!e)return;let a;a="open"===r?e in c?c[e]:l[e]||e:"close"===r?e in p?p[e]:l[e]||e:"bin"===r?u[e]||e:"rel"===r?d[e]||e:l[e]||e,/^\d+$/.test(a)&&t.length>0&&/^\d+$/.test(t[t.length-1])?t[t.length-1]+=a:a&&t.push(a)},m=(e,r)=>{const t=[];e.push(t),r(t)},f=function(e,r,t){if(void 0===r&&(r=[]),e instanceof Array)for(let a=0;a<e.length;a++)f(e[a],r,t);else((e,r,t)=>{switch(e.type){case"accent":m(r,r=>{f(e.base,r,t),r.push("with"),b(e.label,"normal",r),r.push("on top")});break;case"accentUnder":m(r,r=>{f(e.base,r,t),r.push("with"),b(h[e.label],"normal",r),r.push("underneath")});break;case"accent-token":case"color-token":case"kern":case"leftright-right":case"size":case"infix":case"internal":break;case"atom":{const{text:t}=e;switch(e.family){case"bin":b(t,"bin",r);break;case"close":b(t,"close",r);break;case"inner":b(e.text,"inner",r);break;case"open":b(t,"open",r);break;case"punct":b(t,"punct",r);break;case"rel":b(t,"rel",r);break;default:throw e.family,new Error('"'+e.family+'" is not a valid atom type')}break}case"color":{const a=e.color.replace(/katex-/,"");m(r,r=>{r.push("start color "+a),f(e.body,r,t),r.push("end color "+a)});break}case"delimsizing":e.delim&&"."!==e.delim&&b(e.delim,"normal",r);break;case"genfrac":m(r,r=>{const{leftDelim:a,rightDelim:o}=e;e.hasBarLine?(r.push("start fraction"),a&&b(a,"open",r),f(e.numer,r,t),r.push("divided by"),f(e.denom,r,t),o&&b(o,"close",r),r.push("end fraction")):(r.push("start binomial"),a&&b(a,"open",r),f(e.numer,r,t),r.push("over"),f(e.denom,r,t),o&&b(o,"close",r),r.push("end binomial"))});break;case"hbox":case"lap":case"ordgroup":case"raisebox":case"sizing":case"styling":case"smash":case"vcenter":case"operatorname":case"font":case"html":f(e.body,r,t);break;case"leftright":m(r,r=>{b(e.left,"open",r),f(e.body,r,t),b(e.right,"close",r)});break;case"mathord":b(e.text,"normal",r);break;case"op":{const{body:a,name:o}=e;a?f(a,r,t):o&&b(o,"normal",r);break}case"op-token":case"textord":b(e.text,t,r);break;case"overline":m(r,function(r){r.push("start overline"),f(e.body,r,t),r.push("end overline")});break;case"pmb":r.push("bold");break;case"phantom":r.push("empty space");break;case"rule":r.push("rectangle");break;case"spacing":r.push("space");break;case"sqrt":m(r,r=>{const{body:a,index:o}=e;if(o)return"3"===w(f(o,[],t)).join(",")?(r.push("cube root of"),f(a,r,t),void r.push("end cube root")):(r.push("root"),r.push("start index"),f(o,r,t),void r.push("end index"));r.push("square root of"),f(a,r,t),r.push("end square root")});break;case"supsub":{const{base:a,sub:o,sup:n}=e;let s=!1;if(a&&(f(a,r,t),s="op"===a.type&&"\\log"===a.name),o){const e=s?"base":"subscript";m(r,function(r){r.push("start "+e),f(o,r,t),r.push("end "+e)})}n&&m(r,function(e){const r=w(f(n,[],t)).join(",");r in i?e.push(i[r]):(e.push("start superscript"),f(n,e,t),e.push("end superscript"))});break}case"text":if("\\textbf"===e.font){m(r,function(r){r.push("start bold text"),f(e.body,r,t),r.push("end bold text")});break}m(r,function(r){r.push("start text"),f(e.body,r,t),r.push("end text")});break;case"enclose":if(/cancel/.test(e.label)){m(r,function(r){r.push("start cancel"),f(e.body,r,t),r.push("end cancel")});break}if(/box/.test(e.label)){m(r,function(r){r.push("start box"),f(e.body,r,t),r.push("end box")});break}if(/sout/.test(e.label)){m(r,function(r){r.push("start strikeout"),f(e.body,r,t),r.push("end strikeout")});break}if(/phase/.test(e.label)){m(r,function(r){r.push("start phase angle"),f(e.body,r,t),r.push("end phase angle")});break}throw new Error("KaTeX-a11y: enclose node with "+e.label+" not supported yet");case"vphantom":throw new Error("KaTeX-a11y: vphantom not implemented yet");case"hphantom":throw new Error("KaTeX-a11y: hphantom not implemented yet");case"array":throw new Error("KaTeX-a11y: array not implemented yet");case"raw":throw new Error("KaTeX-a11y: raw not implemented yet");case"url":throw new Error("KaTeX-a11y: url not implemented yet");case"tag":throw new Error("KaTeX-a11y: tag not implemented yet");case"verb":b("start verbatim","normal",r),b(e.body,"normal",r),b("end verbatim","normal",r);break;case"environment":throw new Error("KaTeX-a11y: environment not implemented yet");case"horizBrace":b("start "+e.label.slice(1),"normal",r),f(e.base,r,t),b("end "+e.label.slice(1),"normal",r);break;case"includegraphics":throw new Error("KaTeX-a11y: includegraphics not implemented yet");case"href":throw new Error("KaTeX-a11y: href not implemented yet");case"cr":throw new Error("KaTeX-a11y: cr not implemented yet");case"underline":m(r,function(r){r.push("start underline"),f(e.body,r,t),r.push("end underline")});break;case"xArrow":throw new Error("KaTeX-a11y: xArrow not implemented yet");case"cdlabel":throw new Error("KaTeX-a11y: cdlabel not implemented yet");case"cdlabelparent":throw new Error("KaTeX-a11y: cdlabelparent not implemented yet");case"mclass":{const t=e.mclass.slice(1);f(e.body,r,t);break}case"mathchoice":f(e.text,r,t);break;case"htmlmathml":f(e.mathml,r,t);break;case"middle":b(e.delim,t,r);break;default:throw e.type,new Error("KaTeX a11y un-recognized type: "+e.type)}})(e,r,t);return r},w=function(e){let r=[];return e.forEach(function(e){e instanceof Array?r=r.concat(w(e)):r.push(e)}),r};return o.default=function(e,r){const t=s().__parse(e,r),a=f(t,[],"normal");return w(a).join(", ")},o=o.default}()});
1
+ !function(e,r){if("object"==typeof exports&&"object"==typeof module)module.exports=r(require("katex"));else if("function"==typeof define&&define.amd)define(["katex"],r);else{var t="object"==typeof exports?r(require("katex")):r(e.katex);for(var a in t)("object"==typeof exports?exports:e)[a]=t[a]}}("undefined"!=typeof self?self:this,function(e){return function(){"use strict";var r={757:function(r){r.exports=e}},t={};function a(e){var o=t[e];if(void 0!==o)return o.exports;var n=t[e]={exports:{}};return r[e](n,n.exports,a),n.exports}a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,{a:r}),r},a.d=function(e,r){for(var t in r)a.o(r,t)&&!a.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)};var o={},n=a(757),s=a.n(n);const l={"(":"left parenthesis",")":"right parenthesis","[":"open bracket","]":"close bracket","\\{":"left brace","\\}":"right brace","\\lvert":"open vertical bar","\\rvert":"close vertical bar","|":"vertical bar","\\uparrow":"up arrow","\\Uparrow":"up arrow","\\downarrow":"down arrow","\\Downarrow":"down arrow","\\updownarrow":"up down arrow","\\leftarrow":"left arrow","\\Leftarrow":"left arrow","\\rightarrow":"right arrow","\\Rightarrow":"right arrow","\\langle":"open angle","\\rangle":"close angle","\\lfloor":"open floor","\\rfloor":"close floor","\\int":"integral","\\intop":"integral","\\lim":"limit","\\ln":"natural log","\\log":"log","\\sin":"sine","\\cos":"cosine","\\tan":"tangent","\\cot":"cotangent","\\sum":"sum","/":"slash",",":"comma",".":"point","-":"negative","+":"plus","~":"tilde",":":"colon","?":"question mark","'":"apostrophe","\\%":"percent"," ":"space","\\ ":"space","\\$":"dollar sign","\\angle":"angle","\\degree":"degree","\\circ":"circle","\\vec":"vector","\\triangle":"triangle","\\pi":"pi","\\prime":"prime","\\infty":"infinity","\\alpha":"alpha","\\beta":"beta","\\gamma":"gamma","\\omega":"omega","\\theta":"theta","\\sigma":"sigma","\\lambda":"lambda","\\tau":"tau","\\Delta":"delta","\\delta":"delta","\\mu":"mu","\\rho":"rho","\\nabla":"del","\\ell":"ell","\\ldots":"dots","\\hat":"hat","\\acute":"acute"},i={prime:"prime",degree:"degrees",circle:"degrees",2:"squared",3:"cubed"},c={"|":"open vertical bar",".":""},p={"|":"close vertical bar",".":""},u={"+":"plus","-":"minus","\\pm":"plus minus","\\cdot":"dot","*":"times","/":"divided by","\\times":"times","\\div":"divided by","\\circ":"circle","\\bullet":"bullet"},d={"=":"equals","\\approx":"approximately equals","\u2260":"does not equal","\\geq":"is greater than or equal to","\\ge":"is greater than or equal to","\\leq":"is less than or equal to","\\le":"is less than or equal to",">":"is greater than","<":"is less than","\\leftarrow":"left arrow","\\Leftarrow":"left arrow","\\rightarrow":"right arrow","\\Rightarrow":"right arrow",":":"colon"},h={"\\underleftarrow":"left arrow","\\underrightarrow":"right arrow","\\underleftrightarrow":"left-right arrow","\\undergroup":"group","\\underlinesegment":"line segment","\\utilde":"tilde"},b=(e,r,t)=>{if(!e)return;let a;a="open"===r?e in c?c[e]:l[e]||e:"close"===r?e in p?p[e]:l[e]||e:"bin"===r?u[e]||e:"rel"===r?d[e]||e:l[e]||e;const o=t[t.length-1];/^\d+$/.test(a)&&t.length>0&&"string"==typeof o&&/^\d+$/.test(o)?t[t.length-1]+=a:a&&t.push(a)},m=(e,r)=>{const t=[];e.push(t),r(t)},f=function(e,r,t){if(void 0===r&&(r=[]),e instanceof Array)for(let a=0;a<e.length;a++)f(e[a],r,t);else((e,r,t)=>{switch(e.type){case"accent":m(r,r=>{f(e.base,r,t),r.push("with"),b(e.label,"normal",r),r.push("on top")});break;case"accentUnder":m(r,r=>{f(e.base,r,t),r.push("with"),b(h[e.label],"normal",r),r.push("underneath")});break;case"accent-token":case"color-token":case"kern":case"leftright-right":case"size":case"infix":case"internal":break;case"atom":{const{text:t}=e;switch(e.family){case"bin":b(t,"bin",r);break;case"close":b(t,"close",r);break;case"inner":b(e.text,"inner",r);break;case"open":b(t,"open",r);break;case"punct":b(t,"punct",r);break;case"rel":b(t,"rel",r);break;default:throw e.family,new Error('"'+e.family+'" is not a valid atom type')}break}case"color":{const a=e.color.replace(/katex-/,"");m(r,r=>{r.push("start color "+a),f(e.body,r,t),r.push("end color "+a)});break}case"delimsizing":e.delim&&"."!==e.delim&&b(e.delim,"normal",r);break;case"genfrac":m(r,r=>{const{leftDelim:a,rightDelim:o}=e;e.hasBarLine?(r.push("start fraction"),a&&b(a,"open",r),f(e.numer,r,t),r.push("divided by"),f(e.denom,r,t),o&&b(o,"close",r),r.push("end fraction")):(r.push("start binomial"),a&&b(a,"open",r),f(e.numer,r,t),r.push("over"),f(e.denom,r,t),o&&b(o,"close",r),r.push("end binomial"))});break;case"hbox":case"lap":case"ordgroup":case"raisebox":case"sizing":case"styling":case"smash":case"vcenter":case"operatorname":case"font":case"html":f(e.body,r,t);break;case"leftright":m(r,r=>{b(e.left,"open",r),f(e.body,r,t),b(e.right,"close",r)});break;case"mathord":b(e.text,"normal",r);break;case"op":{const{body:a,name:o}=e;a?f(a,r,t):o&&b(o,"normal",r);break}case"op-token":case"textord":b(e.text,t,r);break;case"overline":m(r,function(r){r.push("start overline"),f(e.body,r,t),r.push("end overline")});break;case"pmb":r.push("bold");break;case"phantom":r.push("empty space");break;case"rule":r.push("rectangle");break;case"spacing":r.push("space");break;case"sqrt":m(r,r=>{const{body:a,index:o}=e;if(o)return"3"===w(f(o,[],t)).join(",")?(r.push("cube root of"),f(a,r,t),void r.push("end cube root")):(r.push("root"),r.push("start index"),f(o,r,t),void r.push("end index"));r.push("square root of"),f(a,r,t),r.push("end square root")});break;case"supsub":{const{base:a,sub:o,sup:n}=e;let s=!1;if(a&&(f(a,r,t),s="op"===a.type&&"\\log"===a.name),o){const e=s?"base":"subscript";m(r,function(r){r.push("start "+e),f(o,r,t),r.push("end "+e)})}n&&m(r,function(e){const r=w(f(n,[],t)).join(",");r in i?e.push(i[r]):(e.push("start superscript"),f(n,e,t),e.push("end superscript"))});break}case"text":if("\\textbf"===e.font){m(r,function(r){r.push("start bold text"),f(e.body,r,t),r.push("end bold text")});break}m(r,function(r){r.push("start text"),f(e.body,r,t),r.push("end text")});break;case"enclose":if(/cancel/.test(e.label)){m(r,function(r){r.push("start cancel"),f(e.body,r,t),r.push("end cancel")});break}if(/box/.test(e.label)){m(r,function(r){r.push("start box"),f(e.body,r,t),r.push("end box")});break}if(/sout/.test(e.label)){m(r,function(r){r.push("start strikeout"),f(e.body,r,t),r.push("end strikeout")});break}if(/phase/.test(e.label)){m(r,function(r){r.push("start phase angle"),f(e.body,r,t),r.push("end phase angle")});break}throw new Error("KaTeX-a11y: enclose node with "+e.label+" not supported yet");case"vphantom":throw new Error("KaTeX-a11y: vphantom not implemented yet");case"hphantom":throw new Error("KaTeX-a11y: hphantom not implemented yet");case"array":throw new Error("KaTeX-a11y: array not implemented yet");case"raw":throw new Error("KaTeX-a11y: raw not implemented yet");case"url":throw new Error("KaTeX-a11y: url not implemented yet");case"tag":throw new Error("KaTeX-a11y: tag not implemented yet");case"verb":b("start verbatim","normal",r),b(e.body,"normal",r),b("end verbatim","normal",r);break;case"environment":throw new Error("KaTeX-a11y: environment not implemented yet");case"horizBrace":b("start "+e.label.slice(1),"normal",r),f(e.base,r,t),b("end "+e.label.slice(1),"normal",r);break;case"includegraphics":throw new Error("KaTeX-a11y: includegraphics not implemented yet");case"href":throw new Error("KaTeX-a11y: href not implemented yet");case"cr":throw new Error("KaTeX-a11y: cr not implemented yet");case"underline":m(r,function(r){r.push("start underline"),f(e.body,r,t),r.push("end underline")});break;case"xArrow":throw new Error("KaTeX-a11y: xArrow not implemented yet");case"cdlabel":throw new Error("KaTeX-a11y: cdlabel not implemented yet");case"cdlabelparent":throw new Error("KaTeX-a11y: cdlabelparent not implemented yet");case"mclass":{const t=e.mclass.slice(1);f(e.body,r,t);break}case"mathchoice":f(e.text,r,t);break;case"htmlmathml":f(e.mathml,r,t);break;case"middle":b(e.delim,t,r);break;default:throw new Error("KaTeX a11y un-recognized type: "+e.type)}})(e,r,t);return r},w=function(e){let r=[];return e.forEach(function(e){Array.isArray(e)?r=r.concat(w(e)):r.push(e)}),r};return o.default=function(e,r){const t=s().__parse(e,r),a=f(t,[],"normal");return w(a).join(", ")},o=o.default}()});