Skip to content

Commit 8112859

Browse files
authored
Merge branch 'master' into initial_parser
2 parents f5b4d7e + 53f681a commit 8112859

File tree

183 files changed

+17350
-1466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+17350
-1466
lines changed

Mml-lab.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>MathJax v3 MathML lab</title>
5+
<script src="lib/traceur.min.js"></script>
6+
<script src="lib/system.js"></script>
7+
<style>
8+
#output {
9+
border: 1px solid black;
10+
padding: 10px;
11+
width: auto;
12+
min-width: 50%;
13+
display: inline-block;
14+
font-size: 200%;
15+
}
16+
#container {
17+
display: inline-block;
18+
text-align: right;
19+
}
20+
</style>
21+
</head>
22+
<body>
23+
24+
<div id="container">
25+
<textarea id="mml" cols="80" rows="15" onkeypress="Lab.checkKey(this,event)"></textarea><br>
26+
<input type="button" value="Keep" onclick="Lab.Keep()" />
27+
<input type="button" value="Typeset" onclick="Lab.Typeset()" />
28+
</div>
29+
<p>
30+
<div id="output"></div>
31+
32+
<script>
33+
System.import('./lib/Mml-lab.js').catch(function (error) {console.log(error.message)});
34+
</script>
35+
</body>
36+
</html>
37+
38+

TeX-lab.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>MathJax v3 TeX lab</title>
5+
<script src="lib/traceur.min.js"></script>
6+
<script src="lib/system.js"></script>
7+
<style>
8+
#output {
9+
border: 1px solid black;
10+
padding: 10px;
11+
width: auto;
12+
min-width: 50%;
13+
display: inline-block;
14+
font-size: 200%;
15+
}
16+
#container {
17+
display: inline-block;
18+
text-align: right;
19+
}
20+
</style>
21+
</head>
22+
<body>
23+
24+
<div id="container">
25+
<textarea id="tex" cols="80" rows="15" onkeypress="Lab.checkKey(this,event)"></textarea><br>
26+
<span style="float:left">
27+
<input type="checkbox" id="display" onchange="Lab.setDisplay(this.checked)" checked /> display mode
28+
</span>
29+
<input type="button" value="Keep" onclick="Lab.Keep()" />
30+
<input type="button" value="Typeset" onclick="Lab.Typeset()" />
31+
</div>
32+
<p>
33+
<div id="output"></div>
34+
35+
<script>
36+
System.import('./lib/TeX-lab.js').catch(function (error) {console.log(error.message)});
37+
</script>
38+
</body>
39+
</html>
40+
41+

lib/Mml-lab.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import {MathML} from "mathjax3/input/MathML.js";
2+
import {CHTML} from "mathjax3/output/chtml.js";
3+
import {AbstractMathItem} from "mathjax3/core/MathItem.js";
4+
import {AbstractMathDocument} from "mathjax3/core/MathDocument.js";
5+
import {handleRetriesFor} from "mathjax3/util/Retries.js";
6+
import {browserAdaptor} from "mathjax3/adaptors/browserAdaptor.js";
7+
8+
class LabMathItem extends AbstractMathItem {};
9+
class LabMathDocument extends AbstractMathDocument {};
10+
11+
let mml = new MathML();
12+
let chtml = new CHTML();
13+
14+
let adaptor = new browserAdaptor();
15+
mml.setAdaptor(adaptor);
16+
chtml.setAdaptor(adaptor);
17+
18+
let doc = new LabMathDocument(document,adaptor,{OutputJax: chtml});
19+
document.head.appendChild(chtml.styleSheet(doc));
20+
21+
const Lab = window.Lab = {
22+
mml: document.getElementById('mml'),
23+
output: document.getElementById('output'),
24+
display: true,
25+
26+
Typeset() {
27+
let MML = this.mml.value;
28+
let math = new LabMathItem(MML,mml);
29+
math.setMetrics(16,8,16*20,100000,1);
30+
math.display = this.display;
31+
this.jax = math;
32+
33+
handleRetriesFor(function () {
34+
math.compile();
35+
math.typeset(doc);
36+
}).then(() => Lab.Update(math.typesetRoot.outerHTML))
37+
.catch(err => {console.log("Error: "+err.message); console.log(err.stack)});
38+
},
39+
40+
Keep() {
41+
window.location.search = "?" + encodeURIComponent(this.mml.value);
42+
},
43+
44+
Update(html) {
45+
this.output.innerHTML = html;
46+
},
47+
48+
checkKey: function (textarea, event) {
49+
if (!event) event = window.event;
50+
var code = event.which || event.keyCode;
51+
if ((event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) &&
52+
(code === 13 || code === 10)) {
53+
if (event.preventDefault) event.preventDefault();
54+
event.returnValue = false;
55+
this.Typeset();
56+
}
57+
}
58+
59+
}
60+
61+
if (window.location.search !== "") {
62+
Lab.mml.value = decodeURIComponent(window.location.search.substr(1));
63+
Lab.Typeset();
64+
}
65+

