Welcome, guest | Sign In | My Account | Store | Cart

Html web page to preview latex equations rendered by mathjax. demo here

Equations are updated when shift, space or enter keys are pressed, or when the Textarea lose focus.

In the first block you can try inline-style math, in the second one, display-style math.

HTML, 99 lines
 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<!DOCTYPE html>
<html>
<head>
<!-- released under the GNU GPLv3 - copyleft Yoochan -->
<title>MathJax Test Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style>
body {
	background-color:#99c;
}
#page {
	margin: 0.5em;
	padding: 0.5em;
	min-width: 23em;
	width:50%;
	margin: auto;
	background-color:#668;
}
#block, #inline, #input {
	margin: 0.5em;
	padding: 0.5em;
	text-align:justify;
	background-color:#fff;	
}
textarea {
	width: 100%;
	height: auto;
	border : 0px white solid;

}
</style>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js">
MathJax.Hub.Config({
	extensions: ["tex2jax.js"],
	jax: ["input/TeX","output/SVG"],
	tex2jax: {
		inlineMath: [["\\(","\\)"]],
		displayMath: [["\\[","\\]"]]
	}
});
</script>
<script type="text/javascript">
(function () {
    var mathinline = null;
    var mathblock = null;
    var previous_formula = null;

    MathJax.Hub.queue.Push(function () {
      mathinline = MathJax.Hub.getAllJax("MathInline")[0];
      mathblock = MathJax.Hub.getAllJax("MathBlock")[0];
    });

	window.UpdateMath = function (value) {
		if ((previous_formula === null) || (value != previous_formula)) {
			console.log("window.UpdateMath("+value+")");
			MathJax.Hub.queue.Push(["Text", mathinline, value]);
			MathJax.Hub.queue.Push(["Text", mathblock, value]);
			previous_formula = value;
		}
	};
	
	window.do_keydown = function (event, value) {
		var code = (event.keyCode ? event.keyCode : event.which);
		if (code == 13 || event.shiftKey === true || code == 32) {
			window.UpdateMath(value);
		}
	};
})();
</script>
</head>
<body>
<div id="page">
	<div id="input">
		<textarea id="MathInput" rows="5" cols="30" onblur="UpdateMath(this.value)" onkeydown="do_keydown(event, this.value)" >\sum _{ n = 1 } ^{+\infty} \frac {1} {n^2} = \frac {\pi^2} {6}</textarea>
	</div>
<div id="inline">
<p id="MathInline">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex \(__formula__\) ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div id="block">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>
<p id="MathBlock">\[__formula__\]</p>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</div>
<script type="text/javascript">
var formula = window.document.getElementById("MathInput").value;

var mathblock_div = document.getElementById("MathBlock");
mathblock_div.innerHTML = mathblock_div.innerHTML.replace("__formula__", formula);

var mathinline_div = document.getElementById("MathInline");
mathinline_div.innerHTML = mathinline_div.innerHTML.replace("__formula__", formula);

window.setInterval(function(){
	window.UpdateMath(window.document.getElementById("MathInput").value);
}, 2500);
</script>
</body>
</html>
Created by yota on Fri, 4 Oct 2013 (GPL3)
HTML recipes (12)
yota's recipes (13)

Required Modules

Other Information and Tasks

  • Licensed under the GPL 3
  • Viewed 5516 times
  • Revision 7 (updated 6 years ago)