I already know that mathjax allows very limited html codes inside math areas, however, I have a multiple page document, each having a number of equations, so for \eqref{} to work properly, I have wrapped these commands in a clickable <span> which direct to the page containing the addressed equation, before the page is scrolled to the equation somewhere withing that page.
The relevant part of the markdown application is, first,
content=content
.replace(/(\\ref\{[^\}]+\})/g, "<span class='eqCitationSpan'>$1</span>")
.replace(/(\\eqref\{[^\}]+\})/g, "<span class='eqCitationSpan'>$1</span>")
and then,
// to handle cross-referencing the equations in MathJax, due to the multipage nature of the document
var perPageEqs=[];
MathJax.Hub.Queue(
function () {
for(pageNum=0; pageNum<totalPageNumber; pageNum++){
var jax = MathJax.Hub.getAllJax("resultPage-"+pageNum);
var neWLabelsInPage=[];
for (var i=0, l=jax.length; i<l; i++) {
jax[i].originalText.replace(/\\label\{([^\}]+)\}/g, function(x,y){
neWLabelsInPage.push(y);
return false;
});
}
perPageEqs.push(neWLabelsInPage);
}
var eqCitationArray = document.getElementsByClassName("eqCitationSpan");
var eqsOnWhichPage;
for(var i=0, l=eqCitationArray.length; i<l; i++) {
var key=eqCitationArray[i].innerHTML
.replace(/.*\\ref\{([^\}]+)\}.*/g,"$1").replace(/.*\\eqref\{([^\}]+)\}.*/g,"$1");
eqsOnWhichPage=perPageEqs.findIndex(function(x) {
return x.indexOf(key) !== -1;
});
eqCitationArray[i].outerHTML=
"<span class='eqCitationSpan' onclick='currentPage="+eqsOnWhichPage+"; changePage();'>"
+eqCitationArray[i].innerHTML
+"</span>";
}
}
);
Everything works well except when I want to refer to an equation from within another equation. In that case, MathJax doesn't compile the equation at all, but only the command \eqref{} inside the equation. I know it is intended to be so, but then any work around for such problems?