temml 0.10.12 → 0.10.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,6 @@ import { assertNodeType } from "../parseNode"
5
5
  import { calculateSize } from "../units"
6
6
  import * as mml from "../buildMathML"
7
7
 
8
- const sign = num => num >= 0 ? "+" : "-"
9
-
10
8
  // \raise, \lower, and \raisebox
11
9
 
12
10
  const mathmlBuilder = (group, style) => {
@@ -14,11 +12,13 @@ const mathmlBuilder = (group, style) => {
14
12
  const node = new mathMLTree.MathNode("mpadded", [mml.buildGroup(group.body, newStyle)])
15
13
  const dy = calculateSize(group.dy, style)
16
14
  node.setAttribute("voffset", dy.number + dy.unit)
17
- const dyAbs = Math.abs(dy.number)
18
- // The next two lines do not work in Chromium.
19
- // TODO: Find some other way to adjust height and depth.
20
- node.setAttribute("height", sign(dy.number) + dyAbs + dy.unit)
21
- node.setAttribute("depth", sign(-dy.number) + dyAbs + dy.unit)
15
+ // Add padding, which acts to increase height in Chromium.
16
+ // TODO: Figure out some way to change height in Firefox w/o breaking Chromium.
17
+ if (dy.number > 0) {
18
+ node.style.padding = dy.number + dy.unit + " 0 0 0"
19
+ } else {
20
+ node.style.padding = "0 0 " + Math.abs(dy.number) + dy.unit + " 0"
21
+ }
22
22
  return node
23
23
  }
24
24
 
@@ -26,13 +26,16 @@ import { DocumentFragment } from "./tree"
26
26
  * much of this module.
27
27
  */
28
28
 
29
+ const openDelims = "([{⌊⌈⟨⟮⎰⟦⦃"
30
+ const closeDelims = ")]}⌋⌉⟩⟯⎱⟦⦄"
31
+
29
32
  export default function setLineBreaks(expression, wrapMode, isDisplayMode) {
30
33
  const mtrs = [];
31
34
  let mrows = [];
32
35
  let block = [];
33
36
  let numTopLevelEquals = 0
34
- let canBeBIN = false // The first node cannot be an infix binary operator.
35
37
  let i = 0
38
+ let level = 0
36
39
  while (i < expression.length) {
37
40
  while (expression[i] instanceof DocumentFragment) {
38
41
  expression.splice(i, 1, ...expression[i].children) // Expand the fragment.
@@ -55,7 +58,12 @@ export default function setLineBreaks(expression, wrapMode, isDisplayMode) {
55
58
  }
56
59
  block.push(node);
57
60
  if (node.type && node.type === "mo" && node.children.length === 1) {
58
- if (wrapMode === "=" && node.children[0].text === "=") {
61
+ const ch = node.children[0].text
62
+ if (openDelims.indexOf(ch) > -1) {
63
+ level += 1
64
+ } else if (closeDelims.indexOf(ch) > -1) {
65
+ level -= 1
66
+ } else if (level === 0 && wrapMode === "=" && ch === "=") {
59
67
  numTopLevelEquals += 1
60
68
  if (numTopLevelEquals > 1) {
61
69
  block.pop()
@@ -64,59 +72,48 @@ export default function setLineBreaks(expression, wrapMode, isDisplayMode) {
64
72
  mrows.push(element)
65
73
  block = [node];
66
74
  }
67
- } else if (wrapMode === "tex") {
68
- // This may be a place for a soft line break.
69
- if (canBeBIN && !node.attributes.form) {
70
- // Check if the following node is a \nobreak text node, e.g. "~""
71
- const next = i < expression.length - 1 ? expression[i + 1] : null;
72
- let glueIsFreeOfNobreak = true;
73
- if (
74
- !(
75
- next &&
76
- next.type === "mtext" &&
77
- next.attributes.linebreak &&
78
- next.attributes.linebreak === "nobreak"
79
- )
80
- ) {
81
- // We may need to start a new block.
82
- // First, put any post-operator glue on same line as operator.
83
- for (let j = i + 1; j < expression.length; j++) {
84
- const nd = expression[j];
75
+ } else if (level === 0 && wrapMode === "tex") {
76
+ // Check if the following node is a \nobreak text node, e.g. "~""
77
+ const next = i < expression.length - 1 ? expression[i + 1] : null;
78
+ let glueIsFreeOfNobreak = true;
79
+ if (
80
+ !(
81
+ next &&
82
+ next.type === "mtext" &&
83
+ next.attributes.linebreak &&
84
+ next.attributes.linebreak === "nobreak"
85
+ )
86
+ ) {
87
+ // We may need to start a new block.
88
+ // First, put any post-operator glue on same line as operator.
89
+ for (let j = i + 1; j < expression.length; j++) {
90
+ const nd = expression[j];
91
+ if (
92
+ nd.type &&
93
+ nd.type === "mspace" &&
94
+ !(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
95
+ ) {
96
+ block.push(nd);
97
+ i += 1;
85
98
  if (
86
- nd.type &&
87
- nd.type === "mspace" &&
88
- !(nd.attributes.linebreak && nd.attributes.linebreak === "newline")
99
+ nd.attributes &&
100
+ nd.attributes.linebreak &&
101
+ nd.attributes.linebreak === "nobreak"
89
102
  ) {
90
- block.push(nd);
91
- i += 1;
92
- if (
93
- nd.attributes &&
94
- nd.attributes.linebreak &&
95
- nd.attributes.linebreak === "nobreak"
96
- ) {
97
- glueIsFreeOfNobreak = false;
98
- }
99
- } else {
100
- break;
103
+ glueIsFreeOfNobreak = false;
101
104
  }
105
+ } else {
106
+ break;
102
107
  }
103
108
  }
104
- if (glueIsFreeOfNobreak) {
105
- // Start a new block. (Insert a soft linebreak.)
106
- const element = new mathMLTree.MathNode("mrow", block)
107
- mrows.push(element)
108
- block = [];
109
- }
110
- canBeBIN = false
111
109
  }
112
- const isOpenDelimiter = node.attributes.form && node.attributes.form === "prefix"
113
- // Any operator that follows an open delimiter is unary.
114
- canBeBIN = !(node.attributes.separator || isOpenDelimiter);
115
- } else {
116
- canBeBIN = true
110
+ if (glueIsFreeOfNobreak) {
111
+ // Start a new block. (Insert a soft linebreak.)
112
+ const element = new mathMLTree.MathNode("mrow", block)
113
+ mrows.push(element)
114
+ block = [];
115
+ }
117
116
  }
118
- } else {
119
- canBeBIN = true
120
117
  }
121
118
  i += 1
122
119
  }
package/src/macros.js CHANGED
@@ -238,9 +238,6 @@ defineMacro("\u22ee", "\\vdots");
238
238
  //\newcommand{\substack}[1]{\subarray{c}#1\endsubarray}
239
239
  defineMacro("\\substack", "\\begin{subarray}{c}#1\\end{subarray}");
240
240
 
241
- // \newcommand{\boxed}[1]{\fbox{\m@th$\displaystyle#1$}}
242
- defineMacro("\\boxed", "\\fbox{$\\displaystyle{#1}$}");
243
-
244
241
  // \def\iff{\DOTSB\;\Longleftrightarrow\;}
245
242
  // \def\implies{\DOTSB\;\Longrightarrow\;}
246
243
  // \def\impliedby{\DOTSB\;\Longleftarrow\;}
@@ -489,7 +486,7 @@ defineMacro(
489
486
  defineMacro(
490
487
  "\\Temml",
491
488
  // eslint-disable-next-line max-len
492
- "\\textrm{T}\\kern-0.2em\\lower{0.2em}\\textrm{E}\\kern-0.08em{\\textrm{M}\\kern-0.08em\\raise{0.2em}\\textrm{M}\\kern-0.08em\\textrm{L}}"
489
+ "\\textrm{T}\\kern-0.2em\\lower{0.2em}{\\textrm{E}}\\kern-0.08em{\\textrm{M}\\kern-0.08em\\raise{0.2em}\\textrm{M}\\kern-0.08em\\textrm{L}}"
493
490
  );
494
491
 
495
492
  // \DeclareRobustCommand\hspace{\@ifstar\@hspacer\@hspace}
@@ -8,7 +8,7 @@
8
8
  * https://mit-license.org/
9
9
  */
10
10
 
11
- export const version = "0.10.12";
11
+ export const version = "0.10.14";
12
12
 
13
13
  export function postProcess(block) {
14
14
  const labelMap = {}
package/src/symbols.js CHANGED
@@ -209,6 +209,7 @@ defineSymbol(math, rel, "\u21c1", "\\rightharpoondown", true);
209
209
  defineSymbol(math, rel, "\u2196", "\\nwarrow", true);
210
210
  defineSymbol(math, rel, "\u21cc", "\\rightleftharpoons", true);
211
211
  defineSymbol(math, mathord, "\u21af", "\\lightning", true);
212
+ defineSymbol(math, mathord, "\u220E", "\\QED", true);
212
213
  defineSymbol(math, mathord, "\u2030", "\\permil", true);
213
214
  defineSymbol(text, textord, "\u2030", "\\permil");
214
215
 
@@ -355,6 +356,7 @@ defineSymbol(math, rel, "\u2ab7", "\\precapprox", true);
355
356
  defineSymbol(math, rel, "\u22b2", "\\vartriangleleft");
356
357
  defineSymbol(math, rel, "\u22b4", "\\trianglelefteq");
357
358
  defineSymbol(math, rel, "\u22a8", "\\vDash", true);
359
+ defineSymbol(math, rel, "\u22ab", "\\VDash", true);
358
360
  defineSymbol(math, rel, "\u22aa", "\\Vvdash", true);
359
361
  defineSymbol(math, rel, "\u2323", "\\smallsmile");
360
362
  defineSymbol(math, rel, "\u2322", "\\smallfrown");