Count MathJax code tokens for Puzzling site MathJax problems. (No code snippets there, unfortunately.)
function Count() {
var mathjax = document.getElementById("mathjax").value;
var count = document.getElementById("count");
tokens = mathjax.split(/(\\(?:[a-z]+|.)|##?\d|.)/i);
var n = 0;
for (var i = 0, m = tokens.length; i < m; i++) {
if (!tokens[i].match(/^$|\}|\s|\n/)) n++;
}
count.innerHTML = "Tokens: <b>"+n+"</b>";
}
<input type="button" value="Count Tokens" onclick="Count()" />
<span id="count" style="padding-left:2em"></span><br/>
<span style="vertical-align:-.1em; font-size:80%">Paste MathJax code to be counted:</span><br/>
<textarea cols="80" rows="5" id="mathjax"></textarea>