commit bc9443b25230d7d958aeeb3cda55bba12edd4912
parent 55b5803d0aa06b7a00cc0bb55a1d0a2456aa9c8e
Author: Frédéric Wang <fred.wang@free.fr>
Date: Mon, 3 Jun 2013 17:12:11 +0200
Expose some annotations to the Show Math As menu. Fix issue #357.
Diffstat:
8 files changed, 103 insertions(+), 8 deletions(-)
diff --git a/unpacked/config/default.js b/unpacked/config/default.js
@@ -962,6 +962,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"],
+ "Content MathML": ["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.hidden = 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.hidden = 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
@@ -711,6 +711,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 +992,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 +1029,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"], {hidden:true}),
ITEM.RULE(),
ITEM.CHECKBOX(["texHints","Show TeX hints in MathML"], "texHints")
),
@@ -1095,6 +1113,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
@@ -730,6 +730,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);
}
});
@@ -1174,7 +1178,18 @@ 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].attr.encoding;
+ if (encoding && encodingList.indexOf(encoding) !== -1)
+ return this.data[i];
+ }
+ }
+ return null;
+ }
});
MML.annotation = MML.mbase.Subclass({
type: "annotation", isToken: true,
@@ -1235,7 +1250,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({
diff --git a/unpacked/localization/de/MathMenu.js b/unpacked/localization/de/MathMenu.js
@@ -184,9 +184,16 @@ MathJax.Localization.addTranslation("de","MathMenu",{
// "Close",
EqSource:
- "Original MathJax Formel"
+ "Original MathJax Formel",
// "MathJax Equation Source"
+ "Annotation": "Annotation",
+ "TeX": "TeX",
+ "StarMath": "StarMath",
+ "Maple": "Maple",
+ "Content MathML": "Content MathML",
+ "OpenMath": "OpenMath"
+
}
});
diff --git a/unpacked/localization/en/MathMenu.js b/unpacked/localization/en/MathMenu.js
@@ -145,8 +145,14 @@ MathJax.Localization.addTranslation("en","MathMenu",{
"Close", // NOTE: for closing button in the 'MathJax Menu => SHow Math As' window.
EqSource:
- "MathJax Equation Source"
-
+ "MathJax Equation Source",
+
+ "Annotation": "Annotation",
+ "TeX": "TeX",
+ "StarMath": "StarMath",
+ "Maple": "Maple",
+ "Content MathML": "Content MathML",
+ "OpenMath": "OpenMath"
}
});
diff --git a/unpacked/localization/fr/MathMenu.js b/unpacked/localization/fr/MathMenu.js
@@ -145,8 +145,14 @@ MathJax.Localization.addTranslation("fr","MathMenu",{
"Fermer",
EqSource:
- "Source de l'\u00E9quation MathJax"
-
+ "Source de l'\u00E9quation MathJax",
+
+ "Annotation": "d'annotation",
+ "TeX": "TeX",
+ "StarMath": "StarMath",
+ "Maple": "Maple",
+ "Content MathML": "MathML de contenu",
+ "OpenMath": "OpenMath"
}
});
diff --git a/unpacked/localization/it/MathMenu.js b/unpacked/localization/it/MathMenu.js
@@ -179,9 +179,15 @@ MathJax.Localization.addTranslation("it","MathMenu",{
//"Close", // NOTE: for closing button in the 'MathJax Menu => SHow Math As' window.
EqSource:
- "Codice sorgente formula MathJax"
+ "Codice sorgente formula MathJax",
//"MathJax Equation Source"
+ "Annotation": "Annotation",
+ "TeX": "TeX",
+ "StarMath": "StarMath",
+ "Maple": "Maple",
+ "Content MathML": "Content MathML",
+ "OpenMath": "OpenMath"
}
});