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
@@ -46,26 +46,10 @@ export type FunctionPropSpec = {
46
46
  // should appear before types for mandatory arguments.
47
47
  argTypes?: ArgType[],
48
48
 
49
- // The greediness of the function to use ungrouped arguments.
50
- //
51
- // E.g. if you have an expression
52
- // \sqrt \frac 1 2
53
- // since \frac has greediness=2 vs \sqrt's greediness=1, \frac
54
- // will use the two arguments '1' and '2' as its two arguments,
55
- // then that whole function will be used as the argument to
56
- // \sqrt. On the other hand, the expressions
57
- // \frac \frac 1 2 3
58
- // and
59
- // \frac \sqrt 1 2
60
- // will fail because \frac and \frac have equal greediness
61
- // and \sqrt has a lower greediness than \frac respectively. To
62
- // make these parse, we would have to change them to:
63
- // \frac {\frac 1 2} 3
64
- // and
65
- // \frac {\sqrt 1} 2
66
- //
67
- // The default value is `1`
68
- greediness?: number,
49
+ // Whether it expands to a single token or a braced group of tokens.
50
+ // If it's grouped, it can be used as an argument to primitive commands,
51
+ // such as \sqrt (without the optional argument) and super/subscript.
52
+ allowedInArgument?: boolean,
69
53
 
70
54
  // Whether or not the function is allowed inside text mode
71
55
  // (default false)
@@ -83,6 +67,9 @@ export type FunctionPropSpec = {
83
67
 
84
68
  // Must be true if the function is an infix operator.
85
69
  infix?: boolean,
70
+
71
+ // Whether or not the function is a TeX primitive.
72
+ primitive?: boolean,
86
73
  };
87
74
 
88
75
  type FunctionDefSpec<NODETYPE: NodeType> = {|
@@ -123,11 +110,12 @@ export type FunctionSpec<NODETYPE: NodeType> = {|
123
110
  type: NODETYPE, // Need to use the type to avoid error. See NOTES below.
124
111
  numArgs: number,
125
112
  argTypes?: ArgType[],
126
- greediness: number,
113
+ allowedInArgument: boolean,
127
114
  allowedInText: boolean,
128
115
  allowedInMath: boolean,
129
116
  numOptionalArgs: number,
130
117
  infix: boolean,
118
+ primitive: boolean,
131
119
 
132
120
  // FLOW TYPE NOTES: Doing either one of the following two
133
121
  //
@@ -179,13 +167,14 @@ export default function defineFunction<NODETYPE: NodeType>({
179
167
  type,
180
168
  numArgs: props.numArgs,
181
169
  argTypes: props.argTypes,
182
- greediness: (props.greediness === undefined) ? 1 : props.greediness,
170
+ allowedInArgument: !!props.allowedInArgument,
183
171
  allowedInText: !!props.allowedInText,
184
172
  allowedInMath: (props.allowedInMath === undefined)
185
173
  ? true
186
174
  : props.allowedInMath,
187
175
  numOptionalArgs: props.numOptionalArgs || 0,
188
176
  infix: !!props.infix,
177
+ primitive: !!props.primitive,
189
178
  handler: handler,
190
179
  };
191
180
  for (let i = 0; i < names.length; ++i) {
@@ -223,6 +212,10 @@ export function defineFunctionBuilders<NODETYPE: NodeType>({
223
212
  });
224
213
  }
225
214
 
215
+ export const normalizeArgument = function(arg: AnyParseNode): AnyParseNode {
216
+ return arg.type === "ordgroup" && arg.body.length === 1 ? arg.body[0] : arg;
217
+ };
218
+
226
219
  // Since the corresponding buildHTML/buildMathML function expects a
227
220
  // list of elements, we normalize for different kinds of arguments
228
221
  export const ordargument = function(arg: AnyParseNode): AnyParseNode[] {
package/src/delimiter.js CHANGED
@@ -25,11 +25,12 @@ import ParseError from "./ParseError";
25
25
  import Style from "./Style";
26
26
 
27
27
  import {PathNode, SvgNode, SymbolNode} from "./domTree";
28
- import {sqrtPath} from "./svgGeometry";
28
+ import {sqrtPath, innerPath} from "./svgGeometry";
29
29
  import buildCommon from "./buildCommon";
30
30
  import {getCharacterMetrics} from "./fontMetrics";
31
31
  import symbols from "./symbols";
32
32
  import utils from "./utils";
33
+ import fontMetricsData from "./fontMetricsData";
33
34
 
34
35
  import type Options from "./Options";
35
36
  import type {CharacterMetrics} from "./fontMetrics";
@@ -153,10 +154,10 @@ const makeLargeDelim = function(delim,
153
154
  };
154
155
 
155
156
  /**
156
- * Make an inner span with the given offset and in the given font. This is used
157
- * in `makeStackedDelim` to make the stacking pieces for the delimiter.
157
+ * Make a span from a font glyph with the given offset and in the given font.
158
+ * This is used in makeStackedDelim to make the stacking pieces for the delimiter.
158
159
  */
159
- const makeInner = function(
160
+ const makeGlyphSpan = function(
160
161
  symbol: string,
161
162
  font: "Size1-Regular" | "Size4-Regular",
162
163
  mode: Mode,
@@ -169,17 +170,45 @@ const makeInner = function(
169
170
  sizeClass = "delim-size4";
170
171
  }
171
172
 
172
- const inner = buildCommon.makeSpan(
173
+ const corner = buildCommon.makeSpan(
173
174
  ["delimsizinginner", sizeClass],
174
175
  [buildCommon.makeSpan([], [buildCommon.makeSymbol(symbol, font, mode)])]);
175
176
 
176
177
  // Since this will be passed into `makeVList` in the end, wrap the element
177
178
  // in the appropriate tag that VList uses.
178
- return {type: "elem", elem: inner};
179
+ return {type: "elem", elem: corner};
180
+ };
181
+
182
+ const makeInner = function(
183
+ ch: string,
184
+ height: number,
185
+ options: Options
186
+ ): VListElem {
187
+ // Create a span with inline SVG for the inner part of a tall stacked delimiter.
188
+ const width = fontMetricsData['Size4-Regular'][ch.charCodeAt(0)]
189
+ ? fontMetricsData['Size4-Regular'][ch.charCodeAt(0)][4].toFixed(3)
190
+ : fontMetricsData['Size1-Regular'][ch.charCodeAt(0)][4].toFixed(3);
191
+ const path = new PathNode("inner", innerPath(ch, Math.round(1000 * height)));
192
+ const svgNode = new SvgNode([path], {
193
+ "width": width + "em",
194
+ "height": height + "em",
195
+ // Override CSS rule `.katex svg { width: 100% }`
196
+ "style": "width:" + width + "em",
197
+ "viewBox": "0 0 " + 1000 * width + " " + Math.round(1000 * height),
198
+ "preserveAspectRatio": "xMinYMin",
199
+ });
200
+ const span = buildCommon.makeSvgSpan([], [svgNode], options);
201
+ span.height = height;
202
+ span.style.height = height + "em";
203
+ span.style.width = width + "em";
204
+ return {type: "elem", elem: span};
179
205
  };
180
206
 
181
- // Helper for makeStackedDelim
182
- const lap = {type: "kern", size: -0.005};
207
+ // Helpers for makeStackedDelim
208
+ const lapInEms = 0.008;
209
+ const lap = {type: "kern", size: -1 * lapInEms};
210
+ const verts = ["|", "\\lvert", "\\rvert", "\\vert"];
211
+ const doubleVerts = ["\\|", "\\lVert", "\\rVert", "\\Vert"];
183
212
 
184
213
  /**
185
214
  * Make a stacked delimiter out of a given delimiter, with the total height at
@@ -223,6 +252,10 @@ const makeStackedDelim = function(
223
252
  top = "\\Uparrow";
224
253
  repeat = "\u2016";
225
254
  bottom = "\\Downarrow";
255
+ } else if (utils.contains(verts, delim)) {
256
+ repeat = "\u2223";
257
+ } else if (utils.contains(doubleVerts, delim)) {
258
+ repeat = "\u2225";
226
259
  } else if (delim === "[" || delim === "\\lbrack") {
227
260
  top = "\u23a1";
228
261
  repeat = "\u23a2";
@@ -331,74 +364,44 @@ const makeStackedDelim = function(
331
364
  // Calculate the depth
332
365
  const depth = realHeightTotal / 2 - axisHeight;
333
366
 
334
- // This function differs from the TeX procedure in one way.
335
- // We shift each repeat element downwards by 0.005em, to prevent a gap
336
- // due to browser floating point rounding error.
337
- // Then, at the last element-to element joint, we add one extra repeat
338
- // element to cover the gap created by the shifts.
339
- // Find the shift needed to align the upper end of the extra element at a point
340
- // 0.005em above the lower end of the top element.
341
- const shiftOfExtraElement = (repeatCount + 1) * 0.005 - repeatHeightTotal;
342
367
 
343
368
  // Now, we start building the pieces that will go into the vlist
344
-
345
- // Keep a list of the inner pieces
346
- const inners = [];
369
+ // Keep a list of the pieces of the stacked delimiter
370
+ const stack = [];
347
371
 
348
372
  // Add the bottom symbol
349
- inners.push(makeInner(bottom, font, mode));
373
+ stack.push(makeGlyphSpan(bottom, font, mode));
374
+ stack.push(lap); // overlap
350
375
 
351
376
  if (middle === null) {
352
- // Add that many symbols
353
- for (let i = 0; i < repeatCount; i++) {
354
- inners.push(lap); // overlap
355
- inners.push(makeInner(repeat, font, mode));
356
- }
377
+ // The middle section will be an SVG. Make it an extra 0.016em tall.
378
+ // We'll overlap by 0.008em at top and bottom.
379
+ const innerHeight = realHeightTotal - topHeightTotal - bottomHeightTotal
380
+ + 2 * lapInEms;
381
+ stack.push(makeInner(repeat, innerHeight, options));
357
382
  } else {
358
383
  // When there is a middle bit, we need the middle part and two repeated
359
384
  // sections
360
- for (let i = 0; i < repeatCount; i++) {
361
- inners.push(lap);
362
- inners.push(makeInner(repeat, font, mode));
363
- }
364
- // Insert one extra repeat element.
365
- inners.push({type: "kern", size: shiftOfExtraElement});
366
- inners.push(makeInner(repeat, font, mode));
367
- inners.push(lap);
385
+ const innerHeight = (realHeightTotal - topHeightTotal - bottomHeightTotal -
386
+ middleHeightTotal) / 2 + 2 * lapInEms;
387
+ stack.push(makeInner(repeat, innerHeight, options));
368
388
  // Now insert the middle of the brace.
369
- inners.push(makeInner(middle, font, mode));
370
- for (let i = 0; i < repeatCount; i++) {
371
- inners.push(lap);
372
- inners.push(makeInner(repeat, font, mode));
373
- }
374
- }
375
-
376
- // To cover the gap create by the overlaps, insert one more repeat element,
377
- // at a position that juts 0.005 above the bottom of the top element.
378
- if ((repeat === "\u239c" || repeat === "\u239f") && repeatCount === 0) {
379
- // Parentheses need a short repeat element in order to avoid an overrun.
380
- // We'll make a 0.3em tall element from a SVG.
381
- const overlap = buildCommon.svgData.leftParenInner[2] / 2;
382
- inners.push({type: "kern", size: -overlap});
383
- const pathName = repeat === "\u239c" ? "leftParenInner" : "rightParenInner";
384
- const innerSpan = buildCommon.staticSvg(pathName, options);
385
- inners.push({type: "elem", elem: innerSpan});
386
- inners.push({type: "kern", size: -overlap});
387
- } else {
388
- inners.push({type: "kern", size: shiftOfExtraElement});
389
- inners.push(makeInner(repeat, font, mode));
390
- inners.push(lap);
389
+ stack.push(lap);
390
+ stack.push(makeGlyphSpan(middle, font, mode));
391
+ stack.push(lap);
392
+ stack.push(makeInner(repeat, innerHeight, options));
391
393
  }
392
394
 
393
395
  // Add the top symbol
394
- inners.push(makeInner(top, font, mode));
396
+ stack.push(lap);
397
+ stack.push(makeGlyphSpan(top, font, mode));
395
398
 
396
399
  // Finally, build the vlist
397
400
  const newOptions = options.havingBaseStyle(Style.TEXT);
398
401
  const inner = buildCommon.makeVList({
399
402
  positionType: "bottom",
400
403
  positionData: depth,
401
- children: inners,
404
+ children: stack,
402
405
  }, newOptions);
403
406
 
404
407
  return styleWrap(
@@ -782,6 +785,7 @@ const makeLeftRightDelim = function(
782
785
  export default {
783
786
  sqrtImage: makeSqrtImage,
784
787
  sizedDelim: makeSizedDelim,
788
+ sizeToMaxHeight: sizeToMaxHeight,
785
789
  customSizedDelim: makeCustomSizedDelim,
786
790
  leftRightDelim: makeLeftRightDelim,
787
791
  };
package/src/domTree.js CHANGED
@@ -533,7 +533,7 @@ export class PathNode implements VirtualNode {
533
533
 
534
534
  constructor(pathName: string, alternate?: string) {
535
535
  this.pathName = pathName;
536
- this.alternate = alternate; // Used only for \sqrt
536
+ this.alternate = alternate; // Used only for \sqrt, \phase, & tall delims
537
537
  }
538
538
 
539
539
  toNode(): Node {