katex 0.12.0 → 0.13.3

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 (167) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +1 -1
  3. package/README.md +8 -7
  4. package/contrib/auto-render/auto-render.js +12 -19
  5. package/contrib/auto-render/index.html +9 -3
  6. package/contrib/auto-render/splitAtDelimiters.js +44 -61
  7. package/contrib/auto-render/test/auto-render-spec.js +88 -52
  8. package/contrib/copy-tex/README.md +5 -9
  9. package/contrib/copy-tex/copy-tex.css +0 -3
  10. package/contrib/mathtex-script-type/README.md +5 -5
  11. package/contrib/mhchem/README.md +4 -2
  12. package/contrib/render-a11y-string/render-a11y-string.js +31 -2
  13. package/contrib/render-a11y-string/test/render-a11y-string-spec.js +23 -0
  14. package/dist/README.md +8 -7
  15. package/dist/contrib/auto-render.js +148 -171
  16. package/dist/contrib/auto-render.min.js +1 -1
  17. package/dist/contrib/auto-render.mjs +91 -95
  18. package/dist/contrib/copy-tex.css +3 -3
  19. package/dist/contrib/copy-tex.js +11 -108
  20. package/dist/contrib/copy-tex.min.css +1 -1
  21. package/dist/contrib/copy-tex.min.js +1 -1
  22. package/dist/contrib/copy-tex.mjs +21 -20
  23. package/dist/contrib/mathtex-script-type.js +66 -91
  24. package/dist/contrib/mathtex-script-type.min.js +1 -1
  25. package/dist/contrib/mathtex-script-type.mjs +3 -3
  26. package/dist/contrib/mhchem.js +70 -95
  27. package/dist/contrib/mhchem.min.js +1 -1
  28. package/dist/contrib/mhchem.mjs +2 -2
  29. package/dist/contrib/render-a11y-string.js +97 -92
  30. package/dist/contrib/render-a11y-string.min.js +1 -1
  31. package/dist/contrib/render-a11y-string.mjs +86 -45
  32. package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
  33. package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
  34. package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  35. package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  36. package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  37. package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  38. package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  39. package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  40. package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  41. package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  42. package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  43. package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  44. package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  45. package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  46. package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  47. package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
  48. package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
  49. package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
  50. package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  51. package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  52. package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  53. package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
  54. package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
  55. package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
  56. package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
  57. package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
  58. package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
  59. package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  60. package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  61. package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  62. package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
  63. package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
  64. package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
  65. package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  66. package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  67. package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  68. package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  69. package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  70. package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  71. package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  72. package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  73. package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  74. package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
  75. package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
  76. package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
  77. package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
  78. package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
  79. package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  80. package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
  81. package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
  82. package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  83. package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
  84. package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
  85. package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  86. package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
  87. package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
  88. package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  89. package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  90. package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  91. package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  92. package/dist/katex.css +66 -10
  93. package/dist/katex.js +2714 -1950
  94. package/dist/katex.min.css +1 -1
  95. package/dist/katex.min.js +1 -1
  96. package/dist/katex.mjs +3162 -2372
  97. package/katex.js +4 -3
  98. package/package.json +69 -59
  99. package/src/Lexer.js +4 -2
  100. package/src/MacroExpander.js +117 -37
  101. package/src/Options.js +2 -2
  102. package/src/ParseError.js +1 -1
  103. package/src/Parser.js +100 -159
  104. package/src/Settings.js +2 -2
  105. package/src/Style.js +4 -4
  106. package/src/Token.js +1 -1
  107. package/src/buildCommon.js +12 -5
  108. package/src/buildHTML.js +11 -0
  109. package/src/buildMathML.js +6 -0
  110. package/src/defineEnvironment.js +0 -3
  111. package/src/defineFunction.js +15 -22
  112. package/src/delimiter.js +61 -57
  113. package/src/domTree.js +1 -1
  114. package/src/environments/array.js +223 -35
  115. package/src/environments/cd.js +312 -0
  116. package/src/fontMetrics.js +1 -1
  117. package/src/fontMetricsData.js +2076 -0
  118. package/src/fonts/.gitignore +9 -0
  119. package/src/fonts/Makefile +139 -0
  120. package/src/fonts/default.cfg +20 -0
  121. package/src/fonts/generate_fonts.py +61 -0
  122. package/src/fonts/lib/Extra.otf +0 -0
  123. package/src/fonts/lib/Space.ttx +234 -0
  124. package/src/fonts/makeBlacker +49 -0
  125. package/src/fonts/makeFF +2003 -0
  126. package/src/fonts/xbbold.mf +182 -0
  127. package/src/fonts.less +64 -0
  128. package/src/functions/accent.js +3 -2
  129. package/src/functions/arrow.js +8 -2
  130. package/src/functions/color.js +4 -4
  131. package/src/functions/cr.js +7 -25
  132. package/src/functions/def.js +50 -24
  133. package/src/functions/delimsizing.js +8 -0
  134. package/src/functions/enclose.js +80 -12
  135. package/src/functions/environment.js +1 -1
  136. package/src/functions/font.js +3 -4
  137. package/src/functions/genfrac.js +36 -11
  138. package/src/functions/hbox.js +39 -0
  139. package/src/functions/kern.js +1 -0
  140. package/src/functions/mathchoice.js +1 -0
  141. package/src/functions/mclass.js +2 -1
  142. package/src/functions/op.js +3 -7
  143. package/src/functions/operatorname.js +1 -1
  144. package/src/functions/raisebox.js +0 -1
  145. package/src/functions/styling.js +1 -0
  146. package/src/functions/supsub.js +1 -3
  147. package/src/functions/symbolsOrd.js +0 -2
  148. package/src/functions/text.js +2 -3
  149. package/src/functions/vcenter.js +44 -0
  150. package/src/functions.js +3 -0
  151. package/src/katex.less +69 -16
  152. package/src/macros.js +42 -6
  153. package/src/mathMLTree.js +16 -1
  154. package/src/metrics/.gitignore +1 -0
  155. package/src/metrics/README.md +23 -0
  156. package/src/metrics/extract_tfms.py +114 -0
  157. package/src/metrics/extract_ttfs.py +119 -0
  158. package/src/metrics/format_json.py +28 -0
  159. package/src/metrics/mapping.pl +1224 -0
  160. package/src/metrics/parse_tfm.py +211 -0
  161. package/src/parseNode.js +29 -1
  162. package/src/parseTree.js +6 -0
  163. package/src/stretchy.js +12 -5
  164. package/src/svgGeometry.js +33 -4
  165. package/src/symbols.js +5 -3
  166. package/src/types.js +3 -2
  167. package/src/unicodeScripts.js +5 -0
