forked from tpbarron/mathjax_mathspeak
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinput.html
79 lines (77 loc) · 2.89 KB
/
input.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<title>MathJax Input Demo</title>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
jax: ["input/AsciiMath","output/SVG","output/NativeMML"],
extensions: ["asciimath2jax.js","MathMenu.js","MathZoom.js","toMathML.js"]
});
</script>
<script type="text/javascript" src="unpackedlanguagebuffer/MathJax.js?config=default"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function display() {
var str = document.getElementById("equation_editor").value;
var svg_node = document.getElementById("svg_node");
svg_node.innerHTML = '`' + str + '`';
MathJax.Hub.Typeset(svg_node);
}
<!-- https://groups.google.com/d/topic/mathjax-users/unL8IjcrTto/discussion -->
function toMathML(jax, callback) {
var mml;
try {
mml = jax.root.toMathML("");
} catch(err) {
if (!err.restart) { throw err; }
return MathJax.Callback.After([toMathML, jax, callback], err, restart);
}
MathJax.Callback(callback)(mml);
}
function clearDescription() {
var description_node = document.getElementById("description");
description_node.value = '';
}
function appendToDescription() {
var svg_node = document.getElementById("svg_node");
MathJax.Hub.Queue(function() {
var jaxen = MathJax.Hub.getAllJax(svg_node);
toMathML(jaxen[0], function(mml) {
var str = document.getElementById("equation_editor").value;
var description_node = document.getElementById("description");
$.ajax({
url: "service?equation=" + str,
success: function(mde_description) {
description_node.value += mde_description;
description_node.value += "\n";
description_node.value += mml;
},
error: function() {
description_node.value += mml;
}
});
})});
}
</script>
</head>
<body>
Description:
<textarea id="description" rows="10" cols="80"></textarea>
<p>Equation Editor:
<textarea id="equation_editor" rows="5" cols="30" onkeyup="display()"></textarea>
<div id="svg_node"></div>
</p>
<button onclick=appendToDescription();>Update Description</button>
<button onclick=clearDescription();>Clear Description</button>
<p>Some examples to try (courtesy of
<a href="http://www1.chapman.edu/~jipsen/mathml/asciimath.html">
ASCIIMathML Page
</a>:
</p>
<ul>
<li>\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}</li>
<li>f(x)=\sum_{n=0}^\infty\frac{f^{(n)}(a)}{n!}(x-a)^n</li>
<li>(a,b]={x in RR | a < x <= b}</li>
</ul>
</body>
</html>