temml 0.9.2 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
package/dist/temml.js CHANGED
@@ -669,7 +669,7 @@ var temml = (function () {
669
669
 
670
670
  /**
671
671
  * Converts the text node into a string
672
- * (representing the text iteself).
672
+ * (representing the text itself).
673
673
  */
674
674
  toText() {
675
675
  return this.text;
@@ -846,7 +846,6 @@ var temml = (function () {
846
846
  defineSymbol(math, rel, "\u226b", "\\gg", true);
847
847
  defineSymbol(math, rel, "\u224d", "\\asymp", true);
848
848
  defineSymbol(math, rel, "\u2225", "\\parallel");
849
- defineSymbol(math, rel, "\u22c8", "\\bowtie", true);
850
849
  defineSymbol(math, rel, "\u2323", "\\smile", true);
851
850
  defineSymbol(math, rel, "\u2291", "\\sqsubseteq", true);
852
851
  defineSymbol(math, rel, "\u2292", "\\sqsupseteq", true);
@@ -1163,7 +1162,6 @@ var temml = (function () {
1163
1162
  defineSymbol(math, bin, "\u22b2", "\\lhd");
1164
1163
  defineSymbol(math, bin, "\u22b3", "\\rhd");
1165
1164
  defineSymbol(math, rel, "\u2242", "\\eqsim", true);
1166
- defineSymbol(math, rel, "\u22c8", "\\Join");
1167
1165
  defineSymbol(math, rel, "\u2251", "\\Doteq", true);
1168
1166
  defineSymbol(math, rel, "\u297d", "\\strictif", true);
1169
1167
  defineSymbol(math, rel, "\u297c", "\\strictfi", true);
@@ -1189,6 +1187,11 @@ var temml = (function () {
1189
1187
  defineSymbol(math, bin, "\u22d2", "\\doublecap");
1190
1188
  defineSymbol(math, bin, "\u22d3", "\\doublecup");
1191
1189
  defineSymbol(math, bin, "\u22a0", "\\boxtimes", true);
1190
+ defineSymbol(math, bin, "\u22c8", "\\bowtie", true);
1191
+ defineSymbol(math, bin, "\u22c8", "\\Join");
1192
+ defineSymbol(math, bin, "\u27d5", "\\leftouterjoin", true);
1193
+ defineSymbol(math, bin, "\u27d6", "\\rightouterjoin", true);
1194
+ defineSymbol(math, bin, "\u27d7", "\\fullouterjoin", true);
1192
1195
 
1193
1196
  // AMS Arrows
1194
1197
  // Note: unicode-math maps \u21e2 to their own function \rightdasharrow.
@@ -1235,6 +1238,8 @@ var temml = (function () {
1235
1238
  defineSymbol(math, textord, "$", "\\$");
1236
1239
  defineSymbol(text, textord, "$", "\\$");
1237
1240
  defineSymbol(text, textord, "$", "\\textdollar");
1241
+ defineSymbol(math, textord, "¢", "\\cent");
1242
+ defineSymbol(text, textord, "¢", "\\cent");
1238
1243
  defineSymbol(math, textord, "%", "\\%");
1239
1244
  defineSymbol(text, textord, "%", "\\%");
1240
1245
  defineSymbol(math, textord, "_", "\\_");
@@ -1891,7 +1896,7 @@ var temml = (function () {
1891
1896
  }
1892
1897
 
1893
1898
  /**
1894
- * This file converts a parse tree into a cooresponding MathML tree. The main
1899
+ * This file converts a parse tree into a corresponding MathML tree. The main
1895
1900
  * entry point is the `buildMathML` function, which takes a parse tree from the
1896
1901
  * parser.
1897
1902
  */
@@ -3149,13 +3154,12 @@ var temml = (function () {
3149
3154
  names: ["\\\\"],
3150
3155
  props: {
3151
3156
  numArgs: 0,
3152
- numOptionalArgs: 1,
3153
- argTypes: ["size"],
3157
+ numOptionalArgs: 0,
3154
3158
  allowedInText: true
3155
3159
  },
3156
3160
 
3157
3161
  handler({ parser }, args, optArgs) {
3158
- const size = optArgs[0];
3162
+ const size = parser.gullet.future().text === "[" ? parser.parseSizeGroup(true) : null;
3159
3163
  const newLine = !parser.settings.displayMode;
3160
3164
  return {
3161
3165
  type: "cr",
@@ -3523,6 +3527,11 @@ var temml = (function () {
3523
3527
  "."
3524
3528
  ];
3525
3529
 
3530
+ // Export isDelimiter for benefit of parser.
3531
+ const dels = ["}", "\\left", "\\middle", "\\right"];
3532
+ const isDelimiter = str => str.length > 0 &&
3533
+ (delimiters.includes(str) || delimiterSizes[str] || dels.includes(str));
3534
+
3526
3535
  // Metrics of the different sizes. Found by looking at TeX's output of
3527
3536
  // $\bigl| // \Bigl| \biggl| \Biggl| \showlists$
3528
3537
  // Used to create stacked delimiters of appropriate sizes in makeSizedDelim.
@@ -4915,7 +4924,6 @@ var temml = (function () {
4915
4924
  "\\mathscr",
4916
4925
  "\\mathsf",
4917
4926
  "\\mathtt",
4918
- "\\oldstylenums",
4919
4927
 
4920
4928
  // aliases
4921
4929
  "\\Bbb",
@@ -6206,10 +6214,6 @@ var temml = (function () {
6206
6214
  // Math operators (e.g. \sin) need a space between these types and themselves:
6207
6215
  const ordTypes = ["textord", "mathord", "ordgroup", "close", "leftright"];
6208
6216
 
6209
- const dels$1 = ["}", "\\left", "\\middle", "\\right"];
6210
- const isDelimiter$1 = str => str.length > 0 &&
6211
- (delimiters.includes(str) || delimiterSizes[str] || dels$1.includes(str));
6212
-
6213
6217
  // NOTE: Unlike most `builders`s, this one handles not only "op", but also
6214
6218
  // "supsub" since some of them (like \int) can affect super/subscripting.
6215
6219
 
@@ -6430,7 +6434,7 @@ var temml = (function () {
6430
6434
  parentIsSupSub: false,
6431
6435
  symbol: false,
6432
6436
  stack: false,
6433
- isFollowedByDelimiter: isDelimiter$1(next),
6437
+ isFollowedByDelimiter: isDelimiter(next),
6434
6438
  needsLeadingSpace: prevAtomType.length > 0 && ordTypes.includes(prevAtomType),
6435
6439
  name: funcName
6436
6440
  };
@@ -6455,7 +6459,7 @@ var temml = (function () {
6455
6459
  parentIsSupSub: false,
6456
6460
  symbol: false,
6457
6461
  stack: false,
6458
- isFollowedByDelimiter: isDelimiter$1(next),
6462
+ isFollowedByDelimiter: isDelimiter(next),
6459
6463
  needsLeadingSpace: prevAtomType.length > 0 && ordTypes.includes(prevAtomType),
6460
6464
  name: funcName
6461
6465
  };
@@ -6541,11 +6545,7 @@ var temml = (function () {
6541
6545
  _macros[name] = body;
6542
6546
  }
6543
6547
 
6544
- const dels = ["}", "\\left", "\\middle", "\\right"];
6545
- const isDelimiter = str => str.length > 0 &&
6546
- (delimiters.includes(str) || delimiterSizes[str] || dels.includes(str));
6547
-
6548
- // NOTE: Unlike most builders, this one handles not only
6548
+ // NOTE: Unlike most builders, this one handles not only
6549
6549
  // "operatorname", but also "supsub" since \operatorname* can
6550
6550
  // affect super/subscripting.
6551
6551
 
@@ -6555,8 +6555,12 @@ var temml = (function () {
6555
6555
  // Is expression a string or has it something like a fraction?
6556
6556
  let isAllString = true; // default
6557
6557
  for (let i = 0; i < expression.length; i++) {
6558
- const node = expression[i];
6558
+ let node = expression[i];
6559
6559
  if (node instanceof mathMLTree.MathNode) {
6560
+ if (node.type === "mrow" && node.children.length === 1 &&
6561
+ node.children[0] instanceof mathMLTree.MathNode) {
6562
+ node = node.children[0];
6563
+ }
6560
6564
  switch (node.type) {
6561
6565
  case "mi":
6562
6566
  case "mn":
@@ -6614,7 +6618,9 @@ var temml = (function () {
6614
6618
  let wrapper;
6615
6619
  if (isAllString) {
6616
6620
  wrapper = new mathMLTree.MathNode("mi", expression);
6617
- wrapper.setAttribute("mathvariant", "normal");
6621
+ if (expression[0].text.length === 1) {
6622
+ wrapper.setAttribute("mathvariant", "normal");
6623
+ }
6618
6624
  } else {
6619
6625
  wrapper = new mathMLTree.MathNode("mrow", expression);
6620
6626
  }
@@ -7152,6 +7158,7 @@ var temml = (function () {
7152
7158
  let isOver;
7153
7159
  let isSup;
7154
7160
  let appendApplyFunction = false;
7161
+ let appendSpace = false;
7155
7162
  let needsLeadingSpace = false;
7156
7163
 
7157
7164
  if (group.base && group.base.type === "horizBrace") {
@@ -7166,6 +7173,7 @@ var temml = (function () {
7166
7173
  (group.base.type === "op" || group.base.type === "operatorname")) {
7167
7174
  group.base.parentIsSupSub = true;
7168
7175
  appendApplyFunction = !group.base.symbol;
7176
+ appendSpace = appendApplyFunction && !group.isFollowedByDelimiter;
7169
7177
  needsLeadingSpace = group.base.needsLeadingSpace;
7170
7178
  }
7171
7179
 
@@ -7253,6 +7261,11 @@ var temml = (function () {
7253
7261
  } else {
7254
7262
  node = mathMLTree.newDocumentFragment([node, operator]);
7255
7263
  }
7264
+ if (appendSpace) {
7265
+ const space = new mathMLTree.MathNode("mspace");
7266
+ space.setAttribute("width", "0.1667em"); // thin space.
7267
+ node.children.push(space);
7268
+ }
7256
7269
  } else if (symbolRegEx.test(nodeType)) {
7257
7270
  // Wrap in a <mrow>. Otherwise Firefox stretchy parens will not stretch to include limits.
7258
7271
  node = new mathMLTree.MathNode("mrow", [node]);
@@ -7329,8 +7342,7 @@ var temml = (function () {
7329
7342
  mathfrak: "fraktur",
7330
7343
  mathscr: "script",
7331
7344
  mathsf: "sans-serif",
7332
- mathtt: "monospace",
7333
- oldstylenums: "oldstylenums"
7345
+ mathtt: "monospace"
7334
7346
  };
7335
7347
 
7336
7348
  /**
@@ -7400,8 +7412,6 @@ var temml = (function () {
7400
7412
  return "sans-serif"
7401
7413
  case "mathtt":
7402
7414
  return "monospace"
7403
- case "oldstylenums":
7404
- return "oldstylenums"
7405
7415
  }
7406
7416
 
7407
7417
  let text = group.text;
@@ -7697,10 +7707,7 @@ var temml = (function () {
7697
7707
  let node;
7698
7708
  if (numberRegEx$1.test(group.text)) {
7699
7709
  const tag = group.mode === "text" ? "mtext" : "mn";
7700
- if (variant === "oldstylenums") {
7701
- const ms = new mathMLTree.MathNode("mstyle", [text], ["oldstylenums"]);
7702
- node = new mathMLTree.MathNode(tag, [ms]);
7703
- } else if (variant === "italic" || variant === "bold-italic") {
7710
+ if (variant === "italic" || variant === "bold-italic") {
7704
7711
  return italicNumber(text, variant, tag)
7705
7712
  } else {
7706
7713
  if (variant !== "normal") {
@@ -9113,15 +9120,15 @@ var temml = (function () {
9113
9120
  * Expand the next token only once if possible.
9114
9121
  *
9115
9122
  * If the token is expanded, the resulting tokens will be pushed onto
9116
- * the stack in reverse order and will be returned as an array,
9117
- * also in reverse order.
9123
+ * the stack in reverse order, and the number of such tokens will be
9124
+ * returned. This number might be zero or positive.
9118
9125
  *
9119
- * If not, the next token will be returned without removing it
9120
- * from the stack. This case can be detected by a `Token` return value
9121
- * instead of an `Array` return value.
9126
+ * If not, the return value is `false`, and the next token remains at the
9127
+ * top of the stack.
9122
9128
  *
9123
9129
  * In either case, the next token will be on the top of the stack,
9124
- * or the stack will be empty.
9130
+ * or the stack will be empty (in case of empty expansion
9131
+ * and no other tokens).
9125
9132
  *
9126
9133
  * Used to implement `expandAfterFuture` and `expandNextToken`.
9127
9134
  *
@@ -9137,7 +9144,7 @@ var temml = (function () {
9137
9144
  throw new ParseError("Undefined control sequence: " + name);
9138
9145
  }
9139
9146
  this.pushToken(topToken);
9140
- return topToken;
9147
+ return false;
9141
9148
  }
9142
9149
  this.expansionCount++;
9143
9150
  if (this.expansionCount > this.settings.maxExpand) {
@@ -9171,7 +9178,7 @@ var temml = (function () {
9171
9178
  }
9172
9179
  // Concatenate expansion onto top of stack.
9173
9180
  this.pushTokens(tokens);
9174
- return tokens;
9181
+ return tokens.length;
9175
9182
  }
9176
9183
 
9177
9184
  /**
@@ -9190,14 +9197,13 @@ var temml = (function () {
9190
9197
  */
9191
9198
  expandNextToken() {
9192
9199
  for (;;) {
9193
- const expanded = this.expandOnce();
9194
- // expandOnce returns Token if and only if it's fully expanded.
9195
- if (expanded instanceof Token) {
9200
+ if (this.expandOnce() === false) { // fully expanded
9201
+ const token = this.stack.pop();
9196
9202
  // The token after \noexpand is interpreted as if its meaning were ‘\relax’
9197
- if (expanded.treatAsRelax) {
9198
- expanded.text = "\\relax";
9203
+ if (token.treatAsRelax) {
9204
+ token.text = "\\relax";
9199
9205
  }
9200
- return this.stack.pop(); // === expanded
9206
+ return token
9201
9207
  }
9202
9208
  }
9203
9209
 
@@ -9223,15 +9229,15 @@ var temml = (function () {
9223
9229
  const oldStackLength = this.stack.length;
9224
9230
  this.pushTokens(tokens);
9225
9231
  while (this.stack.length > oldStackLength) {
9226
- const expanded = this.expandOnce(true); // expand only expandable tokens
9227
- // expandOnce returns Token if and only if it's fully expanded.
9228
- if (expanded instanceof Token) {
9229
- if (expanded.treatAsRelax) {
9232
+ // Expand only expandable tokens
9233
+ if (this.expandOnce(true) === false) { // fully expanded
9234
+ const token = this.stack.pop();
9235
+ if (token.treatAsRelax) {
9230
9236
  // the expansion of \noexpand is the token itself
9231
- expanded.noexpand = false;
9232
- expanded.treatAsRelax = false;
9237
+ token.noexpand = false;
9238
+ token.treatAsRelax = false;
9233
9239
  }
9234
- output.push(this.stack.pop());
9240
+ output.push(token);
9235
9241
  }
9236
9242
  }
9237
9243
  return output;
@@ -9531,6 +9537,36 @@ var temml = (function () {
9531
9537
  '\u1DBF': 'θ'
9532
9538
  });
9533
9539
 
9540
+ // Used for Unicode input of calligraphic and script letters
9541
+ const asciiFromScript = Object.freeze({
9542
+ "\ud835\udc9c": "A",
9543
+ "\u212c": "B",
9544
+ "\ud835\udc9e": "C",
9545
+ "\ud835\udc9f": "D",
9546
+ "\u2130": "E",
9547
+ "\u2131": "F",
9548
+ "\ud835\udca2": "G",
9549
+ "\u210B": "H",
9550
+ "\u2110": "I",
9551
+ "\ud835\udca5": "J",
9552
+ "\ud835\udca6": "K",
9553
+ "\u2112": "L",
9554
+ "\u2113": "M",
9555
+ "\ud835\udca9": "N",
9556
+ "\ud835\udcaa": "O",
9557
+ "\ud835\udcab": "P",
9558
+ "\ud835\udcac": "Q",
9559
+ "\u211B": "R",
9560
+ "\ud835\udcae": "S",
9561
+ "\ud835\udcaf": "T",
9562
+ "\ud835\udcb0": "U",
9563
+ "\ud835\udcb1": "V",
9564
+ "\ud835\udcb2": "W",
9565
+ "\ud835\udcb3": "X",
9566
+ "\ud835\udcb4": "Y",
9567
+ "\ud835\udcb5": "Z"
9568
+ });
9569
+
9534
9570
  // Mapping of Unicode accent characters to their LaTeX equivalent in text and
9535
9571
  // math mode (when they exist).
9536
9572
  var unicodeAccents = {
@@ -10029,7 +10065,7 @@ var temml = (function () {
10029
10065
  * Parses an "expression", which is a list of atoms.
10030
10066
  *
10031
10067
  * `breakOnInfix`: Should the parsing stop when we hit infix nodes? This
10032
- * happens when functions have higher precendence han infix
10068
+ * happens when functions have higher precedence han infix
10033
10069
  * nodes in implicit parses.
10034
10070
  *
10035
10071
  * `breakOnTokenText`: The text of the token that the expression should end
@@ -10280,12 +10316,16 @@ var temml = (function () {
10280
10316
  return base
10281
10317
  } else {
10282
10318
  // We got either a superscript or subscript, create a supsub
10319
+ const isFollowedByDelimiter = (!base || base.type !== "op" && base.type !== "operatorname")
10320
+ ? undefined
10321
+ : isDelimiter(this.nextToken.text);
10283
10322
  return {
10284
10323
  type: "supsub",
10285
10324
  mode: this.mode,
10286
10325
  base: base,
10287
10326
  sup: superscript,
10288
- sub: subscript
10327
+ sub: subscript,
10328
+ isFollowedByDelimiter
10289
10329
  }
10290
10330
  }
10291
10331
  } else {
@@ -10446,7 +10486,7 @@ var temml = (function () {
10446
10486
  while (true) {
10447
10487
  const ch = this.fetch().text;
10448
10488
  // \ufe0e is the Unicode variation selector to supress emoji. Ignore it.
10449
- if (ch === " " || ch === "\ufe0e") {
10489
+ if (ch === " " || ch === "\u00a0" || ch === "\ufe0e") {
10450
10490
  this.consume();
10451
10491
  } else {
10452
10492
  break
@@ -10766,6 +10806,22 @@ var temml = (function () {
10766
10806
  text
10767
10807
  };
10768
10808
  } else {
10809
+ if (asciiFromScript[text]) {
10810
+ // Unicode 14 disambiguates chancery from roundhand.
10811
+ // See https://www.unicode.org/charts/PDF/U1D400.pdf
10812
+ this.consume();
10813
+ const nextCode = this.fetch().text.charCodeAt(0);
10814
+ // mathcal is Temml default. Use mathscript if called for.
10815
+ const font = nextCode === 0xfe01 ? "mathscr" : "mathcal";
10816
+ if (nextCode === 0xfe00 || nextCode === 0xfe01) { this.consume(); }
10817
+ return {
10818
+ type: "font",
10819
+ mode: "math",
10820
+ font,
10821
+ body: { type: "mathord", mode: "math", loc, text: asciiFromScript[text] }
10822
+ }
10823
+ }
10824
+ // Default ord character. No disambiguation necessary.
10769
10825
  s = {
10770
10826
  type: group,
10771
10827
  mode: this.mode,
@@ -11022,7 +11078,7 @@ var temml = (function () {
11022
11078
  * https://mit-license.org/
11023
11079
  */
11024
11080
 
11025
- const version = "0.9.2";
11081
+ const version = "0.10.2";
11026
11082
 
11027
11083
  function postProcess(block) {
11028
11084
  const labelMap = {};