Skip to content

Commit 81bb9d7

Browse files
committed
Initial use of defaults.
1 parent 517252f commit 81bb9d7

File tree

2 files changed

+65
-16
lines changed

2 files changed

+65
-16
lines changed

bin/mjsre.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,32 @@ const argv = require("yargs")
2525
.options({
2626
speech: {
2727
boolean: true,
28-
default: true,
28+
default: mj.options.speak,
2929
describe: "include speech text"
3030
},
31-
speechrules: {
32-
default: "mathspeak",
31+
sre: {
32+
array: true,
33+
nargs: 2,
34+
describe: "SRE flags as key value pairs"
35+
},
36+
speechrules: { // deprecated
37+
default: mj.options.speakRules,
3338
describe: "ruleset to use for speech text (chromevox or mathspeak)"
3439
},
35-
speechstyle: {
36-
default: "default",
40+
speechstyle: { // deprecated
41+
default: mj.options.speakStyle,
3742
describe: "style to use for speech text (default, brief, sbrief)"
3843
},
3944
linebreaks: {
4045
boolean: true,
4146
describe: "perform automatic line-breaking"
4247
},
4348
format: {
44-
default: "TeX",
49+
default: mj.options.format,
4550
describe: "input format(s) to look for"
4651
},
4752
font: {
48-
default: "TeX",
53+
default: mj.options.font,
4954
describe: "web font to use"
5055
},
5156
inline: {
@@ -61,24 +66,24 @@ const argv = require("yargs")
6166
describe: "For TeX input and MathML output, don't add TeX-specific classes"
6267
},
6368
output: {
64-
default: "SVG",
69+
default: mj.options.output,
6570
describe: "output format (SVG, CommonHTML, or MML)",
6671
coerce: (x => {return x.toLowerCase();})
6772
},
6873
ex: {
69-
default: 6,
74+
default: mj.options.ex,
7075
describe: "ex-size in pixels"
7176
},
7277
width: {
73-
default: 100,
78+
default: mj.options.width,
7479
describe: "width of equation container in ex (for line-breaking)"
7580
},
7681
extensions: {
77-
default: "",
82+
default: mj.options.extensions,
7883
describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'"
7984
},
8085
fontURL: {
81-
default: "https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS",
86+
default: mj.options.fontURL,
8287
describe: "the URL to use for web fonts"
8388
},
8489
css: {
@@ -124,16 +129,17 @@ const mjinput = {
124129
speakStyle: argv.speechstyle,
125130
ex: argv.ex,
126131
width: argv.width,
127-
linebreaks: argv.linebreaks
128-
}
132+
linebreaks: argv.linebreaks,
133+
sre: argv.sre
134+
};
129135

130136
console.log(argv._[0])
131137
const output = function(result) {
132138
if (result.errors) console.log(result.errors);
133139
else if (argv.css) console.log(result.css);
134140
else console.log(result[argv.output]);
135-
}
141+
};
136142

137143
mj.config(mjconf);
138144
mj.start();
139-
mj.typeset(mjinput, output)
145+
mj.typeset(mjinput, output);

lib/main.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,48 @@ const sre = require('speech-rule-engine');
2121
// speakText: // string with spoken annotation
2222

2323

24+
const optionsDefault = {
25+
speak: true,
26+
speakRules: "mathspeak",
27+
speakStyle: "default",
28+
format: "TeX",
29+
font: "TeX",
30+
output: "SVG",
31+
ex: 6,
32+
width: 100,
33+
extensions: "",
34+
enrich: false,
35+
semantic: false,
36+
fontURL: "https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS"
37+
};
38+
39+
const sreDefault = {
40+
speech: 'deep',
41+
semantics: true,
42+
domain: 'mathspeak',
43+
style: 'default'
44+
};
45+
46+
47+
const sreconfig = function(data) {
48+
let config = {
49+
// TODO: remove as deprecated!
50+
domain: data.speakRules || 'mathspeak',
51+
style: data.speakStyle || 'default',
52+
// TODO: What does that do?
53+
minSTree: data.minSTree
54+
};
55+
if (data.sre) {
56+
for (let i = 0, key; key = data.sre[i]; i++) {
57+
let value = data.sre[++i];
58+
config[key] = value || false;
59+
}
60+
}
61+
Object.assign(sreDefault, config);
62+
return config;
63+
};
64+
65+
2466
const main = function (data, callback) {
2567
const speechConfig = {
2668
speech: data.speech ||'deep',
@@ -138,6 +180,7 @@ const preprocessor = function (data, callback) {
138180
}
139181

140182

183+
exports.options = optionsDefault;
141184
exports.start = mathjax.start;
142185
exports.config = mathjax.config;
143186
const cbTypeset = function (data, callback) {

0 commit comments

Comments
 (0)