Handle KaTeX warnings (#13760)

Co-authored-by: Joe Mooring <joe.mooring@veriphor.com>

Fixes #13735
This commit is contained in:
Bjørn Erik Pedersen
2025-05-30 20:57:54 +02:00
committed by GitHub
parent 75259636c8
commit 6334948515
10 changed files with 76 additions and 15 deletions

View File

@@ -7,6 +7,16 @@ const render = function (input) {
const expression = data.expression;
const options = data.options;
const header = input.header;
header.warnings = [];
if (options.strict == 'warn') {
// By default, KaTeX will write to console.warn, that's a little hard to handle.
options.strict = (errorCode, errorMsg) => {
header.warnings.push(
`katex: LaTeX-incompatible input and strict mode is set to 'warn': ${errorMsg} [${errorCode}]`,
);
};
}
// Any error thrown here will be caught by the common.js readInput function.
const output = katex.renderToString(expression, options);
writeOutput({ header: header, data: { output: output } });