Skip to content

Commit 7a9833b

Browse files
committed
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.
1 parent 0ebff03 commit 7a9833b

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

unpacked/jax/input/AsciiMath/jax.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ junk = null;
12761276

12771277
ASCIIMATH.Augment({
12781278
sourceMenuTitle: /*_(MathMenu)*/ ["AsciiMathInput","AsciiMath Input"],
1279+
annotationEncoding: "text/x-asciimath",
12791280

12801281
prefilterHooks: MathJax.Callback.Hooks(true), // hooks to run before processing AsciiMath
12811282
postfilterHooks: MathJax.Callback.Hooks(true), // hooks to run after processing AsciiMath

unpacked/jax/input/TeX/jax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@
20612061
},
20622062

20632063
sourceMenuTitle: /*_(MathMenu)*/ ["TeXCommands","TeX Commands"],
2064+
annotationEncoding: "application/x-tex",
20642065

20652066
prefilterHooks: MathJax.Callback.Hooks(true), // hooks to run before processing TeX
20662067
postfilterHooks: MathJax.Callback.Hooks(true), // hooks to run after processing TeX
@@ -2087,7 +2088,6 @@
20872088
this.prefilterHooks.Execute(data); math = data.math;
20882089
try {
20892090
mml = TEX.Parse(math).mml();
2090-
// mml = MML.semantics(mml,MML.annotation(math).With({encoding:"application/x-tex"}));
20912091
} catch(err) {
20922092
if (!err.texError) {throw err}
20932093
mml = this.formatError(err,math,display,script);

unpacked/jax/output/NativeMML/jax.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@
299299
//
300300
// Convert to MathML (if restarted, remove any partial math)
301301
//
302-
try {math.toNativeMML(mspan)} catch (err) {
302+
try {math.toNativeMML(mspan,jax)} catch (err) {
303303
if (err.restart) {while (mspan.firstChild) {mspan.removeChild(mspan.firstChild)}}
304304
throw err;
305305
}
@@ -906,8 +906,9 @@
906906
}
907907

908908
MML.math.Augment({
909-
toNativeMML: function (parent) {
910-
var tag = this.NativeMMLelement(this.type), math = tag, jax;
909+
toNativeMML: function (parent,jax) {
910+
var tag = this.NativeMMLelement(this.type), math = tag;
911+
var annotate = (jax ? MathJax.InputJax[jax.inputJax].annotationEncoding : null);
911912
var i, m;
912913
nMML.adjustWidths = [];
913914
//
@@ -921,6 +922,17 @@
921922
//
922923
if (nMML.widthBug) {tag = tag.appendChild(this.NativeMMLelement("mrow"))}
923924
//
925+
// Addannotation if the input jax provides an annotation encoding
926+
//
927+
if (annotate) {
928+
tag = tag.appendChild(this.NativeMMLelement("semantics"))
929+
tag.appendChild(this.NativeMMLelement("mrow"));
930+
var annotation = tag.appendChild(this.NativeMMLelement("annotation"));
931+
annotation.appendChild(document.createTextNode(jax.originalText));
932+
annotation.setAttribute("encoding",annotate);
933+
tag = tag.firstChild; // mrow
934+
}
935+
//
924936
// Add the children
925937
//
926938
for (i = 0, m = this.data.length; i < m; i++) {
@@ -966,7 +978,6 @@
966978
//
967979
// Save size for later when we check if Web fonts have arrived
968980
//
969-
jax = HUB.getJaxFor(parent);
970981
if (jax) {jax.NativeMML.scrollWidth = math.firstChild.scrollWidth}
971982
}
972983
if (nMML.adjustWidths.length) {

0 commit comments

Comments
 (0)