temml 0.10.21 → 0.10.23

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,24 @@
1
+ import defineFunction from "../defineFunction"
2
+ import * as mml from "../buildMathML"
3
+
4
+ defineFunction({
5
+ type: "reflect",
6
+ names: ["\\reflectbox"],
7
+ props: {
8
+ numArgs: 1,
9
+ argTypes: ["hbox"],
10
+ allowedInText: true
11
+ },
12
+ handler({ parser }, args) {
13
+ return {
14
+ type: "reflect",
15
+ mode: parser.mode,
16
+ body: args[0]
17
+ };
18
+ },
19
+ mathmlBuilder(group, style) {
20
+ const node = mml.buildGroup(group.body, style)
21
+ node.style.transform = "scaleX(-1)"
22
+ return node
23
+ }
24
+ })
@@ -44,7 +44,7 @@ defineFunction({
44
44
  // eslint-disable-next-line no-console
45
45
  console.log(`Temml strict-mode warning: Command ${funcName} is invalid in math mode.`)
46
46
  }
47
- const body = parser.parseExpression(false, breakOnTokenText);
47
+ const body = parser.parseExpression(false, breakOnTokenText, true);
48
48
  return {
49
49
  type: "sizing",
50
50
  mode: parser.mode,
@@ -26,7 +26,7 @@ defineFunction({
26
26
  },
27
27
  handler({ breakOnTokenText, funcName, parser }, args) {
28
28
  // parse out the implicit body
29
- const body = parser.parseExpression(true, breakOnTokenText);
29
+ const body = parser.parseExpression(true, breakOnTokenText, true);
30
30
 
31
31
  const scriptLevel = funcName.slice(1, funcName.length - 5);
32
32
  return {
@@ -90,8 +90,6 @@ defineFunctionBuilders({
90
90
  node = new mathMLTree.MathNode("mi", [text])
91
91
  if (text.text === origText && latinRegEx.test(origText)) {
92
92
  node.setAttribute("mathvariant", "italic")
93
- } else if (text.text === "∇" && variant === "normal") {
94
- node.setAttribute("mathvariant", "normal")
95
93
  }
96
94
  }
97
95
  return node
package/src/functions.js CHANGED
@@ -41,6 +41,7 @@ import "./functions/phantom";
41
41
  import "./functions/pmb";
42
42
  import "./functions/raise";
43
43
  import "./functions/ref";
44
+ import "./functions/reflect";
44
45
  import "./functions/relax";
45
46
  import "./functions/rule";
46
47
  import "./functions/sizing";
@@ -57,7 +57,8 @@ export default function setLineBreaks(expression, wrapMode, isDisplayMode) {
57
57
  continue
58
58
  }
59
59
  block.push(node);
60
- if (node.type && node.type === "mo" && node.children.length === 1) {
60
+ if (node.type && node.type === "mo" && node.children.length === 1 &&
61
+ !Object.hasOwn(node.attributes, "movablelimits")) {
61
62
  const ch = node.children[0].text
62
63
  if (openDelims.indexOf(ch) > -1) {
63
64
  level += 1
@@ -72,7 +73,7 @@ export default function setLineBreaks(expression, wrapMode, isDisplayMode) {
72
73
  mrows.push(element)
73
74
  block = [node];
74
75
  }
75
- } else if (level === 0 && wrapMode === "tex") {
76
+ } else if (level === 0 && wrapMode === "tex" && ch !== "∇") {
76
77
  // Check if the following node is a \nobreak text node, e.g. "~""
77
78
  const next = i < expression.length - 1 ? expression[i + 1] : null;
78
79
  let glueIsFreeOfNobreak = true;
package/src/macros.js CHANGED
@@ -184,6 +184,24 @@ defineMacro("\\char", function(context) {
184
184
  return `\\@char{${number}}`;
185
185
  });
186
186
 
187
+ function recreateArgStr(context) {
188
+ // Recreate the macro's original argument string from the array of parse tokens.
189
+ const tokens = context.consumeArgs(1)[0];
190
+ let str = ""
191
+ let expectedLoc = tokens[tokens.length - 1].loc.start
192
+ for (let i = tokens.length - 1; i >= 0; i--) {
193
+ const actualLoc = tokens[i].loc.start
194
+ if (actualLoc > expectedLoc) {
195
+ // context.consumeArgs has eaten a space.
196
+ str += " "
197
+ expectedLoc = actualLoc;
198
+ }
199
+ str += tokens[i].text
200
+ expectedLoc += tokens[i].text.length
201
+ }
202
+ return str
203
+ }
204
+
187
205
  // The Latin Modern font renders <mi>√</mi> at the wrong vertical alignment.
188
206
  // This macro provides a better rendering.
189
207
  defineMacro("\\surd", '\\sqrt{\\vphantom{|}}')
@@ -191,10 +209,6 @@ defineMacro("\\surd", '\\sqrt{\\vphantom{|}}')
191
209
  // See comment for \oplus in symbols.js.
192
210
  defineMacro("\u2295", "\\oplus")
193
211
 
194
- // Per TeXbook p.122, "/" gets zero operator spacing.
195
- // And MDN recommends using U+2044 instead of / for inline
196
- defineMacro("/", "{\u2044}")
197
-
198
212
  // Since Temml has no \par, ignore \long.
199
213
  defineMacro("\\long", "")
200
214
 
@@ -572,6 +586,11 @@ defineMacro("\\argmin", "\\DOTSB\\operatorname*{arg\\,min}");
572
586
  defineMacro("\\argmax", "\\DOTSB\\operatorname*{arg\\,max}");
573
587
  defineMacro("\\plim", "\\DOTSB\\operatorname*{plim}");
574
588
 
589
+ //////////////////////////////////////////////////////////////////////
590
+ // MnSymbol.sty
591
+
592
+ defineMacro("\\leftmodels", "\\mathop{\\reflectbox{$\\models$}}")
593
+
575
594
  //////////////////////////////////////////////////////////////////////
576
595
  // braket.sty
577
596
  // http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/braket/braket.pdf
@@ -581,56 +600,33 @@ defineMacro("\\ket", "\\mathinner{|{#1}\\rangle}");
581
600
  defineMacro("\\braket", "\\mathinner{\\langle{#1}\\rangle}");
582
601
  defineMacro("\\Bra", "\\left\\langle#1\\right|");
583
602
  defineMacro("\\Ket", "\\left|#1\\right\\rangle");
584
- const braketHelper = (one) => (context) => {
585
- const left = context.consumeArg().tokens;
586
- const middle = context.consumeArg().tokens;
587
- const middleDouble = context.consumeArg().tokens;
588
- const right = context.consumeArg().tokens;
589
- const oldMiddle = context.macros.get("|");
590
- const oldMiddleDouble = context.macros.get("\\|");
591
- context.macros.beginGroup();
592
- const midMacro = (double) => (context) => {
593
- if (one) {
594
- // Only modify the first instance of | or \|
595
- context.macros.set("|", oldMiddle);
596
- if (middleDouble.length) {
597
- context.macros.set("\\|", oldMiddleDouble);
598
- }
599
- }
600
- let doubled = double;
601
- if (!double && middleDouble.length) {
602
- // Mimic \@ifnextchar
603
- const nextToken = context.future();
604
- if (nextToken.text === "|") {
605
- context.popToken();
606
- doubled = true;
607
- }
608
- }
609
- return {
610
- tokens: doubled ? middleDouble : middle,
611
- numArgs: 0
612
- };
613
- };
614
- context.macros.set("|", midMacro(false));
615
- if (middleDouble.length) {
616
- context.macros.set("\\|", midMacro(true));
603
+ // A helper for \Braket and \Set
604
+ const replaceVert = (argStr, match) => {
605
+ const ch = match[0] === "|" ? "\\vert" : "\\Vert"
606
+ const replaceStr = `}\\,\\middle${ch}\\,{`
607
+ return argStr.slice(0, match.index) + replaceStr + argStr.slice(match.index + match[0].length)
608
+ }
609
+ defineMacro("\\Braket", function(context) {
610
+ let argStr = recreateArgStr(context)
611
+ const regEx = /\|\||\||\\\|/g
612
+ let match
613
+ while ((match = regEx.exec(argStr)) !== null) {
614
+ argStr = replaceVert(argStr, match)
617
615
  }
618
- const arg = context.consumeArg().tokens;
619
- const expanded = context.expandTokens([...right, ...arg, ...left]); // reversed
620
- context.macros.endGroup();
621
- return {
622
- tokens: expanded.reverse(),
623
- numArgs: 0
624
- };
625
- };
626
- defineMacro("\\bra@ket", braketHelper(false));
627
- defineMacro("\\bra@set", braketHelper(true));
628
- defineMacro("\\Braket", "\\bra@ket{\\left\\langle}" +
629
- "{\\,\\middle\\vert\\,}{\\,\\middle\\vert\\,}{\\right\\rangle}");
630
- defineMacro("\\Set", "\\bra@set{\\left\\{\\:}" +
631
- "{\\;\\middle\\vert\\;}{\\;\\middle\\Vert\\;}{\\:\\right\\}}");
632
- defineMacro("\\set", "\\bra@set{\\{\\,}{\\mid}{}{\\,\\}}");
633
- // has no support for special || or \|
616
+ return "\\left\\langle{" + argStr + "}\\right\\rangle"
617
+ });
618
+ defineMacro("\\Set", function(context) {
619
+ let argStr = recreateArgStr(context)
620
+ const match = /\|\||\||\\\|/.exec(argStr)
621
+ if (match) {
622
+ argStr = replaceVert(argStr, match)
623
+ }
624
+ return "\\left\\{\\:{" + argStr + "}\\:\\right\\}"
625
+ });
626
+ defineMacro("\\set", function(context) {
627
+ const argStr = recreateArgStr(context)
628
+ return "\\{{" + argStr.replace(/\|/, "}\\mid{") + "}\\}"
629
+ });
634
630
 
635
631
  //////////////////////////////////////////////////////////////////////
636
632
  // actuarialangle.dtx
@@ -8,7 +8,7 @@
8
8
  * https://mit-license.org/
9
9
  */
10
10
 
11
- export const version = "0.10.21";
11
+ export const version = "0.10.23";
12
12
 
13
13
  export function postProcess(block) {
14
14
  const labelMap = {}
package/src/replace.js CHANGED
@@ -106,22 +106,22 @@ const offset = Object.freeze({
106
106
  "sans-serif-bold-italic": ch => { return 0x1D5F5 },
107
107
  "monospace": ch => { return 0x1D629 }
108
108
  },
109
- upperCaseGreek: { // A-Ω
109
+ upperCaseGreek: { // A-Ω
110
110
  "normal": ch => { return 0 },
111
- "bold": ch => { return ch === "∇" ? 0x1B4BA : 0x1D317 },
112
- "italic": ch => { return ch === "∇" ? 0x1B4F4 : 0x1D351 },
111
+ "bold": ch => { return 0x1D317 },
112
+ "italic": ch => { return 0x1D351 },
113
113
  // \boldsymbol actually returns upright bold for upperCaseGreek
114
- "bold-italic": ch => { return ch === "∇" ? 0x1B4BA : 0x1D317 },
114
+ "bold-italic": ch => { return 0x1D317 },
115
115
  "script": ch => { return 0 },
116
116
  "script-bold": ch => { return 0 },
117
117
  "fraktur": ch => { return 0 },
118
118
  "fraktur-bold": ch => { return 0 },
119
119
  "double-struck": ch => { return 0 },
120
120
  // Unicode has no code points for regular-weight san-serif Greek. Use bold.
121
- "sans-serif": ch => { return ch === "∇" ? 0x1B568 : 0x1D3C5 },
122
- "sans-serif-bold": ch => { return ch === "∇" ? 0x1B568 : 0x1D3C5 },
121
+ "sans-serif": ch => { return 0x1D3C5 },
122
+ "sans-serif-bold": ch => { return 0x1D3C5 },
123
123
  "sans-serif-italic": ch => { return 0 },
124
- "sans-serif-bold-italic": ch => { return ch === "∇" ? 0x1B5A2 : 0x1D3FF },
124
+ "sans-serif-bold-italic": ch => { return 0x1D3FF },
125
125
  "monospace": ch => { return 0 }
126
126
  },
127
127
  lowerCaseGreek: { // α-ω
@@ -181,7 +181,7 @@ export const variantChar = (ch, variant) => {
181
181
  ? "upperCaseLatin"
182
182
  : 0x60 < codePoint && codePoint < 0x7b
183
183
  ? "lowerCaseLatin"
184
- : (0x390 < codePoint && codePoint < 0x3AA) || ch === "∇"
184
+ : (0x390 < codePoint && codePoint < 0x3AA)
185
185
  ? "upperCaseGreek"
186
186
  : 0x3B0 < codePoint && codePoint < 0x3CA || ch === "\u03d5"
187
187
  ? "lowerCaseGreek"
package/src/symbols.js CHANGED
@@ -128,7 +128,8 @@ defineSymbol(math, textord, "\u2135", "\\aleph", true);
128
128
  defineSymbol(math, textord, "\u2200", "\\forall", true);
129
129
  defineSymbol(math, textord, "\u210f", "\\hbar", true);
130
130
  defineSymbol(math, textord, "\u2203", "\\exists", true);
131
- defineSymbol(math, textord, "\u2207", "\\nabla", true);
131
+ // is actually a unary operator, not binary. But this works.
132
+ defineSymbol(math, bin, "\u2207", "\\nabla", true);
132
133
  defineSymbol(math, textord, "\u266d", "\\flat", true);
133
134
  defineSymbol(math, textord, "\u2113", "\\ell", true);
134
135
  defineSymbol(math, textord, "\u266e", "\\natural", true);
@@ -182,6 +183,7 @@ defineSymbol(math, bin, "\u2021", "\\ddagger");
182
183
  defineSymbol(math, bin, "\u2240", "\\wr", true);
183
184
  defineSymbol(math, bin, "\u2a3f", "\\amalg");
184
185
  defineSymbol(math, bin, "\u0026", "\\And"); // from amsmath
186
+ defineSymbol(math, bin, "\u2AFD", "\\sslash", true); // from stmaryrd
185
187
 
186
188
  // Arrow Symbols
187
189
  defineSymbol(math, rel, "\u27f5", "\\longleftarrow", true);
@@ -216,6 +218,7 @@ defineSymbol(math, mathord, "\u2609", "\\astrosun", true);
216
218
  defineSymbol(math, mathord, "\u263c", "\\sun", true);
217
219
  defineSymbol(math, mathord, "\u263e", "\\leftmoon", true);
218
220
  defineSymbol(math, mathord, "\u263d", "\\rightmoon", true);
221
+ defineSymbol(math, mathord, "\u2295", "\\Earth");
219
222
 
220
223
  // AMS Negated Binary Relations
221
224
  defineSymbol(math, rel, "\u226e", "\\nless", true);
@@ -443,6 +446,8 @@ defineSymbol(math, bin, "\u27d5", "\\leftouterjoin", true);
443
446
  defineSymbol(math, bin, "\u27d6", "\\rightouterjoin", true);
444
447
  defineSymbol(math, bin, "\u27d7", "\\fullouterjoin", true);
445
448
 
449
+ defineSymbol(math, bin, "\u2238", "\\dotminus", true); // stix
450
+
446
451
  // AMS Arrows
447
452
  // Note: unicode-math maps \u21e2 to their own function \rightdasharrow.
448
453
  // We'll map it to AMS function \dashrightarrow. It produces the same atom.
@@ -600,6 +605,7 @@ defineSymbol(math, mathord, "\u2aeb", "\\Bot");
600
605
  defineSymbol(math, bin, "\u2217", "\u2217", true);
601
606
  defineSymbol(math, bin, "+", "+");
602
607
  defineSymbol(math, bin, "*", "*");
608
+ defineSymbol(math, bin, "\u2044", "/", true);
603
609
  defineSymbol(math, bin, "\u2044", "\u2044");
604
610
  defineSymbol(math, bin, "\u2212", "-", true);
605
611
  defineSymbol(math, bin, "\u22c5", "\\cdot", true);