Keep track of ID's uses on the page, and make unique ones if there are repeats. Resolves issue #240.
This commit is contained in:
parent
86792eaf44
commit
6d6eccead0
|
@ -29,6 +29,8 @@ MathJax.Extension["TeX/AMSmath"] = {
|
||||||
|
|
||||||
number: 0, // current equation number
|
number: 0, // current equation number
|
||||||
startNumber: 0, // current starting equation number (for when equation is restarted)
|
startNumber: 0, // current starting equation number (for when equation is restarted)
|
||||||
|
IDs: {}, // IDs used in previous equations
|
||||||
|
eqIDs: {}, // IDs used in this equation
|
||||||
labels: {}, // the set of labels
|
labels: {}, // the set of labels
|
||||||
eqlabels: {}, // labels in the current equation
|
eqlabels: {}, // labels in the current equation
|
||||||
refs: [] // array of jax with unresolved references
|
refs: [] // array of jax with unresolved references
|
||||||
|
@ -187,7 +189,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
||||||
global.label = label;
|
global.label = label;
|
||||||
if (AMS.labels[label] || AMS.eqlabels[label])
|
if (AMS.labels[label] || AMS.eqlabels[label])
|
||||||
{TEX.Error(["MultipleLabel","Label '%1' multiply defined",label])}
|
{TEX.Error(["MultipleLabel","Label '%1' multiply defined",label])}
|
||||||
AMS.eqlabels[label] = "???"; // will be replaced by tag value later
|
AMS.eqlabels[label] = {tag:"???", id:""}; // will be replaced by tag value later
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -197,11 +199,10 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
||||||
HandleRef: function (name,eqref) {
|
HandleRef: function (name,eqref) {
|
||||||
var label = this.GetArgument(name);
|
var label = this.GetArgument(name);
|
||||||
var ref = AMS.labels[label] || AMS.eqlabels[label];
|
var ref = AMS.labels[label] || AMS.eqlabels[label];
|
||||||
if (!ref) {ref = "??"; AMS.badref = !AMS.refUpdate}
|
if (!ref) {ref = {tag:"???",id:""}; AMS.badref = !AMS.refUpdate}
|
||||||
var tag = ref; if (eqref) {tag = CONFIG.formatTag(tag)}
|
var tag = ref.tag; if (eqref) {tag = CONFIG.formatTag(tag)}
|
||||||
if (CONFIG.useLabelIds) {ref = label}
|
|
||||||
this.Push(MML.mrow.apply(MML,this.InternalMath(tag)).With({
|
this.Push(MML.mrow.apply(MML,this.InternalMath(tag)).With({
|
||||||
href:CONFIG.formatURL(CONFIG.formatID(ref)), "class":"MathJax_ref"
|
href:CONFIG.formatURL(ref.id), "class":"MathJax_ref"
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -423,7 +424,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
||||||
if (!global.notag) {
|
if (!global.notag) {
|
||||||
AMS.number++; global.tagID = CONFIG.formatNumber(AMS.number.toString());
|
AMS.number++; global.tagID = CONFIG.formatNumber(AMS.number.toString());
|
||||||
var mml = TEX.Parse("\\text{"+CONFIG.formatTag(global.tagID)+"}",{}).mml();
|
var mml = TEX.Parse("\\text{"+CONFIG.formatTag(global.tagID)+"}",{}).mml();
|
||||||
global.tag = MML.mtd(mml.With({id:CONFIG.formatID(global.tagID)}));
|
global.tag = MML.mtd(mml).With({id:CONFIG.formatID(global.tagID)});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -433,9 +434,20 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
||||||
getTag: function () {
|
getTag: function () {
|
||||||
var global = this.global, tag = global.tag; global.tagged = true;
|
var global = this.global, tag = global.tag; global.tagged = true;
|
||||||
if (global.label) {
|
if (global.label) {
|
||||||
AMS.eqlabels[global.label] = global.tagID;
|
|
||||||
if (CONFIG.useLabelIds) {tag.id = CONFIG.formatID(global.label)}
|
if (CONFIG.useLabelIds) {tag.id = CONFIG.formatID(global.label)}
|
||||||
|
AMS.eqlabels[global.label] = {tag:global.tagID, id:tag.id};
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
// Check for repeated ID's (either in the document or as
|
||||||
|
// a previous tag) and find a unique related one. (#240)
|
||||||
|
//
|
||||||
|
if (document.getElementById(tag.id) || AMS.IDs[tag.id] || AMS.eqIDs[tag.id]) {
|
||||||
|
var i = 0, ID;
|
||||||
|
do {i++; ID = tag.id+"_"+i}
|
||||||
|
while (document.getElementById(ID) || AMS.IDs[ID] || AMS.eqIDs[ID]);
|
||||||
|
tag.id = ID; if (global.label) {AMS.eqlabels[global.label].id = ID}
|
||||||
|
}
|
||||||
|
AMS.eqIDs[tag.id] = 1;
|
||||||
delete global.tag; delete global.tagID; delete global.label;
|
delete global.tag; delete global.tagID; delete global.label;
|
||||||
return tag;
|
return tag;
|
||||||
},
|
},
|
||||||
|
@ -586,12 +598,13 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
||||||
TEX.prefilterHooks.Add(function (data) {
|
TEX.prefilterHooks.Add(function (data) {
|
||||||
AMS.display = data.display;
|
AMS.display = data.display;
|
||||||
AMS.number = AMS.startNumber; // reset equation numbers (in case the equation restarted)
|
AMS.number = AMS.startNumber; // reset equation numbers (in case the equation restarted)
|
||||||
AMS.eqlabels = {}; AMS.badref = false;
|
AMS.eqlabels = AMS.eqIDs = {}; AMS.badref = false;
|
||||||
if (AMS.refUpdate) {AMS.number = data.script.MathJax.startNumber}
|
if (AMS.refUpdate) {AMS.number = data.script.MathJax.startNumber}
|
||||||
});
|
});
|
||||||
TEX.postfilterHooks.Add(function (data) {
|
TEX.postfilterHooks.Add(function (data) {
|
||||||
data.script.MathJax.startNumber = AMS.startNumber;
|
data.script.MathJax.startNumber = AMS.startNumber;
|
||||||
AMS.startNumber = AMS.number; // equation numbers for next equation
|
AMS.startNumber = AMS.number; // equation numbers for next equation
|
||||||
|
MathJax.Hub.Insert(AMS.IDs,AMS.eqIDs); // save IDs from this equation
|
||||||
MathJax.Hub.Insert(AMS.labels,AMS.eqlabels); // save labels from this equation
|
MathJax.Hub.Insert(AMS.labels,AMS.eqlabels); // save labels from this equation
|
||||||
if (AMS.badref && !data.math.texError) {AMS.refs.push(data.script)} // reprocess later
|
if (AMS.badref && !data.math.texError) {AMS.refs.push(data.script)} // reprocess later
|
||||||
});
|
});
|
||||||
|
@ -619,7 +632,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
|
||||||
//
|
//
|
||||||
TEX.resetEquationNumbers = function (n,keepLabels) {
|
TEX.resetEquationNumbers = function (n,keepLabels) {
|
||||||
AMS.startNumber = (n || 0);
|
AMS.startNumber = (n || 0);
|
||||||
if (!keepLabels) {AMS.labels = {}}
|
if (!keepLabels) {AMS.labels = AMS.IDs = {}}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user