@pie-lib/math-rendering 3.2.1 → 3.4.0-beta.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 +16 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/__tests__/mml-to-latex.test.js +18 -0
- package/lib/__tests__/normalization.test.js +54 -0
- package/lib/__tests__/render-math.test.js +170 -0
- package/lib/index.js +1 -1
- package/lib/mml-to-latex.js +3 -5
- package/lib/mstack/__tests__/chtml.test.js +151 -0
- package/lib/mstack/chtml.js +1 -1
- package/lib/mstack/index.js +1 -1
- package/lib/mstack/mml.js +1 -1
- package/lib/normalization.js +1 -1
- package/lib/render-math.js +157 -77
- package/package.json +4 -4
- package/src/__tests__/mml-to-latex.test.js +15 -0
- package/src/__tests__/normalization.test.js +51 -0
- package/src/__tests__/render-math.test.js +155 -0
- package/src/mml-to-latex.js +2 -2
- package/src/mstack/__tests__/__snapshots__/chtml.test.js.snap +9 -0
- package/src/mstack/__tests__/chtml.test.js +104 -0
- package/src/render-math.js +127 -71
- package/lib/index.js.map +0 -1
- package/lib/mml-to-latex.js.map +0 -1
- package/lib/mstack/chtml.js.map +0 -1
- package/lib/mstack/index.js.map +0 -1
- package/lib/mstack/mml.js.map +0 -1
- package/lib/normalization.js.map +0 -1
- package/lib/render-math.js.map +0 -1
- package/playground/demo.html +0 -958
- package/playground/demo.js +0 -108
- package/playground/main.html +0 -158
- package/playground/main.js +0 -16
- package/playground/webpack.config.js +0 -29
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`chtml implicit one row 1`] = `"<table><tr><td></td><td>1</td></tr></table>"`;
|
|
4
|
+
|
|
5
|
+
exports[`chtml one row 1`] = `"<table><tr><td></td><td>1</td></tr></table>"`;
|
|
6
|
+
|
|
7
|
+
exports[`chtml two rows 1`] = `"<table><tr><td></td><td>1</td></tr><tr><td></td><td>2</td></tr></table>"`;
|
|
8
|
+
|
|
9
|
+
exports[`chtml two rows with operator 1`] = `"<table><tr><td></td><td>1</td></tr><tr><td class=\\"inner\\">mo:+</td><td>2</td></tr></table>"`;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { getStackData, Line, Row, CHTMLmstack } from '../chtml';
|
|
2
|
+
// import { CHTMLWrapper, instance } from 'mathjax-full/js/output/chtml/Wrapper';
|
|
3
|
+
import { JSDOM } from 'jsdom';
|
|
4
|
+
|
|
5
|
+
jest.mock('mathjax-full/js/output/chtml/Wrapper', () => {
|
|
6
|
+
const instance = {
|
|
7
|
+
adaptor: {
|
|
8
|
+
document: {
|
|
9
|
+
createElement: jest.fn(),
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
standardCHTMLnode: jest.fn(),
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
instance,
|
|
17
|
+
CHTMLWrapper: class {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.adaptor = { document: { createElement: jest.fn() } };
|
|
20
|
+
this.document = {};
|
|
21
|
+
// return instance;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const node = (kind, extras) => ({ kind, childNodes: [], ...extras });
|
|
28
|
+
|
|
29
|
+
const textNode = (text) => node('text', { text, node: { kind: 'text', text } });
|
|
30
|
+
const mn = (text) => node('mn', { childNodes: [textNode(text)] });
|
|
31
|
+
const mo = (text) =>
|
|
32
|
+
node('mo', {
|
|
33
|
+
childNodes: [textNode(text)],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const mco = (text) => ({
|
|
37
|
+
...mo(text),
|
|
38
|
+
|
|
39
|
+
toCHTML: (n) => {
|
|
40
|
+
const t = `mo:${text}`;
|
|
41
|
+
n.textContent = t;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const msrow = (...childNodes) => node('msrow', { childNodes });
|
|
46
|
+
const mstack = (...rows) => node('mstack', { childNodes: rows });
|
|
47
|
+
const msline = () => node('msline');
|
|
48
|
+
describe('getStackData', () => {
|
|
49
|
+
it.each`
|
|
50
|
+
input | expected
|
|
51
|
+
${mstack(msrow(mo('+'), mn('111')))} | ${[new Row(['1', '1', '1'], mo('+'))]}
|
|
52
|
+
${mstack(msrow(mn('111')))} | ${[new Row(['1', '1', '1'])]}
|
|
53
|
+
${mstack(msrow(mn('1'), mn('1')))} | ${[new Row(['1', '1'])]}
|
|
54
|
+
${mstack(msrow(mn('1')), mn('1'))} | ${[new Row(['1']), new Row(['1'])]}
|
|
55
|
+
${mstack(msline())} | ${[new Line()]}
|
|
56
|
+
${mstack(mn('1'), msline(), msrow(mo('+'), mn('1')))} | ${[new Row(['1']), new Line(), new Row(['1'], mo('+'))]}
|
|
57
|
+
${mstack(mn('1'), mn('1'))} | ${[new Row(['1']), new Row(['1'])]}
|
|
58
|
+
`('$input => $expected', ({ input, expected }) => {
|
|
59
|
+
const d = getStackData(input);
|
|
60
|
+
// console.log('d:', d);
|
|
61
|
+
// console.log('e:', expected);
|
|
62
|
+
expect({ ...d }).toEqual({ ...expected });
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('Row', () => {
|
|
67
|
+
describe('pad', () => {
|
|
68
|
+
it.each`
|
|
69
|
+
cols | count | expected
|
|
70
|
+
${[]} | ${0} | ${[]}
|
|
71
|
+
${[1]} | ${1} | ${[1]}
|
|
72
|
+
${[1]} | ${2} | ${['__pad__', 1]}
|
|
73
|
+
${[1]} | ${3} | ${['__pad__', '__pad__', 1]}
|
|
74
|
+
`('pads to the right', ({ cols, count, expected }) => {
|
|
75
|
+
const r = new Row(cols);
|
|
76
|
+
const p = r.pad(count, 'right');
|
|
77
|
+
expect(p).toEqual(expected);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe.each`
|
|
83
|
+
label | tree
|
|
84
|
+
${'one row'} | ${[msrow(mn('1'))]}
|
|
85
|
+
${'implicit one row'} | ${[mn('1')]}
|
|
86
|
+
${'two rows'} | ${[msrow(mn('1')), msrow(mn('2'))]}
|
|
87
|
+
${'two rows with operator'} | ${[msrow(mn('1')), msrow(mco('+'), mn('2'))]}
|
|
88
|
+
`('chtml', ({ label, tree }) => {
|
|
89
|
+
let html;
|
|
90
|
+
|
|
91
|
+
beforeEach(() => {
|
|
92
|
+
const chtml = new CHTMLmstack({}, {});
|
|
93
|
+
const dom = new JSDOM(`<!DOCTYPE html><body></body>`);
|
|
94
|
+
chtml.standardCHTMLnode = (parent) => parent;
|
|
95
|
+
chtml.ce = dom.window.document.createElement.bind(dom.window.document);
|
|
96
|
+
chtml.childNodes = tree;
|
|
97
|
+
chtml.toCHTML(dom.window.document.body);
|
|
98
|
+
html = dom.window.document.body.innerHTML;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it(label, () => {
|
|
102
|
+
expect(html).toMatchSnapshot();
|
|
103
|
+
});
|
|
104
|
+
});
|
package/src/render-math.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { mathjax } from 'mathjax-full/js/mathjax';
|
|
2
|
+
import { MathJax as globalMathjax } from 'mathjax-full/js/components/global';
|
|
3
|
+
import { AssistiveMmlHandler } from 'mathjax-full/js/a11y/assistive-mml';
|
|
4
|
+
import { EnrichHandler } from 'mathjax-full/js/a11y/semantic-enrich';
|
|
5
|
+
import { MenuHandler } from 'mathjax-full/js/ui/menu/MenuHandler';
|
|
6
|
+
import { FindMathML } from 'mathjax-full/js/input/mathml/FindMathML';
|
|
2
7
|
import { MathML } from 'mathjax-full/js/input/mathml';
|
|
3
8
|
import { TeX } from 'mathjax-full/js/input/tex';
|
|
4
9
|
|
|
@@ -6,12 +11,19 @@ import { CHTML } from 'mathjax-full/js/output/chtml';
|
|
|
6
11
|
import { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';
|
|
7
12
|
import { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';
|
|
8
13
|
import { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';
|
|
14
|
+
import { engineReady } from 'speech-rule-engine/js/common/system';
|
|
9
15
|
|
|
10
16
|
if (typeof window !== 'undefined') {
|
|
11
17
|
RegisterHTMLHandler(browserAdaptor());
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
let sreReady = false;
|
|
21
|
+
|
|
22
|
+
engineReady().then(() => {
|
|
23
|
+
sreReady = true;
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// import pkg from '../../package.json';
|
|
15
27
|
import { mmlNodes, chtmlNodes } from './mstack';
|
|
16
28
|
import debug from 'debug';
|
|
17
29
|
import { wrapMath, unWrapMath } from './normalization';
|
|
@@ -19,6 +31,7 @@ import { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';
|
|
|
19
31
|
import { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';
|
|
20
32
|
import { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';
|
|
21
33
|
import { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';
|
|
34
|
+
import { HTMLDomStrings } from 'mathjax-full/js/handlers/html/HTMLDomStrings';
|
|
22
35
|
|
|
23
36
|
const visitor = new SerializedMmlVisitor();
|
|
24
37
|
const toMMl = (node) => visitor.visitTree(node);
|
|
@@ -29,7 +42,15 @@ const NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
|
|
|
29
42
|
const NEWLINE_LATEX = '\\newline ';
|
|
30
43
|
|
|
31
44
|
const getGlobal = () => {
|
|
32
|
-
|
|
45
|
+
// TODO does it make sense to use version?
|
|
46
|
+
// const key = `${pkg.name}@${pkg.version.split('.')[0]}`;
|
|
47
|
+
// It looks like Ed made this change when he switched from mathjax3 to mathjax-full
|
|
48
|
+
// I think it was supposed to make sure version 1 (using mathjax3) is not used
|
|
49
|
+
// in combination with version 2 (using mathjax-full)
|
|
50
|
+
|
|
51
|
+
// TODO higher level wrappers use this instance of math-rendering, and if 2 different instances are used, math rendering is not working
|
|
52
|
+
// so I will hardcode this for now until a better solution is found
|
|
53
|
+
const key = '@pie-lib/math-rendering@2';
|
|
33
54
|
|
|
34
55
|
if (typeof window !== 'undefined') {
|
|
35
56
|
if (!window[key]) {
|
|
@@ -81,6 +102,18 @@ const adjustMathMLStyle = (el = document) => {
|
|
|
81
102
|
nodes.forEach((node) => node.setAttribute('displaystyle', 'true'));
|
|
82
103
|
};
|
|
83
104
|
|
|
105
|
+
class myFindMathML extends FindMathML {
|
|
106
|
+
processMath(set) {
|
|
107
|
+
const adaptor = this.adaptor;
|
|
108
|
+
for (const mml of Array.from(set)) {
|
|
109
|
+
if (adaptor.kind(adaptor.parent(mml)) === 'mjx-assistive-mml') {
|
|
110
|
+
set.delete(mml);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return super.processMath(set);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
84
117
|
const createMathMLInstance = (opts, docProvided = document) => {
|
|
85
118
|
opts = opts || defaultOpts();
|
|
86
119
|
|
|
@@ -111,56 +144,33 @@ const createMathMLInstance = (opts, docProvided = document) => {
|
|
|
111
144
|
['\\(', '\\)'],
|
|
112
145
|
],
|
|
113
146
|
processEscapes: true,
|
|
114
|
-
options: {
|
|
115
|
-
enableExplorer: true,
|
|
116
|
-
enableAssistiveMml: true,
|
|
117
|
-
a11y: {
|
|
118
|
-
speech: true,
|
|
119
|
-
braille: true,
|
|
120
|
-
subtitles: true,
|
|
121
|
-
},
|
|
122
|
-
sre: {
|
|
123
|
-
domain: 'default',
|
|
124
|
-
style: 'default',
|
|
125
|
-
locale: 'en',
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
147
|
}
|
|
129
148
|
: {
|
|
130
149
|
packages,
|
|
131
150
|
macros,
|
|
132
|
-
options: {
|
|
133
|
-
enableExplorer: true,
|
|
134
|
-
enableAssistiveMml: true,
|
|
135
|
-
a11y: {
|
|
136
|
-
speech: true,
|
|
137
|
-
braille: true,
|
|
138
|
-
subtitles: true,
|
|
139
|
-
},
|
|
140
|
-
sre: {
|
|
141
|
-
domain: 'default',
|
|
142
|
-
style: 'default',
|
|
143
|
-
locale: 'en',
|
|
144
|
-
},
|
|
145
|
-
},
|
|
146
151
|
};
|
|
147
152
|
|
|
148
153
|
const mmlConfig = {
|
|
149
|
-
options: {
|
|
150
|
-
a11y: {
|
|
151
|
-
speech: true,
|
|
152
|
-
braille: true,
|
|
153
|
-
subtitles: true,
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
154
|
parseError: function(node) {
|
|
157
155
|
// function to process parsing errors
|
|
158
156
|
// eslint-disable-next-line no-console
|
|
159
157
|
console.log('error:', node);
|
|
160
158
|
this.error(this.adaptor.textContent(node).replace(/\n.*/g, ''));
|
|
161
159
|
},
|
|
160
|
+
FindMathML: new myFindMathML(),
|
|
162
161
|
};
|
|
163
162
|
|
|
163
|
+
let cachedMathjax;
|
|
164
|
+
|
|
165
|
+
if (globalMathjax && globalMathjax.version !== mathjax.version) {
|
|
166
|
+
// handling other MathJax version on the page
|
|
167
|
+
// replacing it temporarily with the version we have
|
|
168
|
+
window.MathJax._ = window.MathJax._ || {};
|
|
169
|
+
window.MathJax.config = window.MathJax.config || {};
|
|
170
|
+
cachedMathjax = window.MathJax;
|
|
171
|
+
Object.assign(globalMathjax, mathjax);
|
|
172
|
+
}
|
|
173
|
+
|
|
164
174
|
const fontURL = `https://unpkg.com/mathjax-full@${mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;
|
|
165
175
|
const htmlConfig = {
|
|
166
176
|
fontURL,
|
|
@@ -169,12 +179,6 @@ const createMathMLInstance = (opts, docProvided = document) => {
|
|
|
169
179
|
...CHTMLWrapperFactory.defaultNodes,
|
|
170
180
|
...chtmlNodes,
|
|
171
181
|
}),
|
|
172
|
-
|
|
173
|
-
options: {
|
|
174
|
-
renderActions: {
|
|
175
|
-
assistiveMml: [['AssistiveMmlHandler']],
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
182
|
};
|
|
179
183
|
|
|
180
184
|
const mml = new MathML(mmlConfig);
|
|
@@ -183,8 +187,12 @@ const createMathMLInstance = (opts, docProvided = document) => {
|
|
|
183
187
|
...MmlFactory.defaultNodes,
|
|
184
188
|
...mmlNodes,
|
|
185
189
|
});
|
|
190
|
+
const classFactory = EnrichHandler(
|
|
191
|
+
MenuHandler(AssistiveMmlHandler(mathjax.handlers.handlesDocument(docProvided))),
|
|
192
|
+
mml,
|
|
193
|
+
);
|
|
186
194
|
|
|
187
|
-
const html =
|
|
195
|
+
const html = classFactory.create(docProvided, {
|
|
188
196
|
compileError: (mj, math, err) => {
|
|
189
197
|
// eslint-disable-next-line no-console
|
|
190
198
|
console.log('bad math?:', math);
|
|
@@ -199,27 +207,42 @@ const createMathMLInstance = (opts, docProvided = document) => {
|
|
|
199
207
|
doc.typesetError(math, err);
|
|
200
208
|
},
|
|
201
209
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
menuOptions: {
|
|
205
|
-
settings: {
|
|
206
|
-
assistiveMml: true,
|
|
207
|
-
collapsible: true,
|
|
208
|
-
explorer: true,
|
|
209
|
-
},
|
|
210
|
-
},
|
|
210
|
+
sre: {
|
|
211
|
+
speech: 'deep',
|
|
211
212
|
},
|
|
213
|
+
enrichSpeech: 'deep',
|
|
212
214
|
|
|
213
215
|
InputJax: [new TeX(texConfig), mml],
|
|
214
216
|
OutputJax: new CHTML(htmlConfig),
|
|
217
|
+
DomStrings: new HTMLDomStrings({
|
|
218
|
+
skipHtmlTags: [
|
|
219
|
+
'script',
|
|
220
|
+
'noscript',
|
|
221
|
+
'style',
|
|
222
|
+
'textarea',
|
|
223
|
+
'pre',
|
|
224
|
+
'code',
|
|
225
|
+
'annotation',
|
|
226
|
+
'annotation-xml',
|
|
227
|
+
'mjx-assistive-mml',
|
|
228
|
+
'mjx-container',
|
|
229
|
+
],
|
|
230
|
+
}),
|
|
215
231
|
});
|
|
216
232
|
|
|
217
233
|
// Note: we must set this *after* mathjax.document (no idea why)
|
|
218
234
|
mml.setMmlFactory(customMmlFactory);
|
|
219
235
|
|
|
236
|
+
if (cachedMathjax) {
|
|
237
|
+
// if we have a cached version, we replace it here
|
|
238
|
+
window.MathJax = cachedMathjax;
|
|
239
|
+
}
|
|
240
|
+
|
|
220
241
|
return html;
|
|
221
242
|
};
|
|
222
243
|
|
|
244
|
+
let enrichSpeechInitialized = false;
|
|
245
|
+
|
|
223
246
|
const bootstrap = (opts) => {
|
|
224
247
|
if (typeof window === 'undefined') {
|
|
225
248
|
return { Typeset: () => ({}) };
|
|
@@ -231,33 +254,66 @@ const bootstrap = (opts) => {
|
|
|
231
254
|
version: mathjax.version,
|
|
232
255
|
html: html,
|
|
233
256
|
Typeset: function(...elements) {
|
|
234
|
-
const
|
|
235
|
-
.findMath(elements.length ? { elements } : {})
|
|
236
|
-
.compile()
|
|
237
|
-
.getMetrics()
|
|
238
|
-
.typeset()
|
|
239
|
-
.updateDocument();
|
|
257
|
+
const attemptRender = (temporary = false) => {
|
|
258
|
+
let updatedDocument = this.html.findMath(elements.length ? { elements } : {}).compile();
|
|
240
259
|
|
|
241
|
-
|
|
242
|
-
|
|
260
|
+
if (!temporary && sreReady) {
|
|
261
|
+
updatedDocument = updatedDocument.enrich();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
updatedDocument = updatedDocument
|
|
265
|
+
.getMetrics()
|
|
266
|
+
.typeset()
|
|
267
|
+
.assistiveMml()
|
|
268
|
+
.attachSpeech()
|
|
269
|
+
.addMenu()
|
|
270
|
+
.updateDocument();
|
|
243
271
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
272
|
+
if (!enrichSpeechInitialized && typeof updatedDocument.math.list?.next?.data === 'object') {
|
|
273
|
+
enrichSpeechInitialized = true;
|
|
274
|
+
}
|
|
247
275
|
|
|
248
|
-
|
|
276
|
+
try {
|
|
277
|
+
const list = updatedDocument.math.list;
|
|
278
|
+
|
|
279
|
+
if (list) {
|
|
280
|
+
for (let item = list.next; typeof item.data !== 'symbol'; item = item.next) {
|
|
281
|
+
const mathMl = toMMl(item.data.root);
|
|
282
|
+
const parsedMathMl = mathMl.replaceAll('\n', '');
|
|
283
|
+
|
|
284
|
+
item.data.typesetRoot.setAttribute('data-mathml', parsedMathMl);
|
|
285
|
+
item.data.typesetRoot.setAttribute('tabindex', '-1');
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} catch (e) {
|
|
289
|
+
// eslint-disable-next-line no-console
|
|
290
|
+
console.error(e.toString());
|
|
249
291
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
292
|
+
|
|
293
|
+
updatedDocument.clear();
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
if (!enrichSpeechInitialized) {
|
|
297
|
+
attemptRender(true);
|
|
253
298
|
}
|
|
254
299
|
|
|
255
|
-
|
|
300
|
+
mathjax.handleRetriesFor(() => {
|
|
301
|
+
attemptRender();
|
|
302
|
+
});
|
|
256
303
|
},
|
|
257
304
|
};
|
|
258
305
|
};
|
|
259
306
|
|
|
260
307
|
const renderMath = (el, renderOpts) => {
|
|
308
|
+
if (
|
|
309
|
+
window &&
|
|
310
|
+
window.MathJax &&
|
|
311
|
+
window.MathJax.customKey &&
|
|
312
|
+
window.MathJax.customKey == '@pie-lib/math-rendering-accessible@1'
|
|
313
|
+
) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
|
|
261
317
|
const isString = typeof el === 'string';
|
|
262
318
|
let executeOn = document.body;
|
|
263
319
|
|
|
@@ -303,9 +359,9 @@ const renderMath = (el, renderOpts) => {
|
|
|
303
359
|
return;
|
|
304
360
|
}
|
|
305
361
|
|
|
306
|
-
if (el instanceof Element) {
|
|
362
|
+
if (el instanceof Element && getGlobal().instance?.Typeset) {
|
|
307
363
|
getGlobal().instance.Typeset(el);
|
|
308
|
-
} else if (el.length) {
|
|
364
|
+
} else if (el.length && getGlobal().instance?.Typeset) {
|
|
309
365
|
const arr = Array.from(el);
|
|
310
366
|
getGlobal().instance.Typeset(...arr);
|
|
311
367
|
}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/lib/mml-to-latex.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mml-to-latex.js"],"names":["mathml","Mathml2latex","convert"],"mappings":";;;;;;;;;AAAA;;eACe,kBAACA,MAAD;AAAA,SAAYC,0BAAaC,OAAb,CAAqBF,MAArB,CAAZ;AAAA,C","sourcesContent":["import Mathml2latex from 'mathml-to-latex';\nexport default (mathml) => Mathml2latex.convert(mathml);\n"],"file":"mml-to-latex.js"}
|
package/lib/mstack/chtml.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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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M,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"}
|
package/lib/mstack/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/lib/mstack/mml.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/lib/normalization.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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","endsWith","unwrapped","substring","length"],"mappings":";;;;;;;;;;;;;;;AAAO,IAAMA,YAAY,GAAG,EAArB;;AAEPA,YAAY,C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kB,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"}
|
package/lib/render-math.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/render-math.js"],"names":["window","visitor","SerializedMmlVisitor","toMMl","node","visitTree","log","NEWLINE_BLOCK_REGEX","NEWLINE_LATEX","getGlobal","key","pkg","name","version","split","defaultOpts","opts","fixMathElement","element","dataset","mathHandled","property","textContent","unwrapped","replace","fixMathElements","el","document","mathElements","querySelectorAll","forEach","item","adjustMathMLStyle","nodes","setAttribute","createMathMLInstance","docProvided","useSingleDollar","console","warn","packages","AllPackages","filter","push","macros","parallelogram","overarc","napprox","longdiv","texConfig","inlineMath","processEscapes","options","enableExplorer","enableAssistiveMml","a11y","speech","braille","subtitles","sre","domain","style","locale","mmlConfig","parseError","error","adaptor","fontURL","mathjax","htmlConfig","wrapperFactory","CHTMLWrapperFactory","defaultNodes","chtmlNodes","renderActions","assistiveMml","mml","MathML","customMmlFactory","MmlFactory","mmlNodes","html","compileError","mj","math","err","typesetError","doc","menuOptions","settings","collapsible","explorer","InputJax","TeX","OutputJax","CHTML","setMmlFactory","bootstrap","Typeset","elements","updatedDocument","findMath","length","compile","getMetrics","typeset","updateDocument","list","next","data","mathMl","root","parsedMathMl","replaceAll","typesetRoot","e","toString","clear","renderMath","renderOpts","isString","executeOn","body","div","createElement","innerHTML","undefined","instance","Element","arr","Array","from","CHTMLmspace","styles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AAAjB,SAAS,GAAGsH,QAAZ,EAAqB7B,OAArB,gEAAgC+B,GAAhC;AACD;AACF,CApDD;AAsDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAG,oBAAYC,MAAZ,GAAqB;AACnB,gBAAc;AACZC,IAAAA,OAAO,EAAE,OADG;AAEZ,kBAAc,QAFF;AAGZC,IAAAA,MAAM,EAAE;AAHI;AADK,CAArB;eAQejB,U","sourcesContent":["import { mathjax } from 'mathjax-full/js/mathjax';\nimport { MathML } from 'mathjax-full/js/input/mathml';\nimport { TeX } from 'mathjax-full/js/input/tex';\n\nimport { CHTML } from 'mathjax-full/js/output/chtml';\nimport { RegisterHTMLHandler } from 'mathjax-full/js/handlers/html';\nimport { browserAdaptor } from 'mathjax-full/js/adaptors/browserAdaptor';\nimport { AllPackages } from 'mathjax-full/js/input/tex/AllPackages';\n\nif (typeof window !== 'undefined') {\n RegisterHTMLHandler(browserAdaptor());\n}\n\nimport pkg from '../package.json';\nimport { mmlNodes, chtmlNodes } from './mstack';\nimport debug from 'debug';\nimport { wrapMath, unWrapMath } from './normalization';\nimport { MmlFactory } from 'mathjax-full/js/core/MmlTree/MmlFactory';\nimport { SerializedMmlVisitor } from 'mathjax-full/js/core/MmlTree/SerializedMmlVisitor';\nimport { CHTMLWrapperFactory } from 'mathjax-full/js/output/chtml/WrapperFactory';\nimport { CHTMLmspace } from 'mathjax-full/js/output/chtml/Wrappers/mspace';\n\nconst visitor = new SerializedMmlVisitor();\nconst toMMl = (node) => visitor.visitTree(node);\n\nconst log = debug('pie-lib:math-rendering');\n\nconst NEWLINE_BLOCK_REGEX = /\\\\embed\\{newLine\\}\\[\\]/g;\nconst NEWLINE_LATEX = '\\\\newline ';\n\nconst getGlobal = () => {\n const key = `${pkg.name}@${pkg.version.split('.')[0]}`;\n\n if (typeof window !== 'undefined') {\n if (!window[key]) {\n window[key] = {};\n }\n return window[key];\n } else {\n return {};\n }\n};\n\n/** Add temporary support for a global singleDollar override\n * <code>\n * // This will enable single dollar rendering\n * window.pie = window.pie || {};\n * window.pie.mathRendering = {useSingleDollar: true };\n * </code>\n */\nconst defaultOpts = () => getGlobal().opts || {};\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 createMathMLInstance = (opts, docProvided = document) => {\n opts = opts || defaultOpts();\n\n if (opts.useSingleDollar) {\n // eslint-disable-next-line\n console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\\\(...\\\\)');\n }\n\n const packages = AllPackages.filter((name) => name !== 'bussproofs'); // Bussproofs needs an output jax\n\n // The autoload extension predefines all the macros from the extensions that haven't been loaded already\n // so that they automatically load the needed extension when they are first used\n packages.push('autoload');\n\n const macros = {\n parallelogram: '\\\\lower.2em{\\\\Huge\\\\unicode{x25B1}}',\n overarc: '\\\\overparen',\n napprox: '\\\\not\\\\approx',\n longdiv: '\\\\enclose{longdiv}',\n };\n\n const texConfig = opts.useSingleDollar\n ? {\n packages,\n macros,\n inlineMath: [\n ['$', '$'],\n ['\\\\(', '\\\\)'],\n ],\n processEscapes: true,\n options: {\n enableExplorer: true,\n enableAssistiveMml: true,\n a11y: {\n speech: true,\n braille: true,\n subtitles: true,\n },\n sre: {\n domain: 'default',\n style: 'default',\n locale: 'en',\n },\n },\n }\n : {\n packages,\n macros,\n options: {\n enableExplorer: true,\n enableAssistiveMml: true,\n a11y: {\n speech: true,\n braille: true,\n subtitles: true,\n },\n sre: {\n domain: 'default',\n style: 'default',\n locale: 'en',\n },\n },\n };\n\n const mmlConfig = {\n options: {\n a11y: {\n speech: true,\n braille: true,\n subtitles: true,\n },\n },\n parseError: function(node) {\n // function to process parsing errors\n // eslint-disable-next-line no-console\n console.log('error:', node);\n this.error(this.adaptor.textContent(node).replace(/\\n.*/g, ''));\n },\n };\n\n const fontURL = `https://unpkg.com/mathjax-full@${mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;\n const htmlConfig = {\n fontURL,\n\n wrapperFactory: new CHTMLWrapperFactory({\n ...CHTMLWrapperFactory.defaultNodes,\n ...chtmlNodes,\n }),\n\n options: {\n renderActions: {\n assistiveMml: [['AssistiveMmlHandler']],\n },\n },\n };\n\n const mml = new MathML(mmlConfig);\n\n const customMmlFactory = new MmlFactory({\n ...MmlFactory.defaultNodes,\n ...mmlNodes,\n });\n\n const html = mathjax.document(docProvided, {\n compileError: (mj, math, err) => {\n // eslint-disable-next-line no-console\n console.log('bad math?:', math);\n // eslint-disable-next-line no-console\n console.error(err);\n },\n typesetError: function(doc, math, err) {\n // eslint-disable-next-line no-console\n console.log('typeset error');\n // eslint-disable-next-line no-console\n console.error(err);\n doc.typesetError(math, err);\n },\n\n options: {\n enableAssistiveMml: true,\n menuOptions: {\n settings: {\n assistiveMml: true,\n collapsible: true,\n explorer: true,\n },\n },\n },\n\n InputJax: [new TeX(texConfig), mml],\n OutputJax: new CHTML(htmlConfig),\n });\n\n // Note: we must set this *after* mathjax.document (no idea why)\n mml.setMmlFactory(customMmlFactory);\n\n return html;\n};\n\nconst bootstrap = (opts) => {\n if (typeof window === 'undefined') {\n return { Typeset: () => ({}) };\n }\n\n const html = createMathMLInstance(opts);\n\n return {\n version: mathjax.version,\n html: html,\n Typeset: function(...elements) {\n const updatedDocument = this.html\n .findMath(elements.length ? { elements } : {})\n .compile()\n .getMetrics()\n .typeset()\n .updateDocument();\n\n try {\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 }\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(e.toString());\n }\n\n updatedDocument.clear();\n },\n };\n};\n\nconst renderMath = (el, renderOpts) => {\n const isString = typeof el === 'string';\n let executeOn = document.body;\n\n if (isString) {\n const div = document.createElement('div');\n\n div.innerHTML = el;\n executeOn = div;\n }\n\n fixMathElements(executeOn);\n adjustMathMLStyle(executeOn);\n\n if (isString) {\n const html = createMathMLInstance(undefined, executeOn);\n\n const updatedDocument = html\n .findMath()\n .compile()\n .getMetrics()\n .typeset()\n .updateDocument();\n\n const list = updatedDocument.math.list;\n const item = list.next;\n\n if (!item) {\n return '';\n }\n\n const mathMl = toMMl(item.data.root);\n const parsedMathMl = mathMl.replaceAll('\\n', '');\n\n return parsedMathMl;\n }\n\n if (!getGlobal().instance) {\n getGlobal().instance = bootstrap(renderOpts);\n }\n\n if (!el) {\n log('el is undefined');\n return;\n }\n\n if (el instanceof Element) {\n getGlobal().instance.Typeset(el);\n } else if (el.length) {\n const arr = Array.from(el);\n getGlobal().instance.Typeset(...arr);\n }\n};\n\n/**\n * This style is added to overried default styling of mjx-mspace Mathjax tag\n * In mathjax src code \\newline latex gets parsed to <mjx-mspace></mjx-mspace>,\n * but has the default style\n * 'mjx-mspace': {\n \"display\": 'in-line',\n \"text-align\": 'left'\n} which prevents it from showing as a newline value\n */\nCHTMLmspace.styles = {\n 'mjx-mspace': {\n display: 'block',\n 'text-align': 'center',\n height: '5px',\n },\n};\n\nexport default renderMath;\n"],"file":"render-math.js"}
|