@@ -0,0 +1,312 @@
1
+ // @flow
2
+ import buildCommon from "../buildCommon";
3
+ import defineFunction from "../defineFunction";
4
+ import mathMLTree from "../mathMLTree";
5
+ import * as html from "../buildHTML";
6
+ import * as mml from "../buildMathML";
7
+ import {assertSymbolNodeType} from "../parseNode";
8
+ import ParseError from "../ParseError";
9
+
10
+ import type Parser from "../Parser";
11
+ import type {ParseNode, AnyParseNode} from "../parseNode";
12
+
13
+ const cdArrowFunctionName = {
14
+ ">": "\\\\cdrightarrow",
15
+ "<": "\\\\cdleftarrow",
16
+ "=": "\\\\cdlongequal",
17
+ "A": "\\uparrow",
18
+ "V": "\\downarrow",
19
+ "|": "\\Vert",
20
+ ".": "no arrow",
21
+ };
22
+
23
+ const newCell = () => {
24
+ // Create an empty cell, to be filled below with parse nodes.
25
+ // The parseTree from this module must be constructed like the
26
+ // one created by parseArray(), so an empty CD cell must
27
+ // be a ParseNode<"styling">. And CD is always displaystyle.
28
+ // So these values are fixed and flow can do implicit typing.
29
+ return {type: "styling", body: [], mode: "math", style: "display"};
30
+ };
31
+
32
+ const isStartOfArrow = (node: AnyParseNode) => {
33
+ return (node.type === "textord" && node.text === "@");
34
+ };
35
+
36
+ const isLabelEnd = (node: AnyParseNode, endChar: string): boolean => {
37
+ return ((node.type === "mathord" || node.type === "atom") &&
38
+ node.text === endChar);
39
+ };
40
+
41
+ function cdArrow(
42
+ arrowChar: string,
43
+ labels: ParseNode<"ordgroup">[],
44
+ parser: Parser
45
+ ): AnyParseNode {
46
+ // Return a parse tree of an arrow and its labels.
47
+ // This acts in a way similar to a macro expansion.
48
+ const funcName = cdArrowFunctionName[arrowChar];
49
+ switch (funcName) {
50
+ case "\\\\cdrightarrow":
51
+ case "\\\\cdleftarrow":
52
+ return parser.callFunction(
53
+ funcName, [labels[0]], [labels[1]]
54
+ );
55
+ case "\\uparrow":
56
+ case "\\downarrow": {
57
+ const leftLabel = parser.callFunction(
58
+ "\\\\cdleft", [labels[0]], []
59
+ );
60
+ const bareArrow = {
61
+ type: "atom",
62
+ text: funcName,
63
+ mode: "math",
64
+ family: "rel",
65
+ };
66
+ const sizedArrow = parser.callFunction("\\Big", [bareArrow], []);
67
+ const rightLabel = parser.callFunction(
68
+ "\\\\cdright", [labels[1]], []
69
+ );
70
+ const arrowGroup = {
71
+ type: "ordgroup",
72
+ mode: "math",
73
+ body: [leftLabel, sizedArrow, rightLabel],
74
+ };
75
+ return parser.callFunction("\\\\cdparent", [arrowGroup], []);
76
+ }
77
+ case "\\\\cdlongequal":
78
+ return parser.callFunction("\\\\cdlongequal", [], []);
79
+ case "\\Vert": {
80
+ const arrow = {type: "textord", text: "\\Vert", mode: "math"};
81
+ return parser.callFunction("\\Big", [arrow], []);
82
+ }
83
+ default:
84
+ return {type: "textord", text: " ", mode: "math"};
85
+ }
86
+ }
87
+
88
+ export function parseCD(parser: Parser): ParseNode<"array"> {
89
+ // Get the array's parse nodes with \\ temporarily mapped to \cr.
90
+ const parsedRows: AnyParseNode[][] = [];
91
+ parser.gullet.beginGroup();
92
+ parser.gullet.macros.set("\\cr", "\\\\\\relax");
93
+ parser.gullet.beginGroup();
94
+ while (true) { // eslint-disable-line no-constant-condition
95
+ // Get the parse nodes for the next row.
96
+ parsedRows.push(parser.parseExpression(false, "\\\\"));
97
+ parser.gullet.endGroup();
98
+ parser.gullet.beginGroup();
99
+ const next = parser.fetch().text;
100
+ if (next === "&" || next === "\\\\") {
101
+ parser.consume();
102
+ } else if (next === "\\end") {
103
+ if (parsedRows[parsedRows.length - 1].length === 0) {
104
+ parsedRows.pop(); // final row ended in \\
105
+ }
106
+ break;
107
+ } else {
108
+ throw new ParseError("Expected \\\\ or \\cr or \\end",
109
+ parser.nextToken);
110
+ }
111
+ }
112
+
113
+ let row = [];
114
+ const body = [row];
115
+
116
+ // Loop thru the parse nodes. Collect them into cells and arrows.
117
+ for (let i = 0; i < parsedRows.length; i++) {
118
+ // Start a new row.
119
+ const rowNodes = parsedRows[i];
120
+ // Create the first cell.
121
+ let cell = newCell();
122
+
123
+ for (let j = 0; j < rowNodes.length; j++) {
124
+ if (!isStartOfArrow(rowNodes[j])) {
125
+ // If a parseNode is not an arrow, it goes into a cell.
126
+ cell.body.push(rowNodes[j]);
127
+ } else {
128
+ // Parse node j is an "@", the start of an arrow.
129
+ // Before starting on the arrow, push the cell into `row`.
130
+ row.push(cell);
131
+
132
+ // Now collect parseNodes into an arrow.
133
+ // The character after "@" defines the arrow type.
134
+ j += 1;
135
+ const arrowChar = assertSymbolNodeType(rowNodes[j]).text;
136
+
137
+ // Create two empty label nodes. We may or may not use them.
138
+ const labels: ParseNode<"ordgroup">[] = new Array(2);
139
+ labels[0] = {type: "ordgroup", mode: "math", body: []};
140
+ labels[1] = {type: "ordgroup", mode: "math", body: []};
141
+
142
+ // Process the arrow.
143
+ if ("=|.".indexOf(arrowChar) > -1) {
144
+ // Three "arrows", ``@=`, `@|`, and `@.`, do not take labels.
145
+ // Do nothing here.
146
+ } else if ("<>AV".indexOf(arrowChar) > -1) {
147
+ // Four arrows, `@>>>`, `@<<<`, `@AAA`, and `@VVV`, each take
148
+ // two optional labels. E.g. the right-point arrow syntax is
149
+ // really: @>{optional label}>{optional label}>
150
+ // Collect parseNodes into labels.
151
+ for (let labelNum = 0; labelNum < 2; labelNum++) {
152
+ let inLabel = true;
153
+ for (let k = j + 1; k < rowNodes.length; k++) {
154
+ if (isLabelEnd(rowNodes[k], arrowChar)) {
155
+ inLabel = false;
156
+ j = k;
157
+ break;
158
+ }
159
+ if (isStartOfArrow(rowNodes[k])) {
160
+ throw new ParseError("Missing a " + arrowChar +
161
+ " character to complete a CD arrow.", rowNodes[k]);
162
+ }
163
+
164
+ labels[labelNum].body.push(rowNodes[k]);
165
+ }
166
+ if (inLabel) {
167
+ // isLabelEnd never returned a true.
168
+ throw new ParseError("Missing a " + arrowChar +
169
+ " character to complete a CD arrow.", rowNodes[j]);
170
+ }
171
+ }
172
+ } else {
173
+ throw new ParseError(`Expected one of "<>AV=|." after @`,
174
+ rowNodes[j]);
175
+ }
176
+
177
+ // Now join the arrow to its labels.
178
+ const arrow: AnyParseNode = cdArrow(arrowChar, labels, parser);
179
+
180
+ // Wrap the arrow in ParseNode<"styling">.
181
+ // This is done to match parseArray() behavior.
182
+ const wrappedArrow = {
183
+ type: "styling",
184
+ body: [arrow],
185
+ mode: "math",
186
+ style: "display", // CD is always displaystyle.
187
+ };
188
+ row.push(wrappedArrow);
189
+ // In CD's syntax, cells are implicit. That is, everything that
190
+ // is not an arrow gets collected into a cell. So create an empty
191
+ // cell now. It will collect upcoming parseNodes.
192
+ cell = newCell();
193
+ }
194
+ }
195
+ if (i % 2 === 0) {
196
+ // Even-numbered rows consist of: cell, arrow, cell, arrow, ... cell
197
+ // The last cell is not yet pushed into `row`, so:
198
+ row.push(cell);
199
+ } else {
200
+ // Odd-numbered rows consist of: vert arrow, empty cell, ... vert arrow
201
+ // Remove the empty cell that was placed at the beginning of `row`.
202
+ row.shift();
203
+ }
204
+ row = [];
205
+ body.push(row);
206
+ }
207
+
208
+ // End row group
209
+ parser.gullet.endGroup();
210
+ // End array group defining \\
211
+ parser.gullet.endGroup();
212
+
213
+ // define column separation.
214
+ const cols = new Array(body[0].length).fill({
215
+ type: "align",
216
+ align: "c",
217
+ pregap: 0.25, // CD package sets \enskip between columns.
218
+ postgap: 0.25, // So pre and post each get half an \enskip, i.e. 0.25em.
219
+ });
220
+
221
+ return {
222
+ type: "array",
223
+ mode: "math",
224
+ body,
225
+ arraystretch: 1,
226
+ addJot: true,
227
+ rowGaps: [null],
228
+ cols,
229
+ colSeparationType: "CD",
230
+ hLinesBeforeRow: new Array(body.length + 1).fill([]),
231
+ };
232
+ }
233
+
234
+ // The functions below are not available for general use.
235
+ // They are here only for internal use by the {CD} environment in placing labels
236
+ // next to vertical arrows.
237
+
238
+ // We don't need any such functions for horizontal arrows because we can reuse
239
+ // the functionality that already exists for extensible arrows.
240
+
241
+ defineFunction({
242
+ type: "cdlabel",
243
+ names: ["\\\\cdleft", "\\\\cdright"],
244
+ props: {
245
+ numArgs: 1,
246
+ },
247
+ handler({parser, funcName}, args) {
248
+ return {
249
+ type: "cdlabel",
250
+ mode: parser.mode,
251
+ side: funcName.slice(4),
252
+ label: args[0],
253
+ };
254
+ },
255
+ htmlBuilder(group, options) {
256
+ const newOptions = options.havingStyle(options.style.sup());
257
+ const label = buildCommon.wrapFragment(
258
+ html.buildGroup(group.label, newOptions, options), options);
259
+ label.classes.push("cd-label-" + group.side);
260
+ label.style.bottom = (0.8 - label.depth) + "em";
261
+ // Zero out label height & depth, so vertical align of arrow is set
262
+ // by the arrow height, not by the label.
263
+ label.height = 0;
264
+ label.depth = 0;
265
+ return label;
266
+ },
267
+ mathmlBuilder(group, options) {
268
+ let label = new mathMLTree.MathNode("mrow",
269
+ [mml.buildGroup(group.label, options)]);
270
+ label = new mathMLTree.MathNode("mpadded", [label]);
271
+ label.setAttribute("width", "0");
272
+ if (group.side === "left") {
273
+ label.setAttribute("lspace", "-1width");
274
+ }
275
+ // We have to guess at vertical alignment. We know the arrow is 1.8em tall,
276
+ // But we don't know the height or depth of the label.
277
+ label.setAttribute("voffset", "0.7em");
278
+ label = new mathMLTree.MathNode("mstyle", [label]);
279
+ label.setAttribute("displaystyle", "false");
280
+ label.setAttribute("scriptlevel", "1");
281
+ return label;
282
+ },
283
+ });
284
+
285
+ defineFunction({
286
+ type: "cdlabelparent",
287
+ names: ["\\\\cdparent"],
288
+ props: {
289
+ numArgs: 1,
290
+ },
291
+ handler({parser}, args) {
292
+ return {
293
+ type: "cdlabelparent",
294
+ mode: parser.mode,
295
+ fragment: args[0],
296
+ };
297
+ },
298
+ htmlBuilder(group, options) {
299
+ // Wrap the vertical arrow and its labels.
300
+ // The parent gets position: relative. The child gets position: absolute.
301
+ // So CSS can locate the label correctly.
302
+ const parent = buildCommon.wrapFragment(
303
+ html.buildGroup(group.fragment, options), options
304
+ );
305
+ parent.classes.push("cd-vert-arrow");
306
+ return parent;
307
+ },
308
+ mathmlBuilder(group, options) {
309
+ return new mathMLTree.MathNode("mrow",
310
+ [mml.buildGroup(group.fragment, options)]);
311
+ },
312
+ });
@@ -96,7 +96,7 @@ const sigmasAndXis = {
96
96
  // metrics, including height, depth, italic correction, and skew (kern from the
97
97
  // character to the corresponding \skewchar)
98
98
  // This map is generated via `make metrics`. It should not be changed manually.
99
- import metricMap from "../submodules/katex-fonts/fontMetricsData";
99
+ import metricMap from "./fontMetricsData";
100
100
 
101
101
  // These are very rough approximations. We default to Times New Roman which
102
102
  // should have Latin-1 and Cyrillic characters, but may not depending on the