temml 0.11.5 → 0.11.7

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/temml.mjs CHANGED
@@ -769,10 +769,12 @@ var mathMLTree = {
769
769
  // TODO: Remove when Chromium stretches \widetilde & \widehat
770
770
  const estimatedWidth = node => {
771
771
  let width = 0;
772
- if (node.body) {
772
+ if (node.body && Array.isArray(node.body)) {
773
773
  for (const item of node.body) {
774
774
  width += estimatedWidth(item);
775
775
  }
776
+ } else if (node.body) {
777
+ width += estimatedWidth(node.body);
776
778
  } else if (node.type === "supsub") {
777
779
  width += estimatedWidth(node.base);
778
780
  if (node.sub) { width += 0.7 * estimatedWidth(node.sub); }
@@ -8990,88 +8992,6 @@ defineFunction({
8990
8992
  mathmlBuilder: mathmlBuilder$4
8991
8993
  });
8992
8994
 
8993
- defineFunction({
8994
- type: "href",
8995
- names: ["\\href"],
8996
- props: {
8997
- numArgs: 2,
8998
- argTypes: ["url", "original"],
8999
- allowedInText: true
9000
- },
9001
- handler: ({ parser, token }, args) => {
9002
- const body = args[1];
9003
- const href = assertNodeType(args[0], "url").url;
9004
-
9005
- if (
9006
- !parser.settings.isTrusted({
9007
- command: "\\href",
9008
- url: href
9009
- })
9010
- ) {
9011
- throw new ParseError(`Function "\\href" is not trusted`, token)
9012
- }
9013
-
9014
- return {
9015
- type: "href",
9016
- mode: parser.mode,
9017
- href,
9018
- body: ordargument(body)
9019
- };
9020
- },
9021
- mathmlBuilder: (group, style) => {
9022
- const math = new MathNode("math", [buildExpressionRow(group.body, style)]);
9023
- const anchorNode = new AnchorNode(group.href, [], [math]);
9024
- return anchorNode
9025
- }
9026
- });
9027
-
9028
- defineFunction({
9029
- type: "href",
9030
- names: ["\\url"],
9031
- props: {
9032
- numArgs: 1,
9033
- argTypes: ["url"],
9034
- allowedInText: true
9035
- },
9036
- handler: ({ parser, token }, args) => {
9037
- const href = assertNodeType(args[0], "url").url;
9038
-
9039
- if (
9040
- !parser.settings.isTrusted({
9041
- command: "\\url",
9042
- url: href
9043
- })
9044
- ) {
9045
- throw new ParseError(`Function "\\url" is not trusted`, token)
9046
- }
9047
-
9048
- const chars = [];
9049
- for (let i = 0; i < href.length; i++) {
9050
- let c = href[i];
9051
- if (c === "~") {
9052
- c = "\\textasciitilde";
9053
- }
9054
- chars.push({
9055
- type: "textord",
9056
- mode: "text",
9057
- text: c
9058
- });
9059
- }
9060
- const body = {
9061
- type: "text",
9062
- mode: parser.mode,
9063
- font: "\\texttt",
9064
- body: chars
9065
- };
9066
- return {
9067
- type: "href",
9068
- mode: parser.mode,
9069
- href,
9070
- body: ordargument(body)
9071
- };
9072
- }
9073
- });
9074
-
9075
8995
  defineFunction({
9076
8996
  type: "html",
9077
8997
  names: ["\\class", "\\id", "\\style", "\\data"],
@@ -9329,17 +9249,24 @@ defineFunction({
9329
9249
  },
9330
9250
  mathmlBuilder(group, style) {
9331
9251
  const dimension = calculateSize(group.dimension, style);
9332
- const ch = dimension.unit === "em" ? spaceCharacter(dimension.number) : "";
9252
+ const ch = dimension.number > 0 && dimension.unit === "em"
9253
+ ? spaceCharacter(dimension.number)
9254
+ : "";
9333
9255
  if (group.mode === "text" && ch.length > 0) {
9334
9256
  const character = new mathMLTree.TextNode(ch);
9335
9257
  return new mathMLTree.MathNode("mtext", [character]);
9336
9258
  } else {
9337
- const node = new mathMLTree.MathNode("mspace");
9338
- node.setAttribute("width", dimension.number + dimension.unit);
9339
- if (dimension.number < 0) {
9259
+ if (dimension.number >= 0) {
9260
+ const node = new mathMLTree.MathNode("mspace");
9261
+ node.setAttribute("width", dimension.number + dimension.unit);
9262
+ return node
9263
+ } else {
9264
+ // Don't use <mspace> or <mpadded> because
9265
+ // WebKit recognizes negative left margin only on a <mrow> element
9266
+ const node = new mathMLTree.MathNode("mrow");
9340
9267
  node.style.marginLeft = dimension.number + dimension.unit;
9268
+ return node
9341
9269
  }
9342
- return node;
9343
9270
  }
9344
9271
  }
9345
9272
  });
@@ -13970,7 +13897,7 @@ class Style {
13970
13897
  * https://mit-license.org/
13971
13898
  */
13972
13899
 
13973
- const version = "0.11.05";
13900
+ const version = "0.11.07";
13974
13901
 
13975
13902
  function postProcess(block) {
13976
13903
  const labelMap = {};
@@ -11,7 +11,7 @@
11
11
  * https://mit-license.org/
12
12
  */
13
13
 
14
- const version = "0.11.05";
14
+ const version = "0.11.07";
15
15
 
16
16
  function postProcess(block) {
17
17
  const labelMap = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "temml",
3
- "version": "0.11.05",
3
+ "version": "0.11.07",
4
4
  "description": "TeX to MathML conversion in JavaScript.",
5
5
  "main": "dist/temml.js",
6
6
  "engines": {
@@ -45,17 +45,24 @@ defineFunction({
45
45
  },
46
46
  mathmlBuilder(group, style) {
47
47
  const dimension = calculateSize(group.dimension, style);
48
- const ch = dimension.unit === "em" ? spaceCharacter(dimension.number) : "";
48
+ const ch = dimension.number > 0 && dimension.unit === "em"
49
+ ? spaceCharacter(dimension.number)
50
+ : "";
49
51
  if (group.mode === "text" && ch.length > 0) {
50
52
  const character = new mathMLTree.TextNode(ch);
51
53
  return new mathMLTree.MathNode("mtext", [character]);
52
54
  } else {
53
- const node = new mathMLTree.MathNode("mspace");
54
- node.setAttribute("width", dimension.number + dimension.unit);
55
- if (dimension.number < 0) {
55
+ if (dimension.number >= 0) {
56
+ const node = new mathMLTree.MathNode("mspace")
57
+ node.setAttribute("width", dimension.number + dimension.unit)
58
+ return node
59
+ } else {
60
+ // Don't use <mspace> or <mpadded> because
61
+ // WebKit recognizes negative left margin only on a <mrow> element
62
+ const node = new mathMLTree.MathNode("mrow")
56
63
  node.style.marginLeft = dimension.number + dimension.unit
64
+ return node
57
65
  }
58
- return node;
59
66
  }
60
67
  }
61
68
  });
package/src/functions.js CHANGED
@@ -24,7 +24,6 @@ import "./functions/font";
24
24
  import "./functions/genfrac";
25
25
  import "./functions/hbox";
26
26
  import "./functions/horizBrace";
27
- import "./functions/href";
28
27
  import "./functions/html";
29
28
  import "./functions/includegraphics";
30
29
  import "./functions/kern";
@@ -5,7 +5,7 @@
5
5
  * https://mit-license.org/
6
6
  */
7
7
 
8
- export const version = "0.11.05";
8
+ export const version = "0.11.07";
9
9
 
10
10
  export function postProcess(block) {
11
11
  const labelMap = {}
package/src/stretchy.js CHANGED
@@ -7,10 +7,12 @@ import mathMLTree from "./mathMLTree"
7
7
  // TODO: Remove when Chromium stretches \widetilde & \widehat
8
8
  const estimatedWidth = node => {
9
9
  let width = 0
10
- if (node.body) {
10
+ if (node.body && Array.isArray(node.body)) {
11
11
  for (const item of node.body) {
12
12
  width += estimatedWidth(item)
13
13
  }
14
+ } else if (node.body) {
15
+ width += estimatedWidth(node.body)
14
16
  } else if (node.type === "supsub") {
15
17
  width += estimatedWidth(node.base)
16
18
  if (node.sub) { width += 0.7 * estimatedWidth(node.sub) }
@@ -1,88 +0,0 @@
1
- import defineFunction, { ordargument } from "../defineFunction";
2
- import { assertNodeType } from "../parseNode";
3
- import { MathNode } from "../mathMLTree";
4
- import { AnchorNode } from "../domTree";
5
- import * as mml from "../buildMathML";
6
- import ParseError from "../ParseError";
7
-
8
- defineFunction({
9
- type: "href",
10
- names: ["\\href"],
11
- props: {
12
- numArgs: 2,
13
- argTypes: ["url", "original"],
14
- allowedInText: true
15
- },
16
- handler: ({ parser, token }, args) => {
17
- const body = args[1];
18
- const href = assertNodeType(args[0], "url").url;
19
-
20
- if (
21
- !parser.settings.isTrusted({
22
- command: "\\href",
23
- url: href
24
- })
25
- ) {
26
- throw new ParseError(`Function "\\href" is not trusted`, token)
27
- }
28
-
29
- return {
30
- type: "href",
31
- mode: parser.mode,
32
- href,
33
- body: ordargument(body)
34
- };
35
- },
36
- mathmlBuilder: (group, style) => {
37
- const math = new MathNode("math", [mml.buildExpressionRow(group.body, style)])
38
- const anchorNode = new AnchorNode(group.href, [], [math])
39
- return anchorNode
40
- }
41
- });
42
-
43
- defineFunction({
44
- type: "href",
45
- names: ["\\url"],
46
- props: {
47
- numArgs: 1,
48
- argTypes: ["url"],
49
- allowedInText: true
50
- },
51
- handler: ({ parser, token }, args) => {
52
- const href = assertNodeType(args[0], "url").url;
53
-
54
- if (
55
- !parser.settings.isTrusted({
56
- command: "\\url",
57
- url: href
58
- })
59
- ) {
60
- throw new ParseError(`Function "\\url" is not trusted`, token)
61
- }
62
-
63
- const chars = [];
64
- for (let i = 0; i < href.length; i++) {
65
- let c = href[i];
66
- if (c === "~") {
67
- c = "\\textasciitilde";
68
- }
69
- chars.push({
70
- type: "textord",
71
- mode: "text",
72
- text: c
73
- });
74
- }
75
- const body = {
76
- type: "text",
77
- mode: parser.mode,
78
- font: "\\texttt",
79
- body: chars
80
- };
81
- return {
82
- type: "href",
83
- mode: parser.mode,
84
- href,
85
- body: ordargument(body)
86
- };
87
- }
88
- });