@pie-lib/math-rendering-accessible 3.9.0 → 3.10.0
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/CHANGELOG.md +4 -16
- package/lib/index.js +38 -0
- package/lib/index.js.map +1 -0
- package/lib/mathjax-script.js +2 -0
- package/lib/mathjax-script.js.map +1 -0
- package/lib/mml-to-latex.js +15 -0
- package/lib/mml-to-latex.js.map +1 -0
- package/lib/mstack/chtml.js +296 -0
- package/lib/mstack/chtml.js.map +1 -0
- package/lib/mstack/index.js +23 -0
- package/lib/mstack/index.js.map +1 -0
- package/lib/mstack/mml.js +109 -0
- package/lib/mstack/mml.js.map +1 -0
- package/lib/normalization.js +95 -0
- package/lib/normalization.js.map +1 -0
- package/lib/render-math.js +475 -0
- package/lib/render-math.js.map +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
# 3.
|
|
6
|
+
# 3.10.0 (2025-07-31)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @pie-lib/math-rendering-accessible
|
|
9
9
|
|
|
@@ -11,38 +11,26 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
# 3.
|
|
14
|
+
# 3.9.0 (2025-07-31)
|
|
15
15
|
|
|
16
16
|
**Note:** Version bump only for package @pie-lib/math-rendering-accessible
|
|
17
17
|
|
|
18
|
+
# 3.8.0 (2025-07-31)
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
**Note:** Version bump only for package @pie-lib/math-rendering-accessible
|
|
21
21
|
|
|
22
22
|
# 3.7.0 (2025-07-31)
|
|
23
23
|
|
|
24
24
|
**Note:** Version bump only for package @pie-lib/math-rendering-accessible
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
26
|
# 3.6.0 (2025-07-31)
|
|
31
27
|
|
|
32
28
|
**Note:** Version bump only for package @pie-lib/math-rendering-accessible
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
30
|
# 3.5.0 (2025-07-31)
|
|
39
31
|
|
|
40
32
|
**Note:** Version bump only for package @pie-lib/math-rendering-accessible
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
34
|
# 3.7.0 (2025-07-31)
|
|
47
35
|
|
|
48
36
|
**Note:** Version bump only for package @pie-lib/math-rendering-accessible
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports, "mmlToLatex", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _mmlToLatex["default"];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(exports, "renderMath", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function get() {
|
|
17
|
+
return _renderMath["default"];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "unWrapMath", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function get() {
|
|
23
|
+
return _normalization.unWrapMath;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
Object.defineProperty(exports, "wrapMath", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function get() {
|
|
29
|
+
return _normalization.wrapMath;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
var _renderMath = _interopRequireDefault(require("./render-math"));
|
|
34
|
+
|
|
35
|
+
var _mmlToLatex = _interopRequireDefault(require("./mml-to-latex"));
|
|
36
|
+
|
|
37
|
+
var _normalization = require("./normalization");
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["import renderMath from './render-math';\nimport mmlToLatex from './mml-to-latex';\nimport { wrapMath, unWrapMath } from './normalization';\n\nexport { renderMath, wrapMath, unWrapMath, mmlToLatex };\n"],"file":"index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"mathjax-script.js"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _mathmlToLatex = require("@pie-framework/mathml-to-latex");
|
|
9
|
+
|
|
10
|
+
var _default = function _default(mathml) {
|
|
11
|
+
return _mathmlToLatex.MathMLToLaTeX.convert(mathml);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
exports["default"] = _default;
|
|
15
|
+
//# sourceMappingURL=mml-to-latex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mml-to-latex.js"],"names":["mathml","MathMLToLaTeX","convert"],"mappings":";;;;;;;AAAA;;eACe,kBAACA,MAAD;AAAA,SAAYC,6BAAcC,OAAd,CAAsBF,MAAtB,CAAZ;AAAA,C","sourcesContent":["import { MathMLToLaTeX } from '@pie-framework/mathml-to-latex';\nexport default (mathml) => MathMLToLaTeX.convert(mathml);\n"],"file":"mml-to-latex.js"}
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getStackData = exports.Row = exports.Line = exports.CHTMLmstack = void 0;
|
|
9
|
+
|
|
10
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
11
|
+
|
|
12
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
+
|
|
14
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
15
|
+
|
|
16
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
17
|
+
|
|
18
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
19
|
+
|
|
20
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
21
|
+
|
|
22
|
+
var _Wrapper = require("mathjax-full/js/output/chtml/Wrapper");
|
|
23
|
+
|
|
24
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
25
|
+
|
|
26
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
27
|
+
|
|
28
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
29
|
+
|
|
30
|
+
var reduceText = function reduceText(acc, n) {
|
|
31
|
+
if (n.node && n.node.kind === 'text') {
|
|
32
|
+
acc += n.node.text;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return acc;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
var Line = /*#__PURE__*/function () {
|
|
39
|
+
function Line() {
|
|
40
|
+
(0, _classCallCheck2["default"])(this, Line);
|
|
41
|
+
this.kind = 'line';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
(0, _createClass2["default"])(Line, [{
|
|
45
|
+
key: "columns",
|
|
46
|
+
get: function get() {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
}]);
|
|
50
|
+
return Line;
|
|
51
|
+
}();
|
|
52
|
+
|
|
53
|
+
exports.Line = Line;
|
|
54
|
+
|
|
55
|
+
var Row = /*#__PURE__*/function () {
|
|
56
|
+
function Row(columns, operator) {
|
|
57
|
+
(0, _classCallCheck2["default"])(this, Row);
|
|
58
|
+
this.kind = 'row';
|
|
59
|
+
this.operator = operator;
|
|
60
|
+
this.columns = columns;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
(0, _createClass2["default"])(Row, [{
|
|
64
|
+
key: "pad",
|
|
65
|
+
value: function pad(count) {
|
|
66
|
+
var direction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'right';
|
|
67
|
+
|
|
68
|
+
if (count < this.columns.length) {
|
|
69
|
+
throw new Error('no');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
var diff = count - this.columns.length;
|
|
73
|
+
|
|
74
|
+
var padding = _lodash["default"].times(diff).map(function () {
|
|
75
|
+
return '__pad__';
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return direction === 'right' ? [].concat((0, _toConsumableArray2["default"])(padding), (0, _toConsumableArray2["default"])(this.columns)) : [].concat((0, _toConsumableArray2["default"])(this.columns), (0, _toConsumableArray2["default"])(padding));
|
|
79
|
+
}
|
|
80
|
+
}]);
|
|
81
|
+
return Row;
|
|
82
|
+
}();
|
|
83
|
+
|
|
84
|
+
exports.Row = Row;
|
|
85
|
+
|
|
86
|
+
var mathNodeToCharArray = function mathNodeToCharArray(mn) {
|
|
87
|
+
var text = mn.childNodes.reduce(reduceText, '');
|
|
88
|
+
return text.split('');
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Convert child a column entry
|
|
92
|
+
* @param {*} child
|
|
93
|
+
* @return an array of column content
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
var toColumnArray = function toColumnArray(child) {
|
|
98
|
+
if (!child || !child.kind) {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (child.kind === 'msrow') {
|
|
103
|
+
throw new Error('msrow in msrow?');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (child.kind === 'mo') {
|
|
107
|
+
// We are going to treat this operator as a text array.
|
|
108
|
+
// It's probably going to be a decimal point
|
|
109
|
+
// eslint-disable-next-line no-console
|
|
110
|
+
console.warn('mo that is not 1st node in msrow?');
|
|
111
|
+
return mathNodeToCharArray(child); // throw new Error('mo must be first child of msrow');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (child.kind === 'mn') {
|
|
115
|
+
return mathNodeToCharArray(child);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (child.toCHTML) {
|
|
119
|
+
return child;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* convert mstack chtml childNodes into a Row
|
|
124
|
+
* @param child chtml child node of mstack
|
|
125
|
+
* @return Row | Line
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
var rowStack = function rowStack(child) {
|
|
130
|
+
if (!child || !child.kind) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (child.kind === 'msrow') {
|
|
135
|
+
if (!child.childNodes || child.childNodes.length === 0) {
|
|
136
|
+
return new Row([]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var f = _lodash["default"].first(child.childNodes);
|
|
140
|
+
|
|
141
|
+
var nodes = f && f.kind === 'mo' ? _lodash["default"].tail(child.childNodes) : child.childNodes;
|
|
142
|
+
|
|
143
|
+
var columns = _lodash["default"].flatten(nodes.map(toColumnArray));
|
|
144
|
+
|
|
145
|
+
return new Row(columns, f.kind === 'mo' ? f : undefined);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (child.kind === 'mn') {
|
|
149
|
+
var _columns = mathNodeToCharArray(child);
|
|
150
|
+
|
|
151
|
+
return new Row(_columns, undefined);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (child.kind === 'mo') {
|
|
155
|
+
// eslint-disable-next-line no-console
|
|
156
|
+
console.warn('mo on its own row?');
|
|
157
|
+
return new Row([], child);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (child.kind === 'msline') {
|
|
161
|
+
return new Line();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (child.toCHTML) {
|
|
165
|
+
return new Row([child]);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
/** convert MathJax chtml tree to Row[]
|
|
169
|
+
* @param mstack the root of the mathjax chtml tree
|
|
170
|
+
* @return Row[]
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
var getStackData = function getStackData(mstack) {
|
|
175
|
+
if (!mstack || !mstack.childNodes) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return _lodash["default"].compact(mstack.childNodes.map(rowStack));
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
exports.getStackData = getStackData;
|
|
183
|
+
|
|
184
|
+
var CHTMLmstack = /*#__PURE__*/function (_CHTMLWrapper) {
|
|
185
|
+
(0, _inherits2["default"])(CHTMLmstack, _CHTMLWrapper);
|
|
186
|
+
|
|
187
|
+
var _super = _createSuper(CHTMLmstack);
|
|
188
|
+
|
|
189
|
+
function CHTMLmstack(factory, node) {
|
|
190
|
+
var _this;
|
|
191
|
+
|
|
192
|
+
var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
193
|
+
(0, _classCallCheck2["default"])(this, CHTMLmstack);
|
|
194
|
+
_this = _super.call(this, factory, node, parent);
|
|
195
|
+
_this.ce = _this.adaptor.document.createElement.bind(_this.adaptor.document);
|
|
196
|
+
return _this;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
(0, _createClass2["default"])(CHTMLmstack, [{
|
|
200
|
+
key: "toCHTML",
|
|
201
|
+
value: function toCHTML(parent) {
|
|
202
|
+
var _this2 = this;
|
|
203
|
+
|
|
204
|
+
var chtml = this.standardCHTMLnode(parent);
|
|
205
|
+
var stackData = getStackData(this); // console.log('stackData', stackData);
|
|
206
|
+
|
|
207
|
+
var maxCols = stackData.reduce(function (acc, r) {
|
|
208
|
+
if (r && r.columns.length > acc) {
|
|
209
|
+
acc = r.columns.length;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return acc;
|
|
213
|
+
}, 0);
|
|
214
|
+
var table = this.ce('table');
|
|
215
|
+
chtml.appendChild(table);
|
|
216
|
+
stackData.forEach(function (row) {
|
|
217
|
+
var tr = _this2.ce('tr');
|
|
218
|
+
|
|
219
|
+
table.appendChild(tr);
|
|
220
|
+
|
|
221
|
+
if (row.kind === 'row') {
|
|
222
|
+
var td = _this2.ce('td');
|
|
223
|
+
|
|
224
|
+
tr.appendChild(td);
|
|
225
|
+
|
|
226
|
+
if (row.operator && row.operator.toCHTML) {
|
|
227
|
+
td.setAttribute('class', 'inner');
|
|
228
|
+
row.operator.toCHTML(td);
|
|
229
|
+
} else {
|
|
230
|
+
td.textContent = '';
|
|
231
|
+
} // align right for now:
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
var cols = row.pad(maxCols, 'right');
|
|
235
|
+
cols.forEach(function (c) {
|
|
236
|
+
var t = _this2.ce('td');
|
|
237
|
+
|
|
238
|
+
tr.appendChild(t);
|
|
239
|
+
|
|
240
|
+
if (c === '__pad__') {
|
|
241
|
+
t.textContent = '';
|
|
242
|
+
} else if (typeof c === 'string') {
|
|
243
|
+
t.textContent = c;
|
|
244
|
+
} else if (c.kind === 'none') {
|
|
245
|
+
t.textContent = '';
|
|
246
|
+
} else if (c.toCHTML) {
|
|
247
|
+
t.setAttribute('class', 'inner');
|
|
248
|
+
c.toCHTML(t);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
} else if (row.kind === 'line') {
|
|
252
|
+
var _td = _this2.ce('td');
|
|
253
|
+
|
|
254
|
+
tr.appendChild(_td);
|
|
255
|
+
|
|
256
|
+
_td.setAttribute('colspan', maxCols + 1);
|
|
257
|
+
|
|
258
|
+
_td.setAttribute('class', 'mjx-line');
|
|
259
|
+
|
|
260
|
+
_td.textContent = '';
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}]);
|
|
265
|
+
return CHTMLmstack;
|
|
266
|
+
}(_Wrapper.CHTMLWrapper);
|
|
267
|
+
|
|
268
|
+
exports.CHTMLmstack = CHTMLmstack;
|
|
269
|
+
CHTMLmstack.styles = {
|
|
270
|
+
'mjx-mstack > table': {
|
|
271
|
+
'line-height': 'initial',
|
|
272
|
+
border: 'solid 0px red',
|
|
273
|
+
'border-spacing': '0em',
|
|
274
|
+
'border-collapse': 'separate'
|
|
275
|
+
},
|
|
276
|
+
'mjx-mstack > table > tr': {
|
|
277
|
+
'line-height': 'initial'
|
|
278
|
+
},
|
|
279
|
+
'mjx-mstack > table > tr > td': {
|
|
280
|
+
// padding: '1.2rem',
|
|
281
|
+
border: 'solid 0px blue',
|
|
282
|
+
'font-family': 'sans-serif',
|
|
283
|
+
'line-height': 'initial'
|
|
284
|
+
},
|
|
285
|
+
'mjx-mstack > table > tr > td.inner': {
|
|
286
|
+
'font-family': 'inherit'
|
|
287
|
+
},
|
|
288
|
+
'mjx-mstack > table > tr > .mjx-line': {
|
|
289
|
+
padding: 0,
|
|
290
|
+
'border-top': 'solid 1px black'
|
|
291
|
+
},
|
|
292
|
+
'.TEX-A': {
|
|
293
|
+
'font-family': 'MJXZERO, MJXTEX !important'
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
//# sourceMappingURL=chtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mstack/chtml.js"],"names":["reduceText","acc","n","node","kind","text","Line","Row","columns","operator","count","direction","length","Error","diff","padding","_","times","map","mathNodeToCharArray","mn","childNodes","reduce","split","toColumnArray","child","console","warn","toCHTML","rowStack","f","first","nodes","tail","flatten","undefined","getStackData","mstack","compact","CHTMLmstack","factory","parent","ce","adaptor","document","createElement","bind","chtml","standardCHTMLnode","stackData","maxCols","r","table","appendChild","forEach","row","tr","td","setAttribute","textContent","cols","pad","c","t","CHTMLWrapper","styles","border"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;;;;;AAEA,IAAMA,UAAU,GAAG,SAAbA,UAAa,CAACC,GAAD,EAAMC,CAAN,EAAY;AAC7B,MAAIA,CAAC,CAACC,IAAF,IAAUD,CAAC,CAACC,IAAF,CAAOC,IAAP,KAAgB,MAA9B,EAAsC;AACpCH,IAAAA,GAAG,IAAIC,CAAC,CAACC,IAAF,CAAOE,IAAd;AACD;;AACD,SAAOJ,GAAP;AACD,CALD;;IAOaK,I;AACX,kBAAc;AAAA;AACZ,SAAKF,IAAL,GAAY,MAAZ;AACD;;;;SAED,eAAc;AACZ,aAAO,EAAP;AACD;;;;;;;IAGUG,G;AACX,eAAYC,OAAZ,EAAqBC,QAArB,EAA+B;AAAA;AAC7B,SAAKL,IAAL,GAAY,KAAZ;AACA,SAAKK,QAAL,GAAgBA,QAAhB;AACA,SAAKD,OAAL,GAAeA,OAAf;AACD;;;;WAED,aAAIE,KAAJ,EAA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AAf,EAAuB;AAC5B2D,cAAAA,CAAC,CAACJ,WAAF,GAAgB,EAAhB;AACD,aAFM,MAEA,IAAIG,CAAC,CAAClC,OAAN,EAAe;AACpBmC,cAAAA,CAAC,CAACL,YAAF,CAAe,OAAf,EAAwB,OAAxB;AACAI,cAAAA,CAAC,CAAClC,OAAF,CAAUmC,CAAV;AACD;AACF,WAbD;AAcD,SA1BD,MA0BO,IAAIR,GAAG,CAACnD,IAAJ,KAAa,MAAjB,EAAyB;AAC9B,cAAMqD,GAAE,GAAG,MAAI,CAACf,EAAL,CAAQ,IAAR,CAAX;;AACAc,UAAAA,EAAE,CAACH,WAAH,CAAeI,GAAf;;AACAA,UAAAA,GAAE,CAACC,YAAH,CAAgB,SAAhB,EAA2BR,OAAO,GAAG,CAArC;;AACAO,UAAAA,GAAE,CAACC,YAAH,CAAgB,OAAhB,EAAyB,UAAzB;;AACAD,UAAAA,GAAE,CAACE,WAAH,GAAiB,EAAjB;AACD;AACF,OArCD;AAsCD;;;EA7D8BK,qB;;;AA+DjCzB,WAAW,CAAC0B,MAAZ,GAAqB;AACnB,wBAAsB;AACpB,mBAAe,SADK;AAEpBC,IAAAA,MAAM,EAAE,eAFY;AAGpB,sBAAkB,KAHE;AAIpB,uBAAmB;AAJC,GADH;AAOnB,6BAA2B;AACzB,mBAAe;AADU,GAPR;AAUnB,kCAAgC;AAC9B;AACAA,IAAAA,MAAM,EAAE,gBAFsB;AAG9B,mBAAe,YAHe;AAI9B,mBAAe;AAJe,GAVb;AAgBnB,wCAAsC;AACpC,mBAAe;AADqB,GAhBnB;AAmBnB,yCAAuC;AACrCnD,IAAAA,OAAO,EAAE,CAD4B;AAErC,kBAAc;AAFuB,GAnBpB;AAuBnB,YAAU;AACR,mBAAe;AADP;AAvBS,CAArB","sourcesContent":["import { CHTMLWrapper } from 'mathjax-full/js/output/chtml/Wrapper';\nimport _ from 'lodash';\n\nconst reduceText = (acc, n) => {\n if (n.node && n.node.kind === 'text') {\n acc += n.node.text;\n }\n return acc;\n};\n\nexport class Line {\n constructor() {\n this.kind = 'line';\n }\n\n get columns() {\n return [];\n }\n}\n\nexport class Row {\n constructor(columns, operator) {\n this.kind = 'row';\n this.operator = operator;\n this.columns = columns;\n }\n\n pad(count, direction = 'right') {\n if (count < this.columns.length) {\n throw new Error('no');\n }\n\n const diff = count - this.columns.length;\n\n const padding = _.times(diff).map(() => '__pad__');\n return direction === 'right' ? [...padding, ...this.columns] : [...this.columns, ...padding];\n }\n}\n\nconst mathNodeToCharArray = (mn) => {\n const text = mn.childNodes.reduce(reduceText, '');\n return text.split('');\n};\n\n/**\n * Convert child a column entry\n * @param {*} child\n * @return an array of column content\n */\nconst toColumnArray = (child) => {\n if (!child || !child.kind) {\n return [];\n }\n\n if (child.kind === 'msrow') {\n throw new Error('msrow in msrow?');\n }\n\n if (child.kind === 'mo') {\n // We are going to treat this operator as a text array.\n // It's probably going to be a decimal point\n // eslint-disable-next-line no-console\n console.warn('mo that is not 1st node in msrow?');\n return mathNodeToCharArray(child);\n // throw new Error('mo must be first child of msrow');\n }\n\n if (child.kind === 'mn') {\n return mathNodeToCharArray(child);\n }\n\n if (child.toCHTML) {\n return child;\n }\n};\n\n/**\n * convert mstack chtml childNodes into a Row\n * @param child chtml child node of mstack\n * @return Row | Line\n */\nconst rowStack = (child) => {\n if (!child || !child.kind) {\n return;\n }\n\n if (child.kind === 'msrow') {\n if (!child.childNodes || child.childNodes.length === 0) {\n return new Row([]);\n }\n const f = _.first(child.childNodes);\n const nodes = f && f.kind === 'mo' ? _.tail(child.childNodes) : child.childNodes;\n\n const columns = _.flatten(nodes.map(toColumnArray));\n\n return new Row(columns, f.kind === 'mo' ? f : undefined);\n }\n\n if (child.kind === 'mn') {\n const columns = mathNodeToCharArray(child);\n return new Row(columns, undefined);\n }\n\n if (child.kind === 'mo') {\n // eslint-disable-next-line no-console\n console.warn('mo on its own row?');\n return new Row([], child);\n }\n\n if (child.kind === 'msline') {\n return new Line();\n }\n\n if (child.toCHTML) {\n return new Row([child]);\n }\n};\n\n/** convert MathJax chtml tree to Row[]\n * @param mstack the root of the mathjax chtml tree\n * @return Row[]\n */\n\nexport const getStackData = (mstack) => {\n if (!mstack || !mstack.childNodes) {\n return [];\n }\n return _.compact(mstack.childNodes.map(rowStack));\n};\n\nexport class CHTMLmstack extends CHTMLWrapper {\n constructor(factory, node, parent = null) {\n super(factory, node, parent);\n\n this.ce = this.adaptor.document.createElement.bind(this.adaptor.document);\n }\n\n toCHTML(parent) {\n const chtml = this.standardCHTMLnode(parent);\n\n const stackData = getStackData(this);\n\n // console.log('stackData', stackData);\n const maxCols = stackData.reduce((acc, r) => {\n if (r && r.columns.length > acc) {\n acc = r.columns.length;\n }\n return acc;\n }, 0);\n\n const table = this.ce('table');\n chtml.appendChild(table);\n\n stackData.forEach((row) => {\n const tr = this.ce('tr');\n table.appendChild(tr);\n\n if (row.kind === 'row') {\n const td = this.ce('td');\n tr.appendChild(td);\n if (row.operator && row.operator.toCHTML) {\n td.setAttribute('class', 'inner');\n row.operator.toCHTML(td);\n } else {\n td.textContent = '';\n }\n\n // align right for now:\n const cols = row.pad(maxCols, 'right');\n cols.forEach((c) => {\n const t = this.ce('td');\n tr.appendChild(t);\n if (c === '__pad__') {\n t.textContent = '';\n } else if (typeof c === 'string') {\n t.textContent = c;\n } else if (c.kind === 'none') {\n t.textContent = '';\n } else if (c.toCHTML) {\n t.setAttribute('class', 'inner');\n c.toCHTML(t);\n }\n });\n } else if (row.kind === 'line') {\n const td = this.ce('td');\n tr.appendChild(td);\n td.setAttribute('colspan', maxCols + 1);\n td.setAttribute('class', 'mjx-line');\n td.textContent = '';\n }\n });\n }\n}\nCHTMLmstack.styles = {\n 'mjx-mstack > table': {\n 'line-height': 'initial',\n border: 'solid 0px red',\n 'border-spacing': '0em',\n 'border-collapse': 'separate',\n },\n 'mjx-mstack > table > tr': {\n 'line-height': 'initial',\n },\n 'mjx-mstack > table > tr > td': {\n // padding: '1.2rem',\n border: 'solid 0px blue',\n 'font-family': 'sans-serif',\n 'line-height': 'initial',\n },\n 'mjx-mstack > table > tr > td.inner': {\n 'font-family': 'inherit',\n },\n 'mjx-mstack > table > tr > .mjx-line': {\n padding: 0,\n 'border-top': 'solid 1px black',\n },\n '.TEX-A': {\n 'font-family': 'MJXZERO, MJXTEX !important',\n },\n};\n"],"file":"chtml.js"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mmlNodes = exports.chtmlNodes = void 0;
|
|
7
|
+
|
|
8
|
+
var _chtml = require("./chtml");
|
|
9
|
+
|
|
10
|
+
var _mml = require("./mml");
|
|
11
|
+
|
|
12
|
+
var chtmlNodes = {
|
|
13
|
+
mstack: _chtml.CHTMLmstack
|
|
14
|
+
};
|
|
15
|
+
exports.chtmlNodes = chtmlNodes;
|
|
16
|
+
var mmlNodes = {
|
|
17
|
+
mstack: _mml.MmlMstack,
|
|
18
|
+
msline: _mml.MmlMsline,
|
|
19
|
+
msrow: _mml.MmlMsrow,
|
|
20
|
+
none: _mml.MmlNone
|
|
21
|
+
};
|
|
22
|
+
exports.mmlNodes = mmlNodes;
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mstack/index.js"],"names":["chtmlNodes","mstack","CHTMLmstack","mmlNodes","MmlMstack","msline","MmlMsline","msrow","MmlMsrow","none","MmlNone"],"mappings":";;;;;;;AAAA;;AACA;;AAEO,IAAMA,UAAU,GAAG;AACxBC,EAAAA,MAAM,EAAEC;AADgB,CAAnB;;AAIA,IAAMC,QAAQ,GAAG;AACtBF,EAAAA,MAAM,EAAEG,cADc;AAEtBC,EAAAA,MAAM,EAAEC,cAFc;AAGtBC,EAAAA,KAAK,EAAEC,aAHe;AAItBC,EAAAA,IAAI,EAAEC;AAJgB,CAAjB","sourcesContent":["import { CHTMLmstack } from './chtml';\nimport { MmlNone, MmlMsline, MmlMstack, MmlMsrow } from './mml';\n\nexport const chtmlNodes = {\n mstack: CHTMLmstack,\n};\n\nexport const mmlNodes = {\n mstack: MmlMstack,\n msline: MmlMsline,\n msrow: MmlMsrow,\n none: MmlNone,\n};\n"],"file":"index.js"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.MmlNone = exports.MmlMstack = exports.MmlMsrow = exports.MmlMsline = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
|
|
16
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
+
|
|
18
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
+
|
|
20
|
+
var _MmlNode = require("mathjax-full/js/core/MmlTree/MmlNode");
|
|
21
|
+
|
|
22
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
23
|
+
|
|
24
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
25
|
+
|
|
26
|
+
var MmlNone = /*#__PURE__*/function (_AbstractMmlNode) {
|
|
27
|
+
(0, _inherits2["default"])(MmlNone, _AbstractMmlNode);
|
|
28
|
+
|
|
29
|
+
var _super = _createSuper(MmlNone);
|
|
30
|
+
|
|
31
|
+
function MmlNone() {
|
|
32
|
+
(0, _classCallCheck2["default"])(this, MmlNone);
|
|
33
|
+
return _super.apply(this, arguments);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
(0, _createClass2["default"])(MmlNone, [{
|
|
37
|
+
key: "kind",
|
|
38
|
+
get: function get() {
|
|
39
|
+
return 'none';
|
|
40
|
+
}
|
|
41
|
+
}]);
|
|
42
|
+
return MmlNone;
|
|
43
|
+
}(_MmlNode.AbstractMmlNode);
|
|
44
|
+
|
|
45
|
+
exports.MmlNone = MmlNone;
|
|
46
|
+
|
|
47
|
+
var MmlMstack = /*#__PURE__*/function (_AbstractMmlNode2) {
|
|
48
|
+
(0, _inherits2["default"])(MmlMstack, _AbstractMmlNode2);
|
|
49
|
+
|
|
50
|
+
var _super2 = _createSuper(MmlMstack);
|
|
51
|
+
|
|
52
|
+
function MmlMstack() {
|
|
53
|
+
(0, _classCallCheck2["default"])(this, MmlMstack);
|
|
54
|
+
return _super2.apply(this, arguments);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
(0, _createClass2["default"])(MmlMstack, [{
|
|
58
|
+
key: "kind",
|
|
59
|
+
get: function get() {
|
|
60
|
+
return 'mstack';
|
|
61
|
+
}
|
|
62
|
+
}]);
|
|
63
|
+
return MmlMstack;
|
|
64
|
+
}(_MmlNode.AbstractMmlNode);
|
|
65
|
+
|
|
66
|
+
exports.MmlMstack = MmlMstack;
|
|
67
|
+
|
|
68
|
+
var MmlMsrow = /*#__PURE__*/function (_AbstractMmlNode3) {
|
|
69
|
+
(0, _inherits2["default"])(MmlMsrow, _AbstractMmlNode3);
|
|
70
|
+
|
|
71
|
+
var _super3 = _createSuper(MmlMsrow);
|
|
72
|
+
|
|
73
|
+
function MmlMsrow() {
|
|
74
|
+
(0, _classCallCheck2["default"])(this, MmlMsrow);
|
|
75
|
+
return _super3.apply(this, arguments);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
(0, _createClass2["default"])(MmlMsrow, [{
|
|
79
|
+
key: "kind",
|
|
80
|
+
get: function get() {
|
|
81
|
+
return 'msrow';
|
|
82
|
+
}
|
|
83
|
+
}]);
|
|
84
|
+
return MmlMsrow;
|
|
85
|
+
}(_MmlNode.AbstractMmlNode);
|
|
86
|
+
|
|
87
|
+
exports.MmlMsrow = MmlMsrow;
|
|
88
|
+
|
|
89
|
+
var MmlMsline = /*#__PURE__*/function (_AbstractMmlNode4) {
|
|
90
|
+
(0, _inherits2["default"])(MmlMsline, _AbstractMmlNode4);
|
|
91
|
+
|
|
92
|
+
var _super4 = _createSuper(MmlMsline);
|
|
93
|
+
|
|
94
|
+
function MmlMsline() {
|
|
95
|
+
(0, _classCallCheck2["default"])(this, MmlMsline);
|
|
96
|
+
return _super4.apply(this, arguments);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
(0, _createClass2["default"])(MmlMsline, [{
|
|
100
|
+
key: "kind",
|
|
101
|
+
get: function get() {
|
|
102
|
+
return 'msline';
|
|
103
|
+
}
|
|
104
|
+
}]);
|
|
105
|
+
return MmlMsline;
|
|
106
|
+
}(_MmlNode.AbstractMmlNode);
|
|
107
|
+
|
|
108
|
+
exports.MmlMsline = MmlMsline;
|
|
109
|
+
//# sourceMappingURL=mml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/mstack/mml.js"],"names":["MmlNone","AbstractMmlNode","MmlMstack","MmlMsrow","MmlMsline"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;IAEaA,O;;;;;;;;;;;;SACX,eAAW;AACT,aAAO,MAAP;AACD;;;EAH0BC,wB;;;;IAMhBC,S;;;;;;;;;;;;SACX,eAAW;AACT,aAAO,QAAP;AACD;;;EAH4BD,wB;;;;IAMlBE,Q;;;;;;;;;;;;SACX,eAAW;AACT,aAAO,OAAP;AACD;;;EAH2BF,wB;;;;IAKjBG,S;;;;;;;;;;;;SACX,eAAW;AACT,aAAO,QAAP;AACD;;;EAH4BH,wB","sourcesContent":["import { AbstractMmlNode } from 'mathjax-full/js/core/MmlTree/MmlNode';\n\nexport class MmlNone extends AbstractMmlNode {\n get kind() {\n return 'none';\n }\n}\n\nexport class MmlMstack extends AbstractMmlNode {\n get kind() {\n return 'mstack';\n }\n}\n\nexport class MmlMsrow extends AbstractMmlNode {\n get kind() {\n return 'msrow';\n }\n}\nexport class MmlMsline extends AbstractMmlNode {\n get kind() {\n return 'msline';\n }\n}\n"],"file":"mml.js"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.wrapMath = exports.unWrapMath = exports.BracketTypes = void 0;
|
|
9
|
+
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _PAIRS;
|
|
15
|
+
|
|
16
|
+
var BracketTypes = {};
|
|
17
|
+
exports.BracketTypes = BracketTypes;
|
|
18
|
+
BracketTypes.ROUND_BRACKETS = 'round_brackets';
|
|
19
|
+
BracketTypes.SQUARE_BRACKETS = 'square_brackets';
|
|
20
|
+
BracketTypes.DOLLAR = 'dollar';
|
|
21
|
+
BracketTypes.DOUBLE_DOLLAR = 'double_dollar';
|
|
22
|
+
var PAIRS = (_PAIRS = {}, (0, _defineProperty2["default"])(_PAIRS, BracketTypes.ROUND_BRACKETS, ['\\(', '\\)']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.SQUARE_BRACKETS, ['\\[', '\\]']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.DOLLAR, ['$', '$']), (0, _defineProperty2["default"])(_PAIRS, BracketTypes.DOUBLE_DOLLAR, ['$$', '$$']), _PAIRS);
|
|
23
|
+
|
|
24
|
+
var wrapMath = function wrapMath(content, wrapType) {
|
|
25
|
+
if (wrapType === BracketTypes.SQUARE_BRACKETS) {
|
|
26
|
+
console.warn('\\[...\\] is not supported yet'); // eslint-disable-line
|
|
27
|
+
|
|
28
|
+
wrapType = BracketTypes.ROUND_BRACKETS;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (wrapType === BracketTypes.DOUBLE_DOLLAR) {
|
|
32
|
+
console.warn('$$...$$ is not supported yet'); // eslint-disable-line
|
|
33
|
+
|
|
34
|
+
wrapType = BracketTypes.DOLLAR;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var _ref = PAIRS[wrapType] || PAIRS[BracketTypes.ROUND_BRACKETS],
|
|
38
|
+
_ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
39
|
+
start = _ref2[0],
|
|
40
|
+
end = _ref2[1];
|
|
41
|
+
|
|
42
|
+
return "".concat(start).concat(content).concat(end);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.wrapMath = wrapMath;
|
|
46
|
+
|
|
47
|
+
var unWrapMath = function unWrapMath(content) {
|
|
48
|
+
var displayStyleIndex = content.indexOf('\\displaystyle');
|
|
49
|
+
|
|
50
|
+
if (displayStyleIndex !== -1) {
|
|
51
|
+
console.warn('\\displaystyle is not supported - removing'); // eslint-disable-line
|
|
52
|
+
|
|
53
|
+
content = content.replace('\\displaystyle', '').trim();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (content.startsWith('$$') && content.endsWith('$$')) {
|
|
57
|
+
console.warn('$$ syntax is not yet supported'); // eslint-disable-line
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
unwrapped: content.substring(2, content.length - 2),
|
|
61
|
+
wrapType: BracketTypes.DOLLAR
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (content.startsWith('$') && content.endsWith('$')) {
|
|
66
|
+
return {
|
|
67
|
+
unwrapped: content.substring(1, content.length - 1),
|
|
68
|
+
wrapType: BracketTypes.DOLLAR
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (content.startsWith('\\[') && content.endsWith('\\]')) {
|
|
73
|
+
console.warn('\\[..\\] syntax is not yet supported'); // eslint-disable-line
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
unwrapped: content.substring(2, content.length - 2),
|
|
77
|
+
wrapType: BracketTypes.ROUND_BRACKETS
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (content.startsWith('\\(') && content.endsWith('\\)')) {
|
|
82
|
+
return {
|
|
83
|
+
unwrapped: content.substring(2, content.length - 2),
|
|
84
|
+
wrapType: BracketTypes.ROUND_BRACKETS
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
unwrapped: content,
|
|
90
|
+
wrapType: BracketTypes.ROUND_BRACKETS
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
exports.unWrapMath = unWrapMath;
|
|
95
|
+
//# sourceMappingURL=normalization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/normalization.js"],"names":["BracketTypes","ROUND_BRACKETS","SQUARE_BRACKETS","DOLLAR","DOUBLE_DOLLAR","PAIRS","wrapMath","content","wrapType","console","warn","start","end","unWrapMath","displayStyleIndex","indexOf","replace","trim","startsWith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AR,CAAiB,KAAjB,CAAjC,EAA0D;AACxD,WAAO;AACLC,MAAAA,SAAS,EAAEb,OAAO,CAACc,SAAR,CAAkB,CAAlB,EAAqBd,OAAO,CAACe,MAAR,GAAiB,CAAtC,CADN;AAELd,MAAAA,QAAQ,EAAER,YAAY,CAACC;AAFlB,KAAP;AAID;;AAED,SAAO;AACLmB,IAAAA,SAAS,EAAEb,OADN;AAELC,IAAAA,QAAQ,EAAER,YAAY,CAACC;AAFlB,GAAP;AAID,CAxCM","sourcesContent":["export const BracketTypes = {};\n\nBracketTypes.ROUND_BRACKETS = 'round_brackets';\nBracketTypes.SQUARE_BRACKETS = 'square_brackets';\nBracketTypes.DOLLAR = 'dollar';\nBracketTypes.DOUBLE_DOLLAR = 'double_dollar';\n\nconst PAIRS = {\n [BracketTypes.ROUND_BRACKETS]: ['\\\\(', '\\\\)'],\n [BracketTypes.SQUARE_BRACKETS]: ['\\\\[', '\\\\]'],\n [BracketTypes.DOLLAR]: ['$', '$'],\n [BracketTypes.DOUBLE_DOLLAR]: ['$$', '$$'],\n};\n\nexport const wrapMath = (content, wrapType) => {\n if (wrapType === BracketTypes.SQUARE_BRACKETS) {\n console.warn('\\\\[...\\\\] is not supported yet'); // eslint-disable-line\n wrapType = BracketTypes.ROUND_BRACKETS;\n }\n if (wrapType === BracketTypes.DOUBLE_DOLLAR) {\n console.warn('$$...$$ is not supported yet'); // eslint-disable-line\n wrapType = BracketTypes.DOLLAR;\n }\n\n const [start, end] = PAIRS[wrapType] || PAIRS[BracketTypes.ROUND_BRACKETS];\n return `${start}${content}${end}`;\n};\n\nexport const unWrapMath = (content) => {\n const displayStyleIndex = content.indexOf('\\\\displaystyle');\n if (displayStyleIndex !== -1) {\n console.warn('\\\\displaystyle is not supported - removing'); // eslint-disable-line\n content = content.replace('\\\\displaystyle', '').trim();\n }\n\n if (content.startsWith('$$') && content.endsWith('$$')) {\n console.warn('$$ syntax is not yet supported'); // eslint-disable-line\n return {\n unwrapped: content.substring(2, content.length - 2),\n wrapType: BracketTypes.DOLLAR,\n };\n }\n if (content.startsWith('$') && content.endsWith('$')) {\n return {\n unwrapped: content.substring(1, content.length - 1),\n wrapType: BracketTypes.DOLLAR,\n };\n }\n\n if (content.startsWith('\\\\[') && content.endsWith('\\\\]')) {\n console.warn('\\\\[..\\\\] syntax is not yet supported'); // eslint-disable-line\n return {\n unwrapped: content.substring(2, content.length - 2),\n wrapType: BracketTypes.ROUND_BRACKETS,\n };\n }\n\n if (content.startsWith('\\\\(') && content.endsWith('\\\\)')) {\n return {\n unwrapped: content.substring(2, content.length - 2),\n wrapType: BracketTypes.ROUND_BRACKETS,\n };\n }\n\n return {\n unwrapped: content,\n wrapType: BracketTypes.ROUND_BRACKETS,\n };\n};\n"],"file":"normalization.js"}
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.initializeMathJax = exports.getGlobal = exports.fixMathElements = exports.fixMathElement = exports["default"] = exports.MathJaxVersion = void 0;
|
|
9
|
+
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
|
|
12
|
+
var _normalization = require("./normalization");
|
|
13
|
+
|
|
14
|
+
var _SerializedMmlVisitor = require("mathjax-full/js/core/MmlTree/SerializedMmlVisitor");
|
|
15
|
+
|
|
16
|
+
var _TexError = _interopRequireDefault(require("mathjax-full/js/input/tex/TexError"));
|
|
17
|
+
|
|
18
|
+
var visitor = new _SerializedMmlVisitor.SerializedMmlVisitor();
|
|
19
|
+
|
|
20
|
+
var toMMl = function toMMl(node) {
|
|
21
|
+
return visitor.visitTree(node);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
var NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
|
|
25
|
+
var NEWLINE_LATEX = '\\newline ';
|
|
26
|
+
var mathRenderingKEY = '@pie-lib/math-rendering@2';
|
|
27
|
+
var mathRenderingAccessibleKEY = '@pie-lib/math-rendering-accessible@1';
|
|
28
|
+
var MathJaxVersion = '3.2.2';
|
|
29
|
+
exports.MathJaxVersion = MathJaxVersion;
|
|
30
|
+
|
|
31
|
+
var getGlobal = function getGlobal() {
|
|
32
|
+
// TODO does it make sense to use version?
|
|
33
|
+
// const key = `${pkg.name}@${pkg.version.split('.')[0]}`;
|
|
34
|
+
// It looks like Ed made this change when he switched from mathjax3 to mathjax-full
|
|
35
|
+
// I think it was supposed to make sure version 1 (using mathjax3) is not used
|
|
36
|
+
// in combination with version 2 (using mathjax-full)
|
|
37
|
+
// TODO higher level wrappers use this instance of math-rendering, and if 2 different instances are used, math rendering is not working
|
|
38
|
+
// so I will hardcode this for now until a better solution is found
|
|
39
|
+
if (typeof window !== 'undefined') {
|
|
40
|
+
if (!window[mathRenderingAccessibleKEY]) {
|
|
41
|
+
window[mathRenderingAccessibleKEY] = {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return window[mathRenderingAccessibleKEY];
|
|
45
|
+
} else {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
exports.getGlobal = getGlobal;
|
|
51
|
+
|
|
52
|
+
var fixMathElement = function fixMathElement(element) {
|
|
53
|
+
if (element.dataset.mathHandled) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var property = 'innerText';
|
|
58
|
+
|
|
59
|
+
if (element.textContent) {
|
|
60
|
+
property = 'textContent';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (element[property]) {
|
|
64
|
+
element[property] = (0, _normalization.wrapMath)((0, _normalization.unWrapMath)(element[property]).unwrapped); // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.
|
|
65
|
+
// we need to replace the custom embedded elements with valid latex that Mathjax can understand
|
|
66
|
+
|
|
67
|
+
element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);
|
|
68
|
+
element.dataset.mathHandled = true;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
exports.fixMathElement = fixMathElement;
|
|
73
|
+
|
|
74
|
+
var fixMathElements = function fixMathElements() {
|
|
75
|
+
var el = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
|
|
76
|
+
var mathElements = el.querySelectorAll('[data-latex]');
|
|
77
|
+
mathElements.forEach(function (item) {
|
|
78
|
+
return fixMathElement(item);
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
exports.fixMathElements = fixMathElements;
|
|
83
|
+
|
|
84
|
+
var adjustMathMLStyle = function adjustMathMLStyle() {
|
|
85
|
+
var el = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
|
|
86
|
+
var nodes = el.querySelectorAll('math');
|
|
87
|
+
nodes.forEach(function (node) {
|
|
88
|
+
return node.setAttribute('displaystyle', 'true');
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var createPlaceholder = function createPlaceholder(element) {
|
|
93
|
+
var _element$previousSibl;
|
|
94
|
+
|
|
95
|
+
if (!element.previousSibling || !((_element$previousSibl = element.previousSibling.classList) !== null && _element$previousSibl !== void 0 && _element$previousSibl.contains('math-placeholder'))) {
|
|
96
|
+
var _element$parentNode;
|
|
97
|
+
|
|
98
|
+
// Store the original display style before setting it to 'none'
|
|
99
|
+
element.dataset.originalDisplay = element.style.display || '';
|
|
100
|
+
element.style.display = 'none';
|
|
101
|
+
var placeholder = document.createElement('span');
|
|
102
|
+
placeholder.style.cssText = 'height: 10px; width: 50px; display: inline-block; vertical-align: middle; justify-content: center; background: #fafafa; border-radius: 4px;';
|
|
103
|
+
placeholder.classList.add('math-placeholder');
|
|
104
|
+
(_element$parentNode = element.parentNode) === null || _element$parentNode === void 0 ? void 0 : _element$parentNode.insertBefore(placeholder, element);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
var removePlaceholdersAndRestoreDisplay = function removePlaceholdersAndRestoreDisplay() {
|
|
109
|
+
document.querySelectorAll('.math-placeholder').forEach(function (placeholder) {
|
|
110
|
+
var _targetElement$datase;
|
|
111
|
+
|
|
112
|
+
var targetElement = placeholder.nextElementSibling;
|
|
113
|
+
|
|
114
|
+
if (targetElement && ((_targetElement$datase = targetElement.dataset) === null || _targetElement$datase === void 0 ? void 0 : _targetElement$datase.originalDisplay) !== undefined) {
|
|
115
|
+
targetElement.style.display = targetElement.dataset.originalDisplay;
|
|
116
|
+
delete targetElement.dataset.originalDisplay;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
placeholder.remove();
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
var removeExcessMjxContainers = function removeExcessMjxContainers(content) {
|
|
124
|
+
var elements = content.querySelectorAll('[data-latex][data-math-handled="true"]');
|
|
125
|
+
elements.forEach(function (element) {
|
|
126
|
+
var mjxContainers = element.querySelectorAll('mjx-container'); // Check if there are more than one mjx-container children.
|
|
127
|
+
|
|
128
|
+
if (mjxContainers.length > 1) {
|
|
129
|
+
for (var i = 1; i < mjxContainers.length; i++) {
|
|
130
|
+
mjxContainers[i].parentNode.removeChild(mjxContainers[i]);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
var renderContentsWithMathJax = function renderContentsWithMathJax(el) {
|
|
137
|
+
// el sometimes is an array
|
|
138
|
+
// renderMath is used like that in pie-print-support and pie-element-extensions
|
|
139
|
+
// there seems to be no reason for that, however, it's better to handle the case here
|
|
140
|
+
if (el instanceof Array) {
|
|
141
|
+
el.forEach(function (elNode) {
|
|
142
|
+
return renderContentWithMathJax(elNode);
|
|
143
|
+
});
|
|
144
|
+
} else {
|
|
145
|
+
renderContentWithMathJax(el);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
var renderContentWithMathJax = function renderContentWithMathJax(executeOn) {
|
|
150
|
+
executeOn = executeOn || document.body; // this happens for charting - mark-label; we receive a ref which is not yet ready ( el = { current: null })
|
|
151
|
+
// we have to fix this in charting
|
|
152
|
+
|
|
153
|
+
if (!(executeOn instanceof HTMLElement)) return;
|
|
154
|
+
fixMathElements(executeOn);
|
|
155
|
+
adjustMathMLStyle(executeOn);
|
|
156
|
+
var mathJaxInstance = getGlobal().instance;
|
|
157
|
+
|
|
158
|
+
if (mathJaxInstance) {
|
|
159
|
+
// Reset and clear typesetting before processing the new content
|
|
160
|
+
// Reset the tex labels (and automatic equation number).
|
|
161
|
+
mathJaxInstance.texReset(); // Reset the typesetting system (font caches, etc.)
|
|
162
|
+
|
|
163
|
+
mathJaxInstance.typesetClear(); // Use typesetPromise for asynchronous typesetting
|
|
164
|
+
// Using MathJax.typesetPromise() for asynchronous typesetting to handle situations where additional code needs to be loaded (e.g., for certain TeX commands or characters).
|
|
165
|
+
// This ensures typesetting waits for any needed resources to load and complete processing, unlike the synchronous MathJax.typeset() which can't handle such dynamic loading.
|
|
166
|
+
|
|
167
|
+
mathJaxInstance.typesetPromise([executeOn]).then(function () {
|
|
168
|
+
try {
|
|
169
|
+
removePlaceholdersAndRestoreDisplay();
|
|
170
|
+
removeExcessMjxContainers(executeOn);
|
|
171
|
+
var updatedDocument = mathJaxInstance.startup.document;
|
|
172
|
+
var list = updatedDocument.math.list;
|
|
173
|
+
|
|
174
|
+
for (var item = list.next; (0, _typeof2["default"])(item.data) !== 'symbol'; item = item.next) {
|
|
175
|
+
var mathMl = toMMl(item.data.root);
|
|
176
|
+
var parsedMathMl = mathMl.replaceAll('\n', '');
|
|
177
|
+
item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);
|
|
178
|
+
item.data.typesetRoot.setAttribute('tabindex', '-1');
|
|
179
|
+
} // If the original input was a string, return the parsed MathML
|
|
180
|
+
|
|
181
|
+
} catch (e) {
|
|
182
|
+
console.error('Error post-processing MathJax typesetting:', e.toString());
|
|
183
|
+
} // Clearing the document if needed
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
mathJaxInstance.startup.document.clear();
|
|
187
|
+
})["catch"](function (error) {
|
|
188
|
+
// If there was an internal error, put the message into the output instead
|
|
189
|
+
console.error('Error in typesetting with MathJax:', error);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
var convertMathJax2ToMathJax3 = function convertMathJax2ToMathJax3() {
|
|
195
|
+
// Make MathJax v2 compatible with v3
|
|
196
|
+
// https://docs.mathjax.org/en/v3.2-latest/upgrading/v2.html#version-2-compatibility-example
|
|
197
|
+
// Replace the require command map with a new one that checks for
|
|
198
|
+
// renamed extensions and converts them to the new names.
|
|
199
|
+
var CommandMap = MathJax._.input.tex.SymbolMap.CommandMap;
|
|
200
|
+
var requireMap = MathJax.config.startup.requireMap;
|
|
201
|
+
var RequireLoad = MathJax._.input.tex.require.RequireConfiguration.RequireLoad;
|
|
202
|
+
var RequireMethods = {
|
|
203
|
+
Require: function Require(parser, name) {
|
|
204
|
+
var required = parser.GetArgument(name);
|
|
205
|
+
|
|
206
|
+
if (required.match(/[^_a-zA-Z0-9]/) || required === '') {
|
|
207
|
+
throw new _TexError["default"]('BadPackageName', 'Argument for %1 is not a valid package name', name);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (requireMap.hasOwnProperty(required)) {
|
|
211
|
+
required = requireMap[required];
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
RequireLoad(parser, required);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
new CommandMap('require', {
|
|
218
|
+
require: 'Require'
|
|
219
|
+
}, RequireMethods); //
|
|
220
|
+
// Add a replacement for MathJax.Callback command
|
|
221
|
+
//
|
|
222
|
+
|
|
223
|
+
MathJax.Callback = function (args) {
|
|
224
|
+
if (Array.isArray(args)) {
|
|
225
|
+
if (args.length === 1 && typeof args[0] === 'function') {
|
|
226
|
+
return args[0];
|
|
227
|
+
} else if (typeof args[0] === 'string' && args[1] instanceof Object && typeof args[1][args[0]] === 'function') {
|
|
228
|
+
return Function.bind.apply(args[1][args[0]], args.slice(1));
|
|
229
|
+
} else if (typeof args[0] === 'function') {
|
|
230
|
+
return Function.bind.apply(args[0], [window].concat(args.slice(1)));
|
|
231
|
+
} else if (typeof args[1] === 'function') {
|
|
232
|
+
return Function.bind.apply(args[1], [args[0]].concat(args.slice(2)));
|
|
233
|
+
}
|
|
234
|
+
} else if (typeof args === 'function') {
|
|
235
|
+
return args;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
throw Error("Can't make callback from given data");
|
|
239
|
+
}; //
|
|
240
|
+
// Add a replacement for MathJax.Hub commands
|
|
241
|
+
//
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
MathJax.Hub = {
|
|
245
|
+
Queue: function Queue() {
|
|
246
|
+
for (var i = 0, m = arguments.length; i < m; i++) {
|
|
247
|
+
var fn = MathJax.Callback(arguments[i]);
|
|
248
|
+
MathJax.startup.promise = MathJax.startup.promise.then(fn);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return MathJax.startup.promise;
|
|
252
|
+
},
|
|
253
|
+
Typeset: function Typeset(elements, callback) {
|
|
254
|
+
var promise = MathJax.typesetPromise(elements);
|
|
255
|
+
|
|
256
|
+
if (callback) {
|
|
257
|
+
promise = promise.then(callback);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return promise;
|
|
261
|
+
},
|
|
262
|
+
Register: {
|
|
263
|
+
MessageHook: function MessageHook() {
|
|
264
|
+
console.log('MessageHooks are not supported in version 3');
|
|
265
|
+
},
|
|
266
|
+
StartupHook: function StartupHook() {
|
|
267
|
+
console.log('StartupHooks are not supported in version 3');
|
|
268
|
+
},
|
|
269
|
+
LoadHook: function LoadHook() {
|
|
270
|
+
console.log('LoadHooks are not supported in version 3');
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
Config: function Config() {
|
|
274
|
+
console.log('MathJax configurations should be converted for version 3');
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
var initializeMathJax = function initializeMathJax(callback) {
|
|
280
|
+
if (window.mathjaxLoadedP) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
var PreviousMathJaxIsUsed = window.MathJax && window.MathJax.version && window.MathJax.version !== MathJaxVersion && window.MathJax.version[0] === '2';
|
|
285
|
+
var texConfig = {
|
|
286
|
+
macros: {
|
|
287
|
+
parallelogram: "\\lower.2em{\\Huge\\unicode{x25B1}}",
|
|
288
|
+
overarc: '\\overparen',
|
|
289
|
+
napprox: '\\not\\approx',
|
|
290
|
+
longdiv: '\\enclose{longdiv}'
|
|
291
|
+
},
|
|
292
|
+
displayMath: [['$$', '$$'], ['\\[', '\\]']]
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
if (PreviousMathJaxIsUsed) {
|
|
296
|
+
texConfig.autoload = {
|
|
297
|
+
color: [],
|
|
298
|
+
// don't autoload the color extension
|
|
299
|
+
colorv2: ['color'] // do autoload the colorv2 extension
|
|
300
|
+
|
|
301
|
+
};
|
|
302
|
+
} // Create a new promise that resolves when MathJax is ready
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
window.mathjaxLoadedP = new Promise(function (resolve) {
|
|
306
|
+
// Set up the MathJax configuration
|
|
307
|
+
window.MathJax = {
|
|
308
|
+
startup: {
|
|
309
|
+
//
|
|
310
|
+
// Mapping of old extension names to new ones
|
|
311
|
+
//
|
|
312
|
+
requireMap: PreviousMathJaxIsUsed ? {
|
|
313
|
+
AMSmath: 'ams',
|
|
314
|
+
AMSsymbols: 'ams',
|
|
315
|
+
AMScd: 'amscd',
|
|
316
|
+
HTML: 'html',
|
|
317
|
+
noErrors: 'noerrors',
|
|
318
|
+
noUndefined: 'noundefined'
|
|
319
|
+
} : {},
|
|
320
|
+
typeset: false,
|
|
321
|
+
ready: function ready() {
|
|
322
|
+
if (PreviousMathJaxIsUsed) {
|
|
323
|
+
convertMathJax2ToMathJax3();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
var mathjax = MathJax._.mathjax.mathjax;
|
|
327
|
+
var STATE = MathJax._.core.MathItem.STATE;
|
|
328
|
+
var Menu = MathJax._.ui.menu.Menu.Menu;
|
|
329
|
+
var rerender = Menu.prototype.rerender;
|
|
330
|
+
|
|
331
|
+
Menu.prototype.rerender = function () {
|
|
332
|
+
var _this = this;
|
|
333
|
+
|
|
334
|
+
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : STATE.TYPESET;
|
|
335
|
+
mathjax.handleRetriesFor(function () {
|
|
336
|
+
return rerender.call(_this, start);
|
|
337
|
+
});
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
MathJax.startup.defaultReady(); // Set the MathJax instance in the global object
|
|
341
|
+
|
|
342
|
+
var globalObj = getGlobal();
|
|
343
|
+
globalObj.instance = MathJax;
|
|
344
|
+
window.mathjaxLoadedComplete = true;
|
|
345
|
+
console.log('MathJax has initialised!', new Date().toString()); // in this file, initializeMathJax is called with a callback that has to be executed when MathJax was loaded
|
|
346
|
+
|
|
347
|
+
if (callback) {
|
|
348
|
+
callback();
|
|
349
|
+
} // but previous versions of math-rendering-accessible they're expecting window.mathjaxLoadedP to be a Promise, so we also keep the
|
|
350
|
+
// resolve here;
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
resolve();
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
loader: {
|
|
357
|
+
load: ['input/mml'],
|
|
358
|
+
// I just added preLoad: () => {} to prevent the console error: "MathJax.loader.preLoad is not a function",
|
|
359
|
+
// which is being called because in math-rendering-accessible/render-math we're having this line:
|
|
360
|
+
// import * as mr from '@pie-lib/math-rendering';
|
|
361
|
+
// which takes us to: import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';
|
|
362
|
+
// which tries to call MathJax.loader.preLoad.
|
|
363
|
+
// Understand that AllPackages is NOT needed in math-rendering-accessible, so it is not a problem if we hardcode this function.
|
|
364
|
+
// The better solution would be for math-rendering-accessible to import math-rendering only IF needed,
|
|
365
|
+
// but that's actually complicated and could cause other issues.
|
|
366
|
+
preLoad: function preLoad() {},
|
|
367
|
+
// function to call if a component fails to load
|
|
368
|
+
// eslint-disable-next-line no-console
|
|
369
|
+
failed: function failed(error) {
|
|
370
|
+
return console.log("MathJax(".concat(error["package"] || '?', "): ").concat(error.message));
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
tex: texConfig,
|
|
374
|
+
chtml: {
|
|
375
|
+
fontURL: 'https://unpkg.com/mathjax-full@3.2.2/ts/output/chtml/fonts/tex-woff-v2',
|
|
376
|
+
displayAlign: 'center'
|
|
377
|
+
},
|
|
378
|
+
customKey: '@pie-lib/math-rendering-accessible@1',
|
|
379
|
+
options: {
|
|
380
|
+
enableEnrichment: true,
|
|
381
|
+
sre: {
|
|
382
|
+
speech: 'deep'
|
|
383
|
+
},
|
|
384
|
+
menuOptions: {
|
|
385
|
+
settings: {
|
|
386
|
+
assistiveMml: true,
|
|
387
|
+
collapsible: false,
|
|
388
|
+
explorer: false
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}; // Load the MathJax script
|
|
393
|
+
|
|
394
|
+
var script = document.createElement('script');
|
|
395
|
+
script.type = 'text/javascript';
|
|
396
|
+
script.src = "https://cdn.jsdelivr.net/npm/mathjax@".concat(MathJaxVersion, "/es5/tex-chtml-full.js");
|
|
397
|
+
script.async = true;
|
|
398
|
+
document.head.appendChild(script); // at this time of the execution, there's no document.body; setTimeout does the trick
|
|
399
|
+
|
|
400
|
+
setTimeout(function () {
|
|
401
|
+
if (!window.mathjaxLoadedComplete) {
|
|
402
|
+
var _document, _document$body;
|
|
403
|
+
|
|
404
|
+
var mathElements = (_document = document) === null || _document === void 0 ? void 0 : (_document$body = _document.body) === null || _document$body === void 0 ? void 0 : _document$body.querySelectorAll('[data-latex]');
|
|
405
|
+
(mathElements || []).forEach(createPlaceholder);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
exports.initializeMathJax = initializeMathJax;
|
|
412
|
+
|
|
413
|
+
var renderMath = function renderMath(el, renderOpts) {
|
|
414
|
+
var usedForMmlOutput = typeof el === 'string';
|
|
415
|
+
var executeOn = document.body;
|
|
416
|
+
|
|
417
|
+
if (!usedForMmlOutput) {
|
|
418
|
+
// If math-rendering was not available, then:
|
|
419
|
+
// If window.mathjaxLoadedComplete, it means that we initialised MathJax using the function from this file,
|
|
420
|
+
// and it means MathJax is successfully completed, so we can already use it
|
|
421
|
+
if (window.mathjaxLoadedComplete) {
|
|
422
|
+
renderContentsWithMathJax(el);
|
|
423
|
+
} else if (window.mathjaxLoadedP) {
|
|
424
|
+
// However, because there is a small chance that MathJax was initialised by a previous version of math-rendering-accessible,
|
|
425
|
+
// we need to keep the old handling method, which means adding the .then.catch on window.mathjaxLoadedP Promise.
|
|
426
|
+
// We still want to set window.mathjaxLoadedComplete, to prevent adding .then.catch after the first initialization
|
|
427
|
+
// (again, in case MathJax was initialised by a previous math-rendering-accessible version)
|
|
428
|
+
window.mathjaxLoadedP.then(function () {
|
|
429
|
+
window.mathjaxLoadedComplete = true;
|
|
430
|
+
renderContentsWithMathJax(el);
|
|
431
|
+
})["catch"](function (error) {
|
|
432
|
+
return console.error('Error in initializing MathJax:', error);
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
} else {
|
|
436
|
+
// Here we're handling the case when renderMath is being called for mmlOutput
|
|
437
|
+
if (window.MathJax && window.mathjaxLoadedP) {
|
|
438
|
+
var div = document.createElement('div');
|
|
439
|
+
div.innerHTML = el;
|
|
440
|
+
executeOn = div;
|
|
441
|
+
|
|
442
|
+
try {
|
|
443
|
+
MathJax.texReset();
|
|
444
|
+
MathJax.typesetClear();
|
|
445
|
+
window.MathJax.typeset([executeOn]);
|
|
446
|
+
var updatedDocument = window.MathJax.startup.document;
|
|
447
|
+
var list = updatedDocument.math.list;
|
|
448
|
+
var item = list.next;
|
|
449
|
+
var mathMl = toMMl(item.data.root);
|
|
450
|
+
var parsedMathMl = mathMl.replaceAll('\n', '');
|
|
451
|
+
return parsedMathMl;
|
|
452
|
+
} catch (error) {
|
|
453
|
+
console.error('Error rendering math:', error.message);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
return el;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return el;
|
|
460
|
+
}
|
|
461
|
+
}; // this function calls itself
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
(function () {
|
|
465
|
+
initializeMathJax(renderContentWithMathJax);
|
|
466
|
+
window[mathRenderingKEY] = {
|
|
467
|
+
instance: {
|
|
468
|
+
Typeset: renderMath
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
})();
|
|
472
|
+
|
|
473
|
+
var _default = renderMath;
|
|
474
|
+
exports["default"] = _default;
|
|
475
|
+
//# sourceMappingURL=render-math.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/render-math.js"],"names":["visitor","SerializedMmlVisitor","toMMl","node","visitTree","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","mathRenderingKEY","mathRenderingAccessibleKEY","MathJaxVersion","getGlobal","window","fixMathElement","element","dataset","mathHandled","property","textContent","unwrapped","replace","fixMathElements","el","document","mathElements","querySelectorAll","forEach","item","adjustMathMLStyle","nodes","setAttribute","createPlaceholder","previousSibling","classList","contains","originalDisplay","style","display","placeholder","createElement","cssText","add","parentNode","insertBefore","removePlaceholdersAndRestoreDisplay","targetElement","nextElementSibling","undefined","remove","removeExcessMjxContainers","content","elements","mjxContainers","length","i","removeChild","renderContentsWithMathJax","Array","elNode","renderContentWithMathJax","executeOn","body","HTMLElement","mathJaxInstance","instance","texReset","typesetClear","typesetPromise","then","updatedDocument","startup","list","math","next","data","mathMl","root","parsedMathMl","replaceAll","typesetRoot","e","console","error","toString","clear","convertMathJax2ToMathJax3","CommandMap","MathJax","_","input","tex","SymbolMap","requireMap","config","RequireLoad","require","RequireConfiguration","RequireMethods","Require","parser","name","required","GetArgument","match","TexError","hasOwnProperty","Callback","args","isArray","Object","Function","bind","apply","slice","concat","Error","Hub","Queue","m","arguments","fn","promise","Typeset","callback","Register","MessageHook","log","StartupHook","LoadHook","Config","initializeMathJax","mathjaxLoadedP","PreviousMathJaxIsUsed","version","texConfig","macros","parallelogram","overarc","napprox","longdiv","displayMath","autoload","color","colorv2","Promise","resolve","AMSmath","AMSsymbols","AMScd","HTML","noErrors","noUndefined","typeset","ready","mathjax","STATE","core","MathItem","Menu","ui","menu","rerender","prototype","start","TYPESET","handleRetriesFor","call","defaultReady","globalObj","mathjaxLoadedComplete","Date","loader","load","preLoad","failed","message","chtml","fontURL","displayAlign","customKey","options","enableEnrichment","sre","speech","menuOptions","settings","assistiveMml","collapsible","explorer","script","type","src","async","head","appendChild","setTimeout","renderMath","renderOpts","usedForMmlOutput","div","innerHTML"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA,IAAMA,OAAO,GAAG,IAAIC,0CAAJ,EAAhB;;AACA,IAAMC,KAAK,GAAG,SAARA,KAAQ,CAACC,IAAD;AAAA,SAAUH,OAAO,CAACI,SAAR,CAAkBD,IAAlB,CAAV;AAAA,CAAd;;AAEA,IAAME,mBAAmB,GAAG,yBAA5B;AACA,IAAMC,aAAa,GAAG,YAAtB;AAEA,IAAMC,gBAAgB,GAAG,2BAAzB;AACA,IAAMC,0BAA0B,GAAG,sCAAnC;AAEO,IAAMC,cAAc,GAAG,OAAvB;;;AAEA,IAAMC,SAAS,GAAG,SAAZA,SAAY,GAAM;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAI,OAAOC,MAAP,KAAkB,WAAtB,EAAmC;AACjC,QAAI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,YAAMgD,IAAI,GAAGF,eAAe,CAACG,IAAhB,CAAqBD,IAAlC;AACA,YAAM5C,IAAI,GAAG4C,IAAI,CAACE,IAAlB;AACA,YAAME,MAAM,GAAGxE,KAAK,CAACwB,IAAI,CAAC+C,IAAL,CAAUE,IAAX,CAApB;AAEA,YAAMC,YAAY,GAAGF,MAAM,CAACG,UAAP,CAAkB,IAAlB,EAAwB,EAAxB,CAArB;AAEA,eAAOD,YAAP;AACD,OAZD,CAYE,OAAOK,KAAP,EAAc;AACdD,QAAAA,OAAO,CAACC,KAAR,CAAc,uBAAd,EAAuCA,KAAK,CAAC6F,OAA7C;AACD;;AAED,aAAOzJ,EAAP;AACD;;AAED,WAAOA,EAAP;AACD;AACF,CAnDD,C,CAqDA;;;AACA,CAAC,YAAW;AACV4G,EAAAA,iBAAiB,CAACvE,wBAAD,CAAjB;AAEA/C,EAAAA,MAAM,CAACJ,gBAAD,CAAN,GAA2B;AACzBwD,IAAAA,QAAQ,EAAE;AACR0D,MAAAA,OAAO,EAAE0E;AADD;AADe,GAA3B;AAKD,CARD;;eAUeA,U","sourcesContent":["import { wrapMath, unWrapMath } from './normalization';\nimport { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';\nimport TexError from 'mathjax-full/js/input/tex/TexError';\n\nconst visitor = new SerializedMmlVisitor();\nconst toMMl = (node) => visitor.visitTree(node);\n\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\nconst mathRenderingKEY = '@pie-lib/math-rendering@2';\nconst mathRenderingAccessibleKEY = '@pie-lib/math-rendering-accessible@1';\n\nexport const MathJaxVersion = '3.2.2';\n\nexport const getGlobal = () => {\n // TODO does it make sense to use version?\n // const key = `${pkg.name}@${pkg.version.split('.')[0]}`;\n // It looks like Ed made this change when he switched from mathjax3 to mathjax-full\n // I think it was supposed to make sure version 1 (using mathjax3) is not used\n // in combination with version 2 (using mathjax-full)\n // TODO higher level wrappers use this instance of math-rendering, and if 2 different instances are used, math rendering is not working\n // so I will hardcode this for now until a better solution is found\n if (typeof window !== 'undefined') {\n if (!window[mathRenderingAccessibleKEY]) {\n window[mathRenderingAccessibleKEY] = {};\n }\n return window[mathRenderingAccessibleKEY];\n } else {\n return {};\n }\n};\n\nexport const fixMathElement = (element) => {\n if (element.dataset.mathHandled) {\n return;\n }\n\n let property = 'innerText';\n\n if (element.textContent) {\n property = 'textContent';\n }\n\n if (element[property]) {\n element[property] = wrapMath(unWrapMath(element[property]).unwrapped);\n // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.\n // we need to replace the custom embedded elements with valid latex that Mathjax can understand\n element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);\n element.dataset.mathHandled = true;\n }\n};\n\nexport const fixMathElements = (el = document) => {\n const mathElements = el.querySelectorAll('[data-latex]');\n\n mathElements.forEach((item) => fixMathElement(item));\n};\n\nconst adjustMathMLStyle = (el = document) => {\n const nodes = el.querySelectorAll('math');\n nodes.forEach((node) => node.setAttribute('displaystyle', 'true'));\n};\n\nconst createPlaceholder = (element) => {\n if (!element.previousSibling || !element.previousSibling.classList?.contains('math-placeholder')) {\n // Store the original display style before setting it to 'none'\n element.dataset.originalDisplay = element.style.display || '';\n element.style.display = 'none';\n\n const placeholder = document.createElement('span');\n placeholder.style.cssText =\n 'height: 10px; width: 50px; display: inline-block; vertical-align: middle; justify-content: center; background: #fafafa; border-radius: 4px;';\n placeholder.classList.add('math-placeholder');\n element.parentNode?.insertBefore(placeholder, element);\n }\n};\n\nconst removePlaceholdersAndRestoreDisplay = () => {\n document.querySelectorAll('.math-placeholder').forEach((placeholder) => {\n const targetElement = placeholder.nextElementSibling;\n\n if (targetElement && targetElement.dataset?.originalDisplay !== undefined) {\n targetElement.style.display = targetElement.dataset.originalDisplay;\n delete targetElement.dataset.originalDisplay;\n }\n\n placeholder.remove();\n });\n};\nconst removeExcessMjxContainers = (content) => {\n const elements = content.querySelectorAll('[data-latex][data-math-handled=\"true\"]');\n\n elements.forEach((element) => {\n const mjxContainers = element.querySelectorAll('mjx-container');\n\n // Check if there are more than one mjx-container children.\n if (mjxContainers.length > 1) {\n for (let i = 1; i < mjxContainers.length; i++) {\n mjxContainers[i].parentNode.removeChild(mjxContainers[i]);\n }\n }\n });\n};\n\nconst renderContentsWithMathJax = (el) => {\n // el sometimes is an array\n // renderMath is used like that in pie-print-support and pie-element-extensions\n // there seems to be no reason for that, however, it's better to handle the case here\n if (el instanceof Array) {\n el.forEach((elNode) => renderContentWithMathJax(elNode));\n } else {\n renderContentWithMathJax(el);\n }\n};\n\nconst renderContentWithMathJax = (executeOn) => {\n executeOn = executeOn || document.body;\n\n // this happens for charting - mark-label; we receive a ref which is not yet ready ( el = { current: null })\n // we have to fix this in charting\n if (!(executeOn instanceof HTMLElement)) return;\n\n fixMathElements(executeOn);\n adjustMathMLStyle(executeOn);\n\n const mathJaxInstance = getGlobal().instance;\n\n if (mathJaxInstance) {\n // Reset and clear typesetting before processing the new content\n // Reset the tex labels (and automatic equation number).\n\n mathJaxInstance.texReset();\n\n // Reset the typesetting system (font caches, etc.)\n mathJaxInstance.typesetClear();\n\n // Use typesetPromise for asynchronous typesetting\n // Using MathJax.typesetPromise() for asynchronous typesetting to handle situations where additional code needs to be loaded (e.g., for certain TeX commands or characters).\n // This ensures typesetting waits for any needed resources to load and complete processing, unlike the synchronous MathJax.typeset() which can't handle such dynamic loading.\n mathJaxInstance\n .typesetPromise([executeOn])\n .then(() => {\n try {\n removePlaceholdersAndRestoreDisplay();\n removeExcessMjxContainers(executeOn);\n\n const updatedDocument = mathJaxInstance.startup.document;\n const list = updatedDocument.math.list;\n\n for (let item = list.next; typeof item.data !== 'symbol'; item = item.next) {\n const mathMl = toMMl(item.data.root);\n const parsedMathMl = mathMl.replaceAll('\\n', '');\n\n item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);\n item.data.typesetRoot.setAttribute('tabindex', '-1');\n }\n\n // If the original input was a string, return the parsed MathML\n } catch (e) {\n console.error('Error post-processing MathJax typesetting:', e.toString());\n }\n\n // Clearing the document if needed\n mathJaxInstance.startup.document.clear();\n })\n .catch((error) => {\n // If there was an internal error, put the message into the output instead\n\n console.error('Error in typesetting with MathJax:', error);\n });\n }\n};\n\nconst convertMathJax2ToMathJax3 = () => {\n // Make MathJax v2 compatible with v3\n // https://docs.mathjax.org/en/v3.2-latest/upgrading/v2.html#version-2-compatibility-example\n // Replace the require command map with a new one that checks for\n // renamed extensions and converts them to the new names.\n const CommandMap = MathJax._.input.tex.SymbolMap.CommandMap;\n const requireMap = MathJax.config.startup.requireMap;\n const RequireLoad = MathJax._.input.tex.require.RequireConfiguration.RequireLoad;\n const RequireMethods = {\n Require: function(parser, name) {\n let required = parser.GetArgument(name);\n if (required.match(/[^_a-zA-Z0-9]/) || required === '') {\n throw new TexError('BadPackageName', 'Argument for %1 is not a valid package name', name);\n }\n if (requireMap.hasOwnProperty(required)) {\n required = requireMap[required];\n }\n RequireLoad(parser, required);\n },\n };\n\n new CommandMap('require', { require: 'Require' }, RequireMethods);\n\n //\n // Add a replacement for MathJax.Callback command\n //\n MathJax.Callback = function(args) {\n if (Array.isArray(args)) {\n if (args.length === 1 && typeof args[0] === 'function') {\n return args[0];\n } else if (typeof args[0] === 'string' && args[1] instanceof Object && typeof args[1][args[0]] === 'function') {\n return Function.bind.apply(args[1][args[0]], args.slice(1));\n } else if (typeof args[0] === 'function') {\n return Function.bind.apply(args[0], [window].concat(args.slice(1)));\n } else if (typeof args[1] === 'function') {\n return Function.bind.apply(args[1], [args[0]].concat(args.slice(2)));\n }\n } else if (typeof args === 'function') {\n return args;\n }\n throw Error(\"Can't make callback from given data\");\n };\n\n //\n // Add a replacement for MathJax.Hub commands\n //\n MathJax.Hub = {\n Queue: function() {\n for (let i = 0, m = arguments.length; i < m; i++) {\n const fn = MathJax.Callback(arguments[i]);\n MathJax.startup.promise = MathJax.startup.promise.then(fn);\n }\n return MathJax.startup.promise;\n },\n Typeset: function(elements, callback) {\n let promise = MathJax.typesetPromise(elements);\n\n if (callback) {\n promise = promise.then(callback);\n }\n return promise;\n },\n Register: {\n MessageHook: function() {\n console.log('MessageHooks are not supported in version 3');\n },\n StartupHook: function() {\n console.log('StartupHooks are not supported in version 3');\n },\n LoadHook: function() {\n console.log('LoadHooks are not supported in version 3');\n },\n },\n Config: function() {\n console.log('MathJax configurations should be converted for version 3');\n },\n };\n};\nexport const initializeMathJax = (callback) => {\n if (window.mathjaxLoadedP) {\n return;\n }\n\n const PreviousMathJaxIsUsed =\n window.MathJax &&\n window.MathJax.version &&\n window.MathJax.version !== MathJaxVersion &&\n window.MathJax.version[0] === '2';\n\n const texConfig = {\n macros: {\n parallelogram: '\\\\lower.2em{\\\\Huge\\\\unicode{x25B1}}',\n overarc: '\\\\overparen',\n napprox: '\\\\not\\\\approx',\n longdiv: '\\\\enclose{longdiv}',\n },\n displayMath: [\n ['$$', '$$'],\n ['\\\\[', '\\\\]'],\n ],\n };\n\n if (PreviousMathJaxIsUsed) {\n texConfig.autoload = {\n color: [], // don't autoload the color extension\n colorv2: ['color'], // do autoload the colorv2 extension\n };\n }\n\n // Create a new promise that resolves when MathJax is ready\n window.mathjaxLoadedP = new Promise((resolve) => {\n // Set up the MathJax configuration\n window.MathJax = {\n startup: {\n //\n // Mapping of old extension names to new ones\n //\n requireMap: PreviousMathJaxIsUsed\n ? {\n AMSmath: 'ams',\n AMSsymbols: 'ams',\n AMScd: 'amscd',\n HTML: 'html',\n noErrors: 'noerrors',\n noUndefined: 'noundefined',\n }\n : {},\n typeset: false,\n ready: () => {\n if (PreviousMathJaxIsUsed) {\n convertMathJax2ToMathJax3();\n }\n\n const { mathjax } = MathJax._.mathjax;\n const { STATE } = MathJax._.core.MathItem;\n const { Menu } = MathJax._.ui.menu.Menu;\n const rerender = Menu.prototype.rerender;\n Menu.prototype.rerender = function(start = STATE.TYPESET) {\n mathjax.handleRetriesFor(() => rerender.call(this, start));\n };\n MathJax.startup.defaultReady();\n // Set the MathJax instance in the global object\n\n const globalObj = getGlobal();\n globalObj.instance = MathJax;\n\n window.mathjaxLoadedComplete = true;\n console.log('MathJax has initialised!', new Date().toString());\n\n // in this file, initializeMathJax is called with a callback that has to be executed when MathJax was loaded\n if (callback) {\n callback();\n }\n\n // but previous versions of math-rendering-accessible they're expecting window.mathjaxLoadedP to be a Promise, so we also keep the\n // resolve here;\n resolve();\n },\n },\n loader: {\n load: ['input/mml'],\n // I just added preLoad: () => {} to prevent the console error: \"MathJax.loader.preLoad is not a function\",\n // which is being called because in math-rendering-accessible/render-math we're having this line:\n // import * as mr from '@pie-lib/math-rendering';\n // which takes us to: import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';\n // which tries to call MathJax.loader.preLoad.\n // Understand that AllPackages is NOT needed in math-rendering-accessible, so it is not a problem if we hardcode this function.\n // The better solution would be for math-rendering-accessible to import math-rendering only IF needed,\n // but that's actually complicated and could cause other issues.\n preLoad: () => {},\n // function to call if a component fails to load\n // eslint-disable-next-line no-console\n failed: (error) => console.log(`MathJax(${error.package || '?'}): ${error.message}`),\n },\n tex: texConfig,\n chtml: {\n fontURL: 'https://unpkg.com/mathjax-full@3.2.2/ts/output/chtml/fonts/tex-woff-v2',\n displayAlign: 'center',\n },\n customKey: '@pie-lib/math-rendering-accessible@1',\n options: {\n enableEnrichment: true,\n sre: {\n speech: 'deep',\n },\n menuOptions: {\n settings: {\n assistiveMml: true,\n collapsible: false,\n explorer: false,\n },\n },\n },\n };\n // Load the MathJax script\n const script = document.createElement('script');\n script.type = 'text/javascript';\n script.src = `https://cdn.jsdelivr.net/npm/mathjax@${MathJaxVersion}/es5/tex-chtml-full.js`;\n script.async = true;\n document.head.appendChild(script);\n\n // at this time of the execution, there's no document.body; setTimeout does the trick\n setTimeout(() => {\n if (!window.mathjaxLoadedComplete) {\n const mathElements = document?.body?.querySelectorAll('[data-latex]');\n (mathElements || []).forEach(createPlaceholder);\n }\n });\n });\n};\n\nconst renderMath = (el, renderOpts) => {\n const usedForMmlOutput = typeof el === 'string';\n let executeOn = document.body;\n\n if (!usedForMmlOutput) {\n // If math-rendering was not available, then:\n // If window.mathjaxLoadedComplete, it means that we initialised MathJax using the function from this file,\n // and it means MathJax is successfully completed, so we can already use it\n if (window.mathjaxLoadedComplete) {\n renderContentsWithMathJax(el);\n } else if (window.mathjaxLoadedP) {\n // However, because there is a small chance that MathJax was initialised by a previous version of math-rendering-accessible,\n // we need to keep the old handling method, which means adding the .then.catch on window.mathjaxLoadedP Promise.\n // We still want to set window.mathjaxLoadedComplete, to prevent adding .then.catch after the first initialization\n // (again, in case MathJax was initialised by a previous math-rendering-accessible version)\n window.mathjaxLoadedP\n .then(() => {\n window.mathjaxLoadedComplete = true;\n renderContentsWithMathJax(el);\n })\n .catch((error) => console.error('Error in initializing MathJax:', error));\n }\n } else {\n // Here we're handling the case when renderMath is being called for mmlOutput\n if (window.MathJax && window.mathjaxLoadedP) {\n const div = document.createElement('div');\n\n div.innerHTML = el;\n executeOn = div;\n\n try {\n MathJax.texReset();\n MathJax.typesetClear();\n window.MathJax.typeset([executeOn]);\n const updatedDocument = window.MathJax.startup.document;\n const list = updatedDocument.math.list;\n const item = list.next;\n const mathMl = toMMl(item.data.root);\n\n const parsedMathMl = mathMl.replaceAll('\\n', '');\n\n return parsedMathMl;\n } catch (error) {\n console.error('Error rendering math:', error.message);\n }\n\n return el;\n }\n\n return el;\n }\n};\n\n// this function calls itself\n(function() {\n initializeMathJax(renderContentWithMathJax);\n\n window[mathRenderingKEY] = {\n instance: {\n Typeset: renderMath,\n },\n };\n})();\n\nexport default renderMath;\n"],"file":"render-math.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/math-rendering-accessible",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "math rendering utilities",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@pie-framework/mathml-to-latex": "1.4.4",
|
|
14
|
-
"@pie-lib/math-rendering": "^3.
|
|
14
|
+
"@pie-lib/math-rendering": "^3.10.0",
|
|
15
15
|
"debug": "^4.1.1",
|
|
16
16
|
"lodash": "^4.17.11",
|
|
17
17
|
"mathjax-full": "3.2.2",
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
"react": "^16.8.1",
|
|
20
20
|
"slate": "^0.36.2"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "7ca3b0a214af57d742b4a9de6d8b424d31da1469",
|
|
23
23
|
"scripts": {}
|
|
24
24
|
}
|