katex 0.10.0-rc → 0.10.2

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 (144) hide show
  1. package/CHANGELOG.md +214 -126
  2. package/README.md +18 -17
  3. package/cli.js +5 -1
  4. package/contrib/auto-render/README.md +1 -1
  5. package/contrib/auto-render/auto-render.js +4 -1
  6. package/contrib/auto-render/test/auto-render-spec.js +17 -0
  7. package/contrib/copy-tex/README.md +8 -2
  8. package/contrib/copy-tex/copy-tex.js +0 -1
  9. package/contrib/copy-tex/copy-tex.webpack.js +6 -0
  10. package/contrib/mathtex-script-type/README.md +10 -6
  11. package/contrib/mhchem/README.md +19 -0
  12. package/contrib/mhchem/mhchem.js +1695 -0
  13. package/contrib/mhchem/mhchem.patch +235 -0
  14. package/dist/README.md +18 -17
  15. package/dist/contrib/auto-render.js +179 -161
  16. package/dist/contrib/auto-render.min.js +1 -1
  17. package/dist/contrib/auto-render.mjs +215 -0
  18. package/dist/contrib/copy-tex.js +84 -62
  19. package/dist/contrib/copy-tex.min.css +1 -1
  20. package/dist/contrib/copy-tex.min.js +1 -1
  21. package/dist/contrib/copy-tex.mjs +85 -0
  22. package/dist/contrib/mathtex-script-type.js +17 -14
  23. package/dist/contrib/mathtex-script-type.mjs +24 -0
  24. package/dist/contrib/mhchem.js +3241 -0
  25. package/dist/contrib/mhchem.min.js +1 -0
  26. package/dist/contrib/mhchem.mjs +3109 -0
  27. package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
  28. package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
  29. package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  30. package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  31. package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  32. package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  33. package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  34. package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  35. package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  36. package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  37. package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  38. package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  39. package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  40. package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  41. package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  42. package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
  43. package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
  44. package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
  45. package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  46. package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  47. package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  48. package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
  49. package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
  50. package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
  51. package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
  52. package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
  53. package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
  54. package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  55. package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  56. package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  57. package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
  58. package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
  59. package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
  60. package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  61. package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  62. package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  63. package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  64. package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  65. package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  66. package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  67. package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  68. package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  69. package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
  70. package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
  71. package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
  72. package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
  73. package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
  74. package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  75. package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
  76. package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
  77. package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  78. package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
  79. package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
  80. package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  81. package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
  82. package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
  83. package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  84. package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  85. package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  86. package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  87. package/dist/katex.css +24 -9
  88. package/dist/katex.js +13295 -12413
  89. package/dist/katex.min.css +1 -1
  90. package/dist/katex.min.js +1 -1
  91. package/dist/katex.mjs +13388 -11826
  92. package/katex.js +1 -2
  93. package/package.json +60 -48
  94. package/src/Lexer.js +25 -25
  95. package/src/MacroExpander.js +0 -1
  96. package/src/Options.js +11 -75
  97. package/src/Parser.js +231 -313
  98. package/src/Settings.js +6 -0
  99. package/src/buildCommon.js +140 -103
  100. package/src/buildHTML.js +125 -121
  101. package/src/buildMathML.js +14 -4
  102. package/src/buildTree.js +16 -10
  103. package/src/delimiter.js +4 -3
  104. package/src/domTree.js +91 -44
  105. package/src/environments/array.js +120 -7
  106. package/src/fontMetrics.js +3 -2
  107. package/src/functions/arrow.js +21 -7
  108. package/src/functions/color.js +2 -37
  109. package/src/functions/delimsizing.js +18 -11
  110. package/src/functions/enclose.js +19 -4
  111. package/src/functions/environment.js +35 -4
  112. package/src/functions/font.js +1 -2
  113. package/src/functions/genfrac.js +35 -20
  114. package/src/functions/href.js +5 -3
  115. package/src/functions/includegraphics.js +146 -0
  116. package/src/functions/mclass.js +1 -0
  117. package/src/functions/op.js +21 -32
  118. package/src/functions/operatorname.js +1 -2
  119. package/src/functions/ordgroup.js +4 -0
  120. package/src/functions/phantom.js +7 -3
  121. package/src/functions/rule.js +20 -9
  122. package/src/functions/sizing.js +2 -4
  123. package/src/functions/smash.js +5 -2
  124. package/src/functions/sqrt.js +1 -4
  125. package/src/functions/styling.js +0 -1
  126. package/src/functions/supsub.js +6 -2
  127. package/src/functions/symbolsOp.js +4 -0
  128. package/src/functions/symbolsSpacing.js +29 -6
  129. package/src/functions/tag.js +20 -4
  130. package/src/functions/text.js +6 -4
  131. package/src/functions/verb.js +16 -4
  132. package/src/functions.js +2 -0
  133. package/src/katex.less +35 -12
  134. package/src/macros.js +161 -36
  135. package/src/mathMLTree.js +17 -19
  136. package/src/parseNode.js +27 -1
  137. package/src/stretchy.js +3 -1
  138. package/src/svgGeometry.js +1 -1
  139. package/src/symbols.js +39 -17
  140. package/src/tree.js +0 -4
  141. package/src/types.js +4 -3
  142. package/src/unicodeMake.js +1 -1
  143. package/src/utils.js +1 -62
  144. package/src/wide-character.js +2 -2
