Debian Codegraph @

internal/warpc/js/renderkatex.js

raw
1 import { readInput, writeOutput } from './common';
2 import katex from 'katex';
3 import 'katex/contrib/mhchem/mhchem.js';
4
5 const render = function (input) {
6 const data = input.data;
7 const expression = data.expression;
8 const options = data.options;
9 const header = input.header;
10 header.warnings = [];
11
12 if (options.strict == 'warn') {
13 // By default, KaTeX will write to console.warn, that's a little hard to handle.
14 options.strict = (errorCode, errorMsg) => {
15 header.warnings.push(
16 `katex: LaTeX-incompatible input and strict mode is set to 'warn': ${errorMsg} [${errorCode}]`,
17 );
18 };
19 }
20 // Any error thrown here will be caught by the common.js readInput function.
21 const output = katex.renderToString(expression, options);
22 writeOutput({ header: header, data: { output: output } });
23 };
24
25 readInput(render);