commit 4491d2374bdd3442f3e080ca7cdb3a5a16978a61
parent f1be0de1d636094f977c63554d4a6607d7e03cb6
Author: Davide P. Cervone <dpvc@union.edu>
Date: Wed, 7 Aug 2013 05:36:26 -0700
Merge pull request #535 from fred-wang/issue357
Resolves issue #357
Diffstat:
4 files changed, 85 insertions(+), 3 deletions(-)
diff --git a/unpacked/config/default.js b/unpacked/config/default.js
@@ -961,6 +961,20 @@ MathJax.Hub.Config({
showFontMenu: false,
showContext: false,
showDiscoverable: false,
+
+ //
+ // These are the settings for the Annotation menu. If the <math> root has
+ // a <semantics> child that contains one of the following annotation
+ // formats, the source will be available via the "Show Math As" menu.
+ // Each format has a list of possible encodings.
+ //
+ semanticsAnnotations: {
+ "TeX": ["TeX", "LaTeX", "application/x-tex"],
+ "StarMath": ["StarMath 5.0"],
+ "Maple": ["Maple"],
+ "ContentMathML": ["MathML-Content", "application/mathml-content+xml"],
+ "OpenMath": ["OpenMath"]
+ },
//
// These are the settings for the Show Source window. The initial
diff --git a/unpacked/extensions/MathEvents.js b/unpacked/extensions/MathEvents.js
@@ -161,6 +161,24 @@
source.items[0].name = jax.sourceMenuTitle;
source.items[0].format = (jax.sourceMenuFormat||"MathML");
source.items[1].name = INPUT[jax.inputJax].sourceMenuTitle;
+
+ //
+ // Try and find each known annotation format and enable the menu
+ // items accordingly.
+ //
+ var annotations = source.items[2]; annotations.disabled = true;
+ var annotationItems = annotations.menu.items;
+ annotationList = MathJax.Hub.Config.semanticsAnnotations;
+ for (var i = 0, m = annotationItems.length; i < m; i++) {
+ var name = annotationItems[i].name[1]
+ if (jax.root.getAnnotation(name) !== null) {
+ annotations.disabled = false;
+ annotationItems[i].hidden = false;
+ } else {
+ annotationItems[i].hidden = true;
+ }
+ }
+
var MathPlayer = MENU.menu.Find("Math Settings","MathPlayer");
MathPlayer.hidden = !(jax.outputJax === "NativeMML" && HUB.Browser.hasMathPlayer);
return MENU.menu.Post(event);
diff --git a/unpacked/extensions/MathMenu.js b/unpacked/extensions/MathMenu.js
@@ -58,6 +58,14 @@
showLocale: true, // show the "Locale" menu?
showLocaleURL: false, // show the "Load from URL" menu?
+ semanticsAnnotations: {
+ "TeX": ["TeX", "LaTeX", "application/x-tex"],
+ "StarMath": ["StarMath 5.0"],
+ "Maple": ["Maple"],
+ "ContentMathML": ["MathML-Content", "application/mathml-content+xml"],
+ "OpenMath": ["OpenMath"]
+ },
+
windowSettings: { // for source window
status: "no", toolbar: "no", locationbar: "no", menubar: "no",
directories: "no", personalbar: "no", resizable: "yes", scrollbars: "yes",
@@ -711,6 +719,9 @@
}
} else if (this.format === "Error") {
MENU.ShowSource.Text(MENU.jax.errorText,event);
+ } else if (CONFIG.semanticsAnnotations[this.format]) {
+ var annotation = MENU.jax.root.getAnnotation(this.format);
+ if (annotation.data[0]) MENU.ShowSource.Text(annotation.data[0].toString());
} else {
if (MENU.jax.originalText == null) {
alert(_("NoOriginalForm","No original form available"));
@@ -989,6 +1000,20 @@
menu.items.push(items[items.length-2],items[items.length-1]);
};
+ //
+ // Create the annotation menu from MathJax.Hub.config.semanticsAnnotations
+ //
+ MENU.CreateAnnotationMenu = function () {
+ if (!MENU.menu) return;
+ var menu = MENU.menu.Find("Show Math As","Annotation").menu;
+ var annotations = CONFIG.semanticsAnnotations;
+ for (var a in annotations) {
+ if (annotations.hasOwnProperty(a)) {
+ menu.items.push(ITEM.COMMAND([a,a], MENU.ShowSource, {hidden: true, nativeTouch: true, format: a}));
+ }
+ }
+ };
+
/*************************************************************/
HUB.Register.StartupHook("End Config",function () {
@@ -1012,6 +1037,7 @@
ITEM.SUBMENU(["Show","Show Math As"],
ITEM.COMMAND(["MathMLcode","MathML Code"], MENU.ShowSource, {nativeTouch: true, format: "MathML"}),
ITEM.COMMAND(["Original","Original Form"], MENU.ShowSource, {nativeTouch: true}),
+ ITEM.SUBMENU(["Annotation","Annotation"], {disabled:true}),
ITEM.RULE(),
ITEM.CHECKBOX(["texHints","Show TeX hints in MathML"], "texHints")
),
@@ -1095,6 +1121,7 @@
}
MENU.CreateLocaleMenu();
+ MENU.CreateAnnotationMenu();
});
MENU.showRenderer = function (show) {
diff --git a/unpacked/jax/element/mml/jax.js b/unpacked/jax/element/mml/jax.js
@@ -380,7 +380,8 @@ MathJax.ElementJax.mml.Augment({
return false;
},
array: function () {if (this.inferred) {return this.data} else {return [this]}},
- toString: function () {return this.type+"("+this.data.join(",")+")"}
+ toString: function () {return this.type+"("+this.data.join(",")+")"},
+ getAnnotation: function () { return null; }
},{
childrenSpacelike: function () {
for (var i = 0, m = this.data.length; i < m; i++)
@@ -731,6 +732,10 @@ MathJax.ElementJax.mml.Augment({
{if (this.data[i]) {prev = this.data[i].setTeXclass(prev)}}
if (this.data[0]) {this.updateTeXclass(this.data[0])}
return prev;
+ },
+ getAnnotation: function (name) {
+ if (this.data.length != 1) return null;
+ return this.data[0].getAnnotation(name);
}
});
@@ -1175,7 +1180,21 @@ MathJax.ElementJax.mml.Augment({
definitionURL: null,
encoding: null
},
- setTeXclass: MML.mbase.setChildTeXclass
+ setTeXclass: MML.mbase.setChildTeXclass,
+ getAnnotation: function (name) {
+ var encodingList = MathJax.Hub.config.MathMenu.semanticsAnnotations[name];
+ if (encodingList) {
+ for (var i = 0, m = this.data.length; i < m; i++) {
+ var encoding = this.data[i].Get("encoding");
+ if (encoding) {
+ for (var j = 0, n = encodingList.length; j < n; j++) {
+ if (encodingList[j] === encoding) return this.data[i];
+ }
+ }
+ }
+ }
+ return null;
+ }
});
MML.annotation = MML.mbase.Subclass({
type: "annotation", isToken: true,
@@ -1236,7 +1255,11 @@ MathJax.ElementJax.mml.Augment({
return "";
},
linebreakContainer: true,
- setTeXclass: MML.mbase.setChildTeXclass
+ setTeXclass: MML.mbase.setChildTeXclass,
+ getAnnotation: function (name) {
+ if (this.data.length != 1) return null;
+ return this.data[0].getAnnotation(name);
+ }
});
MML.chars = MML.mbase.Subclass({