jsMath2jax.js 1.9 KB

12345678910111213
  1. /*
  2. * /MathJax/extensions/jsMath2jax.js
  3. *
  4. * Copyright (c) 2009-2013 The MathJax Consortium
  5. *
  6. * Part of the MathJax library.
  7. * See http://www.mathjax.org for details.
  8. *
  9. * Licensed under the Apache License, Version 2.0;
  10. * you may not use this file except in compliance with the License.
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. */MathJax.Extension.jsMath2jax={version:"2.2",config:{preview:"TeX"},PreProcess:function(a){this.configured||(this.config=MathJax.Hub.CombineConfig("jsMath2jax",this.config),this.config.Augment&&MathJax.Hub.Insert(this,this.config.Augment),"undefined"===typeof this.config.previewTeX||this.config.previewTeX||(this.config.preview="none"),this.previewClass=MathJax.Hub.config.preRemoveClass,this.configured=!0);"string"===typeof a&&(a=document.getElementById(a));a||(a=document.body);var c=a.getElementsByTagName("span"),b;for(b=c.length-1;0<=b;b--)String(c[b].className).match(/(^| )math( |$)/)&&this.ConvertMath(c[b],"");a=a.getElementsByTagName("div");for(b=a.length-1;0<=b;b--)String(a[b].className).match(/(^| )math( |$)/)&&this.ConvertMath(a[b],"; mode\x3ddisplay")},ConvertMath:function(a,c){if(0===a.getElementsByTagName("script").length){var b=a.parentNode,d=this.createMathTag(c,a.innerHTML);a.nextSibling?b.insertBefore(d,a.nextSibling):b.appendChild(d);"none"!==this.config.preview&&this.createPreview(a);b.removeChild(a)}},createPreview:function(a){var c=this.config.preview;"TeX"===c&&(c=[this.filterPreview(a.innerHTML)]);c&&(c=MathJax.HTML.Element("span",{className:MathJax.Hub.config.preRemoveClass},c),a.parentNode.insertBefore(c,a))},createMathTag:function(a,c){c=c.replace(/&lt;/g,"\x3c").replace(/&gt;/g,"\x3e").replace(/&amp;/g,"\x26");var b=document.createElement("script");b.type="math/tex"+a;MathJax.HTML.setScript(b,c);return b},filterPreview:function(a){return a}};MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.jsMath2jax],8);MathJax.Ajax.loadComplete("[MathJax]/extensions/jsMath2jax.js");