Skip to content

Commit

Permalink
Merge branch '3.1.3-update'
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Apr 28, 2021
2 parents 0602206 + 3c3946f commit 73bf96e
Show file tree
Hide file tree
Showing 21 changed files with 410 additions and 157 deletions.
25 changes: 24 additions & 1 deletion component/mml2svg
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ var argv = require('yargs')
default: 80 * 16,
describe: 'width of container in pixels'
},
styles: {
boolean: true,
default: true,
describe: 'include css styles for stand-alone image'
},
container: {
boolean: true,
describe: 'include <mjx-container> element'
},
css: {
boolean: true,
describe: 'output the required CSS rather than the HTML itself'
Expand All @@ -69,6 +78,19 @@ var argv = require('yargs')
})
.argv;

//
// Minimal CSS needed for stand-alone image
//
const CSS = [
'svg a{fill:blue;stroke:blue}',
'[data-mml-node="merror"]>g{fill:red;stroke:red}',
'[data-mml-node="merror"]>rect[data-background]{fill:yellow;stroke:none}',
'[data-frame],[data-line]{stroke-width:70px;fill:none}',
'.mjx-dashed{stroke-dasharray:140}',
'.mjx-dotted{stroke-linecap:round;stroke-dasharray:0,140}',
'use[data-c]{stroke-width:3px}'
].join('');

//
// Configure MathJax
//
Expand Down Expand Up @@ -113,7 +135,8 @@ MathJax.startup.promise.then(() => {
if (argv.css) {
console.log(adaptor.textContent(MathJax.svgStylesheet()));
} else {
console.log(adaptor.outerHTML(node));
let html = (argv.container ? adaptor.outerHTML(node) : adaptor.innerHTML(node));
console.log(argv.styles ? html.replace(/<defs>/, `<defs><style>${CSS}</style>`) : html);
};
});
}).catch(err => console.log(err));
25 changes: 24 additions & 1 deletion component/tex2svg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
//
const PACKAGES = 'base, autoload, require, ams, newcommand';

//
// Minimal CSS needed for stand-alone image
//
const CSS = [
'svg a{fill:blue;stroke:blue}',
'[data-mml-node="merror"]>g{fill:red;stroke:red}',
'[data-mml-node="merror"]>rect[data-background]{fill:yellow;stroke:none}',
'[data-frame],[data-line]{stroke-width:70px;fill:none}',
'.mjx-dashed{stroke-dasharray:140}',
'.mjx-dotted{stroke-linecap:round;stroke-dasharray:0,140}',
'use[data-c]{stroke-width:3px}'
].join('');

//
// Get the command-line arguments
//
Expand Down Expand Up @@ -56,6 +69,15 @@ var argv = require('yargs')
default: PACKAGES,
describe: 'the packages to use, e.g. "base, ams"; use "*" to represent the default packages, e.g, "*, bbox"'
},
styles: {
boolean: true,
default: true,
describe: 'include css styles for stand-alone image'
},
container: {
boolean: true,
describe: 'include <mjx-container> element'
},
css: {
boolean: true,
describe: 'output the required CSS rather than the HTML itself'
Expand Down Expand Up @@ -125,7 +147,8 @@ MathJax.startup.promise.then(() => {
if (argv.css) {
console.log(adaptor.textContent(MathJax.svgStylesheet()));
} else {
console.log(adaptor.outerHTML(node));
let html = (argv.container ? adaptor.outerHTML(node) : adaptor.innerHTML(node));
console.log(argv.styles ? html.replace(/<defs>/, `<defs><style>${CSS}</style>`) : html);
};
});
}).catch(err => console.log(err));
87 changes: 55 additions & 32 deletions direct/mml2svg
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,57 @@ var argv = require('yargs')
.demand(0).strict()
.usage('$0 [options] "math" > file.html')
.options({
em: {
default: 16,
describe: 'em-size in pixels'
},
ex: {
default: 8,
describe: 'ex-size in pixels'
},
width: {
default: 80 * 16,
describe: 'width of container in pixels'
},
css: {
boolean: true,
describe: 'output the required CSS rather than the SVG itself'
},
fontCache: {
boolean: true,
default: true,
describe: 'whether to use a local font cache or not'
},
assistiveMml: {
boolean: true,
default: false,
describe: 'whether to include assistive MathML output'
}
em: {
default: 16,
describe: 'em-size in pixels'
},
ex: {
default: 8,
describe: 'ex-size in pixels'
},
width: {
default: 80 * 16,
describe: 'width of container in pixels'
},
styles: {
boolean: true,
default: true,
describe: 'include css styles for stand-alone image'
},
container: {
boolean: true,
describe: 'include <mjx-container> element'
},
css: {
boolean: true,
describe: 'output the required CSS rather than the SVG itself'
},
fontCache: {
boolean: true,
default: true,
describe: 'whether to use a local font cache or not'
},
assistiveMml: {
boolean: true,
default: false,
describe: 'whether to include assistive MathML output'
}
})
.argv;

