katex 0.13.2 → 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.
package/dist/katex.mjs CHANGED
@@ -4321,13 +4321,11 @@ defineSymbol(math, main, rel, "\u2192", "\\to");
4321
4321
  defineSymbol(math, ams, rel, "\u2271", "\\ngeq", true);
4322
4322
  defineSymbol(math, ams, rel, "\u2270", "\\nleq", true);
4323
4323
  defineSymbol(math, main, spacing, "\u00a0", "\\ ");
4324
- defineSymbol(math, main, spacing, "\u00a0", "~");
4325
4324
  defineSymbol(math, main, spacing, "\u00a0", "\\space"); // Ref: LaTeX Source 2e: \DeclareRobustCommand{\nobreakspace}{%
4326
4325
 
4327
4326
  defineSymbol(math, main, spacing, "\u00a0", "\\nobreakspace");
4328
4327
  defineSymbol(text$1, main, spacing, "\u00a0", "\\ ");
4329
4328
  defineSymbol(text$1, main, spacing, "\u00a0", " ");
4330
- defineSymbol(text$1, main, spacing, "\u00a0", "~");
4331
4329
  defineSymbol(text$1, main, spacing, "\u00a0", "\\space");
4332
4330
  defineSymbol(text$1, main, spacing, "\u00a0", "\\nobreakspace");
4333
4331
  defineSymbol(math, main, spacing, null, "\\nobreak");
@@ -9866,6 +9864,7 @@ function parseArray(parser, _ref, style) {
9866
9864
  colSeparationType,
9867
9865
  addEqnNum,
9868
9866
  singleRow,
9867
+ emptySingleRow,
9869
9868
  maxNumCols,
9870
9869
  leqno
9871
9870
  } = _ref;
