-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.html
74 lines (68 loc) · 2.19 KB
/
index.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
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href="style.css" />
<title>MathLive with Vue.js</title>
</head>
<body>
<script type="module">
import Vue from "https://cdn.jsdelivr.net/npm/vue/dist/vue.esm.browser.js";
import * as MathLive from "https://unpkg.com/mathlive/dist/mathlive.mjs";
import MathfieldComponent from "https://unpkg.com/mathlive/dist/vue-mathlive.mjs";
Vue.config.devtools = true;
Vue.use(MathfieldComponent, MathLive);
// The default tag for mathfields is <mathlive-mathfield>
// A custom tag can be defined using:
// ```Vue.component("custom-tag", Mathfield);```
new Vue({
el: "main",
data: {
formula: "",
keystroke: "",
},
methods: {
sayIt: (event) => {
this.$refs.mathfield.executeCommand(["speak", "all"]);
},
setIt: (event) => {
this.formula = "x=-b\\pm \\frac {\\sqrt{b^2-4ac}}{2a}";
},
ping: () => {
console.log("ping");
},
displayKeystroke: (keystroke, _ev) => {
this.keystroke = keystroke;
return true;
},
asSpokenText: function () {
return this.$refs.mathfield
? this.$refs.mathfield.getValue("spoken")
: "";
},
},
mounted,
});
async function mounted() {
this.$mathlive.renderMathInElement(this.$refs["static-math"]);
}
</script>
<main>
<h2>MathLive with Vue.js</h2>
<mathlive-mathfield
id="mf"
ref="mathfield"
:options="{smartFence:false, virtualKeyboardMode:'onfocus'}"
@focus="ping"
:on-keystroke="displayKeystroke"
v-model="formula"
>f(x)=</mathlive-mathfield
>
<div><label>Keystroke: </label><span>{{keystroke}}</span></div>
<div class="output">LaTeX: {{formula}}</div>
<div class="output">Spoken text: {{asSpokenText()}}</div>
<button v-on:click="sayIt">Say It</button>
<button v-on:click="setIt">Set It</button>
<div ref="static-math">\[x^2 = x*x\]</div>
</main>
</body>
</html>