//
// Minimal CSS needed for stand-alone image
//
const CSS = [
'svg a{fill:blue;stroke:blue}',
'[data-mml-node="merror"]>g{fill:red;stroke:red}',
'[data-mml-node="merror"]>rect[data-background]{fill:yellow;stroke:none}',
'[data-frame],[data-line]{stroke-width:70px;fill:none}',
'.mjx-dashed{stroke-dasharray:140}',
'.mjx-dotted{stroke-linecap:round;stroke-dasharray:0,140}',
'use[data-c]{stroke-width:3px}'
].join('');

//
// Create DOM adaptor and register it for HTML documents
//
Expand All @@ -87,18 +109,19 @@ const html = mathjax.document('', {InputJax: mml, OutputJax: svg});
// Typeset the math from the command line
//
const node = html.convert(argv._[0] || '', {
display: !argv.inline,
em: argv.em,
ex: argv.ex,
containerWidth: argv.width
display: !argv.inline,
em: argv.em,
ex: argv.ex,
containerWidth: argv.width
});

//
// If the --css option was specified, output the CSS,
// Otherwise, typeset the math and output the HTML
//
if (argv.css) {
console.log(adaptor.textContent(svg.styleSheet(html)));
console.log(adaptor.textContent(svg.styleSheet(html)));
} else {
console.log(adaptor.outerHTML(node));
let html = (argv.container ? adaptor.outerHTML(node) : adaptor.innerHTML(node));
console.log(argv.styles ? html.replace(/<defs>/, `<defs><style>${CSS}</style>`) : html);
}
103 changes: 63 additions & 40 deletions direct/tex2svg
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,69 @@ const {AssistiveMmlHandler} = require('mathjax-full/js/a11y/assistive-mml.js');

const {AllPackages} = require('mathjax-full/js/input/tex/AllPackages.js');

//
// Minimal CSS needed for stand-alone image
//
const CSS = [
'svg a{fill:blue;stroke:blue}',
'[data-mml-node="merror"]>g{fill:red;stroke:red}',
'[data-mml-node="merror"]>rect[data-background]{fill:yellow;stroke:none}',
'[data-frame],[data-line]{stroke-width:70px;fill:none}',
'.mjx-dashed{stroke-dasharray:140}',
'.mjx-dotted{stroke-linecap:round;stroke-dasharray:0,140}',
'use[data-c]{stroke-width:3px}'
].join('');

//
// Get the command-line arguments
//
var argv = require('yargs')
.demand(0).strict()
.usage('$0 [options] "math" > file.svg')
.options({
inline: {
boolean: true,
describe: "process as inline math"
},
em: {
default: 16,
describe: 'em-size in pixels'
},
ex: {
default: 8,
describe: 'ex-size in pixels'
},
width: {
default: 80 * 16,
describe: 'width of container in pixels'
},
packages: {
default: AllPackages.sort().join(', '),
describe: 'the packages to use, e.g. "base, ams"'
},
css: {
boolean: true,
describe: 'output the required CSS rather than the SVG itself'
},
fontCache: {
boolean: true,
default: true,
describe: 'whether to use a local font cache or not'
},
assistiveMml: {
boolean: true,
default: false,
describe: 'whether to include assistive MathML output'
}
inline: {
boolean: true,
describe: "process as inline math"
},
em: {
default: 16,
describe: 'em-size in pixels'
},
ex: {
default: 8,
describe: 'ex-size in pixels'
},
width: {
default: 80 * 16,
describe: 'width of container in pixels'
},
packages: {
default: AllPackages.sort().join(', '),
describe: 'the packages to use, e.g. "base, ams"'
},
styles: {
boolean: true,
default: true,
describe: 'include css styles for stand-alone image'
},
container: {
boolean: true,
describe: 'include <mjx-container> element'
},
css: {
boolean: true,
describe: 'output the required CSS rather than the SVG itself'
},
fontCache: {
boolean: true,
default: true,
describe: 'whether to use a local font cache or not'
},
assistiveMml: {
boolean: true,
default: false,
describe: 'whether to include assistive MathML output'
}
})
.argv;

Expand All @@ -97,18 +119,19 @@ const html = mathjax.document('', {InputJax: tex, OutputJax: svg});
// Typeset the math from the command line
//
const node = html.convert(argv._[0] || '', {
display: !argv.inline,
em: argv.em,
ex: argv.ex,
containerWidth: argv.width
display: !argv.inline,
em: argv.em,
ex: argv.ex,
containerWidth: argv.width
});

//
// If the --css option was specified, output the CSS,
// Otherwise, typeset the math and output the HTML
//
if (argv.css) {
console.log(adaptor.textContent(svg.styleSheet(html)));
console.log(adaptor.textContent(svg.styleSheet(html)));
} else {
console.log(adaptor.outerHTML(node));
let html = (argv.container ? adaptor.outerHTML(node) : adaptor.innerHTML(node));
console.log(argv.styles ? html.replace(/<defs>/, `<defs><style>${CSS}</style>`) : html);
}
2 changes: 1 addition & 1 deletion jsdom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ npm install --production

(If you wish to rebuild the jsdom adaptor component, then leave off the `--production` so that the developer dependencies will be isntalled.)

The exampk files should be executables that you can run. On non-unix systems, you may need to call
The example files should be executables that you can run. On non-unix systems, you may need to call

``` bash
node -r esm <example-name>
Expand Down
Loading

0 comments on commit 73bf96e

Please sign in to comment.