|  | 
|  | 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("mathjax-node"); | 
|  | 27 | + | 
|  | 28 | +var argv = require("yargs") | 
|  | 29 | +  .demand(1).strict() | 
|  | 30 | +  .usage("Usage: am2htmlcss [options] 'math' > file.html",{ | 
|  | 31 | +    speech: { | 
|  | 32 | +      boolean: true, | 
|  | 33 | +      default: true, | 
|  | 34 | +      describe: "include speech text" | 
|  | 35 | +    }, | 
|  | 36 | +    linebreaks: { | 
|  | 37 | +      boolean: true, | 
|  | 38 | +      describe: "perform automatic line-breaking" | 
|  | 39 | +    }, | 
|  | 40 | +    ex: { | 
|  | 41 | +      default: 6, | 
|  | 42 | +      describe: "ex-size in pixels" | 
|  | 43 | +    }, | 
|  | 44 | +    width: { | 
|  | 45 | +      default: 100, | 
|  | 46 | +      describe: "width of container in ex" | 
|  | 47 | +    }, | 
|  | 48 | +    extensions: { | 
|  | 49 | +      default: "", | 
|  | 50 | +      describe: "extra MathJax extensions e.g. 'Safe,TeX/noUndefined'" | 
|  | 51 | +    }, | 
|  | 52 | +    fontURL: { | 
|  | 53 | +      default: "https://cdn.mathjax.org/mathjax/latest/fonts/HTML-CSS", | 
|  | 54 | +      describe: "the URL to use for web fonts" | 
|  | 55 | +    } | 
|  | 56 | +  }) | 
|  | 57 | +  .argv; | 
|  | 58 | + | 
|  | 59 | +mjAPI.config({extensions: argv.extensions, fontURL: argv.fontURL}); | 
|  | 60 | +mjAPI.start(); | 
|  | 61 | + | 
|  | 62 | +mjAPI.typeset({ | 
|  | 63 | +  math: argv._[0], | 
|  | 64 | +  format: "AsciiMath", | 
|  | 65 | +  html:true, css: true, | 
|  | 66 | +  speakText: argv.speech, | 
|  | 67 | +  ex: argv.ex, width: argv.width, | 
|  | 68 | +  linebreaks: argv.linebreaks | 
|  | 69 | +}, function (data) { | 
|  | 70 | +  if (!data.errors) { | 
|  | 71 | +    console.log("<!DOCTYPE html>\n<html>\n<head>"); | 
|  | 72 | +    console.log('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'); | 
|  | 73 | +    console.log("<title></title>\n<style>"); | 
|  | 74 | +    console.log(data.css); | 
|  | 75 | +    console.log("</style>\n</head>\n<body>"); | 
|  | 76 | +    console.log(data.html); | 
|  | 77 | +    console.log("</body>\n</html>"); | 
|  | 78 | +  } | 
|  | 79 | +}); | 
0 commit comments