Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General improvements to input/output errors #491

Merged
merged 3 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions ts/core/MathDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,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 @@ -744,6 +744,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 @@ -774,10 +775,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