"); // % sign
- str = str.replace(/%[^\n]*(?=\n)/g,"");
- str = str.replace(/%[^\r]*(?=\r)/g,""); //Used by Explorer
- str = str.replace(/%[^\n]*$/,"") // End of text segment comment
-
- if(isIE && str.match(/%/g) != null && IEcommentWarning) {
- alert("Comments may not have parsed properly. Try putting in stuff
- //and to identify non-display math content (sections, etc).
-
- str = str.split("");
- // var ntype = TheBody.nodeType;
- var newFrag = document.createDocumentFragment();
-
- for(var i=0;i
- if(isIE) {
- str[i] = str[i].replace(/\r/g," "); // replace \r by a space to aid spacing!
- }
-
-
- //items and appendix
- str[i] = str[i].replace(/\\bibitem\s*([^\{]*\{\s*\w*\s*\})/g," \\[bibitem\\]$1\\[ ");
- str[i] = str[i].replace(/\\bibitem\s*/g," \\[bibitem\\] \\[ ");
- str[i] = str[i].replace(/\\item\s*\[\s*(\w+)\s*\]/g," \\[alistitem\\]$1\\[ ");
- str[i] = str[i].replace(/\\item\s*/g," \\[alistitem\\] \\[ ");
- str[i] = str[i].replace(/\\appendix/g," \\[appendix\\] \\[ ");
-
-
- // \includegraphics[][]{image} -- no processing of options. This treatment is DANGEROUS. It assumes no html will be
- // placed within the \begin{figure} ... \end{figure} structure, and the [\s\S] character class could lead to strange matches
- str[i] = str[i].replace(/\\begin\s*\{\s*figure\s*\}([\s\S]+?)\\end\s*\{\s*figure\s*\}/g," \\[figure\\]$1\\[ ");
- str[i] = str[i].replace(/\\begin\s*\{\s*table\s*\}([\s\S]+?)\\end\s*\{\s*table\s*\}/g," \\[table\\]$1\\[ ");
- //str[i] = str[i].replace(/\\begin\s*\{\s*array\s*\}([\s\S]+?)\\end\s*\{\s*array\s*\}/g," \\[array\\]$1\\[ ");
- //goal is to protect array \\ from being converted into linebreaks
-
- //This construction allows css classes for divs for these elements, but the CSS will have to be supplied through a
- //css file or in the header. (It makes sense to me that style files in LaTeX should correspond
- //to css and/or xslt when translating to mathml, but \ref's are a problem).
- str[i] = str[i].replace(/\\begin\s*\{\s*theorem\s*\}/g," \\[theorem\\]Theorem \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*theorem\s*\}/g," \\[endtheorem\\] \\[ ");
-
- str[i] = str[i].replace(/\\begin\s*\{\s*definition\s*\}/g," \\[definition\\]Definition \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*definition\s*\}/g," \\[enddefinition\\] \\[ ");
-
- str[i] = str[i].replace(/\\begin\s*\{\s*lemma\s*\}/g," \\[lemma\\]Lemma \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*lemma\s*\}/g," \\[endlemma\\] \\[ ");
-
- str[i] = str[i].replace(/\\begin\s*\{\s*corollary\s*\}/g," \\[corollary\\]Corollary \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*corollary\s*\}/g," \\[endcorollary\\] \\[ ");
-
- str[i] = str[i].replace(/\\begin\s*\{\s*proposition\s*\}/g," \\[proposition\\]Proposition \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*proposition\s*\}/g," \\[endproposition\\] \\[ ");
-
- str[i] = str[i].replace(/\\begin\s*\{\s*example\s*\}/g," \\[example\\]Example \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*example\s*\}/g," \\[endexample\\] \\[ ");
-
- str[i] = str[i].replace(/\\begin\s*\{\s*exercise\s*\}/g," \\[exercise\\]Exercise \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*exercise\s*\}/g," \\[endexercise\\] \\[ ");
-
- str[i] = str[i].replace(/\\begin\s*\{\s*thebibliography\s*\}\s*\{\s*\w+\s*\}/g," \\[thebibliography\\]References \\[ ");
- str[i] = str[i].replace(/\\begin\s*\{\s*thebibliography\s*\}/g," \\[thebibliography\\]References \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*thebibliography\s*\}/g," \\[endthebibliography\\]References \\[ ");
-
-
- str[i] = str[i].replace(/\\begin\s*\{\s*proof\s*\}/g," \\[proof\\]Proof: \\[ ");
- if(isIE) { //IE is just so weird
- str[i] = str[i].replace(/\\end\s*\{\s*proof\s*\}/g,"\u220E \\[endproof\\] \\[ ");
- } else {
- str[i] = str[i].replace(/\\end\s*\{\s*proof\s*\}/g," \\[endproof\\] \\[ ");
- }
-
- //The frontmatter -- all translated to div's to be handled by CSS
- str[i] = str[i].replace(/\\title\s*\{\s*([^\}]+)\}/g," \\[title\\] \\[$1 \\[endtitle\\] \\[ ");
- str[i] = str[i].replace(/\\author\s*\{\s*([^\}]+)\}/g," \\[author\\] \\[$1 \\[endauthor\\] \\[ ");
- str[i] = str[i].replace(/\\address\s*\{\s*([^\}]+)\}/g," \\[address\\] \\[$1 \\[endaddress\\] \\[ ");
- str[i] = str[i].replace(/\\date\s*\{\s*([^\}]+)\}/g," \\[date\\] \\[$1 \\[enddate\\] \\[ ");
- str[i] = str[i].replace(/\\begin\s*\{\s*keyword\s*\}/g," \\[keyword\\] \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*keyword\s*\}/g," \\[endkeyword\\] \\[ ");
- str[i] = str[i].replace(/\\begin\s*\{\s*abstract\s*\}/g," \\[abstract\\] \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*abstract\s*\}/g," \\[endabstract\\] \\[ ");
-
- //The rest of the environments -- Users can even "make up their own" -- but it avoids the array and tabular environments
- str[i] = str[i].replace(/\\begin\s*\{\s*(?!array|tabular)(\w+)\s*\}/g," \\[$1\\] \\[ ");
- str[i] = str[i].replace(/\\end\s*\{\s*(?!array|tabular)(\w+)\s*\}/g," \\[end$1\\] \\[ ");
-
- //Next, we look at section--subsection stuff. This is nested -- this would be so much better if LaTeX used
- //some type of \begin{sectionhead}...\end{sectionhead} structure
- var sectionIndex = str[i].search(/\\section\s*\{\s*[\s\S]+\}/);
-
- while(sectionIndex >= 0) {
- str[i] = str[i].replace(/\\section\s*\{/ ," \\[section\\]");
- var delimcnt = 1;
- for(var ii=sectionIndex;ii= 0) {
- str[i] = str[i].replace(/\\subsection\s*\{/ ," \\[subsection\\]");
- var delimcnt = 1;
- for(var ii=sectionIndex;ii= 0) {
- str[i] = str[i].replace(/\\subsubsection\s*\{/ ," \\[subsubsection\\]");
- var delimcnt = 1;
- for(var ii=sectionIndex;ii= 0) { // caption may contain other { } structures -- but not displaymath!!
- var tmp = strtmparray[1];
- var delimcnt = 0;
- var capstart = -1;
- for(var pos=capIndex;pos0) {
- capend = pos-1;
- FIGcap = tmp.substring(capstart,pos);
- break
- }
- }
- }
-
- var FIGtr2 = document.createElement("tr");
- var FIGtd2 = document.createElement("td");
- FIGtd2.className="caption";
-
-
- var FIGanchor = document.createElement("a");
- FIGanchor.className = "figure";
- if(FIGlbl!=null) { FIGanchor.id = FIGlbl[1]; }
- LaTeXCounter["figure"]++;
- var fignmbr = makeNumberString(LaTeXCounter["figure"]);
- var anchorSpan = document.createElement("span");
- anchorSpan.className = "figure";
- anchorSpan.style.display = "none";
- anchorSpan.appendChild(document.createTextNode(fignmbr));
- FIGanchor.appendChild(anchorSpan);
- FIGtd2.appendChild(FIGanchor);
-
- var FIGspan = document.createElement("span");
- FIGspan.className = "figure"; //For CSS counters, comment this line
- FIGspan.appendChild(document.createTextNode("Figure "+fignmbr+". " ) );
- FIGtd2.appendChild(FIGspan);
- FIGtd2.appendChild(document.createTextNode(""+FIGcap));
- FIGtr2.appendChild(FIGtd2);
- FIGtbody.appendChild(FIGtr2);
- var IsSpecial = false;
-
- var FIGinfo = strtmparray[1].match(/\\includegraphics\s*\{([^\}]+)\}/);
- if(FIGinfo==null) { //options not processed, for now
- FIGinfo = strtmparray[1].match(/\\includegraphics\s*\[[^\]]*\]\s*\{\s*([^\}]+)\s*\}/);
- }
- if(FIGinfo==null) {
- FIGinfo = strtmparray[1].match(/\\special\s*\{\s*([^\}]+)\}/);
- IsSpecial=true //Hook: Later can include "special" graphics commands
- };
-
- if(FIGinfo!=null) { //Caption will be above the image
- var FIGtr1 = document.createElement("tr");
- var FIGtd1 = document.createElement("td");
- FIGtd1.className="image";
- var FIGimg = document.createElement("img");
- var FIGsrc = FIGinfo[1]; //options not processed, for now
- FIGimg.src = FIGsrc;
- FIGimg.alt = "Figure "+FIGsrc+" did not load";
- FIGimg.title = "Figure "+fignmbr+". "+FIGcap;
- FIGimg.id = "figure"+fignmbr;
- FIGtd1.appendChild(FIGimg);
- FIGtr1.appendChild(FIGtd1);
- FIGtbody.appendChild(FIGtr1);
- }
- nodeTmp.appendChild(FIGtbody);
- newFrag.appendChild(nodeTmp);
- break;
- case "table":
- var nodeTmp = document.createElement("table");
- if(strtmparray[1].search(/\\centering/) >= 0) {
- nodeTmp.className = 'LaTeXtable centered';
- nodeTmp.align = "center";
- } else {
- nodeTmp.className = 'LaTeXtable';
- };
- tableid++;
- nodeTmp.id = "LaTeXtable"+tableid; //unique id for each table
-
- var TABlbl = strtmparray[1].match(/\\label\s*\{\s*(\w+)\s*\}/);
- strtmparray[1]=strtmparray[1].replace(/\\label\s*\{\w+\}/g,"");
-
- var capIndex = strtmparray[1].search(/\\caption\s*\{[\s\S]+\}/);
- var TABcap = "";
-
- if(capIndex >= 0) { // caption may contain other { } structures -- but not displaymath!!
- var tmp = strtmparray[1];
- var delimcnt = 0;
- var capstart = -1;
- for(var pos=capIndex;pos0) {
- capend = pos-1;
- TABcap = tmp.substring(capstart,pos);
- break
- }
- }
- }
-
- if(TABcap!="") {
- var TABtbody = document.createElement("tbody");
- var TABcaption = document.createElement("caption");
- TABcaption.className="LaTeXtable centered";
- var TABanchor = document.createElement("a");
- TABanchor.className = "LaTeXtable";
- if(TABlbl!=null) { TABanchor.id = TABlbl[1]; }
- LaTeXCounter["table"]++;
- var tabnmbr = makeNumberString(LaTeXCounter["table"]);
- var anchorSpan = document.createElement("span");
- anchorSpan.className = "LaTeXtable";
- anchorSpan.style.display = "none";
- anchorSpan.appendChild(document.createTextNode(tabnmbr));
- TABanchor.appendChild(anchorSpan);
- TABcaption.appendChild(TABanchor);
-
- var TABspan = document.createElement("span");
- TABspan.className = "LaTeXtable"; //For CSS counters, comment this line
- TABspan.appendChild(document.createTextNode("Table "+tabnmbr+". " ) );
- TABcaption.appendChild(TABspan);
- TABcaption.appendChild(document.createTextNode(""+TABcap));
- nodeTmp.appendChild(TABcaption);
- }
- var TABinfo = strtmparray[1].match(/\\begin\s*\{\s*tabular\s*\}([\s\S]+)\\end\s*\{\s*tabular\s*\}/);
- if(TABinfo!=null) {
- var TABtbody = document.createElement('tbody');
- var TABrow = null;
- var TABcell = null;
- var row=0;
- var col=0;
-
- var TABalign = TABinfo[1].match(/^\s*\{([^\}]+)\}/);
- TABinfo = TABinfo[1].replace(/^\s*\{[^\}]+\}/,"");
- TABinfo = TABinfo.replace(/\\hline/g,""); //no horizontal bars
- TABalign[1] = TABalign[1].replace(/\|/g,""); //no vertical bars
- TABalign[1] = TABalign[1].replace(/\s/g,"");
- TABinfo = TABinfo.split("\\\\"); // into rows
- for(row=0;row -- access it with \cite, thus allowing appropriate labels!
- if(strtmparray[1]!="") {
- nodeSpan.appendChild(document.createTextNode(strtmparray[1]));
- } else {
- nodeSpan.appendChild(document.createTextNode("["+bibcntr+"]"));
- }
- nodeTmp.appendChild(nodeSpan);
- newFrag.appendChild(nodeTmp);
- break;
- case "cite":
- var nodeTmp = document.createElement("a");
- nodeTmp.className = 'cite';
- nodeTmp.name = 'cite';
- nodeTmp.href = "#"+strtmparray[1];
- newFrag.appendChild(nodeTmp);
- break;
- case "ref":
- var nodeTmp = document.createElement("a");
- nodeTmp.className = 'ref';
- nodeTmp.name = 'ref';
- nodeTmp.href = "#"+strtmparray[1];
- newFrag.appendChild(nodeTmp);
- break;
- default :
- var nodeTmp = document.createElement("div");
- nodeTmp.className = strtmparray[0];
- if( IsCounter.test(strtmparray[0]) ) {
- LaTeXCounter[strtmparray[0]]++;
- var nodeAnchor = document.createElement("a");
- nodeAnchor.className = strtmparray[0];
- var divnum = makeNumberString(LaTeXCounter[strtmparray[0]]);
- var anchorSpan = document.createElement("span");
- anchorSpan.className = strtmparray[0];
- anchorSpan.appendChild(document.createTextNode(divnum));
- anchorSpan.style.display="none";
- nodeAnchor.appendChild(anchorSpan);
- nodeTmp.appendChild(nodeAnchor);
-
- var nodeSpan = document.createElement("span");
- nodeSpan.className = strtmparray[0];
- nodeSpan.appendChild(document.createTextNode(strtmparray[1]+" "+divnum+". "));
- nodeTmp.appendChild(nodeSpan);
- }
- if(isIE) { //remove if IE supports :before and :after
- if(strtmparray[0]==("thebibliography"||"abstract"||"keyword"||"proof")) {
- var nodeSpan = document.createElement("span");
- nodeSpan.className = strtmparray[0];
- nodeSpan.appendChild(document.createTextNode(strtmparray[1]));
- nodeTmp.appendChild(nodeSpan);
- }
- } //end of IE :before and :after fixes
- if(strtmparray[0]=="endenumerate" || strtmparray[0]=="enditemize" || strtmparray[0]=="enddescription") {
- var endDiv = document.createElement("div");
- endDiv.className = "endlistitem";
- newFrag.appendChild(endDiv);
- }
- newFrag.appendChild(nodeTmp);
- if(strtmparray[0]=="enumerate" || strtmparray[0]=="itemize" || strtmparray[0]=="description") {
- var endDiv = document.createElement("div");
- endDiv.className = "listitem";
- newFrag.appendChild(endDiv);
- }
- }
- } else {
- //even = text, labels, bf, and italics, and linebreaks, and math -- we now remove the math
- strtmp[j] = strtmp[j].replace(/\\\$/g,"");
- strtmp[j] = strtmp[j].replace(/\$([^\$]+)\$/g," \\[$1\\[ ");
- strtmp[j] = strtmp[j].replace(//g,"\\$");
- strtmp[j] = strtmp[j].replace(/\\begin\s*\{\s*math\s*\}([\s\S]+?)\\end\s*\{\s*math\s*\}/g," \\[$1\\[ ");
-
- var strtmptmp = strtmp[j].split("\\[");
-
- for(var jjj=0;jjj-1) {
- if(/^\\textcolor/.test(strtmptmp[jjj].substring(TagIndex,strtmptmp[jjj].length))) {
- strtmptmp[jjj] = strtmptmp[jjj].replace(/\\textcolor\s*\{\s*(\w+)\s*\}\s*/," \\[textcolor\\]$1\\]|");
- } else {
- if(/^\\colorbox/.test(strtmptmp[jjj].substring(TagIndex,strtmptmp[jjj].length))) {
- strtmptmp[jjj] = strtmptmp[jjj].replace(/\\colorbox\s*\{\s*(\w+)\s*\}\s*/," \\[colorbox\\]$1\\]|");
- } else {
- strtmptmp[jjj] = strtmptmp[jjj].substring(0,TagIndex)+strtmptmp[jjj].substring(TagIndex,strtmptmp[jjj].length).replace(/\\\s*(\w+)\s*/," \\[$1\\]|");
- }
- }
- TagIndex +=strtmptmp[jjj].substring(TagIndex,strtmptmp[jjj].length).search(/\|/);
- TagIndex++;
- strtmptmp[jjj] = strtmptmp[jjj].replace(/\\\]\|/,"\\] ");
- if(strtmptmp[jjj].charAt(TagIndex) == "{") {
- strtmptmp[jjj] = strtmptmp[jjj].substring(0,TagIndex)+strtmptmp[jjj].substring(TagIndex+1,strtmptmp[jjj].length);
- var delimcnt = 1;
- for(var kk = TagIndex;kk=0;i--) {
- EndDivClass = AllDivs[i].className.match(/end\w+/ );
- if(EndDivClass!=null) {
- EndDivClass = EndDivClass[0];
- var DivClass = EndDivClass.substring(3,EndDivClass.length);
- var EndDivNode = AllDivs[i];
- break;
- }
- }
- while(EndDivClass!=null) {
- // TrackBack to Beginning, appending to newfrag as we go
- var newFrag = document.createDocumentFragment();
- var RootNode = EndDivNode.parentNode;
- var ClassCount = 1; // because of EndDivNode
- while(EndDivNode.previousSibling!=null && ClassCount>0) {
- switch(EndDivNode.previousSibling.className) {
- case EndDivClass:
- ClassCount++;
- newFrag.insertBefore(EndDivNode.previousSibling,newFrag.firstChild);
- break;
- case DivClass:
- if(EndDivNode.previousSibling.nodeName=="DIV") {
- ClassCount-- ;
- //Must check to see if we need a label here!
- if(lbl2id !="" ) {
- EndDivNode.previousSibling.id = lbl2id;
- lbl2id = ""
- }
- if(ClassCount==0) {
- RootNode = EndDivNode.previousSibling;
- } else {
- newFrag.insertBefore(EndDivNode.previousSibling,newFrag.firstChild);
- }
- };
- break;
- case 'LaTeXMathMLlabel':
- lbl2id = EndDivNode.previousSibling.id;
- EndDivNode.parentNode.removeChild(EndDivNode.previousSibling);
- break;
- default:
- newFrag.insertBefore(EndDivNode.previousSibling,newFrag.firstChild);
- }
- }
- RootNode.appendChild(newFrag);
- EndDivNode.parentNode.removeChild(EndDivNode);
-
- //Look for more end div items
- AllDivs = TheBody.getElementsByTagName("DIV");
- for(i=AllDivs.length-1;i>=0;i--) {
- EndDivClass = AllDivs[i].className.match(/end\w+/ );
- if(EndDivClass!=null) {
- ClassCount = 0;
- EndDivClass = EndDivClass[0];
- DivClass = EndDivClass.substring(3,EndDivClass.length);
- EndDivNode = AllDivs[i];
- RootNode = EndDivNode.parentNode;
- break;
- }
- }
- } // end while!
-
-
-
-
- var AllDivs = TheBody.getElementsByTagName("div"); //Convert itemize and enumerate to html lists:
- var DIV2LI = null;
-
- for(var i=0;i0) {
- for(var m=0;m");
- document.write("");
-}
-
-// GO1.1 Generic onload by Brothercake
-// http://www.brothercake.com/
-//onload function (replaces the onload="translate()" in the tag)
-function generic()
-{
- translate();
-};
-//setup onload function
-if(typeof window.addEventListener != 'undefined')
-{
- //.. gecko, safari, konqueror and standard
- window.addEventListener('load', generic, false);
-}
-else if(typeof document.addEventListener != 'undefined')
-{
- //.. opera 7
- document.addEventListener('load', generic, false);
-}
-else if(typeof window.attachEvent != 'undefined')
-{
- //.. win/ie
- window.attachEvent('onload', generic);
-}
-//** remove this condition to degrade older browsers
-else
-{
- //.. mac/ie5 and anything else that gets this far
- //if there's an existing onload function
- if(typeof window.onload == 'function')
- {
- //store it
- var existing = onload;
- //add new onload handler
- window.onload = function()
- {
- //call existing onload function
- existing();
- //call generic onload function
- generic();
- };
- }
- else
- {
- //setup onload function
- window.onload = generic;
- }
-}