Skip to content

Commit 1cdd8b3

Browse files
committed
Add support for setting the URL for CHTML web fonts, and add command line tools for AsciiMath and MathML to HTML.
1 parent 077899a commit 1cdd8b3

File tree

10 files changed

+380
-18
lines changed

10 files changed

+380
-18
lines changed

bin/am2html

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+
* am2html
6+
*
7+
* Uses MathJax to convert an AsciiMath string to an HTML string.
8+
*
9+
* ----------------------------------------------------------------------
10+
*
11+
* Copyright (c) 2016 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: am2html [options] 'math' > file.html",{
31+
speech: {
32+
boolean: true,
33+
describe: "include speech text"
34+
},
35+
speechrules: {
36+
default: "mathspeak",
37+
describe: "ruleset to use for speech text (chromevox or mathspeak)"
38+
},
39+
speechstyle: {
40+
default: "default",
41+
describe: "style to use for speech text (default, brief, sbrief)"
42+
},
43+
linebreaks: {
44+
boolean: true,
45+
describe: "perform automatic line-breaking"
46+
},
47+
ex: {
48+
default: 6,
49+
describe: "ex-size in pixels"
50+
},
51+
width: {
52+
default: 100,
53+
describe: "width of container in ex"
54+
},
55+
extensions: {
56+
default: "",
57+
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
58+
},
59+
css: {
60+
boolean: true,
61+
describe: "output the required CSS rather than the HTML itself"
62+
},
63+
fontURL: {
64+
default: "https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS",
65+
describe: "the URL to use for web fonts"
66+
}
67+
})
68+
.argv;
69+
70+
mjAPI.config({extensions: argv.extensions, fontURL: argv.fontURL});
71+
mjAPI.start();
72+
73+
mjAPI.typeset({
74+
math: argv._[0],
75+
format: "AsciiMath",
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/am2htmlcss

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+
* am2htmlcss
6+
*
7+
* Uses MathJax to convert an AsciiMath string to an HTML page.
8+
*
9+
* ----------------------------------------------------------------------
10+
*
11+
* Copyright (c) 2016 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: am2htmlcss [options] 'math' > file.html",{
31+
speech: {
32+
boolean: true,
33+
describe: "include speech text"
34+
},
35+
speechrules: {
36+
default: "mathspeak",
37+
describe: "ruleset to use for speech text (chromevox or mathspeak)"
38+
},
39+
speechstyle: {
40+
default: "default",
41+
describe: "style to use for speech text (default, brief, sbrief)"
42+
},
43+
linebreaks: {
44+
boolean: true,
45+
describe: "perform automatic line-breaking"
46+
},
47+
ex: {
48+
default: 6,
49+
describe: "ex-size in pixels"
50+
},
51+
width: {
52+
default: 100,
53+
describe: "width of container in ex"
54+
},
55+
extensions: {
56+
default: "",
57+
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
58+
},
59+
fontURL: {
60+
default: "https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS",
61+
describe: "the URL to use for web fonts"
62+
}
63+
})
64+
.argv;
65+
66+
mjAPI.config({extensions: argv.extensions, fontURL: argv.fontURL});
67+
mjAPI.start();
68+
69+
mjAPI.typeset({
70+
math: argv._[0],
71+
format: "AsciiMath",
72+
html:true, css: 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+
});

bin/mml2html

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+
* mml2html
6+
*
7+
* Uses MathJax to convert a MathML string to an HTML string.
8+
*
9+
* ----------------------------------------------------------------------
10+
*
11+
* Copyright (c) 2016 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: mml2html [options] 'math' > file.html",{
31+
speech: {
32+
boolean: true,
33+
describe: "include speech text"
34+
},
35+
speechrules: {
36+
default: "mathspeak",
37+
describe: "ruleset to use for speech text (chromevox or mathspeak)"
38+
},
39+
speechstyle: {
40+
default: "default",
41+
describe: "style to use for speech text (default, brief, sbrief)"
42+
},
43+
linebreaks: {
44+
boolean: true,
45+
describe: "perform automatic line-breaking"
46+
},
47+
ex: {
48+
default: 6,
49+
describe: "ex-size in pixels"
50+
},
51+
width: {
52+
default: 100,
53+
describe: "width of container in ex"
54+
},
55+
extensions: {
56+
default: "",
57+
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
58+
},
59+
css: {
60+
boolean: true,
61+
describe: "output the required CSS rather than the HTML itself"
62+
},
63+
fontURL: {
64+
default: "https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS",
65+
describe: "the URL to use for web fonts"
66+
}
67+
})
68+
.argv;
69+
70+
mjAPI.config({extensions: argv.extensions});
71+
mjAPI.start();
72+
73+
mjAPI.typeset({
74+
math: argv._[0],
75+
format: "MathML",
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/mml2htmlcss

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+
* mml2htmlcss
6+
*
7+
* Uses MathJax to convert a MathML string to an HTML page.
8+
*
9+
* ----------------------------------------------------------------------
10+
*
11+
* Copyright (c) 2016 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: mml2htmlcss [options] 'math' > file.html",{
31+
speech: {
32+
boolean: true,
33+
describe: "include speech text"
34+
},
35+
speechrules: {
36+
default: "mathspeak",
37+
describe: "ruleset to use for speech text (chromevox or mathspeak)"
38+
},
39+
speechstyle: {
40+
default: "default",
41+
describe: "style to use for speech text (default, brief, sbrief)"
42+
},
43+
linebreaks: {
44+
boolean: true,
45+
describe: "perform automatic line-breaking"
46+
},
47+
ex: {
48+
default: 6,
49+
describe: "ex-size in pixels"
50+
},
51+
width: {
52+
default: 100,
53+
describe: "width of container in ex"
54+
},
55+
extensions: {
56+
default: "",
57+
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
58+
},
59+
fontURL: {
60+
default: "https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS",
61+
describe: "the URL to use for web fonts"
62+
}
63+
})
64+
.argv;
65+
66+
mjAPI.config({extensions: argv.extensions});
67+
mjAPI.start();
68+
69+
mjAPI.typeset({
70+
math: argv._[0],
71+
format: "MathML",
72+
html:true, css: 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+
});

bin/mml2mml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var mjAPI = require("../lib/mj-single.js");
2828

2929
var argv = require("yargs")
3030
.demand(1).strict()
31-
.usage("Usage: mml2mml [options] 'math' > file.xml",{
31+
.usage("Usage: mml2mml [options] 'math' > file.mml",{
3232
speech: {
3333
boolean: true,
3434
describe: "include speech text"

0 commit comments

Comments
 (0)