Skip to content

Commit d536272

Browse files
authored
Merge pull request #1602 from dpvc/issue1589
Handle \ref properly when there is a <base> tag. #1589
2 parents f0d730e + 33ee93d commit d536272

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

unpacked/config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,8 @@ MathJax.Hub.Config({
550550
// formatTag: function (n) {return '('+n+')'}, // format for \tag and \eqref
551551
// formatID: function (n) {return 'mjx-eqn-'+String(n).replace(/[:'"<>&]/g,"")},
552552
// // element ID to use for reference
553-
// formatURL: function (id) {return '#'+escape(id)}, // URL to use for references
553+
// formatURL: function (id,base) {return base+'#'+escape(id)},
554+
// // URL to use for references
554555
useLabelIds: true // make element ID's use \label name rather than equation number
555556
},
556557

unpacked/extensions/TeX/AMSmath.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
5353
return WW.join(" ");
5454
};
5555

56+
//
57+
// Get the URL of the page (for use with formatURL) when there
58+
// is a <base> element on the page.
59+
//
60+
var baseURL = (document.getElementsByTagName("base").length === 0) ? "" :
61+
String(document.location).replace(/#.*$/,"");
62+
63+
5664
/******************************************************************************/
5765

5866
TEXDEF.Add({
@@ -203,7 +211,7 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
203211
if (!ref) {ref = {tag:"???",id:""}; AMS.badref = !AMS.refUpdate}
204212
var tag = ref.tag; if (eqref) {tag = CONFIG.formatTag(tag)}
205213
this.Push(MML.mrow.apply(MML,this.InternalMath(tag)).With({
206-
href:CONFIG.formatURL(ref.id), "class":"MathJax_ref"
214+
href:CONFIG.formatURL(ref.id,baseURL), "class":"MathJax_ref"
207215
}));
208216
},
209217

unpacked/jax/input/TeX/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ MathJax.InputJax.TeX = MathJax.InputJax({
4242
formatNumber: function (n) {return n},
4343
formatTag: function (n) {return '('+n+')'},
4444
formatID: function (n) {return 'mjx-eqn-'+String(n).replace(/[:"'<>&]/g,"")},
45-
formatURL: function (id) {return '#'+escape(id)},
45+
formatURL: function (id,base) {return base+'#'+escape(id)},
4646
useLabelIds: true
4747
}
4848
},

0 commit comments

Comments
 (0)