@@ -9940,9 +9939,10 @@ function parseArray(parser, _ref, style) {
9940
9939
  parser.consume();
9941
9940
  } else if (next === "\\end") {
9942
9941
  // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
9943
- // the last line is empty.
9942
+ // the last line is empty. However, AMS environments keep the
9943
+ // empty row if it's the only one.
9944
9944
  // NOTE: Currently, `cell` is the last item added into `row`.
9945
- if (row.length === 1 && cell.type === "styling" && cell.body[0].body.length === 0) {
9945
+ if (row.length === 1 && cell.type === "styling" && cell.body[0].body.length === 0 && (body.length > 1 || !emptySingleRow)) {
9946
9946
  body.pop();
9947
9947
  }
9948
9948
 
@@ -10439,6 +10439,7 @@ var alignedHandler = function alignedHandler(context, args) {
10439
10439
  cols,
10440
10440
  addJot: true,
10441
10441
  addEqnNum: context.envName === "align" || context.envName === "alignat",
10442
+ emptySingleRow: true,
10442
10443
  colSeparationType: separationType,
10443
10444
  maxNumCols: context.envName === "split" ? 2 : undefined,
10444
10445
  leqno: context.parser.settings.leqno
@@ -10800,6 +10801,7 @@ defineEnvironment({
10800
10801
  addJot: true,
10801
10802
  colSeparationType: "gather",
10802
10803
  addEqnNum: context.envName === "gather",
10804
+ emptySingleRow: true,
10803
10805
  leqno: context.parser.settings.leqno
10804
10806
  };
10805
10807
  return parseArray(context.parser, res, "display");
@@ -10832,6 +10834,7 @@ defineEnvironment({
10832
10834
  validateAmsEnvironmentContext(context);
10833
10835
  var res = {
10834
10836
  addEqnNum: context.envName === "equation",
10837
+ emptySingleRow: true,
10835
10838
  singleRow: true,
10836
10839
  maxNumCols: 1,
10837
10840
  leqno: context.parser.settings.leqno
@@ -14472,7 +14475,8 @@ combiningDiacriticalMarkString + "*") + // ...plus accents
14472
14475
  /** Main Lexer class */
14473
14476
 
14474
14477
  class Lexer {
14475
- // category codes, only supports comment characters (14) for now
14478
+ // Category codes. The lexer only supports comment characters (14) for now.
14479
+ // MacroExpander additionally distinguishes active (13).
14476
14480
  constructor(input, settings) {
14477
14481
  this.input = void 0;
14478
14482
  this.settings = void 0;
@@ -14483,7 +14487,9 @@ class Lexer {
14483
14487
  this.settings = settings;
14484
14488
  this.tokenRegex = new RegExp(tokenRegexString, 'g');
14485
14489
  this.catcodes = {
14486
- "%": 14 // comment character
14490
+ "%": 14,
14491
+ // comment character
14492
+ "~": 13 // active character
14487
14493
 
14488
14494
  };
14489
14495
  }
@@ -14924,11 +14930,13 @@ defineMacro("\\show", context => {
14924
14930
 
14925
14931
  defineMacro("\\bgroup", "{");
14926
14932
  defineMacro("\\egroup", "}"); // Symbols from latex.ltx:
14933
+ // \def~{\nobreakspace{}}
14927
14934
  // \def\lq{`}
14928
14935
  // \def\rq{'}
14929
14936
  // \def \aa {\r a}
14930
14937
  // \def \AA {\r A}
14931
14938
 
14939
+ defineMacro("~", "\\nobreakspace");
14932
14940
  defineMacro("\\lq", "`");
14933
14941
  defineMacro("\\rq", "'");
14934
14942
  defineMacro("\\aa", "\\r a");
@@ -16001,6 +16009,16 @@ class MacroExpander {
16001
16009
  if (definition == null) {
16002
16010
  // mainly checking for undefined here
16003
16011
  return definition;
16012
+ } // If a single character has an associated catcode other than 13
16013
+ // (active character), then don't expand it.
16014
+
16015
+
16016
+ if (name.length === 1) {
16017
+ var catcode = this.lexer.catcodes[name];
16018
+
16019
+ if (catcode != null && catcode !== 13) {
16020
+ return;
16021
+ }
16004
16022
  }
16005
16023
 
16006
16024
  var expansion = typeof definition === "function" ? definition(this) : definition;
@@ -17146,9 +17164,13 @@ class Parser {
17146
17164
  parseUrlGroup(optional) {
17147
17165
  this.gullet.lexer.setCatcode("%", 13); // active character
17148
17166
 
17167
+ this.gullet.lexer.setCatcode("~", 12); // other character
17168
+
17149
17169
  var res = this.parseStringGroup("url", optional);
17150
17170
  this.gullet.lexer.setCatcode("%", 14); // comment character
17151
17171
 
17172
+ this.gullet.lexer.setCatcode("~", 13); // active character
17173
+
17152
17174
  if (res == null) {
17153
17175
  return null;
17154
17176
  } // hyperref package allows backslashes alone in href, but doesn't
@@ -17594,7 +17616,7 @@ var katex = {
17594
17616
  /**
17595
17617
  * Current KaTeX version
17596
17618
  */
17597
- version: "0.13.2",
17619
+ version: "0.13.3",
17598
17620
 
17599
17621
  /**
17600
17622
  * Renders the given LaTeX into an HTML+MathML combination, and adds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "katex",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "description": "Fast math typesetting for the web.",
5
5
  "main": "dist/katex.js",
6
6
  "homepage": "https://katex.org",
package/src/Lexer.js CHANGED
@@ -60,7 +60,8 @@ export default class Lexer implements LexerInterface {
60
60
  input: string;
61
61
  settings: Settings;
62
62
  tokenRegex: RegExp;
63
- // category codes, only supports comment characters (14) for now
63
+ // Category codes. The lexer only supports comment characters (14) for now.
64
+ // MacroExpander additionally distinguishes active (13).
64
65
  catcodes: {[string]: number};
65
66
 
66
67
  constructor(input: string, settings: Settings) {
@@ -70,6 +71,7 @@ export default class Lexer implements LexerInterface {
70
71
  this.tokenRegex = new RegExp(tokenRegexString, 'g');
71
72
  this.catcodes = {
72
73
  "%": 14, // comment character
74
+ "~": 13, // active character
73
75
  };
74
76
  }
75
77
 
@@ -395,6 +395,14 @@ export default class MacroExpander implements MacroContextInterface {
395
395
  if (definition == null) { // mainly checking for undefined here
396
396
  return definition;
397
397
  }
398
+ // If a single character has an associated catcode other than 13
399
+ // (active character), then don't expand it.
400
+ if (name.length === 1) {
401
+ const catcode = this.lexer.catcodes[name];
402
+ if (catcode != null && catcode !== 13) {
403
+ return;
404
+ }
405
+ }
398
406
  const expansion =
399
407
  typeof definition === "function" ? definition(this) : definition;
400
408
  if (typeof expansion === "string") {
package/src/Parser.js CHANGED
@@ -682,8 +682,10 @@ export default class Parser {
682
682
  */
683
683
  parseUrlGroup(optional: boolean): ?ParseNode<"url"> {
684
684
  this.gullet.lexer.setCatcode("%", 13); // active character
685
+ this.gullet.lexer.setCatcode("~", 12); // other character
685
686
  const res = this.parseStringGroup("url", optional);
686
687
  this.gullet.lexer.setCatcode("%", 14); // comment character
688
+ this.gullet.lexer.setCatcode("~", 13); // active character
687
689
  if (res == null) {
688
690
  return null;
689
691
  }
@@ -70,6 +70,7 @@ function parseArray(
70
70
  colSeparationType,
71
71
  addEqnNum,
72
72
  singleRow,
73
+ emptySingleRow,
73
74
  maxNumCols,
74
75
  leqno,
75
76
  }: {|
@@ -80,6 +81,7 @@ function parseArray(
80
81
  colSeparationType?: ColSeparationType,
81
82
  addEqnNum?: boolean,
82
83
  singleRow?: boolean,
84
+ emptySingleRow?: boolean,
83
85
  maxNumCols?: number,
84
86
  leqno?: boolean,
85
87
  |},
@@ -153,10 +155,12 @@ function parseArray(
153
155
  parser.consume();
154
156
  } else if (next === "\\end") {
155
157
  // Arrays terminate newlines with `\crcr` which consumes a `\cr` if
156
- // the last line is empty.
158
+ // the last line is empty. However, AMS environments keep the
159
+ // empty row if it's the only one.
157
160
  // NOTE: Currently, `cell` is the last item added into `row`.
158
161
  if (row.length === 1 && cell.type === "styling" &&
159
- cell.body[0].body.length === 0) {
162
+ cell.body[0].body.length === 0 &&
163
+ (body.length > 1 || !emptySingleRow)) {
160
164
  body.pop();
161
165
  }
162
166
  if (hLinesBeforeRow.length < body.length + 1) {
@@ -630,6 +634,7 @@ const alignedHandler = function(context, args) {
630
634
  cols,
631
635
  addJot: true,
632
636
  addEqnNum: context.envName === "align" || context.envName === "alignat",
637
+ emptySingleRow: true,
633
638
  colSeparationType: separationType,
634
639
  maxNumCols: context.envName === "split" ? 2 : undefined,
635
640
  leqno: context.parser.settings.leqno,
@@ -977,6 +982,7 @@ defineEnvironment({
977
982
  addJot: true,
978
983
  colSeparationType: "gather",
979
984
  addEqnNum: context.envName === "gather",
985
+ emptySingleRow: true,
980
986
  leqno: context.parser.settings.leqno,
981
987
  };
982
988
  return parseArray(context.parser, res, "display");
@@ -1009,6 +1015,7 @@ defineEnvironment({
1009
1015
  validateAmsEnvironmentContext(context);
1010
1016
  const res = {
1011
1017
  addEqnNum: context.envName === "equation",
1018
+ emptySingleRow: true,
1012
1019
  singleRow: true,
1013
1020
  maxNumCols: 1,
1014
1021
  leqno: context.parser.settings.leqno,
package/src/macros.js CHANGED
@@ -327,10 +327,12 @@ defineMacro("\\bgroup", "{");
327
327
  defineMacro("\\egroup", "}");
328
328
 
329
329
  // Symbols from latex.ltx:
330
+ // \def~{\nobreakspace{}}
330
331
  // \def\lq{`}
331
332
  // \def\rq{'}
332
333
  // \def \aa {\r a}
333
334
  // \def \AA {\r A}
335
+ defineMacro("~", "\\nobreakspace");
334
336
  defineMacro("\\lq", "`");
335
337
  defineMacro("\\rq", "'");
336
338
  defineMacro("\\aa", "\\r a");
package/src/symbols.js CHANGED
@@ -582,13 +582,11 @@ defineSymbol(math, main, rel, "\u2192", "\\to");
582
582
  defineSymbol(math, ams, rel, "\u2271", "\\ngeq", true);
583
583
  defineSymbol(math, ams, rel, "\u2270", "\\nleq", true);
584
584
  defineSymbol(math, main, spacing, "\u00a0", "\\ ");
585
- defineSymbol(math, main, spacing, "\u00a0", "~");
586
585
  defineSymbol(math, main, spacing, "\u00a0", "\\space");
587
586
  // Ref: LaTeX Source 2e: \DeclareRobustCommand{\nobreakspace}{%
588
587
  defineSymbol(math, main, spacing, "\u00a0", "\\nobreakspace");
589
588
  defineSymbol(text, main, spacing, "\u00a0", "\\ ");
590
589
  defineSymbol(text, main, spacing, "\u00a0", " ");
591
- defineSymbol(text, main, spacing, "\u00a0", "~");
592
590
  defineSymbol(text, main, spacing, "\u00a0", "\\space");
593
591
  defineSymbol(text, main, spacing, "\u00a0", "\\nobreakspace");
594
592
  defineSymbol(math, main, spacing, null, "\\nobreak");