-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
313 lines (287 loc) · 14.1 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<!doctype html>
<html>
<head>
<title>TeXZilla</title>
<meta charset="utf-8"/>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<script type="text/javascript" src="TeXZilla-min.js"></script>
<style type="text/css">
/* Asana */
.Asana math {
font-family: Asana Math;
}
/* Cambria */
.Cambria math {
font-family: Cambria Math;
}
/* DejaVu */
.DejaVu math {
font-family: DejaVu Math TeX Gyre;
}
/* LatinModern */
.LatinModern math {
font-family: Latin Modern Math;
}
/* Libertinus */
.Libertinus math {
font-family: Libertinus Math;
}
/* Lucida */
.Lucida math {
font-family: Lucida Bright Math;
}
/* Minion */
.Minion math {
font-family: Minion Math;
}
/* STIX */
.STIX math {
font-family: STIX Math;
}
/* TeXGyreBonum */
.TeXGyreBonum math {
font-family: TeX Gyre Bonum Math;
}
/* TeXGyrePagella */
.TeXGyrePagella math {
font-family: TeX Gyre Pagella Math;
}
/* TeXGyreSchola */
.TeXGyreSchola math {
font-family: TeX Gyre Schola Math;
}
/* TeXGyreTermes */
.TeXGyreTermes math {
font-family: TeX Gyre Termes Math;
}
/* XITS */
.XITS math {
font-family: XITS Math;
}
</style>
<script type="text/javascript">
function update(aValue)
{
var input = document.getElementById("input");
var output = document.getElementById("output");
while (output.firstChild)
output.removeChild(output.firstChild);
if (aValue) input.value = aValue;
if (!TeXZilla) throw "TeXZilla is not defined. Did you do 'make minify'?";
try {
output.style.color = "inherit";
var math = TeXZilla.
toMathML(input.value,
document.getElementById("mode").value === "display",
document.getElementById("dir").value === "RTL", true);
output.appendChild(math);
} catch(e) {
output.style.color = "red";
output.textContent = input.value;
}
}
function updateMathFont()
{
var mathFont = document.getElementById("MathFont").value;
if (mathFont === "Default") {
document.body.removeAttribute("class");
} else {
document.body.setAttribute("class", mathFont);
}
if (!document.getElementById("output").firstElementChild) {
update();
}
}
function updateMode()
{
var math = document.getElementById("output").firstElementChild;
if (math) {
math.setAttribute("display",
document.getElementById("mode").value === "display" ?
"block" : "inline");
} else {
update();
}
}
function updateDir()
{
var math = document.getElementById("output").firstElementChild;
if (math) {
math.setAttribute("dir",
document.getElementById("dir").value === "RTL" ?
"rtl" : "ltr");
} else {
update();
}
}
</script>
</head>
<body>
<h1>TeXZilla</h1>
<h2>Description</h2>
<p><a href="http://fred-wang.github.io/TeXZilla/">TeXZilla</a> is a
Javascript LaTeX-to-MathML converter which is compatible
with Unicode. It is generated by
<a href="http://zaach.github.io/jison/">Jison</a> using a grammar
similar to the one of
<a href="http://golem.ph.utexas.edu/~distler/blog/itex2MML.html">itex2MML</a>
and the
<a href="http://www.w3.org/TR/xml-entity-names/">XML Entity Definitions
for Characters</a> specification.
<h2>Live Demo</h2>
<p>Enter your LaTeX source or
pick an example and check how the MathML output is rendered by your
browser.</p>
<p>
<select id="mode" onchange="updateMode()">
<option value="display">Display Mode</option>
<option value="inline">Inline Mode</option>
</select> ;
<select id="dir" onchange="updateDir()">
<option value="LTR">LTR</option>
<option value="RTL">RTL</option>
</select> ;
<select id="examples" onchange="update(this.value)">
<option value="" selected="selected">-- select an example --</option>
<option value="\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1">Ellipse Equation</option>
<option value="\sum_{n=1}^{+\infty} \frac{1}{n^2} = \frac{\pi^2}{6}">Sum 1/n²</option>
<option value="∑_{n=1}^{+∞} \frac{1}{n^2} = \frac{π^2}{6}">Sum 1/n² (Unicode)</option>
<option value="x = \frac{-b\pm\sqrt{b^2-4ac}}{2a}">Quadratic Formula</option>
<option value="س = \frac{-ب\pm\sqrt{ب^٢-٤اج}}{٢ا}">Quadratic Formula (Arabic)</option>
<option value="f(x)=\sum_{n=-\infty}^\infty c_n e^{2\pi i(n/T) x} =\sum_{n=-\infty}^\infty \hat{f}(\xi_n) e^{2\pi i\xi_n x}\Delta\xi">Fourier Transform</option>
<option value="\Gamma(t) = \lim_{n \to \infty} \frac{n! \; n^t}{t \; (t+1)\cdots(t+n)}= \frac{1}{t} \prod_{n=1}^\infty \frac{\left(1+\frac{1}{n}\right)^t}{1+\frac{t}{n}} = \frac{e^{-\gamma t}}{t} \prod_{n=1}^\infty \left(1 + \frac{t}{n}\right)^{-1} e^{\frac{t}{n}}">Gamma function</option>
<option value="{\Gamma(t)} = {\int_{0}^{+\infty} x^{t-1} e^{-x} dx} = {\frac{1}{t} \prod_{n=1}^\infty \frac{\left(1+\frac{1}{n}\right)^t}{1+\frac{t}{n}} } \sim {\sqrt{\frac{2\pi}{t}} \left(\frac{t}{e}\right)^t}">Gamma function (integral, large operator and square root)</option>
<option value="\mathfrak{sl}(n, \mathbb{F}) = \left\{ A \in \mathscr{M}_n(\mathbb{F}) : \operatorname{Tr}(A) = 0 \right\}">Lie Algebra</option>
<option value="x^2 y^2">Mozilla MathML Torture Test 1</option>
<option value="\multiscripts{_2}{F}{_3}">Mozilla MathML Torture Test 2</option>
<option value="\frac{x+y^2}{k+1}">Mozilla MathML Torture Test 3</option>
<option value="x+y^{\frac 2 {k+1}}">Mozilla MathML Torture Test 4</option>
<option value="\frac{a}{b/2}">Mozilla MathML Torture Test 5</option>
<option value="\displaystyle a_0 + \frac{1}{\displaystyle a_1+\frac{1}{\displaystyle a_2+\frac{1}{\displaystyle a_3+\frac{1}{\displaystyle a_4}}}}">Mozilla MathML Torture Test 6</option>
<option value="a_0 + \frac{1}{a_1+\frac{1}{a_2+\frac{1}{a_3+\frac{1}{a_4}}}}">Mozilla MathML Torture Test 7</option>
<option value="\binom{n}{k/2}">Mozilla MathML Torture Test 8</option>
<option value="\binom{p}{2} x^2 y^{p-2} - \frac{1}{1-x} \frac{1}{1-x^2}">Mozilla MathML Torture Test 9</option>
<option value="\sum_{\substack{
0 \le i \le m \\
0 < j < n
}} {P(i,j)}">Mozilla MathML Torture Test 10</option>
<option value="x^{2y}">Mozilla MathML Torture Test 11</option>
<option value="\sum_{i=1}^p \sum_{j=1}^q \sum_{k=1}^r {a_{i j} b_{j k} c_{k i}}">Mozilla MathML Torture Test 12</option>
<option value="\sqrt{1+\sqrt{1+\sqrt{1+\sqrt{1+\sqrt{1+\sqrt{1+\sqrt{1+x}}}}}}}">Mozilla MathML Torture Test 13</option>
<option value="\left( \frac{\partial^2}{\partial x^2} + \frac{\partial^2}{\partial y^2} \right) {| \varphi(x+ i y)|}^2 = 0">Mozilla MathML Torture Test 14</option>
<option value="2^{2^{2^x}}">Mozilla MathML Torture Test 15</option>
<option value="\int_1^x \frac{dt}{t}">Mozilla MathML Torture Test 16</option>
<option value="\iint_D {dx dy}">Mozilla MathML Torture Test 17</option>
<option value="f(x) =
\begin{cases}
1/3 & \text{if} \quad 0 \leq x \leq 1; \\
2/3 & \text{if} \quad 3 \leq x \leq 4; \\
0 & \text{elsewhere}.
\end{cases}
">Mozilla MathML Torture Test 18</option>
<option value="\overset{k \, \text{times}}{\overbrace{x+\dots+x}}">Mozilla MathML Torture Test 19</option>
<option value="y_{x^2}">Mozilla MathML Torture Test 20</option>
<option value="\sum_{p \, \text{prime}} {f(p)} = \int_{t > 1} {f(t) d\pi(t)} ">Mozilla MathML Torture Test 21</option>
<option value="\{\underset{k+l \, \text{elements}}{
\underbrace{
\overset{k \, a\text{'s}}{\overbrace{\mathrlap \phantom{(} a,\dots,a}},
\overset{l \, b\text{'s}}{\overbrace{\mathrlap \phantom{(} b,\dots,b}}
}}\}">Mozilla MathML Torture Test 22</option>
<option value="\begin{pmatrix}
\begin{pmatrix} a & b \\ c & d \end{pmatrix} &
\begin{pmatrix} e & f \\ g & h \end{pmatrix} \\
0 &
\begin{pmatrix} i & j \\ k & l \end{pmatrix}
\end{pmatrix}">Mozilla MathML Torture Test 23</option>
<option value="\det
\begin{vmatrix}
c_0 & c_1 & c_2 & \dots & c_n \\
c_1 & c_2 & c_3 & \dots & c_{n+1} \\
c_2 & c_3 & c_4 & \dots & c_{n+2} \\
\vdots & \vdots & \vdots & & \vdots \\
c_n & c_{n+1} & c_{n+2} & \dots & c_{2n}
\end{vmatrix}
> 0">Mozilla MathML Torture Test 24</option>
<option value="y_{x_2}">Mozilla MathML Torture Test 25</option>
<option value="x^31415_92 + \pi">Mozilla MathML Torture Test 26</option>
<option value="x^{z^d_c}_{y_b^a}">Mozilla MathML Torture Test 27</option>
<option value="y_3'''">Mozilla MathML Torture Test 28</option>
<option value="\begin{aligned}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{aligned}">MathJax - The Lorenz Equations</option>
<option value="\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)">MathJax - The Cauchy-Schwarz Inequality</option>
<option value="\mathbf{V}_1 \times \mathbf{V}_2 = \begin{vmatrix}
\mathbf{i} & \mathbf{j} & \mathbf{k} \\
\frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\
\frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0
\end{vmatrix}">MathJax - A Cross Product Formula</option>
<option value="P(E) = {n \choose k} p^k (1-p)^{ n-k}">MathJax - The probability of getting k heads when flipping n coins</option>
<option value="\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} =
1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}}
{1+\frac{e^{-8\pi}} {1+\ldots} } } }">MathJax - An Identity of Ramanujan</option>
<option value="1 + \frac{q^2}{(1-q)}+\frac{q^6}{(1-q)(1-q^2)}+\cdots =
\prod_{j=0}^{\infty}\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},
\quad\quad \text{for} \quad |q| < 1.">MathJax - A Rogers-Ramanujan Identity</option>
<option value="\begin{aligned}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\
\nabla \cdot \vec{\mathbf{B}} & = 0 \end{aligned}">MathJax - Maxwell’s Equations</option>
</select><br/> Font:
<select id="MathFont" onchange="updateMathFont()">
<option value="Default" selected="selected">Default fonts</option>
<option value="Asana">Asana</option>
<option value="Cambria">Cambria</option>
<option value="DejaVu">DejaVu</option>
<option value="LatinModern">Latin Modern</option>
<option value="Libertinus">Libertinus</option>
<option value="Lucida">Lucida</option>
<option value="Minion">Minion</option>
<option value="STIX">STIX</option>
<option value="TeXGyreBonum">TeX Gyre Bonum</option>
<option value="TeXGyrePagella">TeX Gyre Pagella</option>
<option value="TeXGyreSchola">TeX Gyre Schola</option>
<option value="TeXGyreTermes">TeX Gyre Termes</option>
<option value="XITS">XITS</option>
</select> (see <a href="https://developer.mozilla.org/en-US/docs/Mozilla/MathML_Project/Fonts">Fonts for Mozilla's MathML engine</a>)
</p>
<textarea id="input" cols="80" rows="5" oninput="update()" dir="ltr"></textarea>
<div id="output"></div>
<h2>More Examples</h2>
<ol>
<li>Converting the LaTeX content of a Web page:
<ul>
<li><a href="examples/convertClientSide.html">Convert the LaTeX source when the DOM is ready</a> using <a href="examples/TeXZilla-parse.js">TeXZilla-parse.js</a></li>
<li><a href="examples/convertClientSideDelimiters.html">Converting the LaTeX fragments inside an element</a></li>
<li>
<a href="examples/customElement.html">Using a custom <la-tex>
tag</a> that automaticaly converts its LaTeX content into MathML.</li>
</ul>
</li>
<li>Embedding TeXZilla in your program:
<ul>
<li><a href="examples/commonJS.js">Basic commonJS program</a> using TeXZilla.</li>
<li><a href="examples/commonJS-DOMParser.js">Another commonJS program</a> using TeXZilla that requires a DOMParser instance to work.</li>
<li><a href="examples/TeXZillaParser.java">Basic Java program</a> that runs TeXZilla with the Rhino/Nashorn Javascript engines.</li>
<li><a href="examples/TeXZillaParser.py">Basic Python program</a> that runs TeXZilla with the SpiderMonkey Javascript engine.</li>
<li><a href="examples/TeXZillaParser.pl">Basic Perl program</a> that runs TeXZilla with the V8 Javascript engine.</li>
<li><a href="examples/TeXZillaParser.rb">Basic Ruby program</a> that runs TeXZilla with the V8 Javascript engine.</li>
</ul>
</li>
<li>Using the TeXZilla API:
<ul>
<li><a href="examples/toImage.html">Create an SVG image</a>
of the MathML formula for use in a <canvas> 2D context.</li>
<li><a href="examples/toImageWebGL.html">Create an SVG image</a>
of the MathML formula for use in a <canvas> WebGL context.</li>
<li><a href="examples/getTeXSource.html">Show the TeX source</a> when one double clicks on a MathML expression, using <a href="examples/TeXZilla-show-source.js">TeXZilla-show-source.js</a></li>
<li><a href="examples/handleParsingError.html">Handle errors</a>
by asking TeXZilla to throw an exception when the parsing fails.</li>
</ul>
</li>
</ol>
</body>
</html>