2019-08-31 20:48:37 +03:00
|
|
|
export function renderEquation( equation, element, engine = 'katex', display = false ) {
|
|
|
|
if ( engine === 'mathjax' && typeof katex !== 'mathjax' ) {
|
|
|
|
if (display) {
|
|
|
|
element.innerHTML = '\\[' + equation + '\\]';
|
|
|
|
} else {
|
|
|
|
element.innerHTML = '\\(' + equation + '\\)';
|
|
|
|
}
|
|
|
|
/* eslint-disable */
|
|
|
|
MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, element ] );
|
|
|
|
/* eslint-enable */
|
2019-09-17 16:19:35 +03:00
|
|
|
} else if ( engine === 'katex' && typeof katex !== 'undefined' ) {
|
2019-08-31 20:48:37 +03:00
|
|
|
/* eslint-disable */
|
|
|
|
katex.render( equation, element, {
|
|
|
|
throwOnError: false,
|
|
|
|
displayMode: display
|
|
|
|
} );
|
|
|
|
/* eslint-enable */
|
2019-09-17 16:19:35 +03:00
|
|
|
} else if ( typeof engine === 'function' ) {
|
|
|
|
engine(equation, element, display);
|
2019-08-31 20:48:37 +03:00
|
|
|
} else {
|
|
|
|
element.innerHTML = equation;
|
2019-09-17 16:19:35 +03:00
|
|
|
console.warn( `math-tex-typesetting-missing: Missing the mathematical typesetting engine (${engine}) for tex.` );
|
2019-08-31 20:48:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSelectedMathModelWidget( selection ) {
|
|
|
|
const selectedElement = selection.getSelectedElement();
|
|
|
|
|
|
|
|
if ( selectedElement && selectedElement.is( 'mathtex' ) ) {
|
|
|
|
return selectedElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2019-09-17 16:31:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
export const defaultConfig = {
|
2019-09-17 19:39:49 +03:00
|
|
|
/*
|
|
|
|
engine: (equation, element, display) => {
|
|
|
|
console.log(equation, element, display);
|
|
|
|
},
|
|
|
|
*/
|
2019-09-17 16:31:39 +03:00
|
|
|
engine: 'mathjax',
|
2019-09-17 19:39:49 +03:00
|
|
|
outputType: 'script',
|
|
|
|
forceOutputType: false
|
2019-09-17 16:31:39 +03:00
|
|
|
}
|