-
Notifications
You must be signed in to change notification settings - Fork 107
/
mml-attribute.html
46 lines (43 loc) · 1.48 KB
/
mml-attribute.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width">
<title>Add a data-mathml attribute to each math element</title>
<script>
MathJax = {
startup: {
ready: function () {
//
// Do the usual startup ready actions (create document, input/output jax, etc).
//
MathJax.startup.defaultReady();
const toMML = MathJax.startup.toMML;
//
// Add a post-filter to the output jax to add the extra attributes
//
MathJax.startup.output.postFilters.add((args) => {
const math = args.math, node = args.data;
const original = (math.math ? math.math :
math.inputJax.processStrings ? '' : math.start.node.outerHTML);
node.setAttribute('data-original', original);
node.setAttribute('data-mathml', toMML(math.root).replace(/\n\s*/g, ''));
});
}
}
};
</script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
</head>
<body>
<p>
This math will have a <code>data-mathml</code> attribute containing
the MathML representation of the expression, and a
<code>data-original</code> attribute holding the original TeX format
of the expression. Inspect the document DOM to see these in place
(on the <code>mjx-container</code> element).
</p>
$$\sqrt{\frac{1+x}{1-x}}$$
</body>
</html>