Throw an error instead of embedding error message in output
astoff opened this issue · 2 comments
I would like to never generate a SVG with a <text>Some error message</text>
element inside it and instead throw an error. Following this, I was hoping one could re-throw the error in the compileError
or typesetError
functions.
However, I modified simple/tex2svg to include the following and it seems to have no effect. How can I proceed?
require('mathjax-full').init({
//
// The MathJax configuration
//
options: {
enableAssistiveMml: argv.assistiveMml,
compileError: (_, __, err) => { console.log(err) },
typesetError: (_, __, err) => { console.log(err) },
},
The compileError()
and typesetError()
function are what produce the Math input error
and Math output error
message when something causes the compilation or typesetting to fail internally. A TeX syntax error is not something that does that, as this is something MathJax detects and handles.
To trap that, you want to use the tex.formatError()
function (see here). You can use
require('mathjax-full').init({
//
// The MathJax configuration
//
options: {
enableAssistiveMml: argv.assistiveMml,
compileError: (_, __, err) => { console.log(err) },
typesetError: (_, __, err) => { console.log(err) },
},
tex: {
formatError: (jax, err) => {console.log(err); return jax.formatError(err)}
},
...
or you could use
formatError: (jax, err) => {throw err}
and add a .catch()
clause to the MathJax.tex2svgPromise()
call to catch it.
That works, thanks!