Skip to content

Commit 87d38cd

Browse files
committed
Merge branch 'issue814' into v2.4-beta. (semantic annotations in
toMathML output). Issue #814.
2 parents a314139 + 3a8afa4 commit 87d38cd

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

unpacked/MathJax.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,8 @@ MathJax.Hub = {
18521852
locale: "en", // the language to use for messages
18531853
mpContext: false, // true means pass menu events to MathPlayer in IE
18541854
mpMouse: false, // true means pass mouse events to MathPlayer in IE
1855-
texHints: true // include class names for TeXAtom elements
1855+
texHints: true, // include class names for TeXAtom elements
1856+
semantics: false // add semantics tag with original form in MathML output
18561857
},
18571858

18581859
errorSettings: {

unpacked/config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ MathJax.Hub.Config({
243243
context: "MathJax", // or "Browser" for pass-through to browser menu
244244
mpContext: false, // true means pass menu events to MathPlayer in IE
245245
mpMouse: false, // true means pass mouse events to MathPlayer in IE
246-
texHints: true // include class names for TeXAtom elements
246+
texHints: true, // include class names for TeXAtom elements
247+
semantics: false // add semantics tag with original form in MathML output
247248
},
248249

249250
//

unpacked/extensions/MathEvents.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
source.items[0].name = jax.sourceMenuTitle;
161161
source.items[0].format = (jax.sourceMenuFormat||"MathML");
162162
source.items[1].name = INPUT[jax.inputJax].sourceMenuTitle;
163+
source.items[5].disabled = !INPUT[jax.inputJax].annotationEncoding;
163164

164165
//
165166
// Try and find each known annotation format and enable the menu

unpacked/extensions/MathMenu.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@
717717
var MML = MathJax.ElementJax.mml;
718718
if (MML && typeof(MML.mbase.prototype.toMathML) !== "undefined") {
719719
// toMathML() can call MathJax.Hub.RestartAfter, so trap errors and check
720-
try {MENU.ShowSource.Text(MENU.jax.root.toMathML(),event)} catch (err) {
720+
try {MENU.ShowSource.Text(MENU.jax.root.toMathML("",MENU.jax),event)} catch (err) {
721721
if (!err.restart) {throw err}
722722
CALLBACK.After([this,MENU.ShowSource,EVENT],err.restart);
723723
}
@@ -1060,7 +1060,8 @@
10601060
ITEM.COMMAND(["Original","Original Form"], MENU.ShowSource, {nativeTouch: true}),
10611061
ITEM.SUBMENU(["Annotation","Annotation"], {disabled:true}),
10621062
ITEM.RULE(),
1063-
ITEM.CHECKBOX(["texHints","Show TeX hints in MathML"], "texHints")
1063+
ITEM.CHECKBOX(["texHints","Show TeX hints in MathML"], "texHints"),
1064+
ITEM.CHECKBOX(["semantics","Add original form as annotation"], "semantics")
10641065
),
10651066
ITEM.RULE(),
10661067
ITEM.SUBMENU(["Settings","Math Settings"],

unpacked/extensions/toMathML.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,38 @@ MathJax.Hub.Register.LoadHook("[MathJax]/jax/element/mml/jax.js",function () {
136136
}
137137
});
138138

139+
//
140+
// Override math.toMathML in order to add semantics tag
141+
// for the input format, if the user requests that in the
142+
// Show As menu.
143+
//
144+
MML.math.Augment({
145+
toMathML: function (space,jax) {
146+
var annotation;
147+
if (space == null) {space = ""}
148+
if (jax && jax.originalText && SETTINGS.semantics)
149+
{annotation = MathJax.InputJax[jax.inputJax].annotationEncoding}
150+
var nested = (this.data[0] && this.data[0].data.length > 1);
151+
var tag = this.type, attr = this.toMathMLattributes();
152+
var data = [], SPACE = space + (annotation ? " " : "") + (nested ? " " : "");
153+
for (var i = 0, m = this.data.length; i < m; i++) {
154+
if (this.data[i]) {data.push(this.data[i].toMathML(SPACE))}
155+
else {data.push(SPACE+"<mrow />")}
156+
}
157+
if (data.length === 0 || (data.length === 1 && data[0] === "")) {
158+
if (!annotation) {return "<"+tag+attr+" />"}
159+
data.push(SPACE+"<mrow />");
160+
}
161+
if (annotation) {
162+
if (nested) {data.unshift(space+" <mrow>"); data.push(space+" </mrow>")}
163+
data.unshift(space+" <semantics>");
164+
data.push(space+' <annotation encoding="'+annotation+'">'+jax.originalText+"</annotation>");
165+
data.push(space+" </semantics>");
166+
}
167+
return space+"<"+tag+attr+">\n"+data.join("\n")+"\n"+space+"</"+tag+">";
168+
}
169+
});
170+
139171
MML.msubsup.Augment({
140172
toMathML: function (space) {
141173
var tag = this.type;

0 commit comments

Comments
 (0)