From 7a9833becd3fcf702d51f673e269d95e4f7c0c25 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 28 May 2014 10:30:03 -0400 Subject: [PATCH] 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. --- unpacked/jax/input/AsciiMath/jax.js | 1 + unpacked/jax/input/TeX/jax.js | 2 +- unpacked/jax/output/NativeMML/jax.js | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/unpacked/jax/input/AsciiMath/jax.js b/unpacked/jax/input/AsciiMath/jax.js index 8a491b831..bbbf2c88d 100644 --- a/unpacked/jax/input/AsciiMath/jax.js +++ b/unpacked/jax/input/AsciiMath/jax.js @@ -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 diff --git a/unpacked/jax/input/TeX/jax.js b/unpacked/jax/input/TeX/jax.js index 095d04eec..6ca4bc7ee 100644 --- a/unpacked/jax/input/TeX/jax.js +++ b/unpacked/jax/input/TeX/jax.js @@ -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); diff --git a/unpacked/jax/output/NativeMML/jax.js b/unpacked/jax/output/NativeMML/jax.js index 5b4e046aa..3eb4f698f 100644 --- a/unpacked/jax/output/NativeMML/jax.js +++ b/unpacked/jax/output/NativeMML/jax.js @@ -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) {