Add support for semantics annotations to toMathML, and use a menu item to control it.
This commit is contained in:
parent
a314139f59
commit
3a8afa4dcb
|
@ -1852,7 +1852,8 @@ MathJax.Hub = {
|
|||
locale: "en", // the language to use for messages
|
||||
mpContext: false, // true means pass menu events to MathPlayer in IE
|
||||
mpMouse: false, // true means pass mouse events to MathPlayer in IE
|
||||
texHints: true // include class names for TeXAtom elements
|
||||
texHints: true, // include class names for TeXAtom elements
|
||||
semantics: false // add semantics tag with original form in MathML output
|
||||
},
|
||||
|
||||
errorSettings: {
|
||||
|
|
|
@ -243,7 +243,8 @@ MathJax.Hub.Config({
|
|||
context: "MathJax", // or "Browser" for pass-through to browser menu
|
||||
mpContext: false, // true means pass menu events to MathPlayer in IE
|
||||
mpMouse: false, // true means pass mouse events to MathPlayer in IE
|
||||
texHints: true // include class names for TeXAtom elements
|
||||
texHints: true, // include class names for TeXAtom elements
|
||||
semantics: false // add semantics tag with original form in MathML output
|
||||
},
|
||||
|
||||
//
|
||||
|
|
|
@ -160,6 +160,7 @@
|
|||
source.items[0].name = jax.sourceMenuTitle;
|
||||
source.items[0].format = (jax.sourceMenuFormat||"MathML");
|
||||
source.items[1].name = INPUT[jax.inputJax].sourceMenuTitle;
|
||||
source.items[5].disabled = !INPUT[jax.inputJax].annotationEncoding;
|
||||
|
||||
//
|
||||
// Try and find each known annotation format and enable the menu
|
||||
|
|
|
@ -717,7 +717,7 @@
|
|||
var MML = MathJax.ElementJax.mml;
|
||||
if (MML && typeof(MML.mbase.prototype.toMathML) !== "undefined") {
|
||||
// toMathML() can call MathJax.Hub.RestartAfter, so trap errors and check
|
||||
try {MENU.ShowSource.Text(MENU.jax.root.toMathML(),event)} catch (err) {
|
||||
try {MENU.ShowSource.Text(MENU.jax.root.toMathML("",MENU.jax),event)} catch (err) {
|
||||
if (!err.restart) {throw err}
|
||||
CALLBACK.After([this,MENU.ShowSource,EVENT],err.restart);
|
||||
}
|
||||
|
@ -1060,7 +1060,8 @@
|
|||
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")
|
||||
ITEM.CHECKBOX(["texHints","Show TeX hints in MathML"], "texHints"),
|
||||
ITEM.CHECKBOX(["semantics","Add original form as annotation"], "semantics")
|
||||
),
|
||||
ITEM.RULE(),
|
||||
ITEM.SUBMENU(["Settings","Math Settings"],
|
||||
|
|
|
@ -136,6 +136,38 @@ MathJax.Hub.Register.LoadHook("[MathJax]/jax/element/mml/jax.js",function () {
|
|||
}
|
||||
});
|
||||
|
||||
//
|
||||
// Override math.toMathML in order to add semantics tag
|
||||
// for the input format, if the user requests that in the
|
||||
// Show As menu.
|
||||
//
|
||||
MML.math.Augment({
|
||||
toMathML: function (space,jax) {
|
||||
var annotation;
|
||||
if (space == null) {space = ""}
|
||||
if (jax && jax.originalText && SETTINGS.semantics)
|
||||
{annotation = MathJax.InputJax[jax.inputJax].annotationEncoding}
|
||||
var nested = (this.data[0] && this.data[0].data.length > 1);
|
||||
var tag = this.type, attr = this.toMathMLattributes();
|
||||
var data = [], SPACE = space + (annotation ? " " : "") + (nested ? " " : "");
|
||||
for (var i = 0, m = this.data.length; i < m; i++) {
|
||||
if (this.data[i]) {data.push(this.data[i].toMathML(SPACE))}
|
||||
else {data.push(SPACE+"<mrow />")}
|
||||
}
|
||||
if (data.length === 0 || (data.length === 1 && data[0] === "")) {
|
||||
if (!annotation) {return "<"+tag+attr+" />"}
|
||||
data.push(SPACE+"<mrow />");
|
||||
}
|
||||
if (annotation) {
|
||||
if (nested) {data.unshift(space+" <mrow>"); data.push(space+" </mrow>")}
|
||||
data.unshift(space+" <semantics>");
|
||||
data.push(space+' <annotation encoding="'+annotation+'">'+jax.originalText+"</annotation>");
|
||||
data.push(space+" </semantics>");
|
||||
}
|
||||
return space+"<"+tag+attr+">\n"+data.join("\n")+"\n"+space+"</"+tag+">";
|
||||
}
|
||||
});
|
||||
|
||||
MML.msubsup.Augment({
|
||||
toMathML: function (space) {
|
||||
var tag = this.type;
|
||||
|
|
Loading…
Reference in New Issue
Block a user