Skip to content

Commit 93ae1a8

Browse files
committed
Merge branch 'chtml' into develop
2 parents 34f3cc8 + b8b4e28 commit 93ae1a8

File tree

6 files changed

+606
-26
lines changed

6 files changed

+606
-26
lines changed

bin/page2html

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#! /usr/bin/env node
2+
3+
/************************************************************************
4+
*
5+
* page2svg
6+
*
7+
* Reads an HTML5 file from stdin that contains math
8+
* and writes a new HTML5 document to stdout that
9+
* contains SVG versions of the math instead.
10+
*
11+
* ----------------------------------------------------------------------
12+
*
13+
* Copyright (c) 2014 The MathJax Consortium
14+
*
15+
* Licensed under the Apache License, Version 2.0 (the "License");
16+
* you may not use this file except in compliance with the License.
17+
* You may obtain a copy of the License at
18+
*
19+
* http://www.apache.org/licenses/LICENSE-2.0
20+
*
21+
* Unless required by applicable law or agreed to in writing, software
22+
* distributed under the License is distributed on an "AS IS" BASIS,
23+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24+
* See the License for the specific language governing permissions and
25+
* limitations under the License.
26+
*/
27+
28+
var mjAPI = require("../lib/mj-page.js");
29+
var fs = require('fs');
30+
var jsdom = require('jsdom').jsdom;
31+
32+
var argv = require("yargs")
33+
.strict()
34+
.usage("Usage: page2svg [options] < input.html > output.html",{
35+
preview: {
36+
boolean: true,
37+
describe: "make SVG into a MathJax preview"
38+
},
39+
speech: {
40+
boolean: true,
41+
describe: "include speech text"
42+
},
43+
speechrules: {
44+
default: "mathspeak",
45+
describe: "ruleset to use for speech text (chromevox or mathspeak)"
46+
},
47+
speechstyle: {
48+
default: "default",
49+
describe: "style to use for speech text (default, brief, sbrief)"
50+
},
51+
linebreaks: {
52+
boolean: true,
53+
describe: "perform automatic line-breaking"
54+
},
55+
nodollars: {
56+
boolean: true,
57+
describe: "don't use single-dollar delimiters"
58+
},
59+
format: {
60+
default: "AsciiMath,TeX,MathML",
61+
describe: "input format(s) to look for"
62+
},
63+
eqno: {
64+
default: "none",
65+
describe: "equation number style (none, AMS, or all)"
66+
},
67+
ex: {
68+
default: 6,
69+
describe: "ex-size in pixels"
70+
},
71+
width: {
72+
default: 100,
73+
describe: "width of container in ex"
74+
},
75+
extensions: {
76+
default: "",
77+
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
78+
}
79+
})
80+
.argv;
81+
82+
argv.format = argv.format.split(/ *, */);
83+
mjAPI.config({extensions: argv.extensions});
84+
mjAPI.start();
85+
86+
//
87+
// Process an HTML file:
88+
//
89+
function processHTML(html,callback) {
90+
var document = jsdom(html,{features:{FetchExternalResources: false}});
91+
var xmlns = getXMLNS(document);
92+
mjAPI.typeset({
93+
html: document.body.innerHTML,
94+
renderer: "CommonHTML",
95+
inputs: argv.format,
96+
equationNumbers: argv.eqno,
97+
singleDollars: !argv.nodollars,
98+
addPreview: argv.preview,
99+
speakText: argv.speech,
100+
speakRuleset: argv.speechrules.replace(/^chromevox$/i,"default"),
101+
speakStyle: argv.speechstyle,
102+
ex: argv.ex, width: argv.width,
103+
linebreaks: argv.linebreaks,
104+
xmlns:xmlns
105+
}, function (result) {
106+
document.body.innerHTML = result.html;
107+
document.head.appendChild(document.body.firstChild);
108+
var HTML = "<!DOCTYPE html>\n"+document.documentElement.outerHTML.replace(/^(\n|\s)*/,"");
109+
callback(HTML);
110+
});
111+
}
112+
113+
//
114+
// Look up the MathML namespace from the <html> attributes
115+
//
116+
function getXMLNS(document) {
117+
var html = document.head.parentNode;
118+
for (var i = 0, m = html.attributes.length; i < m; i++) {
119+
var attr = html.attributes[i];
120+
if (attr.nodeName.substr(0,6) === "xmlns:" &&
121+
attr.nodeValue === "http://www.w3.org/1998/Math/MathML")
122+
{return attr.nodeName.substr(6)}
123+
}
124+
return "mml";
125+
}
126+
127+
//
128+
// Read the input file and collect the file contents
129+
// When done, process the HTML.
130+
//
131+
var html = [];
132+
process.stdin.on("readable",function (block) {
133+
var chunk = process.stdin.read();
134+
if (chunk) html.push(chunk.toString('utf8'));
135+
});
136+
process.stdin.on("end",function () {
137+
processHTML(html.join(""), function(html) {
138+
process.stdout.write(html);
139+
});
140+
});

