/*
* LaTeX IT - JavaScript to Convert Latex within an HTML page into Equations
* Copyright (C) 2009 William Bateman, 2008 Waipot Ngamsaad
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
var LatexIT = {
mode : 'gif',
imgnum : 0,
isFirefox:false,
init : function() {
// We need to review the support for SVG. Latest released versions are not supporting this as they should
// if(document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"))
// this.mode='svg';
// browser name
// svg support in FireFox is not allowing two images to occur currently on the same line.
var ua = navigator.userAgent.toLowerCase();
if(ua.indexOf("firefox")!=-1)
{
// this.isFirefox = true;
}
},
pre : function(txt) {
if ( !txt.match(//i) )
{
//Clean code
txt=txt.replace(/ /mgi,"");
txt=txt.replace(/ /mgi,"");
//Create img tag
// txt = " ";
// txt = " ";
if(this.mode=='svg')
{
// Best for Firefox
if(this.isFirefox)
txt = " ";
else // Best for Chrome
// txt = " ";
txt = " ";
}
else
txt = " ";
}
return txt;
},
latex : function(txt) {
var html, htmlinline;
if(this.isFirefox) {
html=" ";
htmlinline=" ";
}
else {
html=" ";
htmlinline=" ";
}
txt=txt.replace(/(^\$|[^\\]\$)(.*?[^\\])\$/gm, htmlinline);
txt=txt.replace(/(^\\|[^\\]\\)\[(.*?[^\\])\\\]/mg," "+html+" ");
txt=txt.replace(/\\\$/mg,"\$");
txt=txt.replace(/\\\\(\[|\])/mg,"$1");
return txt;
},
render : function(tag, latexmode) {
var eqn = window.document.getElementsByTagName(tag);
for (var i=0; i