From ff6d6935dfe6335b8613c4711c282b66ed113748 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 8 Nov 2014 09:29:47 -0500 Subject: [PATCH] Handle loading of CommonHTML jax better (do it when we detect it is not present, rather than trying to hook into the input jax require array). --- unpacked/extensions/CHTML-preview.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/unpacked/extensions/CHTML-preview.js b/unpacked/extensions/CHTML-preview.js index 1add241fe..1ab0e1f15 100644 --- a/unpacked/extensions/CHTML-preview.js +++ b/unpacked/extensions/CHTML-preview.js @@ -39,7 +39,7 @@ // config: HUB.CombineConfig("CHTML-preview",{ Chunks: {EqnChunk: 10000, EqnChunkFactor: 1, EqnChunkDelay: 0}, - color: "inherit", + color: "inherit!important", updateTime: 10, updateDelay: 10, messageStyle: "none", disabled: false @@ -56,6 +56,7 @@ MathJax.Ajax.Styles({".MathJax_Preview":{color:this.config.color}}); var update, delay, style, done, saved; var config = this.config; + HUB.Register.MessageHook("Begin Math Output",function () { if (!done && !config.disabled && SETTINGS.CHTMLpreview && SETTINGS.renderer !== "CommonHTML") { @@ -97,25 +98,28 @@ try { data.math.root.toCommonHTML(preview); } catch (err) { + // + // Load the CommonHTML jax if it is not already loaded + // + if (!data.math.root.toCommonHTML) { + var queue = MathJax.Callback.Queue(); + HUB.RestartAfter(queue.Push( + ["Require",MathJax.Ajax,"[MathJax]/jax/output/CommonHTML/config.js"], + ["Require",MathJax.Ajax,"[MathJax]/jax/output/CommonHTML/jax.js"] + )); + } if (!err.restart) {throw err} // an actual error return MathJax.Callback.After(["postFilter",this,preview,data],err.restart); } }, // - // Hook into the inut jax postFilter to create the previews as + // Hook into the input jax postFilter to create the previews as // the input jax are processed. // Register: function (name) { HUB.Register.StartupHook(name+" Jax Require",function () { var jax = MathJax.InputJax[name]; - var delay = HUB.config.delayJaxRegistration; - HUB.config.delayJaxRegistration = true; - HUB.Register.StartupHook(name+" Jax Ready",function () {HUB.config.delayJaxRegistration = delay}); - jax.require.push( - "[MathJax]/jax/output/CommonHTML/config.js", - "[MathJax]/jax/output/CommonHTML/jax.js" - ); jax.postfilterHooks.Add(["Preview",MathJax.Extension["CHTML-preview"]],50); }); }