bin/tex2html

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#! /usr/bin/env node
2+
3+
/*************************************************************************
4+
*
5+
* tex2html
6+
*
7+
* Uses MathJax to convert a TeX or LaTeX string to an HTML string.
8+
*
9+
* ----------------------------------------------------------------------
10+
*
11+
* Copyright (c) 2014 The MathJax Consortium
12+
*
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
24+
*/
25+
26+
var mjAPI = require("../lib/mj-single.js");
27+
28+
var argv = require("yargs")
29+
.demand(1).strict()
30+
.usage("Usage: tex2html [options] 'math' > file.mml",{
31+
inline: {
32+
boolean: true,
33+
describe: "process as in-line TeX"
34+
},
35+
speech: {
36+
boolean: true,
37+
describe: "include speech text"
38+
},
39+
speechrules: {
40+
default: "mathspeak",
41+
describe: "ruleset to use for speech text (chromevox or mathspeak)"
42+
},
43+
speechstyle: {
44+
default: "default",
45+
describe: "style to use for speech text (default, brief, sbrief)"
46+
},
47+
linebreaks: {
48+
boolean: true,
49+
describe: "perform automatic line-breaking"
50+
},
51+
css: {
52+
boolean: true,
53+
describe: "output the CSS required for html output rather than the HTML itself"
54+
},
55+
ex: {
56+
default: 6,
57+
describe: "ex-size in pixels"
58+
},
59+
width: {
60+
default: 100,
61+
describe: "width of container in ex"
62+
},
63+
extensions: {
64+
default: "",
65+
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
66+
}
67+
})
68+
.argv;
69+
70+
mjAPI.config({extensions: argv.extensions});
71+
mjAPI.start();
72+
73+
mjAPI.typeset({
74+
math: argv._[0],
75+
format: (argv.inline ? "inline-TeX" : "TeX"),
76+
html:true, css: argv.css,
77+
speakText: argv.speech,
78+
speakRuleset: argv.speechrules.replace(/^chromevox$/i,"default"),
79+
speakStyle: argv.speechstyle,
80+
ex: argv.ex, width: argv.width,
81+
linebreaks: argv.linebreaks
82+
}, function (data) {
83+
if (!data.errors) {console.log(argv.css ? data.css : data.html)}
84+
});

bin/tex2htmlcss

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#! /usr/bin/env node
2+
3+
/*************************************************************************
4+
*
5+
* tex2htmlcss
6+
*
7+
* Uses MathJax to convert a TeX or LaTeX string to an HTML page.
8+
*
9+
* ----------------------------------------------------------------------
10+
*
11+
* Copyright (c) 2014 The MathJax Consortium
12+
*
13+
* Licensed under the Apache License, Version 2.0 (the "License");
14+
* you may not use this file except in compliance with the License.
15+
* You may obtain a copy of the License at
16+
*
17+
* http://www.apache.org/licenses/LICENSE-2.0
18+
*
19+
* Unless required by applicable law or agreed to in writing, software
20+
* distributed under the License is distributed on an "AS IS" BASIS,
21+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22+
* See the License for the specific language governing permissions and
23+
* limitations under the License.
24+
*/
25+
26+
var mjAPI = require("../lib/mj-single.js");
27+
28+
var argv = require("yargs")
29+
.demand(1).strict()
30+
.usage("Usage: tex2htmlcss [options] 'math' > file.mml",{
31+
inline: {
32+
boolean: true,
33+
describe: "process as in-line TeX"
34+
},
35+
speech: {
36+
boolean: true,
37+
describe: "include speech text"
38+
},
39+
speechrules: {
40+
default: "mathspeak",
41+
describe: "ruleset to use for speech text (chromevox or mathspeak)"
42+
},
43+
speechstyle: {
44+
default: "default",
45+
describe: "style to use for speech text (default, brief, sbrief)"
46+
},
47+
linebreaks: {
48+
boolean: true,
49+
describe: "perform automatic line-breaking"
50+
},
51+
ex: {
52+
default: 6,
53+
describe: "ex-size in pixels"
54+
},
55+
width: {
56+
default: 100,
57+
describe: "width of container in ex"
58+
},
59+
extensions: {
60+
default: "",
61+
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
62+
}
63+
})
64+
.argv;
65+
66+
mjAPI.config({extensions: argv.extensions});
67+
mjAPI.start();
68+
69+
mjAPI.typeset({
70+
math: argv._[0],
71+
format: (argv.inline ? "inline-TeX" : "TeX"),
72+
html:true, css: true, svg:true,
73+
speakText: argv.speech,
74+
speakRuleset: argv.speechrules.replace(/^chromevox$/i,"default"),
75+
speakStyle: argv.speechstyle,
76+
ex: argv.ex, width: argv.width,
77+
linebreaks: argv.linebreaks
78+
}, function (data) {
79+
if (!data.errors) {
80+
console.log("<!DOCTYPE html>\n<html>\n<head>");
81+
console.log('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />');
82+
console.log("<title></title>\n<style>");
83+
console.log(data.css);
84+
console.log("</style>\n</head>\n<body>");
85+
console.log(data.html);
86+
console.log("</body>\n</html>");
87+
}
88+
});

0 commit comments

Comments
 (0)