temml 0.10.14 → 0.10.15

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.
@@ -73,149 +73,3 @@ math > mrow {
73
73
  body {
74
74
  counter-reset: tmlEqnNo;
75
75
  }
76
-
77
- /* Environment arrays */
78
-
79
- /* Environments that addjot to row spacing */
80
- mtable.tml-jot > mtr > mtd {
81
- padding-top: calc(0.5ex + 0.09em);
82
- padding-bottom: calc(0.5ex + 0.09em);
83
- }
84
-
85
- /* Zero column gap for {alignat}, {split}, etc */
86
- mtable.tml-abut > mtr > mtd,
87
- mtable.tml-align > mtr > mtd:nth-child(odd),
88
- mtable.tml-align-star > mtr > mtd:nth-child(even) {
89
- padding-left: 0em;
90
- padding-right: 0em;
91
- }
92
-
93
- mtable.tml-align > mtr > mtd:nth-child(even),
94
- mtable.tml-align-star > mtr > mtd:nth-child(odd) {
95
- padding-left: 1em;
96
- padding-right: 0em;
97
- }
98
-
99
- mtable.tml-align > mtr > mtd:nth-child(1) {
100
- padding-left: 0em;
101
- }
102
-
103
- mtable.tml-align > mtr > mtd:nth-child(odd),
104
- mtable.tml-alignat > mtr > mtd:nth-child(odd),
105
- mtable.tml-aligned > mtr > mtd:nth-child(even) {
106
- text-align: -webkit-left;
107
- text-align: -moz-left;
108
- }
109
-
110
- mtable.tml-align > mtr > mtd:nth-child(even),
111
- mtable.tml-alignat > mtr > mtd:nth-child(even),
112
- mtable.tml-aligned > mtr > mtd:nth-child(odd) {
113
- text-align: -webkit-right;
114
- text-align: -moz-right;
115
- }
116
-
117
- mtable.tml-cases > mtr > mtd {
118
- padding-left: 0em;
119
- padding-right: 0em;
120
- text-align: -webkit-left;
121
- text-align: -moz-left;
122
- }
123
-
124
- mtable.tml-cases > mtr > mtd:nth-child(2) {
125
- padding-left: 1em;
126
- }
127
-
128
- mtable.tml-small > mtr > mtd {
129
- padding-top: 0.35ex;
130
- padding-bottom: 0.35ex;
131
- padding-left: 0.1389em;
132
- padding-right: 0.1389em;
133
- }
134
-
135
- mtable.tml-subarray > mtr > mtd {
136
- padding-top: 0em;
137
- padding-left: 0em;
138
- }
139
-
140
- mtable.tml-cd > mtr > mtd {
141
- padding-left: 0.25em;
142
- padding-right: 0.25em;
143
- }
144
-
145
- mtable > mtr:first-child > mtr > mtd {
146
- padding-top: 0em;
147
- }
148
-
149
- mtable > mtr:last-child > mtr > mtd {
150
- padding-bottom: 0em;
151
- }
152
-
153
- mtable:not(.tml-array) > mtr > mtd:first-child {
154
- padding-left: 0em;
155
- }
156
-
157
- mtable:not(.tml-array) > mtr > mtd:last-child {
158
- padding-right: 0em;
159
- }
160
-
161
- mtr.tml-top-solid > mtd {
162
- border-top: 0.06em solid;
163
- }
164
-
165
- mtr.tml-top-double > mtd {
166
- border-top: 0.15em double;
167
- }
168
-
169
- mtr.tml-top-dashed > mtd {
170
- border-top: 0.06em dashed;
171
- }
172
-
173
- mtr.tml-hline-solid > mtd {
174
- border-bottom: 0.06em solid;
175
- }
176
-
177
- mtr.tml-hline-double > mtd {
178
- border-bottom: 0.15em double;
179
- }
180
-
181
- mtr.tml-hline-dashed > mtd {
182
- border-bottom: 0.06em dashed;
183
- }
184
-
185
- /* MathML-Core does not support <menclose> attributes.
186
- * So Use background images for \cancel */
187
- mrow.cancel {
188
- background:
189
- linear-gradient(to top left,
190
- rgba(0,0,0,0) 0%,
191
- rgba(0,0,0,0) calc(50% - 0.06em),
192
- rgba(0,0,0,1) 50%,
193
- rgba(0,0,0,0) calc(50% + 0.06em),
194
- rgba(0,0,0,0) 100%);
195
- }
196
-
197
- mrow.bcancel {
198
- background:
199
- linear-gradient(to top right,
200
- rgba(0,0,0,0) 0%,
201
- rgba(0,0,0,0) calc(50% - 0.06em),
202
- rgba(0,0,0,1) 50%,
203
- rgba(0,0,0,0) calc(50% + 0.06em),
204
- rgba(0,0,0,0) 100%);
205
- }
206
-
207
- mrow.xcancel {
208
- background:
209
- linear-gradient(to top left,
210
- rgba(0,0,0,0) 0%,
211
- rgba(0,0,0,0) calc(50% - 0.06em),
212
- rgba(0,0,0,1) 50%,
213
- rgba(0,0,0,0) calc(50% + 0.06em),
214
- rgba(0,0,0,0) 100%),
215
- linear-gradient(to top right,
216
- rgba(0,0,0,0) 0%,
217
- rgba(0,0,0,0) calc(50% - 0.06em),
218
- rgba(0,0,0,1) 50%,
219
- rgba(0,0,0,0) calc(50% + 0.06em),
220
- rgba(0,0,0,0) 100%);
221
- }
package/dist/temml.cjs CHANGED
@@ -973,6 +973,10 @@ defineSymbol(math, mathord, "\u21af", "\\lightning", true);
973
973
  defineSymbol(math, mathord, "\u220E", "\\QED", true);
974
974
  defineSymbol(math, mathord, "\u2030", "\\permil", true);
975
975
  defineSymbol(text, textord, "\u2030", "\\permil");
976
+ defineSymbol(math, mathord, "\u2609", "\\astrosun", true);
977
+ defineSymbol(math, mathord, "\u263c", "\\sun", true);
978
+ defineSymbol(math, mathord, "\u263e", "\\leftmoon", true);
979
+ defineSymbol(math, mathord, "\u263d", "\\rightmoon", true);
976
980
 
977
981
  // AMS Negated Binary Relations
978
982
  defineSymbol(math, rel, "\u226e", "\\nless", true);
@@ -2131,9 +2135,7 @@ function buildMathML(tree, texExpression, style, settings) {
2131
2135
  }
2132
2136
  if (settings.displayMode) {
2133
2137
  math.setAttribute("display", "block");
2134
- math.style.display = math.children.length === 1 && math.children[0].type === "mtable"
2135
- ? "inline"
2136
- : "block math"; // necessary in Chromium.
2138
+ math.style.display = "block math"; // necessary in Chromium.
2137
2139
  // Firefox and Safari do not recognize display: "block math".
2138
2140
  // Set a class so that the CSS file can set display: block.
2139
2141
  math.classes = ["tml-display"];
@@ -3824,10 +3826,20 @@ const mathmlBuilder$8 = (group, style) => {
3824
3826
  node.style.borderBottom = "0.065em solid";
3825
3827
  break
3826
3828
  case "\\cancel":
3827
- node.classes.push("cancel");
3829
+ node.style.background = `linear-gradient(to top left,
3830
+ rgba(0,0,0,0) 0%,
3831
+ rgba(0,0,0,0) calc(50% - 0.06em),
3832
+ rgba(0,0,0,1) 50%,
3833
+ rgba(0,0,0,0) calc(50% + 0.06em),
3834
+ rgba(0,0,0,0) 100%);`;
3828
3835
  break
3829
3836
  case "\\bcancel":
3830
- node.classes.push("bcancel");
3837
+ node.style.background = `linear-gradient(to top right,
3838
+ rgba(0,0,0,0) 0%,
3839
+ rgba(0,0,0,0) calc(50% - 0.06em),
3840
+ rgba(0,0,0,1) 50%,
3841
+ rgba(0,0,0,0) calc(50% + 0.06em),
3842
+ rgba(0,0,0,0) 100%);`;
3831
3843
  break
3832
3844
  /*
3833
3845
  case "\\longdiv":
@@ -3871,7 +3883,18 @@ const mathmlBuilder$8 = (group, style) => {
3871
3883
  break
3872
3884
  }
3873
3885
  case "\\xcancel":
3874
- node.classes.push("xcancel");
3886
+ node.style.background = `linear-gradient(to top left,
3887
+ rgba(0,0,0,0) 0%,
3888
+ rgba(0,0,0,0) calc(50% - 0.06em),
3889
+ rgba(0,0,0,1) 50%,
3890
+ rgba(0,0,0,0) calc(50% + 0.06em),
3891
+ rgba(0,0,0,0) 100%),
3892
+ linear-gradient(to top right,
3893
+ rgba(0,0,0,0) 0%,
3894
+ rgba(0,0,0,0) calc(50% - 0.06em),
3895
+ rgba(0,0,0,1) 50%,
3896
+ rgba(0,0,0,0) calc(50% + 0.06em),
3897
+ rgba(0,0,0,0) 100%);`;
3875
3898
  break
3876
3899
  }
3877
3900
  if (group.backgroundColor) {
@@ -4302,24 +4325,94 @@ const mathmlBuilder$7 = function(group, style) {
4302
4325
  // Write horizontal rules
4303
4326
  if (i === 0 && hlines[0].length > 0) {
4304
4327
  if (hlines[0].length === 2) {
4305
- mtr.classes.push("tml-top-double");
4328
+ mtr.children.forEach(cell => { cell.style.borderTop = "0.15em double"; });
4306
4329
  } else {
4307
- mtr.classes.push(hlines[0][0] ? "tml-top-dashed" : "tml-top-solid");
4330
+ mtr.children.forEach(cell => {
4331
+ cell.style.borderTop = hlines[0][0] ? "0.06em dashed" : "0.06em solid";
4332
+ });
4308
4333
  }
4309
4334
  }
4310
4335
  if (hlines[i + 1].length > 0) {
4311
4336
  if (hlines[i + 1].length === 2) {
4312
- mtr.classes.push("tml-hline-double");
4337
+ mtr.children.forEach(cell => { cell.style.borderBottom = "0.15em double"; });
4313
4338
  } else {
4314
- mtr.classes.push(hlines[i + 1][0] ? "tml-hline-dashed" : "tml-hline-solid");
4339
+ mtr.children.forEach(cell => {
4340
+ cell.style.borderBottom = hlines[i + 1][0] ? "0.06em dashed" : "0.06em solid";
4341
+ });
4315
4342
  }
4316
4343
  }
4317
4344
  tbl.push(mtr);
4318
4345
  }
4319
- let table = new mathMLTree.MathNode("mtable", tbl);
4346
+
4320
4347
  if (group.envClasses.length > 0) {
4321
- table.classes = group.envClasses.map(e => "tml-" + e);
4348
+ const pad = group.envClasses.includes("jot")
4349
+ ? "0.7" // 0.5ex + 0.09em top & bot padding
4350
+ : group.envClasses.includes("small")
4351
+ ? "0.35"
4352
+ : "0.5"; // 0.5ex default top & bot padding
4353
+ const sidePadding = group.envClasses.includes("abut")
4354
+ ? "0"
4355
+ : group.envClasses.includes("cases")
4356
+ ? "0"
4357
+ : group.envClasses.includes("small")
4358
+ ? "0.1389"
4359
+ : group.envClasses.includes("cd")
4360
+ ? "0.25"
4361
+ : "0.4"; // default side padding
4362
+
4363
+ const numCols = tbl.length === 0 ? 0 : tbl[0].children.length;
4364
+
4365
+ const sidePad = (j, hand) => {
4366
+ if (j === 0 && hand === 0) { return "0" }
4367
+ if (j === numCols - 1 && hand === 1) { return "0" }
4368
+ if (group.envClasses[0] !== "align") { return sidePadding }
4369
+ if (hand === 1) { return "0" }
4370
+ if (group.addEqnNum) {
4371
+ return (j % 2) ? "1" : "0"
4372
+ } else {
4373
+ return (j % 2) ? "0" : "1"
4374
+ }
4375
+ };
4376
+
4377
+ // Padding
4378
+ for (let i = 0; i < tbl.length; i++) {
4379
+ for (let j = 0; j < tbl[i].children.length; j++) {
4380
+ tbl[i].children[j].style.padding = `${pad}ex ${sidePad(j, 1)}em ${pad}ex ${sidePad(j, 0)}em`;
4381
+ }
4382
+ }
4383
+
4384
+ // Justification
4385
+ const align = group.envClasses.includes("align") || group.envClasses.includes("alignat");
4386
+ for (let i = 0; i < tbl.length; i++) {
4387
+ const row = tbl[i];
4388
+ if (align) {
4389
+ for (let j = 0; j < row.children.length; j++) {
4390
+ // Chromium does not recognize text-align: left. Use -webkit-
4391
+ // TODO: Remove -webkit- when Chromium no longer needs it.
4392
+ row.children[j].style.textAlign = "-webkit-" + (j % 2 ? "left" : "right");
4393
+ }
4394
+ }
4395
+ if (row.children.length > 1 && group.envClasses.includes("cases")) {
4396
+ row.children[1].style.padding = row.children[1].style.padding.replace(/0em$/, "1em");
4397
+ }
4398
+
4399
+ if (group.envClasses.includes("cases") || group.envClasses.includes("subarray")) {
4400
+ for (const cell of row.children) {
4401
+ cell.style.textAlign = "-webkit-" + "left";
4402
+ }
4403
+ }
4404
+ }
4405
+ } else {
4406
+ // Set zero padding on side of the matrix
4407
+ for (let i = 0; i < tbl.length; i++) {
4408
+ tbl[i].children[0].style.paddingLeft = "0em";
4409
+ if (tbl[i].children.length === tbl[0].children.length) {
4410
+ tbl[i].children[tbl[i].children.length - 1].style.paddingRight = "0em";
4411
+ }
4412
+ }
4322
4413
  }
4414
+
4415
+ let table = new mathMLTree.MathNode("mtable", tbl);
4323
4416
  if (group.scriptLevel === "display") { table.setAttribute("displaystyle", "true"); }
4324
4417
 
4325
4418
  if (group.addEqnNum || group.envClasses.includes("multline")) {
@@ -4399,6 +4492,8 @@ const mathmlBuilder$7 = function(group, style) {
4399
4492
  align = "left " + (align.length > 0 ? align : "center ") + "right ";
4400
4493
  }
4401
4494
  if (align) {
4495
+ // Firefox reads this attribute, not the -webkit-left|right written above.
4496
+ // TODO: When Chrome no longer needs "-webkit-", use CSS and delete the next line.
4402
4497
  table.setAttribute("columnalign", align.trim());
4403
4498
  }
4404
4499
 
@@ -4423,7 +4518,7 @@ const alignedHandler = function(context, args) {
4423
4518
  cols,
4424
4519
  addEqnNum: context.envName === "align" || context.envName === "alignat",
4425
4520
  emptySingleRow: true,
4426
- envClasses: ["jot", "abut"], // set row spacing & provisional column spacing
4521
+ envClasses: ["abut", "jot"], // set row spacing & provisional column spacing
4427
4522
  maxNumCols: context.envName === "split" ? 2 : undefined,
4428
4523
  leqno: context.parser.settings.leqno
4429
4524
  },
@@ -4441,18 +4536,22 @@ const alignedHandler = function(context, args) {
4441
4536
  // binary. This behavior is implemented in amsmath's \start@aligned.
4442
4537
  let numMaths;
4443
4538
  let numCols = 0;
4444
- if (args[0] && args[0].type === "ordgroup") {
4539
+ const isAlignedAt = context.envName.indexOf("at") > -1;
4540
+ if (args[0] && isAlignedAt) {
4541
+ // alignat environment takes an argument w/ number of columns
4445
4542
  let arg0 = "";
4446
4543
  for (let i = 0; i < args[0].body.length; i++) {
4447
4544
  const textord = assertNodeType(args[0].body[i], "textord");
4448
4545
  arg0 += textord.text;
4449
4546
  }
4547
+ if (isNaN(arg0)) {
4548
+ throw new ParseError("The alignat enviroment requires a numeric first argument.")
4549
+ }
4450
4550
  numMaths = Number(arg0);
4451
4551
  numCols = numMaths * 2;
4452
4552
  }
4453
- const isAligned = !numCols;
4454
4553
  res.body.forEach(function(row) {
4455
- if (!isAligned) {
4554
+ if (isAlignedAt) {
4456
4555
  // Case 1
4457
4556
  const curMaths = row.length / 2;
4458
4557
  if (numMaths < curMaths) {
@@ -4480,14 +4579,10 @@ const alignedHandler = function(context, args) {
4480
4579
  align: align
4481
4580
  };
4482
4581
  }
4483
- if (context.envName === "split") ; else if (context.envName.indexOf("ed") > -1) {
4484
- res.envClasses.push("aligned"); // Sets justification
4485
- } else if (isAligned) {
4486
- res.envClasses[1] = context.envName === "align*"
4487
- ? "align-star"
4488
- : "align"; // Sets column spacing & justification
4582
+ if (context.envName === "split") ; else if (isAlignedAt) {
4583
+ res.envClasses.push("alignat"); // Sets justification
4489
4584
  } else {
4490
- res.envClasses.push("aligned"); // Sets justification
4585
+ res.envClasses[0] = "align"; // Sets column spacing & justification
4491
4586
  }
4492
4587
  return res;
4493
4588
  };
@@ -4737,7 +4832,7 @@ defineEnvironment({
4737
4832
  }
4738
4833
  const res = {
4739
4834
  cols: [],
4740
- envClasses: ["jot", "abut"],
4835
+ envClasses: ["abut", "jot"],
4741
4836
  addEqnNum: context.envName === "gather",
4742
4837
  emptySingleRow: true,
4743
4838
  leqno: context.parser.settings.leqno
@@ -12901,7 +12996,7 @@ class Style {
12901
12996
  * https://mit-license.org/
12902
12997
  */
12903
12998
 
12904
- const version = "0.10.14";
12999
+ const version = "0.10.15";
12905
13000
 
12906
13001
  function postProcess(block) {
12907
13002
  const labelMap = {};
@@ -12952,6 +13047,7 @@ function postProcess(block) {
12952
13047
  /* eslint no-console:0 */
12953
13048
 
12954
13049
  /**
13050
+ * @type {import('./temml').render}
12955
13051
  * Parse and build an expression, and place that expression in the DOM node
12956
13052
  * given.
12957
13053
  */
@@ -12989,6 +13085,7 @@ if (typeof document !== "undefined") {
12989
13085
  }
12990
13086
 
12991
13087
  /**
13088
+ * @type {import('./temml').renderToString}
12992
13089
  * Parse and build an expression, and return the markup for that.
12993
13090
  */
12994
13091
  const renderToString = function(expression, options) {
@@ -12997,6 +13094,7 @@ const renderToString = function(expression, options) {
12997
13094
  };
12998
13095
 
12999
13096
  /**
13097
+ * @type {import('./temml').generateParseTree}
13000
13098
  * Parse an expression and return the parse tree.
13001
13099
  */
13002
13100
  const generateParseTree = function(expression, options) {
@@ -13005,6 +13103,7 @@ const generateParseTree = function(expression, options) {
13005
13103
  };
13006
13104
 
13007
13105
  /**
13106
+ * @type {import('./temml').definePreamble}
13008
13107
  * Take an expression which contains a preamble.
13009
13108
  * Parse it and return the macros.
13010
13109
  */
@@ -13037,6 +13136,7 @@ const renderError = function(error, expression, options) {
13037
13136
  };
13038
13137
 
13039
13138
  /**
13139
+ * @type {import('./temml').renderToMathMLTree}
13040
13140
  * Generates and returns the Temml build tree. This is used for advanced
13041
13141
  * use cases (like rendering to custom output).
13042
13142
  */
@@ -13054,6 +13154,7 @@ const renderToMathMLTree = function(expression, options) {
13054
13154
  }
13055
13155
  };
13056
13156
 
13157
+ /** @type {import('./temml').default} */
13057
13158
  var temml = {
13058
13159
  /**
13059
13160
  * Current Temml version
@@ -0,0 +1,60 @@
1
+ export interface Options {
2
+ displayMode?: boolean;
3
+ annotate?: boolean;
4
+ leqno?: boolean;
5
+ throwOnError?: boolean;
6
+ errorColor?: string;
7
+ macros?: Record<string, string>;
8
+ wrap?: "tex" | "=" | "none";
9
+ xml?: boolean;
10
+ colorIsTextColor?: boolean;
11
+ strict?: boolean;
12
+ trust?: boolean | ((context: any) => boolean);
13
+ maxSize?: [number, number];
14
+ maxExpand?: number;
15
+ }
16
+
17
+ export function render(
18
+ expression: string,
19
+ baseNode: HTMLElement,
20
+ options?: Options,
21
+ ): void;
22
+
23
+ export function renderToString(expression: string, options?: Options): string;
24
+
25
+ export function generateParseTree(expression: string, options?: Options): any;
26
+
27
+ export function definePreamble(expression: string, options?: Options): any;
28
+
29
+ export function renderToMathMLTree(expression: string, options?: Options): any;
30
+
31
+ declare function postProcess(block: any): void;
32
+ declare function defineMacro(name: string, body: any): void;
33
+ declare function defineSymbol(
34
+ mode: string,
35
+ group: string,
36
+ replace: string,
37
+ name: string,
38
+ acceptUnicodeChar: boolean,
39
+ ): void;
40
+ declare class ParseError {
41
+ constructor(
42
+ message: string, // The error message
43
+ token: any, // An object providing position information
44
+ ) {}
45
+ }
46
+
47
+ declare const Temml: {
48
+ version: string;
49
+ render: typeof render;
50
+ renderToString: typeof renderToString;
51
+ postProcess: typeof postProcess;
52
+ ParseError: typeof ParseError;
53
+ definePreamble: typeof definePreamble;
54
+ __parse: typeof generateParseTree;
55
+ __renderToMathMLTree: typeof renderToMathMLTree;
56
+ __defineSymbol: typeof defineSymbol;
57
+ __defineMacro: typeof defineMacro;
58
+ };
59
+
60
+ export default Temml;