@@ -35,47 +35,69 @@ const {AssistiveMmlHandler} = require('mathjax-full/js/a11y/assistive-mml.js');
3535
3636const { AllPackages} = require ( 'mathjax-full/js/input/tex/AllPackages.js' ) ;
3737
38+ //
39+ // Minimal CSS needed for stand-alone image
40+ //
41+ const CSS = [
42+ 'svg a{fill:blue;stroke:blue}' ,
43+ '[data-mml-node="merror"]>g{fill:red;stroke:red}' ,
44+ '[data-mml-node="merror"]>rect[data-background]{fill:yellow;stroke:none}' ,
45+ '[data-frame],[data-line]{stroke-width:70px;fill:none}' ,
46+ '.mjx-dashed{stroke-dasharray:140}' ,
47+ '.mjx-dotted{stroke-linecap:round;stroke-dasharray:0,140}' ,
48+ 'use[data-c]{stroke-width:3px}'
49+ ] . join ( '' ) ;
50+
3851//
3952// Get the command-line arguments
4053//
4154var argv = require ( 'yargs' )
4255 . demand ( 0 ) . strict ( )
4356 . usage ( '$0 [options] "math" > file.svg' )
4457 . options ( {
45- inline : {
46- boolean : true ,
47- describe : "process as inline math"
48- } ,
49- em : {
50- default : 16 ,
51- describe : 'em-size in pixels'
52- } ,
53- ex : {
54- default : 8 ,
55- describe : 'ex-size in pixels'
56- } ,
57- width : {
58- default : 80 * 16 ,
59- describe : 'width of container in pixels'
60- } ,
61- packages : {
62- default : AllPackages . sort ( ) . join ( ', ' ) ,
63- describe : 'the packages to use, e.g. "base, ams"'
64- } ,
65- css : {
66- boolean : true ,
67- describe : 'output the required CSS rather than the SVG itself'
68- } ,
69- fontCache : {
70- boolean : true ,
71- default : true ,
72- describe : 'whether to use a local font cache or not'
73- } ,
74- assistiveMml : {
75- boolean : true ,
76- default : false ,
77- describe : 'whether to include assistive MathML output'
78- }
58+ inline : {
59+ boolean : true ,
60+ describe : "process as inline math"
61+ } ,
62+ em : {
63+ default : 16 ,
64+ describe : 'em-size in pixels'
65+ } ,
66+ ex : {
67+ default : 8 ,
68+ describe : 'ex-size in pixels'
69+ } ,
70+ width : {
71+ default : 80 * 16 ,
72+ describe : 'width of container in pixels'
73+ } ,
74+ packages : {
75+ default : AllPackages . sort ( ) . join ( ', ' ) ,
76+ describe : 'the packages to use, e.g. "base, ams"'
77+ } ,
78+ styles : {
79+ boolean : true ,
80+ default : true ,
81+ describe : 'include css styles for stand-alone image'
82+ } ,
83+ container : {
84+ boolean : true ,
85+ describe : 'include <mjx-container> element'
86+ } ,
87+ css : {
88+ boolean : true ,
89+ describe : 'output the required CSS rather than the SVG itself'
90+ } ,
91+ fontCache : {
92+ boolean : true ,
93+ default : true ,
94+ describe : 'whether to use a local font cache or not'
95+ } ,
96+ assistiveMml : {
97+ boolean : true ,
98+ default : false ,
99+ describe : 'whether to include assistive MathML output'
100+ }
79101 } )
80102 . argv ;
81103
@@ -97,18 +119,19 @@ const html = mathjax.document('', {InputJax: tex, OutputJax: svg});
97119// Typeset the math from the command line
98120//
99121const node = html . convert ( argv . _ [ 0 ] || '' , {
100- display : ! argv . inline ,
101- em : argv . em ,
102- ex : argv . ex ,
103- containerWidth : argv . width
122+ display : ! argv . inline ,
123+ em : argv . em ,
124+ ex : argv . ex ,
125+ containerWidth : argv . width
104126} ) ;
105127
106128//
107129// If the --css option was specified, output the CSS,
108130// Otherwise, typeset the math and output the HTML
109131//
110132if ( argv . css ) {
111- console . log ( adaptor . textContent ( svg . styleSheet ( html ) ) ) ;
133+ console . log ( adaptor . textContent ( svg . styleSheet ( html ) ) ) ;
112134} else {
113- console . log ( adaptor . outerHTML ( node ) ) ;
135+ let html = ( argv . container ? adaptor . outerHTML ( node ) : adaptor . innerHTML ( node ) ) ;
136+ console . log ( argv . styles ? html . replace ( / < d e f s > / , `<defs><style>${ CSS } </style>` ) : html ) ;
114137}
0 commit comments