-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
61 lines (61 loc) · 2.03 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
<!DOCTYPE html>
<html>
<head>
<title>tex2svg-webworker demo</title>
<style>
.render { display: inline-block; border: solid; }
.error { border: solid; padding: 1em; }
/* LaTeX errors get rendered with these rects as background: */
rect[data-background="true"] { fill: #f88; cursor: help; }
</style>
<script>
function error(e) {
var div = document.createElement('div');
div.className = 'error';
div.innerHTML = e.toString();
if (e.name === 'SecurityError' &&
document.location.protocol === 'file:') {
div.innerHTML += "<b>You need to open this HTML file from a web server; web workers don't work with <code>file:</code> protocol.</b>";
}
document.body.appendChild(div);
}
window.onload = function() {
try {
worker = new Worker('tex2svg.js');
} catch (e) {
error(e);
}
worker.onerror = function(e) {
error('Failed to load worker');
};
worker.onmessage = function(e) {
var div = document.createElement('div');
div.className = 'render';
div.innerHTML = e.data.svg;
document.body.appendChild(div);
};
};
function render() {
worker.postMessage({
formula: document.getElementById('formula').value,
display: true,
});
}
</script>
</head>
<body>
<h1>tex2svg-webworker demo</h1>
<% if (false) { %>
<div style="border: solid thick; padding: 1em; margin: 1em; font-size: large; font-weight: bold; background: yellow;">
Do not open this HTML file directly; to test,
run <code>npm install</code> and instead
serve <code>dist/index.html</code> from an http server.
</div>
<% } %>
<form style="display:flex" onSubmit="event.preventDefault(); render()">
<textarea id="formula" style="flex-grow: 1">\int_0^1 x^2 \, dx</textarea>
<button type="submit">Render</button>
</form>
<h2>Renders:</h2>
</body>
</html>