Mon, 06 Jul 2020 13:01:18 -0500
Use @neilsustc/markdown-it-katex instead of markdown-it-katex.
The latter is broken
#!/usr/bin/env node /*eslint no-console:0*/ var fs = require('fs'); var hljs = require('highlight.js'); var katexOptions = { throwOnError: false, macros: { "\\iprod": "{\\langle #1, #2\\rangle}", "\\grad": "\\nabla", "\\isect": "\\cap", "\\union": "\\cup", "\\Isect": "\\bigcap", "\\Union": "\\bigcup", "\\supp": "\\mathop{\\mathrm{supp}}", "\\sign": "\\mathop{\\mathrm{sign}}", "\\Id": "\\mathop{\\mathrm{Id}}", "\\linear": "\\mathbb{L}" } }; // process.argv[0] seems to be the node executable itself if(process.argv.length<=2){ console.error(`Usage: ${process.argv[1]} input_file`) process.exit(1); } fs.readFile(process.argv[2], 'utf8', function (err, input) { var output, md; if(err){ console.error(err.stack || err.message || String(err)); process.exit(1); } try{ var md = require('markdown-it')({ html: true, xhtmlOut: true, breaks: false, linkify: true, highlight: function (str, lang) { if (lang && hljs.getLanguage(lang)) { try{ return hljs.highlight(lang, str).value; } catch (__){} } return ''; } }) var mk = require('@neilsustc/markdown-it-katex'); var mm = require('markdown-it-mark'); md.use(mk, katexOptions).use(mm); output = md.render(input); } catch(e) { console.error(e.stack || e.message || String(e)); process.exit(1); } process.stdout.write(output); });