@@ -195,6 +195,10 @@ function ConfigureMathJax() {
195195 AddError ( "SVG - Unknown character: U+" + message [ 1 ] . toString ( 16 ) . toUpperCase ( ) +
196196 " in " + ( message [ 2 ] . fonts || [ "unknown" ] ) . join ( "," ) , ! undefinedChar ) ;
197197 } ) ;
198+ MathJax . Hub . Register . MessageHook ( "CommonHTML Jax - unknown char" , function ( message ) {
199+ AddError ( "CHTML - Unknown character: U+" + message [ 1 ] . toString ( 16 ) . toUpperCase ( ) +
200+ " in " + ( message [ 2 ] . fonts || [ "unknown" ] ) . join ( "," ) , ! undefinedChar ) ;
201+ } ) ;
198202 MathJax . Hub . Register . MessageHook ( "MathML Jax - unknown node type" , function ( message ) {
199203 AddError ( "MathML - Unknown node type: " + message [ 1 ] ) ;
200204 } ) ;
@@ -825,7 +829,9 @@ function RestartMathJax() {
825829// %%% cache results?
826830// %%% check types and values of parameters
827831//
828- exports . typeset = function ( data , callback ) {
832+
833+ // callback API for compatibility with MathJax
834+ var cbTypeset = function ( data , callback ) {
829835 if ( ! callback || typeof ( callback ) !== "function" ) {
830836 if ( displayErrors ) console . error ( "Missing callback" ) ;
831837 return ;
@@ -841,6 +847,17 @@ exports.typeset = function (data,callback) {
841847 if ( serverState == STATE . READY ) StartQueue ( ) ;
842848}
843849
850+ // main API, callback and promise compatible
851+ exports . typeset = function ( data , callback ) {
852+ if ( callback ) cbTypeset ( data , callback ) ;
853+ else return new Promise ( function ( resolve , reject ) {
854+ cbTypeset ( data , function ( output , input ) {
855+ if ( output . errors ) reject ( output . errors ) ;
856+ else resolve ( output , input ) ;
857+ } ) ;
858+ } ) ;
859+ } ;
860+
844861//
845862// Manually start MathJax (this is done automatically
846863// when the first typeset() call is made)
0 commit comments