lib/TeX-lab.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import {TeX} from "mathjax3/input/tex.js";
2+
import {CHTML} from "mathjax3/output/chtml.js";
3+
import {AbstractMathItem} from "mathjax3/core/MathItem.js";
4+
import {AbstractMathDocument} from "mathjax3/core/MathDocument.js";
5+
import {handleRetriesFor} from "mathjax3/util/Retries.js";
6+
import {browserAdaptor} from "mathjax3/adaptors/browserAdaptor.js";
7+
8+
class LabMathItem extends AbstractMathItem {};
9+
class LabMathDocument extends AbstractMathDocument {};
10+
11+
let tex = new TeX();
12+
let chtml = new CHTML();
13+
14+
let adaptor = new browserAdaptor();
15+
tex.setAdaptor(adaptor);
16+
chtml.setAdaptor(adaptor);
17+
18+
let doc = new LabMathDocument(document,adaptor,{OutputJax: chtml});
19+
document.head.appendChild(chtml.styleSheet(doc));
20+
21+
const Lab = window.Lab = {
22+
tex: document.getElementById('tex'),
23+
output: document.getElementById('output'),
24+
display: true,
25+
26+
Typeset() {
27+
let TeX = this.tex.value;
28+
let math = new LabMathItem(TeX,tex);
29+
math.setMetrics(16,8,16*20,100000,1);
30+
math.display = this.display;
31+
this.jax = math;
32+
33+
handleRetriesFor(function () {
34+
math.compile();
35+
math.typeset(doc);
36+
}).then(() => Lab.Update(math.typesetRoot.outerHTML))
37+
.catch(err => {console.log("Error: "+err.message); console.log(err.stack)});
38+
},
39+
40+
Keep() {
41+
window.location.search = "?" + (this.display ? 1 : 0) + encodeURIComponent(this.tex.value);
42+
},
43+
44+
Update(html) {
45+
this.output.innerHTML = html;
46+
},
47+
48+
setDisplay(checked) {
49+
this.display = checked;
50+
this.Typeset();
51+
},
52+
53+
checkKey: function (textarea, event) {
54+
if (!event) event = window.event;
55+
var code = event.which || event.keyCode;
56+
if ((event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) &&
57+
(code === 13 || code === 10)) {
58+
if (event.preventDefault) event.preventDefault();
59+
event.returnValue = false;
60+
this.Typeset();
61+
}
62+
}
63+
64+
}
65+
66+
if (window.location.search !== "") {
67+
Lab.tex.value = decodeURIComponent(window.location.search.substr(2));
68+
Lab.display = window.location.search.substr(1,1) === '1';
69+
document.getElementById('display').checked = Lab.display;
70+
Lab.Typeset();
71+
}
72+

load.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
<script src="lib/system.js"></script>
77
<script>
88
(function () {
9-
var argv = ['browser','load.html'].concat(
10-
decodeURI(location.search.substr(1) || 'main.js').split(/&/)
11-
);
9+
var args = (location.search.substr(1) || 'main.js').split(/&/);
10+
var argv = ['browser','load.html'].concat(args.map(x => decodeURIComponent(x)));
1211
window.process = {argv: argv};
1312
System.import(argv[2])
1413
.then(function () {document.body.appendChild(document.createTextNode("Done"))})

main.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import {MathJax} from "mathjax3/mathjax.js";
22
export {MathJax} from "mathjax3/mathjax.js";
33

4-
import "mathjax3/handlers/html.js";
54
import {TeX} from "mathjax3/input/tex.js";
5+
import {RegisterHTMLHandler} from "mathjax3/handlers/html.js";
6+
import {chooseAdaptor} from "mathjax3/adaptors/chooseAdaptor.js";
67
import {CHTML} from "mathjax3/output/chtml.js";
78

8-
let html = MathJax.Document("<html></html>", {
9+
RegisterHTMLHandler(chooseAdaptor());
10+
11+
let html = MathJax.document("<html></html>", {
912
InputJax: new TeX(),
1013
OutputJax: new CHTML()
1114
});
1215

13-
MathJax.HandleRetriesFor(function () {
16+
MathJax.handleRetriesFor(function () {
1417

15-
html.TestMath(process.argv[3] || '').Compile().Typeset();
18+
html.TestMath(process.argv[3] || '').compile().typeset();
1619
let math = html.math.pop();
1720
console.log(math.typeset.outerHTML);
1821

mathjax2/css/otf/MathJax_Zero.otf

2.33 KB
Binary file not shown.

0 commit comments

Comments
 (0)