temml 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.
@@ -14,13 +14,11 @@ defineFunction({
14
14
  },
15
15
  handler: ({ parser, funcName }, args, optArgs) => {
16
16
  // Find out if the author has defined custom delimiters
17
- let delimiters = ["(", ")"]
17
+ let delimiters = ["(", ")"]; // default
18
18
  if (funcName === "\\bordermatrix" && optArgs[0] && optArgs[0].body) {
19
19
  const body = optArgs[0].body
20
- if (body.length === 2 && body[0].type === "atom" && body[1].type === "atom") {
21
- if (body[0].family === "open" && body[1].family === "close") {
22
- delimiters = [body[0].text, body[1].text]
23
- }
20
+ if (body.length === 1 && body[0].type === "delimiter") {
21
+ delimiters = [body[0].left, body[0].right]
24
22
  }
25
23
  }
26
24
  // consume the opening brace
@@ -424,17 +424,14 @@ defineFunction({
424
424
  mathmlBuilder: (group) => {
425
425
  const textNode = mml.makeText(group.delim, group.mode);
426
426
  const middleNode = new mathMLTree.MathNode("mo", [textNode]);
427
- middleNode.setAttribute("fence", "true");
428
- if (group.delim.indexOf("arrow") > -1) {
429
- middleNode.setAttribute("stretchy", "true")
427
+ middleNode.setAttribute("stretchy", "true")
428
+ middleNode.setAttribute("form", "infix")
429
+ if (textNode.text !== "/") {
430
+ // MathML gives 5/18em spacing to each <mo> element.
431
+ // \middle should get delimiter spacing instead.
432
+ middleNode.setAttribute("lspace", "0.05em");
433
+ middleNode.setAttribute("rspace", "0.05em");
430
434
  }
431
- // The next line is not semantically correct, but
432
- // Chromium fails to stretch if it is not there.
433
- middleNode.setAttribute("form", "prefix")
434
- // MathML gives 5/18em spacing to each <mo> element.
435
- // \middle should get delimiter spacing instead.
436
- middleNode.setAttribute("lspace", "0.05em");
437
- middleNode.setAttribute("rspace", "0.05em");
438
435
  return middleNode;
439
436
  }
440
437
  });
@@ -166,7 +166,7 @@ defineFunction({
166
166
 
167
167
  defineFunction({
168
168
  type: "enclose",
169
- names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\sout", "\\overline",
169
+ names: ["\\angl", "\\cancel", "\\bcancel", "\\xcancel", "\\overline",
170
170
  "\\boxed", "\\longdiv", "\\phase"],
171
171
  props: {
172
172
  numArgs: 1
@@ -183,6 +183,25 @@ defineFunction({
183
183
  mathmlBuilder
184
184
  });
185
185
 
186
+ defineFunction({
187
+ type: "enclose",
188
+ names: ["\\sout"],
189
+ props: {
190
+ numArgs: 1,
191
+ allowedInText: true
192
+ },
193
+ handler({ parser, funcName }, args) {
194
+ const body = args[0];
195
+ return {
196
+ type: "enclose",
197
+ mode: parser.mode,
198
+ label: funcName,
199
+ body
200
+ };
201
+ },
202
+ mathmlBuilder
203
+ });
204
+
186
205
  defineFunction({
187
206
  type: "enclose",
188
207
  names: ["\\underline"],
@@ -1,9 +1,13 @@
1
1
  import defineFunction, { normalizeArgument } from "../defineFunction"
2
2
  import * as mml from "../buildMathML"
3
3
  import * as mathMLTree from "../mathMLTree"
4
+ import { variantChar } from "../replace"
5
+
6
+ const varNameFonts = ["mathrm", "mathit"];
4
7
 
5
8
  const isLongVariableName = (group, font) => {
6
- if (font !== "mathrm" || group.body.type !== "ordgroup" || group.body.body.length === 1) {
9
+ if (!varNameFonts.includes(font) || !group.body || group.body.type !== "ordgroup" ||
10
+ group.body.body.length === 1) {
7
11
  return false
8
12
  }
9
13
  if (group.body.body[0].type !== "mathord") { return false }
@@ -29,8 +33,7 @@ const mathmlBuilder = (group, style) => {
29
33
  }
30
34
  // Check if it is possible to consolidate elements into a single <mi> element.
31
35
  if (isLongVariableName(group, font)) {
32
- // This is a \mathrm{…} group. It gets special treatment because symbolsOrd.js
33
- // wraps <mi> elements with <mpadded>s to work around a Firefox bug.
36
+ // This is a \mathrm{…} or \mathit{…} group. It gets special treatment.
34
37
  const mi = mathGroup.children[0].children[0].children
35
38
  ? mathGroup.children[0].children[0]
36
39
  : mathGroup.children[0];
@@ -40,7 +43,14 @@ const mathmlBuilder = (group, style) => {
40
43
  ? mathGroup.children[i].children[0].children[0].text
41
44
  : mathGroup.children[i].children[0].text
42
45
  }
43
- // Wrap in a <mpadded> to prevent the same Firefox bug.
46
+ if (font === "mathit") {
47
+ // Long <mi> elements are normally rendered in upright font.
48
+ // To get italic, we need to convert each character to the corresponding italic character.
49
+ mi.children[0].text = mi.children[0].text.split("")
50
+ .map(c => variantChar(c, "italic")).join("")
51
+ return mi
52
+ }
53
+ // Otherwise, font is "mathrm". Wrap in a <mpadded> to prevent a Firefox spacing bug.
44
54
  const mpadded = new mathMLTree.MathNode("mpadded", [mi])
45
55
  mpadded.setAttribute("lspace", "0")
46
56
  return mpadded
@@ -67,7 +67,7 @@ defineFunction({
67
67
  const inner = mml.buildExpression(ordargument(group.body), style);
68
68
  const phantom = new mathMLTree.MathNode("mphantom", inner);
69
69
  const node = new mathMLTree.MathNode("mpadded", [phantom]);
70
- node.setAttribute("width", "0px");
70
+ node.setAttribute("width", "0.1px");
71
71
  return node;
72
72
  }
73
73
  });
@@ -5,7 +5,7 @@
5
5
  * https://mit-license.org/
6
6
  */
7
7
 
8
- export const version = "0.13.02";
8
+ export const version = "0.13.3";
9
9
 
10
10
  export function postProcess(block) {
11
11
  const labelMap = {}