@@ -4,6 +4,8 @@ import buildCommon from "../buildCommon";
4
4
  import mathMLTree from "../mathMLTree";
5
5
  import ParseError from "../ParseError";
6
6
 
7
+ import type {ParseNode} from "../parseNode";
8
+
7
9
  defineFunction({
8
10
  type: "verb",
9
11
  names: ["\\verb"],
@@ -20,7 +22,7 @@ defineFunction({
20
22
  "\\verb ended by end of line instead of matching delimiter");
21
23
  },
22
24
  htmlBuilder(group, options) {
23
- const text = buildCommon.makeVerb(group, options);
25
+ const text = makeVerb(group);
24
26
  const body = [];
25
27
  // \verb enters text mode and therefore is sized like \textstyle
26
28
  const newOptions = options.havingStyle(options.style.text());
@@ -32,15 +34,25 @@ defineFunction({
32
34
  body.push(buildCommon.makeSymbol(c, "Typewriter-Regular",
33
35
  group.mode, newOptions, ["mord", "texttt"]));
34
36
  }
35
- buildCommon.tryCombineChars(body);
36
37
  return buildCommon.makeSpan(
37
38
  ["mord", "text"].concat(newOptions.sizingClasses(options)),
38
- body, newOptions);
39
+ buildCommon.tryCombineChars(body),
40
+ newOptions,
41
+ );
39
42
  },
40
43
  mathmlBuilder(group, options) {
41
- const text = new mathMLTree.TextNode(buildCommon.makeVerb(group, options));
44
+ const text = new mathMLTree.TextNode(makeVerb(group));
42
45
  const node = new mathMLTree.MathNode("mtext", [text]);
43
46
  node.setAttribute("mathvariant", "monospace");
44
47
  return node;
45
48
  },
46
49
  });
50
+
51
+ /**
52
+ * Converts verb group into body string.
53
+ *
54
+ * \verb* replaces each space with an open box \u2423
55
+ * \verb replaces each space with a no-break space \xA0
56
+ */
57
+ const makeVerb = (group: ParseNode<"verb">): string =>
58
+ group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');
package/src/functions.js CHANGED
@@ -21,6 +21,8 @@ import "./functions/genfrac";
21
21
  import "./functions/horizBrace";
22
22
  import "./functions/href";
23
23
  import "./functions/htmlmathml";
24
+ // Disabled until https://github.com/KaTeX/KaTeX/pull/1794 is merged.
25
+ // import "./functions/includegraphics";
24
26
  import "./functions/kern";
25
27
  import "./functions/lap";
26
28
  import "./functions/math";
package/src/katex.less CHANGED
@@ -4,6 +4,9 @@
4
4
  // The mu unit is defined as 1/18 em
5
5
  @mu: 1/18em;
6
6
 
