I would like to find all children of an element that contain what MathJax would see as valid math. I want to be able to call this function before any typesetting has been applied. Does MathJax support this or will I have to write my own function to do this? My preference would be to call a MathJax api since that way I could be confident that the returned nodes will be seen as math by MathJax whereas if I write my own I might potentially return nodes that MathJax does not see as math.Thank you in advance!
--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<div id='myMathField" ng-bind-html="model"><p>Some latex math</p><p><br>\[x + 5 = -3 \]</div>
var elementsContainingMath = Math.Hub.getAllMathElements($('#myMathField')[0]);
console.log(elementsContainingMath.length);
console.log(elementsContainingMath[0]);
> 2
> <p>
MathJax.Extension.tex2jax.isElementMath = function(element, el) { // copied and altered from MathJax.Extension.tex2jax.scanText
if (element.nodeValue.replace(/\s+/, '') == '') { return element } var match, prev; this.search = { start: true }; this.pattern = this.start; while (element) { this.pattern.lastIndex = 0; while (element && element.nodeName.toLowerCase() === '#text' && (match = this.pattern.exec(element.nodeValue))) { if (this.search.start) { element = this.startMatch(match, element) } else { element = this.evalEndMatch(match, element); if (this.search.matched) { return true; } } }
if (element) { do { prev = element; element = element.nextSibling } while (element && (element.nodeName.toLowerCase() === 'br' || element.nodeName.toLowerCase() === '#comment')); if (!element || element.nodeName !== '#text') { return false; } } } return false; //element;};
MathJax.Extension.tex2jax.evalEndMatch = function (match,element) { //copied and altered from MathJax.Extension.tex2jax.endMath var search = this.search; if (match[0] == search.end) { if (!search.close || search.pcount === 0) { search.close = element; search.cpos = this.pattern.lastIndex; search.clen = (search.isBeginEnd ? 0 : match[0].length); } if (search.pcount === 0) { search.matched = true; this.switchPattern(this.start); } } else if (match[0] === "{") {search.pcount++} else if (match[0] === "}" && search.pcount) {search.pcount--} return element;}
var getTextNodesIn = function (el) { return $(el).find(":not(iframe)").addBack().contents().filter(function () { return this.nodeType == 3; });};
var getMathNodesIn = function(el) { var nodes = getTextNodesIn(el); var mathNodes = []; if (MathJax.Extension.tex2jax.createPatterns()) { _.forEach(nodes, function (node) { if (MathJax.Extension.tex2jax.isElementMath(node)) { mathNodes.push(node); } }); } return mathNodes;}
var mathNodes = getMathNodesIn(($('#myMathField')[0]);
var mathNodes = MathJax.Hub.getMathNodesIn(($('#myMathField')[0]); //returns any type of math nodes depending on the loaded extensions. i.e. presentation mathml, content mathml, latex and possibly others.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-users+unsubscribe@googlegroups.com.