Skip to content

Commit af33057

Browse files
committed
Update TeX lab to work with changes in processing, and save the package list on 'keep'
1 parent 20d05af commit af33057

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

TeX-lab.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<input type="button" value="Keep" onclick="Lab.Keep()" />
3030
<input type="button" value="Typeset" onclick="Lab.Typeset()" />
3131
</div>
32-
<p>
3332
<div id="package"></div>
3433
<p>
3534
<div id="output"></div>

lib/Mml-lab.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ const Lab = window.Lab = {
2121
let text = this.output.appendChild(document.createTextNode(''));
2222

2323
let MML = this.mml.value;
24-
let math = new HTMLMathItem(MML,mml);
24+
let math = new HTMLMathItem(MML, mml, this.display);
2525
math.setMetrics(16,8,16*20,100000,1);
26-
math.display = this.display;
2726
math.start = {node: text, n: 0, delim: ''};
2827
math.end = {node: text, n: 0, delim: ''};
2928
this.jax = math;

lib/TeX-lab.js

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import {TeX} from "mathjax3/input/tex.js";
2-
import {CHTML} from "mathjax3/output/chtml.js";
3-
import {HTMLMathItem} from "mathjax3/handlers/html/HTMLMathItem.js";
4-
import {HTMLDocument} from "mathjax3/handlers/html/HTMLDocument.js";
5-
import {handleRetriesFor} from "mathjax3/util/Retries.js";
6-
import {browserAdaptor} from "mathjax3/adaptors/browserAdaptor.js";
1+
import {TeX} from '../mathjax3/input/tex.js';
2+
import {CHTML} from '../mathjax3/output/chtml.js';
3+
import {HTMLMathItem} from '../mathjax3/handlers/html/HTMLMathItem.js';
4+
import {HTMLDocument} from '../mathjax3/handlers/html/HTMLDocument.js';
5+
import {handleRetriesFor} from '../mathjax3/util/Retries.js';
6+
import {browserAdaptor} from '../mathjax3/adaptors/browserAdaptor.js';
77

8-
import {ConfigurationHandler} from 'mathjax3/input/tex/Configuration.js';
8+
import {ConfigurationHandler} from '../mathjax3/input/tex/Configuration.js';
9+
import '../mathjax3/input/tex/base/BaseConfiguration.js';
10+
import '../mathjax3/input/tex/ams/AmsConfiguration.js';
11+
import '../mathjax3/input/tex/noundefined/NoUndefinedConfiguration.js';
12+
import '../mathjax3/input/tex/boldsymbol/BoldsymbolConfiguration.js';
13+
import '../mathjax3/input/tex/newcommand/NewcommandConfiguration.js';
914

10-
import 'mathjax3/input/tex/base/BaseConfiguration.js';
11-
import 'mathjax3/input/tex/ams/AmsConfiguration.js';
12-
import 'mathjax3/input/tex/noundefined/NoUndefinedConfiguration.js';
13-
import 'mathjax3/input/tex/boldsymbol/BoldsymbolConfiguration.js';
14-
import 'mathjax3/input/tex/newcommand/NewcommandConfiguration.js';
15-
16-
let tex = new TeX();
17-
let chtml = new CHTML();
18-
19-
let doc = new HTMLDocument(document, browserAdaptor(), {InputJax: tex, OutputJax: chtml});
15+
const chtml = new CHTML();
16+
const adaptor = browserAdaptor();
17+
const doc = new HTMLDocument(document, adaptor, {OutputJax: chtml});
2018
document.head.appendChild(chtml.styleSheet(doc));
2119

2220
const Lab = window.Lab = {
21+
doc: doc,
22+
TeX: null,
2323
tex: document.getElementById('tex'),
2424
output: document.getElementById('output'),
2525
display: true,
@@ -29,24 +29,28 @@ const Lab = window.Lab = {
2929
this.output.innerHTML = '';
3030
let text = this.output.appendChild(document.createTextNode(''));
3131

32-
let tex = new TeX({packages: this.getPackages()});
3332
let LaTeX = this.tex.value;
34-
let math = new HTMLMathItem(LaTeX,tex);
35-
math.setMetrics(16,8,16*20,100000,1);
36-
math.display = this.display;
33+
let math = new HTMLMathItem(LaTeX, this.TeX, this.display);
34+
math.setMetrics(16, 8, 16*20, 100000, 1);
3735
math.start = {node: text, n: 0, delim: ''};
3836
math.end = {node: text, n: 0, delim: ''};
3937
this.jax = math;
4038

4139
handleRetriesFor(function () {
4240
math.compile();
43-
math.typeset(doc);
44-
math.updateDocument(doc);
45-
}).catch(err => {console.log("Error: " + err.message); console.log(err.stack)});
41+
math.typeset(this.doc);
42+
math.updateDocument(this.doc);
43+
}.bind(this)).catch(err => {console.log('Error: ' + err.message); console.log(err.stack)});
4644
},
4745

4846
Keep() {
49-
window.location.search = "?" + (this.display ? 1 : 0) + encodeURIComponent(this.tex.value);
47+
const flags = this.getPackageFlags();
48+
window.location.search = '?' + (this.display ? 1 : 0) + flags + encodeURIComponent(this.tex.value);
49+
},
50+
51+
getPackageFlags() {
52+
const keys = Object.keys(this.packages);
53+
return keys.map(key => document.getElementById(this.packages[key]).checked ? 1 : 0).join('');
5054
},
5155

5256
Update(html) {
@@ -69,10 +73,11 @@ const Lab = window.Lab = {
6973
for (let key of ConfigurationHandler.getInstance().keys()) {
7074
if (key === 'empty') continue;
7175
let checkbox = document.createElement('input');
72-
checkbox.type = "checkbox";
76+
checkbox.type = 'checkbox';
7377
checkbox.name = key;
7478
checkbox.value = key;
7579
checkbox.id = 'package-' + key;
80+
checkbox.onchange = function () {Lab.newPackages()};
7681
if (key === 'base') checkbox.checked = true;
7782
let label = document.createElement('label');
7883
label.htmlFor = 'package-' + key;
@@ -83,6 +88,12 @@ const Lab = window.Lab = {
8388
this.packages[key] = 'package-' + key;
8489
}
8590
},
91+
92+
newPackages() {
93+
this.TeX = new TeX({packages: this.getPackages()});
94+
this.doc = new HTMLDocument(document, adaptor, {InputJax: this.TeX, OutputJax: chtml});
95+
Lab.Typeset();
96+
},
8697

8798
setDisplay(checked) {
8899
this.display = checked;
@@ -102,11 +113,20 @@ const Lab = window.Lab = {
102113

103114
}
104115

105-
if (window.location.search !== "") {
106-
Lab.tex.value = decodeURIComponent(window.location.search.substr(2));
116+
Lab.Packages();
117+
118+
if (window.location.search !== '') {
119+
const n = Lab.getPackageFlags().length;
120+
Lab.tex.value = decodeURIComponent(window.location.search.substr(n + 2));
107121
Lab.display = window.location.search.substr(1,1) === '1';
108122
document.getElementById('display').checked = Lab.display;
109-
Lab.Packages();
110-
Lab.Typeset();
123+
const flags = window.location.search.substr(2,n);
124+
let i = 0;
125+
for (const key in Lab.packages) {
126+
if (flags.charAt(i++) === '1') {
127+
document.getElementById(Lab.packages[key]).checked = true;
128+
}
129+
}
111130
}
112131

132+
Lab.newPackages();

0 commit comments

Comments
 (0)