katex 0.16.30 → 0.16.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/katex.mjs CHANGED
@@ -5523,11 +5523,12 @@ var makeOrd = function makeOrd(group, options, type) {
5523
5523
  };
5524
5524
  /**
5525
5525
  * Returns true if subsequent symbolNodes have the same classes, skew, maxFont,
5526
- * and styles.
5526
+ * and styles. For mathnormal text, the left node must also have zero italic
5527
+ * correction so we don't lose spacing between combined glyphs.
5527
5528
  */
5528
5529
 
5529
5530
  var canCombine = (prev, next) => {
5530
- if (createClass(prev.classes) !== createClass(next.classes) || prev.skew !== next.skew || prev.maxFontSize !== next.maxFontSize) {
5531
+ if (createClass(prev.classes) !== createClass(next.classes) || prev.skew !== next.skew || prev.maxFontSize !== next.maxFontSize || prev.italic !== 0 && prev.hasClass("mathnormal")) {
5531
5532
  return false;
5532
5533
  } // If prev and next both are just "mbin"s or "mord"s we don't combine them
5533
5534
  // so that the proper spacing can be preserved.
@@ -11601,30 +11602,9 @@ defineFunction({
11601
11602
  mathmlBuilder: mathmlBuilder$4
11602
11603
  });
11603
11604
 
11604
- var adjustStyle = (size, originalStyle) => {
11605
- // Figure out what style this fraction should be in based on the
11606
- // function used
11607
- var style = originalStyle;
11608
-
11609
- if (size === "display") {
11610
- // Get display style as a default.
11611
- // If incoming style is sub/sup, use style.text() to get correct size.
11612
- style = style.id >= Style$1.SCRIPT.id ? style.text() : Style$1.DISPLAY;
11613
- } else if (size === "text" && style.size === Style$1.DISPLAY.size) {
11614
- // We're in a \tfrac but incoming style is displaystyle, so:
11615
- style = Style$1.TEXT;
11616
- } else if (size === "script") {
11617
- style = Style$1.SCRIPT;
11618
- } else if (size === "scriptscript") {
11619
- style = Style$1.SCRIPTSCRIPT;
11620
- }
11621
-
11622
- return style;
11623
- };
11624
-
11625
11605
  var htmlBuilder$4 = (group, options) => {
11626
11606
  // Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
11627
- var style = adjustStyle(group.size, options.style);
11607
+ var style = options.style;
11628
11608
  var nstyle = style.fracNum();
11629
11609
  var dstyle = style.fracDen();
11630
11610
  var newOptions;
@@ -11667,7 +11647,7 @@ var htmlBuilder$4 = (group, options) => {
11667
11647
  var clearance;
11668
11648
  var denomShift;
11669
11649
 
11670
- if (style.size === Style$1.DISPLAY.size || group.size === "display") {
11650
+ if (style.size === Style$1.DISPLAY.size) {
11671
11651
  numShift = options.fontMetrics().num1;
11672
11652
 
11673
11653
  if (ruleWidth > 0) {
@@ -11789,15 +11769,6 @@ var mathmlBuilder$3 = (group, options) => {
11789
11769
  node.setAttribute("linethickness", makeEm(ruleWidth));
11790
11770
  }
11791
11771
 
11792
- var style = adjustStyle(group.size, options.style);
11793
-
11794
- if (style.size !== options.style.size) {
11795
- node = new MathNode("mstyle", [node]);
11796
- var isDisplay = style.size === Style$1.DISPLAY.size ? "true" : "false";
11797
- node.setAttribute("displaystyle", isDisplay);
11798
- node.setAttribute("scriptlevel", "0");
11799
- }
11800
-
11801
11772
  if (group.leftDelim != null || group.rightDelim != null) {
11802
11773
  var withDelims = [];
11803
11774
 
@@ -11821,9 +11792,24 @@ var mathmlBuilder$3 = (group, options) => {
11821
11792
  return node;
11822
11793
  };
11823
11794
 
11795
+ var wrapWithStyle = (frac, style) => {
11796
+ if (!style) {
11797
+ return frac;
11798
+ }
11799
+
11800
+ var wrapper = {
11801
+ type: "styling",
11802
+ mode: frac.mode,
11803
+ style,
11804
+ body: [frac]
11805
+ }; // $FlowFixMe: defineFunction handler needs to return ParseNode<"genfrac">
11806
+
11807
+ return wrapper;
11808
+ };
11809
+
11824
11810
  defineFunction({
11825
11811
  type: "genfrac",
11826
- names: ["\\dfrac", "\\frac", "\\tfrac", "\\dbinom", "\\binom", "\\tbinom", "\\\\atopfrac", // can’t be entered directly
11812
+ names: ["\\cfrac", "\\dfrac", "\\frac", "\\tfrac", "\\dbinom", "\\binom", "\\tbinom", "\\\\atopfrac", // can’t be entered directly
11827
11813
  "\\\\bracefrac", "\\\\brackfrac" // ditto
11828
11814
  ],
11829
11815
  props: {
@@ -11840,9 +11826,9 @@ defineFunction({
11840
11826
  var hasBarLine;
11841
11827
  var leftDelim = null;
11842
11828
  var rightDelim = null;
11843
- var size = "auto";
11844
11829
 
11845
11830
  switch (funcName) {
11831
+ case "\\cfrac":
11846
11832
  case "\\dfrac":
11847
11833
  case "\\frac":
11848
11834
  case "\\tfrac":
@@ -11877,60 +11863,29 @@ defineFunction({
11877
11863
  throw new Error("Unrecognized genfrac command");
11878
11864
  }
11879
11865
 
11880
- switch (funcName) {
11881
- case "\\dfrac":
11882
- case "\\dbinom":
11883
- size = "display";
11884
- break;
11866
+ var continued = funcName === "\\cfrac";
11867
+ var style = null;
11885
11868
 
11886
- case "\\tfrac":
11887
- case "\\tbinom":
11888
- size = "text";
11889
- break;
11869
+ if (continued || funcName.startsWith("\\d")) {
11870
+ style = "display";
11871
+ } else if (funcName.startsWith("\\t")) {
11872
+ style = "text";
11890
11873
  }
11891
11874
 
11892
- return {
11875
+ return wrapWithStyle({
11893
11876
  type: "genfrac",
11894
11877
  mode: parser.mode,
11895
- continued: false,
11896
11878
  numer,
11897
11879
  denom,
11880
+ continued,
11898
11881
  hasBarLine,
11899
11882
  leftDelim,
11900
11883
  rightDelim,
11901
- size,
11902
11884
  barSize: null
11903
- };
11885
+ }, style);
11904
11886
  },
11905
11887
  htmlBuilder: htmlBuilder$4,
11906
11888
  mathmlBuilder: mathmlBuilder$3
11907
- });
11908
- defineFunction({
11909
- type: "genfrac",
11910
- names: ["\\cfrac"],
11911
- props: {
11912
- numArgs: 2
11913
- },
11914
- handler: (_ref2, args) => {
11915
- var {
11916
- parser,
11917
- funcName
11918
- } = _ref2;
11919
- var numer = args[0];
11920
- var denom = args[1];
11921
- return {
11922
- type: "genfrac",
11923
- mode: parser.mode,
11924
- continued: true,
11925
- numer,
11926
- denom,
11927
- hasBarLine: true,
11928
- leftDelim: null,
11929
- rightDelim: null,
11930
- size: "display",
11931
- barSize: null
11932
- };
11933
- }
11934
11889
  }); // Infix generalized fractions -- these are not rendered directly, but replaced
11935
11890
  // immediately by one of the variants above.
11936
11891
 
@@ -11942,12 +11897,12 @@ defineFunction({
11942
11897
  infix: true
11943
11898
  },
11944
11899
 
11945
- handler(_ref3) {
11900
+ handler(_ref2) {
11946
11901
  var {
11947
11902
  parser,
11948
11903
  funcName,
11949
11904
  token
11950
- } = _ref3;
11905
+ } = _ref2;
11951
11906
  var replaceWith;
11952
11907
 
11953
11908
  switch (funcName) {
@@ -12006,10 +11961,10 @@ defineFunction({
12006
11961
  argTypes: ["math", "math", "size", "text", "math", "math"]
12007
11962
  },
12008
11963
 
12009
- handler(_ref4, args) {
11964
+ handler(_ref3, args) {
12010
11965
  var {
12011
11966
  parser
12012
- } = _ref4;
11967
+ } = _ref3;
12013
11968
  var numer = args[4];
12014
11969
  var denom = args[5]; // Look into the parse nodes to get the desired delimiters.
12015
11970
 
@@ -12032,7 +11987,7 @@ defineFunction({
12032
11987
  } // Find out if we want displaystyle, textstyle, etc.
12033
11988
 
12034
11989
 
12035
- var size = "auto";
11990
+ var size = null;
12036
11991
  var styl = args[3];
12037
11992
 
12038
11993
  if (styl.type === "ordgroup") {
@@ -12045,7 +12000,7 @@ defineFunction({
12045
12000
  size = stylArray[Number(styl.text)];
12046
12001
  }
12047
12002
 
12048
- return {
12003
+ return wrapWithStyle({
12049
12004
  type: "genfrac",
12050
12005
  mode: parser.mode,
12051
12006
  numer,
@@ -12054,13 +12009,10 @@ defineFunction({
12054
12009
  hasBarLine,
12055
12010
  barSize,
12056
12011
  leftDelim,
12057
- rightDelim,
12058
- size
12059
- };
12060
- },
12012
+ rightDelim
12013
+ }, size);
12014
+ }
12061
12015
 
12062
- htmlBuilder: htmlBuilder$4,
12063
- mathmlBuilder: mathmlBuilder$3
12064
12016
  }); // \above is an infix fraction that also defines a fraction bar size.
12065
12017
 
12066
12018
  defineFunction({
@@ -12072,12 +12024,12 @@ defineFunction({
12072
12024
  infix: true
12073
12025
  },
12074
12026
 
12075
- handler(_ref5, args) {
12027
+ handler(_ref4, args) {
12076
12028
  var {
12077
12029
  parser,
12078
12030
  funcName,
12079
12031
  token
12080
- } = _ref5;
12032
+ } = _ref4;
12081
12033
  return {
12082
12034
  type: "infix",
12083
12035
  mode: parser.mode,
@@ -12095,11 +12047,11 @@ defineFunction({
12095
12047
  numArgs: 3,
12096
12048
  argTypes: ["math", "size", "math"]
12097
12049
  },
12098
- handler: (_ref6, args) => {
12050
+ handler: (_ref5, args) => {
12099
12051
  var {
12100
12052
  parser,
12101
12053
  funcName
12102
- } = _ref6;
12054
+ } = _ref5;
12103
12055
  var numer = args[0];
12104
12056
  var barSize = assertNodeType(args[1], "infix").size;
12105
12057
 
@@ -12118,12 +12070,9 @@ defineFunction({
12118
12070
  hasBarLine,
12119
12071
  barSize,
12120
12072
  leftDelim: null,
12121
- rightDelim: null,
12122
- size: "auto"
12073
+ rightDelim: null
12123
12074
  };
12124
- },
12125
- htmlBuilder: htmlBuilder$4,
12126
- mathmlBuilder: mathmlBuilder$3
12075
+ }
12127
12076
  });
12128
12077
 
12129
12078
  // NOTE: Unlike most `htmlBuilder`s, this one handles not only "horizBrace", but
@@ -18350,7 +18299,7 @@ var renderToHTMLTree = function renderToHTMLTree(expression, options) {
18350
18299
  }
18351
18300
  };
18352
18301
 
18353
- var version = "0.16.30";
18302
+ var version = "0.16.32";
18354
18303
  var __domTree = {
18355
18304
  Span,
18356
18305
  Anchor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.16.30",
3
+ "version": "0.16.32",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "types": "types/katex.d.ts",
@@ -238,12 +238,14 @@ export const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
238
238
 
239
239
  /**
240
240
  * Returns true if subsequent symbolNodes have the same classes, skew, maxFont,
241
- * and styles.
241
+ * and styles. For mathnormal text, the left node must also have zero italic
242
+ * correction so we don't lose spacing between combined glyphs.
242
243
  */
243
244
  const canCombine = (prev: SymbolNode, next: SymbolNode) => {
244
245
  if (createClass(prev.classes) !== createClass(next.classes)
245
246
  || prev.skew !== next.skew
246
- || prev.maxFontSize !== next.maxFontSize) {
247
+ || prev.maxFontSize !== next.maxFontSize
248
+ || (prev.italic !== 0 && prev.hasClass("mathnormal"))) {
247
249
  return false;
248
250
  }
249
251
 
@@ -3,36 +3,18 @@ import defineFunction, {normalizeArgument} from "../defineFunction";
3
3
  import {makeLineSpan, makeSpan, makeVList} from "../buildCommon";
4
4
  import {makeCustomSizedDelim} from "../delimiter";
5
5
  import {MathNode, TextNode} from "../mathMLTree";
6
+ import type {ParseNode} from "../parseNode";
6
7
  import Style from "../Style";
7
8
  import {assertNodeType} from "../parseNode";
9
+ import type {StyleStr} from "../types";
8
10
 
9
11
  import * as html from "../buildHTML";
10
12
  import * as mml from "../buildMathML";
11
13
  import {calculateSize, makeEm} from "../units";
12
14
 
13
- const adjustStyle = (size, originalStyle) => {
14
- // Figure out what style this fraction should be in based on the
15
- // function used
16
- let style = originalStyle;
17
- if (size === "display") {
18
- // Get display style as a default.
19
- // If incoming style is sub/sup, use style.text() to get correct size.
20
- style = style.id >= Style.SCRIPT.id ? style.text() : Style.DISPLAY;
21
- } else if (size === "text" &&
22
- style.size === Style.DISPLAY.size) {
23
- // We're in a \tfrac but incoming style is displaystyle, so:
24
- style = Style.TEXT;
25
- } else if (size === "script") {
26
- style = Style.SCRIPT;
27
- } else if (size === "scriptscript") {
28
- style = Style.SCRIPTSCRIPT;
29
- }
30
- return style;
31
- };
32
-
33
15
  const htmlBuilder = (group, options) => {
34
16
  // Fractions are handled in the TeXbook on pages 444-445, rules 15(a-e).
35
- const style = adjustStyle(group.size, options.style);
17
+ const style = options.style;
36
18
 
37
19
  const nstyle = style.fracNum();
38
20
  const dstyle = style.fracDen();
@@ -75,7 +57,7 @@ const htmlBuilder = (group, options) => {
75
57
  let numShift;
76
58
  let clearance;
77
59
  let denomShift;
78
- if (style.size === Style.DISPLAY.size || group.size === "display") {
60
+ if (style.size === Style.DISPLAY.size) {
79
61
  numShift = options.fontMetrics().num1;
80
62
  if (ruleWidth > 0) {
81
63
  clearance = 3 * ruleSpacing;
@@ -184,7 +166,7 @@ const htmlBuilder = (group, options) => {
184
166
  };
185
167
 
186
168
  const mathmlBuilder = (group, options) => {
187
- let node = new MathNode(
169
+ const node = new MathNode(
188
170
  "mfrac",
189
171
  [
190
172
  mml.buildGroup(group.numer, options),
@@ -198,14 +180,6 @@ const mathmlBuilder = (group, options) => {
198
180
  node.setAttribute("linethickness", makeEm(ruleWidth));
199
181
  }
200
182
 
201
- const style = adjustStyle(group.size, options.style);
202
- if (style.size !== options.style.size) {
203
- node = new MathNode("mstyle", [node]);
204
- const isDisplay = (style.size === Style.DISPLAY.size) ? "true" : "false";
205
- node.setAttribute("displaystyle", isDisplay);
206
- node.setAttribute("scriptlevel", "0");
207
- }
208
-
209
183
  if (group.leftDelim != null || group.rightDelim != null) {
210
184
  const withDelims = [];
211
185
 
@@ -239,10 +213,29 @@ const mathmlBuilder = (group, options) => {
239
213
  return node;
240
214
  };
241
215
 
216
+ const wrapWithStyle = (
217
+ frac: ParseNode<"genfrac">,
218
+ style?: StyleStr | null,
219
+ ): ParseNode<"genfrac"> => {
220
+ if (!style) {
221
+ return frac;
222
+ }
223
+
224
+ const wrapper: ParseNode<"styling"> = {
225
+ type: "styling",
226
+ mode: frac.mode,
227
+ style,
228
+ body: [frac],
229
+ };
230
+
231
+ // $FlowFixMe: defineFunction handler needs to return ParseNode<"genfrac">
232
+ return wrapper;
233
+ };
234
+
242
235
  defineFunction({
243
236
  type: "genfrac",
244
237
  names: [
245
- "\\dfrac", "\\frac", "\\tfrac",
238
+ "\\cfrac", "\\dfrac", "\\frac", "\\tfrac",
246
239
  "\\dbinom", "\\binom", "\\tbinom",
247
240
  "\\\\atopfrac", // can’t be entered directly
248
241
  "\\\\bracefrac", "\\\\brackfrac", // ditto
@@ -257,9 +250,9 @@ defineFunction({
257
250
  let hasBarLine;
258
251
  let leftDelim = null;
259
252
  let rightDelim = null;
260
- let size = "auto";
261
253
 
262
254
  switch (funcName) {
255
+ case "\\cfrac":
263
256
  case "\\dfrac":
264
257
  case "\\frac":
265
258
  case "\\tfrac":
@@ -289,60 +282,31 @@ defineFunction({
289
282
  throw new Error("Unrecognized genfrac command");
290
283
  }
291
284
 
292
- switch (funcName) {
293
- case "\\dfrac":
294
- case "\\dbinom":
295
- size = "display";
296
- break;
297
- case "\\tfrac":
298
- case "\\tbinom":
299
- size = "text";
300
- break;
285
+ const continued = funcName === "\\cfrac";
286
+ let style = null;
287
+ if (continued || funcName.startsWith("\\d")) {
288
+ style = "display";
289
+ } else if (funcName.startsWith("\\t")) {
290
+ style = "text";
301
291
  }
302
292
 
303
- return {
293
+ return wrapWithStyle({
304
294
  type: "genfrac",
305
295
  mode: parser.mode,
306
- continued: false,
307
296
  numer,
308
297
  denom,
298
+ continued,
309
299
  hasBarLine,
310
300
  leftDelim,
311
301
  rightDelim,
312
- size,
313
302
  barSize: null,
314
- };
303
+ }, style);
315
304
  },
316
305
 
317
306
  htmlBuilder,
318
307
  mathmlBuilder,
319
308
  });
320
309
 
321
- defineFunction({
322
- type: "genfrac",
323
- names: ["\\cfrac"],
324
- props: {
325
- numArgs: 2,
326
- },
327
- handler: ({parser, funcName}, args) => {
328
- const numer = args[0];
329
- const denom = args[1];
330
-
331
- return {
332
- type: "genfrac",
333
- mode: parser.mode,
334
- continued: true,
335
- numer,
336
- denom,
337
- hasBarLine: true,
338
- leftDelim: null,
339
- rightDelim: null,
340
- size: "display",
341
- barSize: null,
342
- };
343
- },
344
- });
345
-
346
310
  // Infix generalized fractions -- these are not rendered directly, but replaced
347
311
  // immediately by one of the variants above.
348
312
  defineFunction({
@@ -427,7 +391,7 @@ defineFunction({
427
391
  }
428
392
 
429
393
  // Find out if we want displaystyle, textstyle, etc.
430
- let size = "auto";
394
+ let size = null;
431
395
  let styl = args[3];
432
396
  if (styl.type === "ordgroup") {
433
397
  if (styl.body.length > 0) {
@@ -439,7 +403,7 @@ defineFunction({
439
403
  size = stylArray[Number(styl.text)];
440
404
  }
441
405
 
442
- return {
406
+ return wrapWithStyle({
443
407
  type: "genfrac",
444
408
  mode: parser.mode,
445
409
  numer,
@@ -449,12 +413,8 @@ defineFunction({
449
413
  barSize,
450
414
  leftDelim,
451
415
  rightDelim,
452
- size,
453
- };
416
+ }, size);
454
417
  },
455
-
456
- htmlBuilder,
457
- mathmlBuilder,
458
418
  });
459
419
 
460
420
  // \above is an infix fraction that also defines a fraction bar size.
@@ -506,10 +466,6 @@ defineFunction({
506
466
  barSize,
507
467
  leftDelim: null,
508
468
  rightDelim: null,
509
- size: "auto",
510
469
  };
511
470
  },
512
-
513
- htmlBuilder,
514
- mathmlBuilder,
515
471
  });
package/src/parseNode.js CHANGED
@@ -268,7 +268,6 @@ type ParseNodeTypes = {
268
268
  hasBarLine: boolean,
269
269
  leftDelim: ?string,
270
270
  rightDelim: ?string,
271
- size: StyleStr | "auto",
272
271
  barSize: Measurement | null,
273
272
  |},
274
273
  "hbox": {|