temml 0.10.21 → 0.10.22

Sign up to get free protection for your applications and to get access to all the features.
package/dist/temml.js CHANGED
@@ -937,7 +937,8 @@ var temml = (function () {
937
937
  defineSymbol(math, textord, "\u2200", "\\forall", true);
938
938
  defineSymbol(math, textord, "\u210f", "\\hbar", true);
939
939
  defineSymbol(math, textord, "\u2203", "\\exists", true);
940
- defineSymbol(math, textord, "\u2207", "\\nabla", true);
940
+ // is actually a unary operator, not binary. But this works.
941
+ defineSymbol(math, bin, "\u2207", "\\nabla", true);
941
942
  defineSymbol(math, textord, "\u266d", "\\flat", true);
942
943
  defineSymbol(math, textord, "\u2113", "\\ell", true);
943
944
  defineSymbol(math, textord, "\u266e", "\\natural", true);
@@ -991,6 +992,7 @@ var temml = (function () {
991
992
  defineSymbol(math, bin, "\u2240", "\\wr", true);
992
993
  defineSymbol(math, bin, "\u2a3f", "\\amalg");
993
994
  defineSymbol(math, bin, "\u0026", "\\And"); // from amsmath
995
+ defineSymbol(math, bin, "\u2AFD", "\\sslash", true); // from stmaryrd
994
996
 
995
997
  // Arrow Symbols
996
998
  defineSymbol(math, rel, "\u27f5", "\\longleftarrow", true);
@@ -1409,6 +1411,7 @@ var temml = (function () {
1409
1411
  defineSymbol(math, bin, "\u2217", "\u2217", true);
1410
1412
  defineSymbol(math, bin, "+", "+");
1411
1413
  defineSymbol(math, bin, "*", "*");
1414
+ defineSymbol(math, bin, "\u2044", "/", true);
1412
1415
  defineSymbol(math, bin, "\u2044", "\u2044");
1413
1416
  defineSymbol(math, bin, "\u2212", "-", true);
1414
1417
  defineSymbol(math, bin, "\u22c5", "\\cdot", true);
@@ -1865,7 +1868,8 @@ var temml = (function () {
1865
1868
  continue
1866
1869
  }
1867
1870
  block.push(node);
1868
- if (node.type && node.type === "mo" && node.children.length === 1) {
1871
+ if (node.type && node.type === "mo" && node.children.length === 1 &&
1872
+ !Object.hasOwn(node.attributes, "movablelimits")) {
1869
1873
  const ch = node.children[0].text;
1870
1874
  if (openDelims.indexOf(ch) > -1) {
1871
1875
  level += 1;
@@ -1880,7 +1884,7 @@ var temml = (function () {
1880
1884
  mrows.push(element);
1881
1885
  block = [node];
1882
1886
  }
1883
- } else if (level === 0 && wrapMode === "tex") {
1887
+ } else if (level === 0 && wrapMode === "tex" && ch !== "∇") {
1884
1888
  // Check if the following node is a \nobreak text node, e.g. "~""
1885
1889
  const next = i < expression.length - 1 ? expression[i + 1] : null;
1886
1890
  let glueIsFreeOfNobreak = true;
@@ -3259,7 +3263,7 @@ var temml = (function () {
3259
3263
  }
3260
3264
 
3261
3265
  // Parse out the implicit body that should be colored.
3262
- const body = parser.parseExpression(true, breakOnTokenText);
3266
+ const body = parser.parseExpression(true, breakOnTokenText, true);
3263
3267
 
3264
3268
  return {
3265
3269
  type: "color",
@@ -3701,17 +3705,13 @@ var temml = (function () {
3701
3705
 
3702
3706
  // Delimiter functions
3703
3707
  function checkDelimiter(delim, context) {
3704
- if (delim.type === "ordgroup" && delim.body.length === 1 && delim.body[0].text === "\u2044") {
3705
- // Recover "/" from the zero spacing group. (See macros.js)
3706
- delim = { type: "textord", text: "/", mode: "math" };
3707
- }
3708
3708
  const symDelim = checkSymbolNodeType(delim);
3709
3709
  if (symDelim && delimiters.includes(symDelim.text)) {
3710
3710
  // If a character is not in the MathML operator dictionary, it will not stretch.
3711
3711
  // Replace such characters w/characters that will stretch.
3712
+ if (["/", "\u2044"].includes(symDelim.text)) { symDelim.text = "\u2215"; }
3712
3713
  if (["<", "\\lt"].includes(symDelim.text)) { symDelim.text = "⟨"; }
3713
3714
  if ([">", "\\gt"].includes(symDelim.text)) { symDelim.text = "⟩"; }
3714
- if (symDelim.text === "/") { symDelim.text = "\u2215"; }
3715
3715
  if (symDelim.text === "\\backslash") { symDelim.text = "\u2216"; }
3716
3716
  return symDelim;
3717
3717
  } else if (symDelim) {
@@ -3820,8 +3820,26 @@ var temml = (function () {
3820
3820
  const parser = context.parser;
3821
3821
  // Parse out the implicit body
3822
3822
  ++parser.leftrightDepth;
3823
- // parseExpression stops before '\\right'
3824
- const body = parser.parseExpression(false);
3823
+ // parseExpression stops before '\\right' or `\\middle`
3824
+ let body = parser.parseExpression(false, null, true);
3825
+ let nextToken = parser.fetch();
3826
+ while (nextToken.text === "\\middle") {
3827
+ // `\middle`, from the ε-TeX package, ends one group and starts another group.
3828
+ // We had to parse this expression with `breakOnMiddle` enabled in order
3829
+ // to get TeX-compliant parsing of \over.
3830
+ // But we do not want, at this point, to end on \middle, so continue
3831
+ // to parse until we fetch a `\right`.
3832
+ parser.consume();
3833
+ const middle = parser.fetch().text;
3834
+ if (!symbols.math[middle]) {
3835
+ throw new ParseError(`Invalid delimiter '${middle}' after '\\middle'`);
3836
+ }
3837
+ checkDelimiter({ type: "atom", mode: "math", text: middle }, { funcName: "\\middle" });
3838
+ body.push({ type: "middle", mode: "math", delim: middle });
3839
+ parser.consume();
3840
+ body = body.concat(parser.parseExpression(false, null, true));
3841
+ nextToken = parser.fetch();
3842
+ }
3825
3843
  --parser.leftrightDepth;
3826
3844
  // Check the next token
3827
3845
  parser.expect("\\right", false);
@@ -5196,7 +5214,7 @@ var temml = (function () {
5196
5214
  },
5197
5215
  handler: ({ parser, funcName, breakOnTokenText }, args) => {
5198
5216
  const { mode } = parser;
5199
- const body = parser.parseExpression(true, breakOnTokenText);
5217
+ const body = parser.parseExpression(true, breakOnTokenText, true);
5200
5218
  const fontStyle = `math${funcName.slice(1)}`;
5201
5219
 
5202
5220
  return {
@@ -6157,6 +6175,9 @@ var temml = (function () {
6157
6175
  if (group.isCharacterBox || inner[0].type === "mathord") {
6158
6176
  node = inner[0];
6159
6177
  node.type = "mi";
6178
+ if (node.children.length === 1 && node.children[0].text && node.children[0].text === "∇") {
6179
+ node.setAttribute("mathvariant", "normal");
6180
+ }
6160
6181
  } else {
6161
6182
  node = new mathMLTree.MathNode("mi", inner);
6162
6183
  }
@@ -7144,6 +7165,28 @@ var temml = (function () {
7144
7165
  }
7145
7166
  });
7146
7167
 
7168
+ defineFunction({
7169
+ type: "reflect",
7170
+ names: ["\\reflectbox"],
7171
+ props: {
7172
+ numArgs: 1,
7173
+ argTypes: ["hbox"],
7174
+ allowedInText: true
7175
+ },
7176
+ handler({ parser }, args) {
7177
+ return {
7178
+ type: "reflect",
7179
+ mode: parser.mode,
7180
+ body: args[0]
7181
+ };
7182
+ },
7183
+ mathmlBuilder(group, style) {
7184
+ const node = buildGroup$1(group.body, style);
7185
+ node.style.transform = "scaleX(-1)";
7186
+ return node
7187
+ }
7188
+ });
7189
+
7147
7190
  defineFunction({
7148
7191
  type: "internal",
7149
7192
  names: ["\\relax"],
@@ -7249,7 +7292,7 @@ var temml = (function () {
7249
7292
  // eslint-disable-next-line no-console
7250
7293
  console.log(`Temml strict-mode warning: Command ${funcName} is invalid in math mode.`);
7251
7294
  }
7252
- const body = parser.parseExpression(false, breakOnTokenText);
7295
+ const body = parser.parseExpression(false, breakOnTokenText, true);
7253
7296
  return {
7254
7297
  type: "sizing",
7255
7298
  mode: parser.mode,
@@ -7382,7 +7425,7 @@ var temml = (function () {
7382
7425
  },
7383
7426
  handler({ breakOnTokenText, funcName, parser }, args) {
7384
7427
  // parse out the implicit body
7385
- const body = parser.parseExpression(true, breakOnTokenText);
7428
+ const body = parser.parseExpression(true, breakOnTokenText, true);
7386
7429
 
7387
7430
  const scriptLevel = funcName.slice(1, funcName.length - 5);
7388
7431
  return {
@@ -7813,22 +7856,22 @@ var temml = (function () {
7813
7856
  "sans-serif-bold-italic": ch => { return 0x1D5F5 },
7814
7857
  "monospace": ch => { return 0x1D629 }
7815
7858
  },
7816
- upperCaseGreek: { // A-Ω
7859
+ upperCaseGreek: { // A-Ω
7817
7860
  "normal": ch => { return 0 },
7818
- "bold": ch => { return ch === "∇" ? 0x1B4BA : 0x1D317 },
7819
- "italic": ch => { return ch === "∇" ? 0x1B4F4 : 0x1D351 },
7861
+ "bold": ch => { return 0x1D317 },
7862
+ "italic": ch => { return 0x1D351 },
7820
7863
  // \boldsymbol actually returns upright bold for upperCaseGreek
7821
- "bold-italic": ch => { return ch === "∇" ? 0x1B4BA : 0x1D317 },
7864
+ "bold-italic": ch => { return 0x1D317 },
7822
7865
  "script": ch => { return 0 },
7823
7866
  "script-bold": ch => { return 0 },
7824
7867
  "fraktur": ch => { return 0 },
7825
7868
  "fraktur-bold": ch => { return 0 },
7826
7869
  "double-struck": ch => { return 0 },
7827
7870
  // Unicode has no code points for regular-weight san-serif Greek. Use bold.
7828
- "sans-serif": ch => { return ch === "∇" ? 0x1B568 : 0x1D3C5 },
7829
- "sans-serif-bold": ch => { return ch === "∇" ? 0x1B568 : 0x1D3C5 },
7871
+ "sans-serif": ch => { return 0x1D3C5 },
7872
+ "sans-serif-bold": ch => { return 0x1D3C5 },
7830
7873
  "sans-serif-italic": ch => { return 0 },
7831
- "sans-serif-bold-italic": ch => { return ch === "∇" ? 0x1B5A2 : 0x1D3FF },
7874
+ "sans-serif-bold-italic": ch => { return 0x1D3FF },
7832
7875
  "monospace": ch => { return 0 }
7833
7876
  },
7834
7877
  lowerCaseGreek: { // α-ω
@@ -7888,7 +7931,7 @@ var temml = (function () {
7888
7931
  ? "upperCaseLatin"
7889
7932
  : 0x60 < codePoint && codePoint < 0x7b
7890
7933
  ? "lowerCaseLatin"
7891
- : (0x390 < codePoint && codePoint < 0x3AA) || ch === "∇"
7934
+ : (0x390 < codePoint && codePoint < 0x3AA)
7892
7935
  ? "upperCaseGreek"
7893
7936
  : 0x3B0 < codePoint && codePoint < 0x3CA || ch === "\u03d5"
7894
7937
  ? "lowerCaseGreek"
@@ -8017,8 +8060,6 @@ var temml = (function () {
8017
8060
  node = new mathMLTree.MathNode("mi", [text]);
8018
8061
  if (text.text === origText && latinRegEx.test(origText)) {
8019
8062
  node.setAttribute("mathvariant", "italic");
8020
- } else if (text.text === "∇" && variant === "normal") {
8021
- node.setAttribute("mathvariant", "normal");
8022
8063
  }
8023
8064
  }
8024
8065
  return node
@@ -8655,6 +8696,24 @@ var temml = (function () {
8655
8696
  return `\\@char{${number}}`;
8656
8697
  });
8657
8698
 
8699
+ function recreateArgStr(context) {
8700
+ // Recreate the macro's original argument string from the array of parse tokens.
8701
+ const tokens = context.consumeArgs(1)[0];
8702
+ let str = "";
8703
+ let expectedLoc = tokens[tokens.length - 1].loc.start;
8704
+ for (let i = tokens.length - 1; i >= 0; i--) {
8705
+ const actualLoc = tokens[i].loc.start;
8706
+ if (actualLoc > expectedLoc) {
8707
+ // context.consumeArgs has eaten a space.
8708
+ str += " ";
8709
+ expectedLoc = actualLoc;
8710
+ }
8711
+ str += tokens[i].text;
8712
+ expectedLoc += tokens[i].text.length;
8713
+ }
8714
+ return str
8715
+ }
8716
+
8658
8717
  // The Latin Modern font renders <mi>√</mi> at the wrong vertical alignment.
8659
8718
  // This macro provides a better rendering.
8660
8719
  defineMacro("\\surd", '\\sqrt{\\vphantom{|}}');
@@ -8662,10 +8721,6 @@ var temml = (function () {
8662
8721
  // See comment for \oplus in symbols.js.
8663
8722
  defineMacro("\u2295", "\\oplus");
8664
8723
 
8665
- // Per TeXbook p.122, "/" gets zero operator spacing.
8666
- // And MDN recommends using U+2044 instead of / for inline
8667
- defineMacro("/", "{\u2044}");
8668
-
8669
8724
  // Since Temml has no \par, ignore \long.
8670
8725
  defineMacro("\\long", "");
8671
8726
 
@@ -9043,6 +9098,11 @@ var temml = (function () {
9043
9098
  defineMacro("\\argmax", "\\DOTSB\\operatorname*{arg\\,max}");
9044
9099
  defineMacro("\\plim", "\\DOTSB\\operatorname*{plim}");
9045
9100
 
9101
+ //////////////////////////////////////////////////////////////////////
9102
+ // MnSymbol.sty
9103
+
9104
+ defineMacro("\\leftmodels", "\\mathop{\\reflectbox{$\\models$}}");
9105
+
9046
9106
  //////////////////////////////////////////////////////////////////////
9047
9107
  // braket.sty
9048
9108
  // http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/braket/braket.pdf
@@ -9052,56 +9112,33 @@ var temml = (function () {
9052
9112
  defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
9053
9113
  defineMacro("\\Bra", "\\left\\langle#1\\right|");
9054
9114
  defineMacro("\\Ket", "\\left|#1\\right\\rangle");
9055
- const braketHelper = (one) => (context) => {
9056
- const left = context.consumeArg().tokens;
9057
- const middle = context.consumeArg().tokens;
9058
- const middleDouble = context.consumeArg().tokens;
9059
- const right = context.consumeArg().tokens;
9060
- const oldMiddle = context.macros.get("|");
9061
- const oldMiddleDouble = context.macros.get("\\|");
9062
- context.macros.beginGroup();
9063
- const midMacro = (double) => (context) => {
9064
- if (one) {
9065
- // Only modify the first instance of | or \|
9066
- context.macros.set("|", oldMiddle);
9067
- if (middleDouble.length) {
9068
- context.macros.set("\\|", oldMiddleDouble);
9069
- }
9070
- }
9071
- let doubled = double;
9072
- if (!double && middleDouble.length) {
9073
- // Mimic \@ifnextchar
9074
- const nextToken = context.future();
9075
- if (nextToken.text === "|") {
9076
- context.popToken();
9077
- doubled = true;
9078
- }
9079
- }
9080
- return {
9081
- tokens: doubled ? middleDouble : middle,
9082
- numArgs: 0
9083
- };
9084
- };
9085
- context.macros.set("|", midMacro(false));
9086
- if (middleDouble.length) {
9087
- context.macros.set("\\|", midMacro(true));
9088
- }
9089
- const arg = context.consumeArg().tokens;
9090
- const expanded = context.expandTokens([...right, ...arg, ...left]); // reversed
9091
- context.macros.endGroup();
9092
- return {
9093
- tokens: expanded.reverse(),
9094
- numArgs: 0
9095
- };
9115
+ // A helper for \Braket and \Set
9116
+ const replaceVert = (argStr, match) => {
9117
+ const ch = match[0] === "|" ? "\\vert" : "\\Vert";
9118
+ const replaceStr = `}\\,\\middle${ch}\\,{`;
9119
+ return argStr.slice(0, match.index) + replaceStr + argStr.slice(match.index + match[0].length)
9096
9120
  };
9097
- defineMacro("\\bra@ket", braketHelper(false));
9098
- defineMacro("\\bra@set", braketHelper(true));
9099
- defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" +
9100
- "{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
9101
- defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" +
9102
- "{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
9103
- defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}");
9104
- // has no support for special || or \|
9121
+ defineMacro("\\Braket", function(context) {
9122
+ let argStr = recreateArgStr(context);
9123
+ const regEx = /\|\||\||\\\|/g;
9124
+ let match;
9125
+ while ((match = regEx.exec(argStr)) !== null) {
9126
+ argStr = replaceVert(argStr, match);
9127
+ }
9128
+ return "\\left\\langle{" + argStr + "}\\right\\rangle"
9129
+ });
9130
+ defineMacro("\\Set", function(context) {
9131
+ let argStr = recreateArgStr(context);
9132
+ const match = /\|\||\||\\\|/.exec(argStr);
9133
+ if (match) {
9134
+ argStr = replaceVert(argStr, match);
9135
+ }
9136
+ return "\\left\\{\\:{" + argStr + "}\\:\\right\\}"
9137
+ });
9138
+ defineMacro("\\set", function(context) {
9139
+ const argStr = recreateArgStr(context);
9140
+ return "\\{{" + argStr.replace(/\|/, "}\\mid{") + "}\\}"
9141
+ });
9105
9142
 
9106
9143
  //////////////////////////////////////////////////////////////////////
9107
9144
  // actuarialangle.dtx
@@ -10250,8 +10287,12 @@ var temml = (function () {
10250
10287
  * `breakOnTokenText`: The text of the token that the expression should end
10251
10288
  * with, or `null` if something else should end the
10252
10289
  * expression.
10290
+ *
10291
+ * `breakOnMiddle`: \color, \over, and old styling functions work on an implicit group.
10292
+ * These groups end just before the usual tokens, but they also
10293
+ * end just before `\middle`.
10253
10294
  */
10254
- parseExpression(breakOnInfix, breakOnTokenText) {
10295
+ parseExpression(breakOnInfix, breakOnTokenText, breakOnMiddle) {
10255
10296
  const body = [];
10256
10297
  // Keep adding atoms to the body until we can't parse any more atoms (either
10257
10298
  // we reached the end, a }, or a \right)
@@ -10267,6 +10308,9 @@ var temml = (function () {
10267
10308
  if (breakOnTokenText && lex.text === breakOnTokenText) {
10268
10309
  break;
10269
10310
  }
10311
+ if (breakOnMiddle && lex.text === "\\middle") {
10312
+ break
10313
+ }
10270
10314
  if (breakOnInfix && functions[lex.text] && functions[lex.text].infix) {
10271
10315
  break;
10272
10316
  }
@@ -11245,7 +11289,7 @@ var temml = (function () {
11245
11289
  * https://mit-license.org/
11246
11290
  */
11247
11291
 
11248
- const version = "0.10.21";
11292
+ const version = "0.10.22";
11249
11293
 
11250
11294
  function postProcess(block) {
11251
11295
  const labelMap = {};