Skip to content

Commit

Permalink
Merge pull request #491 from mathjax/better-errors
Browse files Browse the repository at this point in the history
General improvements to input/output errors
  • Loading branch information
dpvc authored Jun 16, 2020
2 parents f6c9be7 + 834f317 commit 8b8e9a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
33 changes: 28 additions & 5 deletions ts/core/MathDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ export abstract class AbstractMathDocument<N, T, D> implements MathDocument<N, T
*/
public compileError(math: MathItem<N, T, D>, err: Error) {
math.root = this.mmlFactory.create('math', null, [
this.mmlFactory.create('merror', {'data-mjx-error': err.message}, [
this.mmlFactory.create('merror', {'data-mjx-error': err.message, title: err.message}, [
this.mmlFactory.create('mtext', null, [
(this.mmlFactory.create('text') as TextNode).setText('Math input error')
])
Expand All @@ -745,6 +745,7 @@ export abstract class AbstractMathDocument<N, T, D> implements MathDocument<N, T
if (math.display) {
math.root.attributes.set('display', 'block');
}
math.inputData.error = err.message;
}

/**
Expand Down Expand Up @@ -775,10 +776,32 @@ export abstract class AbstractMathDocument<N, T, D> implements MathDocument<N, T
* @param {Error} err The Error object for the error
*/
public typesetError(math: MathItem<N, T, D>, err: Error) {
math.typesetRoot = this.adaptor.node('span',
{'data-mjx-error': err.message},
[this.adaptor.text('Math output error')]);
math.isEscaped = true;
math.typesetRoot = this.adaptor.node('mjx-container', {
class: 'MathJax mjx-output-error',
jax: this.outputJax.name,
}, [
this.adaptor.node('span', {
'data-mjx-error': err.message,
title: err.message,
style: {
color: 'red',
'background-color': 'yellow',
'line-height': 'normal'
}
}, [
this.adaptor.text('Math output error')
])
]);
if (math.display) {
this.adaptor.setAttributes(math.typesetRoot, {
style: {
display: 'block',
margin: '1em 0',
'text-align': 'center'
}
});
}
math.outputData.error = err.message;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion ts/input/tex/noerrors/NoErrorsConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {NodeFactory} from '../NodeFactory.js';
function noErrors(factory: NodeFactory,
message: string, _id: string, expr: string) {
let mtext = factory.create('token', 'mtext', {}, expr.replace(/\n/g, ' '));
let error = factory.create('node', 'merror', [mtext], {'data-mjx-error': message});
let error = factory.create('node', 'merror', [mtext], {'data-mjx-error': message, title: message});
return error;
}

Expand Down
4 changes: 4 additions & 0 deletions ts/output/svg/Wrappers/merror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export class SVGmerror<N, T, D> extends SVGWrapper<N, T, D> {
'data-background': true,
width: this.fixed(w), height: this.fixed(h + d), y: this.fixed(-d)
}));
const title = this.node.attributes.get('title') as string;
if (title) {
this.adaptor.append(this.element, this.svg('title', {}, [this.adaptor.text(title)]));
}
this.addChildren(svg);
}

Expand Down

0 comments on commit 8b8e9a5

Please sign in to comment.