Add semantics annotation to NativeMML output. This is done in the NativeMML output jax rather than the input jax so that it can be done for any input format (that provides an encoding for it). Also, it avoids having the Show As MathML output include the annotation. Resolves issue #814.

This commit is contained in:
Davide P. Cervone 2014-05-28 10:30:03 -04:00
parent 0ebff03dc1
commit 7a9833becd
3 changed files with 17 additions and 5 deletions

View File

@ -1276,6 +1276,7 @@ junk = null;
ASCIIMATH.Augment({
sourceMenuTitle: /*_(MathMenu)*/ ["AsciiMathInput","AsciiMath Input"],
annotationEncoding: "text/x-asciimath",
prefilterHooks: MathJax.Callback.Hooks(true), // hooks to run before processing AsciiMath
postfilterHooks: MathJax.Callback.Hooks(true), // hooks to run after processing AsciiMath

View File

@ -2061,6 +2061,7 @@
},
sourceMenuTitle: /*_(MathMenu)*/ ["TeXCommands","TeX Commands"],
annotationEncoding: "application/x-tex",
prefilterHooks: MathJax.Callback.Hooks(true), // hooks to run before processing TeX
postfilterHooks: MathJax.Callback.Hooks(true), // hooks to run after processing TeX
@ -2087,7 +2088,6 @@
this.prefilterHooks.Execute(data); math = data.math;
try {
mml = TEX.Parse(math).mml();
// mml = MML.semantics(mml,MML.annotation(math).With({encoding:"application/x-tex"}));
} catch(err) {
if (!err.texError) {throw err}
mml = this.formatError(err,math,display,script);

View File

@ -299,7 +299,7 @@
//
// Convert to MathML (if restarted, remove any partial math)
//
try {math.toNativeMML(mspan)} catch (err) {
try {math.toNativeMML(mspan,jax)} catch (err) {
if (err.restart) {while (mspan.firstChild) {mspan.removeChild(mspan.firstChild)}}
throw err;
}
@ -906,8 +906,9 @@
}
MML.math.Augment({
toNativeMML: function (parent) {
var tag = this.NativeMMLelement(this.type), math = tag, jax;
toNativeMML: function (parent,jax) {
var tag = this.NativeMMLelement(this.type), math = tag;
var annotate = (jax ? MathJax.InputJax[jax.inputJax].annotationEncoding : null);
var i, m;
nMML.adjustWidths = [];
//
@ -921,6 +922,17 @@
//
if (nMML.widthBug) {tag = tag.appendChild(this.NativeMMLelement("mrow"))}
//
// Addannotation if the input jax provides an annotation encoding
//
if (annotate) {
tag = tag.appendChild(this.NativeMMLelement("semantics"))
tag.appendChild(this.NativeMMLelement("mrow"));
var annotation = tag.appendChild(this.NativeMMLelement("annotation"));
annotation.appendChild(document.createTextNode(jax.originalText));
annotation.setAttribute("encoding",annotate);
tag = tag.firstChild; // mrow
}
//
// Add the children
//
for (i = 0, m = this.data.length; i < m; i++) {
@ -966,7 +978,6 @@
//
// Save size for later when we check if Web fonts have arrived
//
jax = HUB.getJaxFor(parent);
if (jax) {jax.NativeMML.scrollWidth = math.firstChild.scrollWidth}
}
if (nMML.adjustWidths.length) {