Skip to content

Commit 4ec3192

Browse files
committed
Merge pull request mathjax#577 from fred-wang/issue557
Issue557
2 parents badfa0b + 6e442e3 commit 4ec3192

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

unpacked/config/default.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -432,20 +432,23 @@ MathJax.Hub.Config({
432432

433433
//
434434
// Controls whether mml2jax inserts MathJax_Preview spans to make a
435-
// preview available, and what preview to use, whrn it locates
436-
// mathematics on the page. The default is "alttext", which means use
437-
// the <math> tag's alttext attribute as the preview (until it is
438-
// processed by MathJax), if the tag has one. Set to "none" to
435+
// preview available, and what preview to use, when it locates
436+
// mathematics on the page. The default is "mathml" which means use
437+
// the <math> tag as the preview (until it is processed by MathJax).
438+
// Set to "alttext", to use the <math> tag's alttext attribute as the
439+
// preview, if the tag has one. Set to "none" to
439440
// prevent the previews from being inserted (the math will simply
440-
// disappear until it is typeset). Set to an array containing the
441+
// disappear until it is typeset). Set to "altimg" to use an image
442+
// described by the altimg* attributes of the <math> element.
443+
// Set to an array containing the
441444
// description of an HTML snippet in order to use the same preview for
442445
// all equations on the page (e.g., you could have it say "[math]" or
443446
// load an image).
444447
//
445448
// E.g., preview: ["[math]"],
446449
// or preview: [["img",{src: "http://myserver.com/images/mypic.jpg"}]]
447450
//
448-
preview: "alttext"
451+
preview: "mathml"
449452

450453
},
451454

unpacked/extensions/mml2jax.js

+32-7
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
MathJax.Extension.mml2jax = {
3030
version: "2.2",
3131
config: {
32-
preview: "alttext" // Use the <math> element's alttext as the
32+
preview: "mathml" // Use the <math> element as the
3333
// preview. Set to "none" for no preview,
34+
// set to "alttext" to use the alttext attribute
35+
// of the <math> element, set to "altimg" to use
36+
// an image described by the altimg* attributes
3437
// or set to an array specifying an HTML snippet
3538
// to use a fixed preview for all math
3639

@@ -181,13 +184,35 @@ MathJax.Extension.mml2jax = {
181184
createPreview: function (math,script) {
182185
var preview = this.config.preview;
183186
if (preview === "none") return;
184-
if (preview === "alttext") {
185-
var text = math.getAttribute("alttext");
186-
if (text != null) {preview = [this.filterPreview(text)]} else {preview = null}
187-
}
187+
var isNodePreview = false;
188+
if (preview === "mathml") {
189+
isNodePreview = true;
190+
// mathml preview does not work with IE < 9, so fallback to alttext.
191+
if (this.MathTagBug) {preview = "alttext"} else {preview = math}
192+
}
193+
if (preview === "alttext" || preview === "altimg") {
194+
isNodePreview = true;
195+
var alttext = this.filterPreview(math.getAttribute("alttext"));
196+
if (preview === "alttext") {
197+
if (alttext != null) {preview = MathJax.HTML.TextNode(alttext)} else {preview = null}
198+
} else {
199+
var src = math.getAttribute("altimg");
200+
if (src != null) {
201+
// FIXME: use altimg-valign when display="inline"?
202+
var style = {width: math.getAttribute("altimg-width"), height: math.getAttribute("altimg-height")};
203+
preview = MathJax.HTML.Element("img",{src:src,alt:alttext,style:style});
204+
} else {preview = null}
205+
}
206+
}
188207
if (preview) {
189-
preview = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},preview);
190-
script.parentNode.insertBefore(preview,script);
208+
var span;
209+
if (isNodePreview) {
210+
span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass});
211+
span.appendChild(preview);
212+
} else {
213+
span = MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},preview);
214+
}
215+
script.parentNode.insertBefore(span,script);
191216
}
192217
},
193218

0 commit comments

Comments
 (0)