7
+ // The version is dynamically set from package.json via webpack.common.js
8
+ @version: "";
9
+
7
10
  .katex {
8
11
  font: normal 1.21em KaTeX_Main, Times New Roman, serif;
9
12
  line-height: 1.2;
@@ -18,6 +21,10 @@
18
21
  // mode, while still allowing background/foreground setting on root .katex
19
22
  * { -ms-high-contrast-adjust: none !important; }
20
23
 
24
+ .katex-version::after {
25
+ content: @version;
26
+ }
27
+
21
28
  .katex-mathml {
22
29
  // Accessibility hack to only show to screen readers
23
30
  // Found at: http://a11yproject.com/posts/how-to-hide-content/
@@ -74,11 +81,16 @@
74
81
  }
75
82
 
76
83
  // Math fonts.
77
- .mathit {
84
+ .mathdefault {
78
85
  font-family: KaTeX_Math;
79
86
  font-style: italic;
80
87
  }
81
88
 
89
+ .mathit {
90
+ font-family: KaTeX_Main;
91
+ font-style: italic;
92
+ }
93
+
82
94
  .mathrm {
83
95
  font-style: normal;
84
96
  }
@@ -138,11 +150,6 @@
138
150
  font-style: italic;
139
151
  }
140
152
 
141
- .mainit {
142
- font-family: KaTeX_Main;
143
- font-style: italic;
144
- }
145
-
146
153
  .mainrm {
147
154
  font-family: KaTeX_Main;
148
155
  font-style: normal;
@@ -464,6 +471,14 @@
464
471
  stroke-opacity: 1;
465
472
  }
466
473
 
474
+ img {
475
+ border-style: none;
476
+ min-width: 0;
477
+ min-height: 0;
478
+ max-width: none;
479
+ max-height: none;
480
+ }
481
+
467
482
  // Define CSS for image whose width will match its span width.
468
483
  .stretchy {
469
484
  width: 100%;
@@ -534,14 +549,10 @@
534
549
  padding: 0 0.3em 0 0.3em; // \fboxsep = 3pt
535
550
  }
536
551
 
537
- .fbox {
538
- box-sizing: border-box;
539
- border: 0.04em solid black; // \fboxrule = 0.4pt
540
- }
541
-
552
+ .fbox,
542
553
  .fcolorbox {
543
554
  box-sizing: border-box;
544
- border: 0.04em solid; // \fboxrule = 0.4pt
555
+ border: 0.04em solid; // \fboxrule = 0.4pt
545
556
  }
546
557
 
547
558
  .cancel-pad {
@@ -571,6 +582,7 @@
571
582
 
572
583
  > .katex-html {
573
584
  display: block;
585
+ position: relative;
574
586
 
575
587
  > .tag {
576
588
  position: absolute;
@@ -579,3 +591,14 @@
579
591
  }
580
592
  }
581
593
  }
594
+
595
+ // Left-justified tags (default is right-justified)
596
+ .katex-display.leqno > .katex > .katex-html > .tag {
597
+ left: 0;
598
+ right: auto;
599
+ }
600
+
601
+ // Flush-left display math
602
+ .katex-display.fleqn > .katex {
603
+ text-align: left;
604
+ }
package/src/macros.js CHANGED
@@ -298,8 +298,6 @@ defineMacro("\\providecommand", (context) => newcommand(context, true, true));
298
298
  // \let\bgroup={ \let\egroup=}
299
299
  defineMacro("\\bgroup", "{");
300
300
  defineMacro("\\egroup", "}");
301
- defineMacro("\\begingroup", "{");
302
- defineMacro("\\endgroup", "}");
303
301
 
304
302
  // Symbols from latex.ltx:
305
303
  // \def\lq{`}
@@ -323,17 +321,6 @@ defineMacro("\\copyright",
323
321
  defineMacro("\\textregistered",
324
322
  "\\html@mathml{\\textcircled{\\scriptsize R}}{\\char`®}");
325
323
 
326
- // Unicode double-struck letters
327
- defineMacro("\u2102", "\\mathbb{C}");
328
- defineMacro("\u210D", "\\mathbb{H}");
329
- defineMacro("\u2115", "\\mathbb{N}");
330
- defineMacro("\u2119", "\\mathbb{P}");
331
- defineMacro("\u211A", "\\mathbb{Q}");
332
- defineMacro("\u211D", "\\mathbb{R}");
333
- defineMacro("\u2124", "\\mathbb{Z}");
334
-
335
- defineMacro("\u210E", "\\mathit{h}"); // Planck constant
336
-
337
324
  // Characters omitted from Unicode range 1D400–1D7FF
338
325
  defineMacro("\u212C", "\\mathscr{B}"); // script
339
326
  defineMacro("\u2130", "\\mathscr{E}");
@@ -347,6 +334,9 @@ defineMacro("\u212D", "\\mathfrak{C}"); // Fraktur
347
334
  defineMacro("\u210C", "\\mathfrak{H}");
348
335
  defineMacro("\u2128", "\\mathfrak{Z}");
349
336
 
337
+ // Define \Bbbk with a macro that works in both HTML and MathML.
338
+ defineMacro("\\Bbbk", "\\Bbb{k}");
339
+
350
340
  // Unicode middle dot
351
341
  // The KaTeX fonts do not contain U+00B7. Instead, \cdotp displays
352
342
  // the dot at U+22C5 and gives it punct spacing.
@@ -361,7 +351,8 @@ defineMacro("\\clap", "\\mathclap{\\textrm{#1}}");
361
351
  // \DeclareMathSymbol{\not}{\mathrel}{symbols}{"36}
362
352
  // It's thus treated like a \mathrel, but defined by a symbol that has zero
363
353
  // width but extends to the right. We use \rlap to get that spacing.
364
- defineMacro("\\not", '\\mathrel{\\mathrlap\\@not}');
354
+ // For MathML we write U+0338 here. buildMathML.js will then do the overlay.
355
+ defineMacro("\\not", '\\html@mathml{\\mathrel{\\mathrlap\\@not}}{\\char"338}');
365
356
 
366
357
  // Negated symbols from base/fontmath.ltx:
367
358
  // \def\neq{\not=} \let\ne=\neq
@@ -605,8 +596,10 @@ defineMacro("\\tmspace", "\\TextOrMath{\\kern#1#3}{\\mskip#1#2}\\relax");
605
596
  defineMacro("\\,", "\\tmspace+{3mu}{.1667em}");
606
597
  // \let\thinspace\,
607
598
  defineMacro("\\thinspace", "\\,");
599
+ // \def\>{\mskip\medmuskip}
608
600
  // \renewcommand{\:}{\tmspace+\medmuskip{.2222em}}
609
- // TODO: math mode should use \medmuskip = 4mu plus 2mu minus 4mu
601
+ // TODO: \> and math mode of \: should use \medmuskip = 4mu plus 2mu minus 4mu
602
+ defineMacro("\\>", "\\mskip{4mu}");
610
603
  defineMacro("\\:", "\\tmspace+{4mu}{.2222em}");
611
604
  // \let\medspace\:
612
605
  defineMacro("\\medspace", "\\:");
@@ -730,40 +723,61 @@ defineMacro("\\ordinarycolon", ":");
730
723
  //TODO(edemaine): Not yet centered. Fix via \raisebox or #726
731
724
  defineMacro("\\vcentcolon", "\\mathrel{\\mathop\\ordinarycolon}");
732
725
  // \providecommand*\dblcolon{\vcentcolon\mathrel{\mkern-.9mu}\vcentcolon}
733
- defineMacro("\\dblcolon",
734
- "\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}");
726
+ defineMacro("\\dblcolon", "\\html@mathml{" +
727
+ "\\mathrel{\\vcentcolon\\mathrel{\\mkern-.9mu}\\vcentcolon}}" +
728
+ "{\\mathop{\\char\"2237}}");
735
729
  // \providecommand*\coloneqq{\vcentcolon\mathrel{\mkern-1.2mu}=}
736
- defineMacro("\\coloneqq", "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}");
730
+ defineMacro("\\coloneqq", "\\html@mathml{" +
731
+ "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}=}}" +
732
+ "{\\mathop{\\char\"2254}}"); // ≔
737
733
  // \providecommand*\Coloneqq{\dblcolon\mathrel{\mkern-1.2mu}=}
738
- defineMacro("\\Coloneqq", "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}");
734
+ defineMacro("\\Coloneqq", "\\html@mathml{" +
735
+ "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}=}}" +
736
+ "{\\mathop{\\char\"2237\\char\"3d}}");
739
737
  // \providecommand*\coloneq{\vcentcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
740
- defineMacro("\\coloneq",
741
- "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}");
738
+ defineMacro("\\coloneq", "\\html@mathml{" +
739
+ "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" +
740
+ "{\\mathop{\\char\"3a\\char\"2212}}");
742
741
  // \providecommand*\Coloneq{\dblcolon\mathrel{\mkern-1.2mu}\mathrel{-}}
743
- defineMacro("\\Coloneq",
744
- "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}");
742
+ defineMacro("\\Coloneq", "\\html@mathml{" +
743
+ "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\mathrel{-}}}" +
744
+ "{\\mathop{\\char\"2237\\char\"2212}}");
745
745
  // \providecommand*\eqqcolon{=\mathrel{\mkern-1.2mu}\vcentcolon}
746
- defineMacro("\\eqqcolon", "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
746
+ defineMacro("\\eqqcolon", "\\html@mathml{" +
747
+ "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" +
748
+ "{\\mathop{\\char\"2255}}"); // ≕
747
749
  // \providecommand*\Eqqcolon{=\mathrel{\mkern-1.2mu}\dblcolon}
748
- defineMacro("\\Eqqcolon", "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}");
750
+ defineMacro("\\Eqqcolon", "\\html@mathml{" +
751
+ "\\mathrel{=\\mathrel{\\mkern-1.2mu}\\dblcolon}}" +
752
+ "{\\mathop{\\char\"3d\\char\"2237}}");
749
753
  // \providecommand*\eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\vcentcolon}
750
- defineMacro("\\eqcolon",
751
- "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}");
754
+ defineMacro("\\eqcolon", "\\html@mathml{" +
755
+ "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\vcentcolon}}" +
756
+ "{\\mathop{\\char\"2239}}");
752
757
  // \providecommand*\Eqcolon{\mathrel{-}\mathrel{\mkern-1.2mu}\dblcolon}
753
- defineMacro("\\Eqcolon",
754
- "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}");
758
+ defineMacro("\\Eqcolon", "\\html@mathml{" +
759
+ "\\mathrel{\\mathrel{-}\\mathrel{\\mkern-1.2mu}\\dblcolon}}" +
760
+ "{\\mathop{\\char\"2212\\char\"2237}}");
755
761
  // \providecommand*\colonapprox{\vcentcolon\mathrel{\mkern-1.2mu}\approx}
756
- defineMacro("\\colonapprox",
757
- "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}");
762
+ defineMacro("\\colonapprox", "\\html@mathml{" +
763
+ "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\approx}}" +
764
+ "{\\mathop{\\char\"3a\\char\"2248}}");
758
765
  // \providecommand*\Colonapprox{\dblcolon\mathrel{\mkern-1.2mu}\approx}
759
- defineMacro("\\Colonapprox",
760
- "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}");
766
+ defineMacro("\\Colonapprox", "\\html@mathml{" +
767
+ "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\approx}}" +
768
+ "{\\mathop{\\char\"2237\\char\"2248}}");
761
769
  // \providecommand*\colonsim{\vcentcolon\mathrel{\mkern-1.2mu}\sim}
762
- defineMacro("\\colonsim", "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}");
770
+ defineMacro("\\colonsim", "\\html@mathml{" +
771
+ "\\mathrel{\\vcentcolon\\mathrel{\\mkern-1.2mu}\\sim}}" +
772
+ "{\\mathop{\\char\"3a\\char\"223c}}");
763
773
  // \providecommand*\Colonsim{\dblcolon\mathrel{\mkern-1.2mu}\sim}
764
- defineMacro("\\Colonsim", "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}");
774
+ defineMacro("\\Colonsim", "\\html@mathml{" +
775
+ "\\mathrel{\\dblcolon\\mathrel{\\mkern-1.2mu}\\sim}}" +
776
+ "{\\mathop{\\char\"2237\\char\"223c}}");
765
777
 
766
778
  // Some Unicode characters are implemented with macros to mathtools functions.
779
+ defineMacro("\u2237", "\\dblcolon"); // ::
780
+ defineMacro("\u2239", "\\eqcolon"); // -:
767
781
  defineMacro("\u2254", "\\coloneqq"); // :=
768
782
  defineMacro("\u2255", "\\eqqcolon"); // =:
769
783
  defineMacro("\u2A74", "\\Coloneqq"); // ::=
@@ -802,6 +816,52 @@ defineMacro("\\notni", "\\html@mathml{\\not\\ni}{\\mathrel{\\char`\u220C}}");
802
816
  defineMacro("\\limsup", "\\DOTSB\\mathop{\\operatorname{lim\\,sup}}\\limits");
803
817
  defineMacro("\\liminf", "\\DOTSB\\mathop{\\operatorname{lim\\,inf}}\\limits");
804
818
 
819
+ //////////////////////////////////////////////////////////////////////
820
+ // MathML alternates for KaTeX glyphs in the Unicode private area
821
+ defineMacro("\\gvertneqq", "\\html@mathml{\\@gvertneqq}{\u2269}");
822
+ defineMacro("\\lvertneqq", "\\html@mathml{\\@lvertneqq}{\u2268}");
823
+ defineMacro("\\ngeqq", "\\html@mathml{\\@ngeqq}{\u2271}");
824
+ defineMacro("\\ngeqslant", "\\html@mathml{\\@ngeqslant}{\u2271}");
825
+ defineMacro("\\nleqq", "\\html@mathml{\\@nleqq}{\u2270}");
826
+ defineMacro("\\nleqslant", "\\html@mathml{\\@nleqslant}{\u2270}");
827
+ defineMacro("\\nshortmid", "\\html@mathml{\\@nshortmid}{∤}");
828
+ defineMacro("\\nshortparallel", "\\html@mathml{\\@nshortparallel}{∦}");
829
+ defineMacro("\\nsubseteqq", "\\html@mathml{\\@nsubseteqq}{\u2288}");
830
+ defineMacro("\\nsupseteqq", "\\html@mathml{\\@nsupseteqq}{\u2289}");
831
+ defineMacro("\\varsubsetneq", "\\html@mathml{\\@varsubsetneq}{⊊}");
832
+ defineMacro("\\varsubsetneqq", "\\html@mathml{\\@varsubsetneqq}{⫋}");
833
+ defineMacro("\\varsupsetneq", "\\html@mathml{\\@varsupsetneq}{⊋}");
834
+ defineMacro("\\varsupsetneqq", "\\html@mathml{\\@varsupsetneqq}{⫌}");
835
+
836
+ //////////////////////////////////////////////////////////////////////
837
+ // stmaryrd and semantic
838
+
839
+ // The stmaryrd and semantic packages render the next four items by calling a
840
+ // glyph. Those glyphs do not exist in the KaTeX fonts. Hence the macros.
841
+
842
+ defineMacro("\\llbracket", "\\html@mathml{" +
843
+ "\\mathopen{[\\mkern-3.2mu[}}" +
844
+ "{\\mathopen{\\char`\u27e6}}");
845
+ defineMacro("\\rrbracket", "\\html@mathml{" +
846
+ "\\mathclose{]\\mkern-3.2mu]}}" +
847
+ "{\\mathclose{\\char`\u27e7}}");
848
+
849
+ defineMacro("\u27e6", "\\llbracket"); // blackboard bold [
850
+ defineMacro("\u27e7", "\\rrbracket"); // blackboard bold ]
851
+
852
+ defineMacro("\\lBrace", "\\html@mathml{" +
853
+ "\\mathopen{\\{\\mkern-3.2mu[}}" +
854
+ "{\\mathopen{\\char`\u2983}}");
855
+ defineMacro("\\rBrace", "\\html@mathml{" +
856
+ "\\mathclose{]\\mkern-3.2mu\\}}}" +
857
+ "{\\mathclose{\\char`\u2984}}");
858
+
859
+ defineMacro("\u2983", "\\lBrace"); // blackboard bold {
860
+ defineMacro("\u2984", "\\rBrace"); // blackboard bold }
861
+
862
+ // TODO: Create variable sized versions of the last two items. I believe that
863
+ // will require new font glyphs.
864
+
805
865
  //////////////////////////////////////////////////////////////////////
806
866
  // texvc.sty
807
867
 
@@ -863,7 +923,7 @@ defineMacro("\\Rarr", "\\Rightarrow");
863
923
  defineMacro("\\real", "\\Re");
864
924
  defineMacro("\\reals", "\\mathbb{R}");
865
925
  defineMacro("\\Reals", "\\mathbb{R}");
866
- defineMacro("\\Rho", "\\mathrm{R}");
926
+ defineMacro("\\Rho", "\\mathrm{P}");
867
927
  defineMacro("\\sdot", "\\cdot");
868
928
  defineMacro("\\sect", "\\S");
869
929
  defineMacro("\\spades", "\\spadesuit");
@@ -875,3 +935,68 @@ defineMacro("\\thetasym", "\\vartheta");
875
935
  // TODO: defineMacro("\\varcoppa", "\\\mbox{\\coppa}");
876
936
  defineMacro("\\weierp", "\\wp");
877
937
  defineMacro("\\Zeta", "\\mathrm{Z}");
938
+
939
+ //////////////////////////////////////////////////////////////////////
940
+ // statmath.sty
941
+ // https://ctan.math.illinois.edu/macros/latex/contrib/statmath/statmath.pdf
942
+
943
+ defineMacro("\\argmin", "\\DOTSB\\mathop{\\operatorname{arg\\,min}}\\limits");
944
+ defineMacro("\\argmax", "\\DOTSB\\mathop{\\operatorname{arg\\,max}}\\limits");
945
+
946
+ // Custom Khan Academy colors, should be moved to an optional package
947
+ defineMacro("\\blue", "\\textcolor{##6495ed}{#1}");
948
+ defineMacro("\\orange", "\\textcolor{##ffa500}{#1}");
949
+ defineMacro("\\pink", "\\textcolor{##ff00af}{#1}");
950
+ defineMacro("\\red", "\\textcolor{##df0030}{#1}");
951
+ defineMacro("\\green", "\\textcolor{##28ae7b}{#1}");
952
+ defineMacro("\\gray", "\\textcolor{gray}{##1}");
953
+ defineMacro("\\purple", "\\textcolor{##9d38bd}{#1}");
954
+ defineMacro("\\blueA", "\\textcolor{##ccfaff}{#1}");
955
+ defineMacro("\\blueB", "\\textcolor{##80f6ff}{#1}");
956
+ defineMacro("\\blueC", "\\textcolor{##63d9ea}{#1}");
957
+ defineMacro("\\blueD", "\\textcolor{##11accd}{#1}");
958
+ defineMacro("\\blueE", "\\textcolor{##0c7f99}{#1}");
959
+ defineMacro("\\tealA", "\\textcolor{##94fff5}{#1}");
960
+ defineMacro("\\tealB", "\\textcolor{##26edd5}{#1}");
961
+ defineMacro("\\tealC", "\\textcolor{##01d1c1}{#1}");
962
+ defineMacro("\\tealD", "\\textcolor{##01a995}{#1}");
963
+ defineMacro("\\tealE", "\\textcolor{##208170}{#1}");
964
+ defineMacro("\\greenA", "\\textcolor{##b6ffb0}{#1}");
965
+ defineMacro("\\greenB", "\\textcolor{##8af281}{#1}");
966
+ defineMacro("\\greenC", "\\textcolor{##74cf70}{#1}");
967
+ defineMacro("\\greenD", "\\textcolor{##1fab54}{#1}");
968
+ defineMacro("\\greenE", "\\textcolor{##0d923f}{#1}");
969
+ defineMacro("\\goldA", "\\textcolor{##ffd0a9}{#1}");
970
+ defineMacro("\\goldB", "\\textcolor{##ffbb71}{#1}");
971
+ defineMacro("\\goldC", "\\textcolor{##ff9c39}{#1}");
972
+ defineMacro("\\goldD", "\\textcolor{##e07d10}{#1}");
973
+ defineMacro("\\goldE", "\\textcolor{##a75a05}{#1}");
974
+ defineMacro("\\redA", "\\textcolor{##fca9a9}{#1}");
975
+ defineMacro("\\redB", "\\textcolor{##ff8482}{#1}");
976
+ defineMacro("\\redC", "\\textcolor{##f9685d}{#1}");
977
+ defineMacro("\\redD", "\\textcolor{##e84d39}{#1}");
978
+ defineMacro("\\redE", "\\textcolor{##bc2612}{#1}");
979
+ defineMacro("\\maroonA", "\\textcolor{##ffbde0}{#1}");
980
+ defineMacro("\\maroonB", "\\textcolor{##ff92c6}{#1}");
981
+ defineMacro("\\maroonC", "\\textcolor{##ed5fa6}{#1}");
982
+ defineMacro("\\maroonD", "\\textcolor{##ca337c}{#1}");
983
+ defineMacro("\\maroonE", "\\textcolor{##9e034e}{#1}");
984
+ defineMacro("\\purpleA", "\\textcolor{##ddd7ff}{#1}");
985
+ defineMacro("\\purpleB", "\\textcolor{##c6b9fc}{#1}");
986
+ defineMacro("\\purpleC", "\\textcolor{##aa87ff}{#1}");
987
+ defineMacro("\\purpleD", "\\textcolor{##7854ab}{#1}");
988
+ defineMacro("\\purpleE", "\\textcolor{##543b78}{#1}");
989
+ defineMacro("\\mintA", "\\textcolor{##f5f9e8}{#1}");
990
+ defineMacro("\\mintB", "\\textcolor{##edf2df}{#1}");
991
+ defineMacro("\\mintC", "\\textcolor{##e0e5cc}{#1}");
992
+ defineMacro("\\grayA", "\\textcolor{##f6f7f7}{#1}");
993
+ defineMacro("\\grayB", "\\textcolor{##f0f1f2}{#1}");
994
+ defineMacro("\\grayC", "\\textcolor{##e3e5e6}{#1}");
995
+ defineMacro("\\grayD", "\\textcolor{##d6d8da}{#1}");
996
+ defineMacro("\\grayE", "\\textcolor{##babec2}{#1}");
997
+ defineMacro("\\grayF", "\\textcolor{##888d93}{#1}");
998
+ defineMacro("\\grayG", "\\textcolor{##626569}{#1}");
999
+ defineMacro("\\grayH", "\\textcolor{##3b3e40}{#1}");
1000
+ defineMacro("\\grayI", "\\textcolor{##21242c}{#1}");
1001
+ defineMacro("\\kaBlue", "\\textcolor{##314453}{#1}");
1002
+ defineMacro("\\kaGreen", "\\textcolor{##71B307}{#1}");
package/src/mathMLTree.js CHANGED
@@ -25,7 +25,7 @@ export type MathNodeType =
25
25
  "mfrac" | "mroot" | "msqrt" |
26
26
  "mtable" | "mtr" | "mtd" | "mlabeledtr" |
27
27
  "mrow" | "menclose" |
28
- "mstyle" | "mpadded" | "mphantom";
28
+ "mstyle" | "mpadded" | "mphantom" | "mglyph";
29
29
 
30
30
  export interface MathDomNode extends VirtualNode {
31
31
  toText(): string;
@@ -126,18 +126,16 @@ export class MathNode implements MathDomNode {
126
126
  */
127
127
  export class TextNode implements MathDomNode {
128
128
  text: string;
129
- needsEscape: boolean;
130
129
 
131
- constructor(text: string, needsEscape: boolean = true) {
130
+ constructor(text: string) {
132
131
  this.text = text;
133
- this.needsEscape = needsEscape;
134
132
  }
135
133
 
136
134
  /**
137
135
  * Converts the text node into a DOM text node.
138
136
  */
139
137
  toNode(): Node {
140
- return document.createTextNode(this.toText());
138
+ return document.createTextNode(this.text);
141
139
  }
142
140
 
143
141
  /**
@@ -145,15 +143,15 @@ export class TextNode implements MathDomNode {
145
143
  * (representing the text itself).
146
144
  */
147
145
  toMarkup(): string {
148
- return this.toText();
146
+ return utils.escape(this.toText());
149
147
  }
150
148
 
151
149
  /**
152
- * Converts the text node into an escaped string
150
+ * Converts the text node into a string
153
151
  * (representing the text iteself).
154
152
  */
155
153
  toText(): string {
156
- return this.needsEscape ? utils.escape(this.text) : this.text;
154
+ return this.text;
157
155
  }
158
156
  }
159
157
 
@@ -171,25 +169,25 @@ class SpaceNode implements MathDomNode {
171
169
  constructor(width: number) {
172
170
  this.width = width;
173
171
  // See https://www.w3.org/TR/2000/WD-MathML2-20000328/chapter6.html
174
- // for a table of space-like characters. We consistently use the
175
- // &LongNames; because Unicode does not have single characters for
176
- // &ThickSpace; (\u2005\u200a) and all negative spaces.
172
+ // for a table of space-like characters. We use Unicode
173
+ // representations instead of &LongNames; as it's not clear how to
174
+ // make the latter via document.createTextNode.
177
175
  if (width >= 0.05555 && width <= 0.05556) {
178
- this.character = "&VeryThinSpace;"; // \u200a
176
+ this.character = "\u200a"; // &VeryThinSpace;
179
177
  } else if (width >= 0.1666 && width <= 0.1667) {
180
- this.character = "&ThinSpace;"; // \u2009
178
+ this.character = "\u2009"; // &ThinSpace;
181
179
  } else if (width >= 0.2222 && width <= 0.2223) {
182
- this.character = "&MediumSpace;"; // \u2005
180
+ this.character = "\u2005"; // &MediumSpace;
183
181
  } else if (width >= 0.2777 && width <= 0.2778) {
184
- this.character = "&ThickSpace;"; // \u2005\u200a
182
+ this.character = "\u2005\u200a"; // &ThickSpace;
185
183
  } else if (width >= -0.05556 && width <= -0.05555) {
186
- this.character = "&NegativeVeryThinSpace;";
184
+ this.character = "\u200a\u2063"; // &NegativeVeryThinSpace;
187
185
  } else if (width >= -0.1667 && width <= -0.1666) {
188
- this.character = "&NegativeThinSpace;";
186
+ this.character = "\u2009\u2063"; // &NegativeThinSpace;
189
187
  } else if (width >= -0.2223 && width <= -0.2222) {
190
- this.character = "&NegativeMediumSpace;";
188
+ this.character = "\u205f\u2063"; // &NegativeMediumSpace;
191
189
  } else if (width >= -0.2778 && width <= -0.2777) {
192
- this.character = "&NegativeThickSpace;";
190
+ this.character = "\u2005\u2063"; // &NegativeThickSpace;
193
191
  } else {
194
192
  this.character = null;
195
193
  }
package/src/parseNode.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @flow
2
2
  import {NON_ATOMS} from "./symbols";
3
3
  import type SourceLocation from "./SourceLocation";
4
- import type {AlignSpec} from "./environments/array";
4
+ import type {AlignSpec, ColSeparationType} from "./environments/array";
5
5
  import type {Atom} from "./symbols";
6
6
  import type {Mode, StyleStr} from "./types";
7
7
  import type {Token} from "./Token";
@@ -28,6 +28,7 @@ type ParseNodeTypes = {
28
28
  type: "array",
29
29
  mode: Mode,
30
30
  loc?: ?SourceLocation,
31
+ colSeparationType?: ColSeparationType,
31
32
  hskipBeforeAndAfter?: boolean,
32
33
  addJot?: boolean,
33
34
  cols?: AlignSpec[],
@@ -49,6 +50,12 @@ type ParseNodeTypes = {
49
50
  loc?: ?SourceLocation,
50
51
  color: string,
51
52
  |},
53
+ "keyVals": {|
54
+ type: "keyVals",
55
+ mode: Mode,
56
+ loc?: ?SourceLocation,
57
+ keyVals: string,
58
+ |},
52
59
  // To avoid requiring run-time type assertions, this more carefully captures
53
60
  // the requirements on the fields per the op.js htmlBuilder logic:
54
61
  // - `body` and `value` are NEVER set simultanouesly.
@@ -60,6 +67,7 @@ type ParseNodeTypes = {
60
67
  limits: boolean,
61
68
  alwaysHandleSupSub?: boolean,
62
69
  suppressBaseShift?: boolean,
70
+ parentIsSupSub: boolean,
63
71
  symbol: boolean,
64
72
  name: string,
65
73
  body?: void,
@@ -70,6 +78,7 @@ type ParseNodeTypes = {
70
78
  limits: boolean,
71
79
  alwaysHandleSupSub?: boolean,
72
80
  suppressBaseShift?: boolean,
81
+ parentIsSupSub: boolean,
73
82
  symbol: false, // If 'symbol' is true, `body` *must* be set.
74
83
  name?: void,
75
84
  body: AnyParseNode[],
@@ -79,6 +88,13 @@ type ParseNodeTypes = {
79
88
  mode: Mode,
80
89
  loc?: ?SourceLocation,
81
90
  body: AnyParseNode[],
91
+ semisimple?: boolean,
92
+ |},
93
+ "raw": {|
94
+ type: "raw",
95
+ mode: Mode,
96
+ loc?: ?SourceLocation,
97
+ string: string,
82
98
  |},
83
99
  "size": {|
84
100
  type: "size",
@@ -264,6 +280,16 @@ type ParseNodeTypes = {
264
280
  html: AnyParseNode[],
265
281
  mathml: AnyParseNode[],
266
282
  |},
283
+ "includegraphics": {|
284
+ type: "includegraphics",
285
+ mode: Mode,
286
+ loc?: ?SourceLocation,
287
+ alt: string,
288
+ width: Measurement,
289
+ height: Measurement,
290
+ totalheight: Measurement,
291
+ src: string,
292
+ |},
267
293
  "infix": {|
268
294
  type: "infix",
269
295
  mode: Mode,
package/src/stretchy.js CHANGED
@@ -25,8 +25,10 @@ const stretchyCodePoint: {[string]: string} = {
25
25
  overrightarrow: "\u2192",
26
26
  underrightarrow: "\u2192",
27
27
  xrightarrow: "\u2192",
28
- underbrace: "\u23b5",
28
+ underbrace: "\u23df",
29
29
  overbrace: "\u23de",
30
+ overgroup: "\u23e0",
31
+ undergroup: "\u23e1",
30
32
  overleftrightarrow: "\u2194",
31
33
  underleftrightarrow: "\u2194",
32
34
  xleftrightarrow: "\u2194",
@@ -325,7 +325,7 @@ s-74.2 66.3 -121.5 85c-10 4 -16 7.7 -18 11c0 8.7 6 14.3 18 17c47.3 18.7 87.8 47
325
325
  121.5 85s56.5 81.3 68.5 130c0.7 2 1.3 5 2 9s1.2 6.7 1.5 8c0.3 1.3 1 3.3 2 6
326
326
  s2.2 4.5 3.5 5.5c1.3 1 3.3 1.8 6 2.5s6 1 10 1c14 0 21 -3.7 21 -11
327
327
  c0 -2 -2 -10.3 -6 -25c-20 -79.3 -65 -146.7 -135 -202l-3 -3h399890z
328
- M100 241v40h399900v-40z M0 241v40h399900v-40zM0 241v40h399900v-40z`,
328
+ M100 620v40h399900v-40z M0 241v40h399900v-40zM0 241v40h399900v-40z`,
329
329
 
330
330
  // rightarrowabovebar is mostly from glyph U+2192, KaTeX Main
331
331
  rightarrowabovebar: `M0 241v40h399891c-47.3 35.3-84 78-110 128-16.7 32