12345678910111213141516171819202122232425262728293031323334 |
- /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
- /* vim: set ts=2 et sw=2 tw=80: */
- /*************************************************************
- *
- * MathJax/extensions/jsMath2jax.js
- *
- * Implements a jsMath to Jax preprocessor that locates jsMath-style
- * <SPAN CLASS="math">...</SPAN> and <DIV CLASS="math">...</DIV> tags
- * and replaces them with SCRIPT tags for processing by MathJax.
- * (Note: use the tex2jax preprocessor to convert TeX delimiters or
- * custom delimiters to MathJax SCRIPT tags. This preprocessor is
- * only for the SPAN and DIV form of jsMath delimiters).
- *
- * To use this preprocessor, include "jsMath2jax.js" in the extensions
- * array in your config/MathJax.js file, or the MathJax.Hub.Config() call
- * in your HTML document.
- *
- * ---------------------------------------------------------------------
- *
- * Copyright (c) 2010-2013 The MathJax Consortium
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */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(/</g,"\x3c").replace(/>/g,"\x3e").replace(/&/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");
|