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

How to get the ParseError from the auto-render extension? #2682

Open
q2apro opened this issue Dec 13, 2020 · 0 comments
Open

How to get the ParseError from the auto-render extension? #2682

q2apro opened this issue Dec 13, 2020 · 0 comments

Comments

@q2apro
Copy link

q2apro commented Dec 13, 2020

I am using the Auto-render extension heavily (github).

I use the error handling like this:

renderMathInElement(document.body, {
	delimiters: [
		{left: "$$", right: "$$", display: true},
		{left: "\\(", right: "\\)", display: false},
		{left: "\\[", right: "\\]", display: false},
	],
	macros: {
		":": "{\\char`:}",
		",": "{\\char`,}",
		"·": "{\\char`·}",
	},
	fleqn: true,
	errorCallback: function(error) 
	{
		// LATEX ERROR FOUND - Katex cannot parse
		// show error box bottom right
		var $div = $("<div>", {id: "dialog-box-error", "class": "error-bg" });
		// $div.click( function(){ $(this).remove() });
		$('.main').append($div);
		$div.text(error.replace('\\(', '').replace('\\)', '').replace(' with', ''));
		//console.log(error);
	},
	preProcess: (math) => math.replace(/&nbsp;/g, ' '),
});
console.log('Katex rendered');

With autorender I get (example):

KaTeX auto-render: Failed to parse a_N(150 \frac{ \mbox {km}}{\text{h}})=\frac{v^2}{r}=\frac{ \left(150 \frac{ \mbox {km}}{\text{h}} \right) ^2 }{200\text{m} }= \frac{\left( 150\frac{1000\mbox {m}}{3600\text{s}} \right)^2 }{200\text{m}} \approx 8,681 \frac{\text{m}}{\text{s}^2}KaTeX auto-render: Failed to parse s=v_0 \cdot t + \frac{1}{2}a_T \cdot t^2=120 \frac{\mbox {km}}{\text{h}} \cdot 3\text{s} + \frac{1}{2} 2,778\frac{\text{m}}{\text{s}^2} \cdot (3\text{s})^2=112,5\text{m} with

With Katex error handling, however, I get:

KaTeX auto-render: Failed to parse s=v_0 \cdot t + \frac{1}{2}a_T  \cdot t^2=120 \frac{\mbox {km}}{\text{h}} \cdot 3\text{s} + \frac{1}{2} 2,778\frac{\text{m}}{\text{s}^2} \cdot (3\text{s})^2=112,5\text{m} with ParseError: KaTeX parse error: Undefined control sequence: \mbox at position 53: … t^2=120 \frac{\̲m̲b̲o̲x̲ ̲{km}}{\text{h}}…

The important part is missing:

ParseError: KaTeX parse error: Undefined control sequence: \mbox at position 53: … t^2=120 \frac{\̲m̲b̲o̲x̲ ̲{km}}{\text{h}}…

How to get the ParseError message in the callback?


REF: #2616

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant