diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js
index c324ebfbf..e02be80b4 100644
--- a/unpacked/jax/output/HTML-CSS/jax.js
+++ b/unpacked/jax/output/HTML-CSS/jax.js
@@ -668,11 +668,16 @@
//
this.initImg(span);
this.initHTML(math,span);
- math.setTeXclass();
- try {math.toHTML(span,div)} catch (err) {
+ this.savePreview(script);
+ try {
+ math.setTeXclass();
+ math.toHTML(span,div);
+ } catch (err) {
if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}}
+ this.restorePreview(script);
throw err;
}
+ this.restorePreview(script);
//
// Put it in place, and remove the processing marker
//
@@ -701,6 +706,25 @@
}
}
},
+ //
+ // MathML previews can contain the same ID's as the HTML output,
+ // which confuses HTMLspanElement(), so remove the preview temporarily
+ // and restore it after typesetting the math.
+ //
+ savePreview: function (script) {
+ var preview = script.MathJax.preview;
+ if (preview) {
+ script.MathJax.tmpPreview = document.createElement("span");
+ preview.parentNode.replaceChild(script.MathJax.tmpPreview,preview);
+ }
+ },
+ restorePreview: function (script) {
+ var tmpPreview = script.MathJax.tmpPreview;
+ if (tmpPreview) {
+ tmpPreview.parentNode.replaceChild(script.MathJax.preview,tmpPreview);
+ delete script.MathJax.tmpPreview;
+ }
+ },
postTranslate: function (state,partial) {
var scripts = state.jax[this.id];