cli.js (935B)
1 #!/usr/bin/env node 2 // Simple CLI for KaTeX. 3 // Reads TeX from stdin, outputs HTML to stdout. 4 /* eslint no-console:0 */ 5 6 const katex = require("./"); 7 let input = ""; 8 9 // Skip the first two args, which are just "node" and "cli.js" 10 const args = process.argv.slice(2); 11 12 if (args.indexOf("--help") !== -1) { 13 console.log(process.argv[0] + " " + process.argv[1] + 14 " [ --help ]" + 15 " [ --display-mode ]"); 16 17 console.log("\n" + 18 "Options:"); 19 console.log(" --help Display this help message"); 20 console.log(" --display-mode Render in display mode (not inline mode)"); 21 process.exit(); 22 } 23 24 process.stdin.on("data", function(chunk) { 25 input += chunk.toString(); 26 }); 27 28 process.stdin.on("end", function() { 29 const options = { displayMode: args.indexOf("--display-mode") !== -1 }; 30 const output = katex.renderToString(input, options); 31 console.log(output); 32 });