//this code includes many bits and pieces.Some of them are open source when indicated. All other pieces were written by Arek Goetz @2004-2009. They cannot be used without a written permission elsewhere. var headID = document.getElementsByTagName("head")[0]; var cssNode = document.createElement('link'); cssNode.type = "text/css"; cssNode.rel = "stylesheet"; cssNode.href = "http://calculus.sfsu.edu/javascript/latex.css"; headID.appendChild(cssNode); /* Cross-Browser Split 0.3 By Steven Levithan MIT license Provides a consistent cross-browser, ECMA-262 v3 compliant split method */ String.prototype._$$split = String.prototype._$$split || String.prototype.split; String.prototype.split = function (s /* separator */, limit) { if (!(s instanceof RegExp)) return String.prototype._$$split.apply(this, arguments); var flags = (s.global ? "g" : "") + (s.ignoreCase ? "i" : "") + (s.multiline ? "m" : ""), s2 = new RegExp("^" + s.source + "$", flags), output = [], origLastIndex = s.lastIndex, lastLastIndex = 0, i = 0, match, lastLength; /* behavior for limit: if it's... - undefined: no limit - NaN or zero: return an empty arrayf - a positive number: use limit after dropping any decimal - a negative number: no limit - other: type-convert, then use the above rules */ if (limit === undefined || +limit < 0) { limit = false; } else { limit = Math.floor(+limit); if (!limit) return []; } if (s.global) s.lastIndex = 0; else s = new RegExp(s.source, "g" + flags); while ((!limit || i++ <= limit) && (match = s.exec(this))) { var emptyMatch = !match[0].length; if (emptyMatch && s.lastIndex > match.index) s.lastIndex--; if (s.lastIndex > lastLastIndex) { if (match.length > 1) { match[0].replace(s2, function () { for (var j = 1; j < arguments.length - 2; j++) { if (arguments[j] === undefined) match[j] = undefined; } }); } output = output.concat(this.slice(lastLastIndex, match.index)); if (1 < match.length && match.index < this.length) output = output.concat(match.slice(1)); lastLength = match[0].length; lastLastIndex = s.lastIndex; } if (emptyMatch) s.lastIndex++; } output = lastLastIndex === this.length ? (s.test("") && !lastLength ? output : output.concat("")) : (limit ? output : output.concat(this.slice(lastLastIndex))); s.lastIndex = origLastIndex; return output; }; function decode_entities(str) { return str .replace(/>/g,'>') .replace(/</g,'<') .replace(/"/g,'"') .replace(/ /g,'~') .replace(/&/g,'&'); } function encode_entities(str) { return str.replace(/(<|>|~|&|")/g, function (st, p1, offset, s){ return (p1 == '>') ? '>' : (p1=='<') ? '<' : (p1=='~') ? ' ' : (p1=='"') ? '"': '&' ; } ); } function ABC(i) { return String.fromCharCode(i+64); } function odd_number_backslashes_to_left( str, pos) { var i = 1; while (str.charAt(pos-i) == '\\') { i = i+1; } return (i % 2 == 0); } function naive_complete_braces(str) { var s=str.replace(/\\\\/g,'').replace(/\\{/g,'').replace(/\\}/g,''); var bal= ('{'+s).match(/{/g).length - ('}'+s).match(/}/g).length ; while (bal < 0) { str = '{' + str; bal = bal +1; } while (bal > 0) { str = str + '}'; bal = bal - 1; } return(str); } function bracket_substring(string, pos, left_p) { if ( (left_p == '{') || (left_p == null) || (typeof left_p == 'undefined' ) ) { left_p = '{'; right_p = '}'; } if (left_p == '(' ) { right_p = ')'; } if (left_p == '[' ) { right_p = ']'; } n = string.length; counter = 1; index = pos - 1; while ( (counter > 0) && (index < n-1) ) { index++; if ( (string.charAt(index) == '\\') && (!odd_number_backslashes_to_left( string, index)) ) { index = index + 2; } if (string.charAt(index) == right_p ) { counter--; } if ( (string.charAt(index) == left_p ) && (index != pos) ) counter++; } pos_right = (counter == 0) ? index : -1; counter = 1; index = pos + 1; while ( (counter > 0) && (index > -1) ) { index--; ind = (index > 0) ? (index - 1) : 0; if ( (string.charAt(index) == right_p ) && (string.charAt(ind) != '\\') && (index != pos) ) counter++; if ( (string.charAt(index) == left_p ) && (string.charAt(ind) != '\\') ) counter--; } pos_left = (counter == 0) ? index + 1 : -1; if ( (pos_left != -1) && (pos_right != -1) ) result = string.substring(pos_left,pos_right); else { if ( (pos_left == -1) && (pos_right == -1) ) result = -1; else result = ''; } return ([result, pos_left, pos_right]); } function split_to_coordinates(str, sep) { var str_tem = str.replace(/[\[\{]/g,'(').replace(/[\]\}]/g,')'); if (typeof sep == 'undefined') sep =','; var chunks = new Array(); chunks[0]=0; for(var pos=0;pos' +'' +'' +'' +'' +''; var html_control= '' +'' +'' +'' +''; html= '' +' ' +p2+' | pop-out' +'
'+html+html_control+'
'; return '
'+html+'
'; } ); string = styling_html(string,/\\href\s*{/,'', ''); return string; } function itemizing_html (string) { string = string.replace (/\\begin{itemize}((\n|.)+?)\\end{itemize}/g, function (str, p1, offset, s) { return ''; } ); string = string.replace (/\\begin{enumerate}\s*(?:\[(\d+)\.?\])*((\n|.)+?)\\end{enumerate}/g, function (str, p1, p2, offset, s) { if (typeof p1 =='undefined') p1 = '1'; return '
    ' + p2.replace(/\\item/, '
  1. ').replace(/\\item/g, parskip0 + '
  2. ') + '
'; } ); return string; } function choicing(str,j) { str = str.replace(/\\begin\s*{\s*(choices)\s*}((\n|.)+?)\\end\s*{\1\s*}/g, function (s,p1,p2,offset,t) { var a=p2.split(/\\choice/); if (a.length==1) return p2; var h = ''; h +='\n
    '+a[0]; for (var i=1;i'; h+=''; h+=''; } h +='\n
\n'; return h; } ); return str; } function questioning(str) { var number_blocks = 0; str = str.replace(/\\begin\s*{\s*(quiz|questions)\s*}((\n|.)+?)\\end\s*{\1\s*}/g, function (s,p1,p2,offset,t) { var a=p2.split(/\\question/); if (a.length==1) return p2; var n = a.length -1; var h = '
\n'; h+='
\n'; //+''; h+=''+ n + ' Questions'; h +='\n
    '+encode_entities(a[0]); for (var i=1;i'; if (i Theorem' + str + '. ' + p2 + '' + parskip2; } ). replace(/\\begin{lemma}(?:\s*\[([^\[\]]*)\])?((?:\n|.)+?)\\end{lemma}/g, function (str, p1, p2, offset, s) { var str = ( ( p1 != null ) && (p1 != '') ) ? ' (' + p1 + ')' : ''; return parskip1 + '
    Lemma' + str + '. ' + p2 + '
    ' + parskip2; } ) . replace(/\\begin{proposition}(?:\s*\[([^\[\]]*)\])?((?:\n|.)+?)\\end{proposition}/g, function (str, p1, p2, offset, s) { var str = ( ( p1 != null )&& (p1 != '') ) ? ' (' + p1 + ')' : ''; return parskip1 + '
    Proposition' + str + '. ' + p2 + '
    ' + parskip2; } ).replace(/\\begin{solution}(?:\s*\[([^\[\]]*)\])?((?:\n|.)+?)\\end{solution}/g, function (str, p1, p2, offset, s) { var str = ( ( p1 != null ) && (p1 != '') ) ? ' (' + p1 + ')' : ''; return parskip1 + '
    Solution' + str + '. ' + p2 + '
    ' + parskip2; } ); return string; } function line_section_snippet(str) { str = latex_to_plain_text( remove_function_and_arguments(str, 'margin' ) ); if (str.length < 140) return (str); str = str.substr(0,140); return ( str + '...'); } function title_snippet(str, l) { if (typeof l =='undefined') l = 36; while(str.length < l) { str =str + ' '; } if (str.length > l) str=str.substr(str,l-3) + '...'; return str.replace(/\s/g,' '); } function collapse_section(el) { el.title=el.title.replace(/Collapse/,'Expand'); el.lastChild.style.display = 'inline'; el.style.fontWeight='normal'; el.style.fontSize='100%'; el.nextSibling.style.display = 'none'; } function expand_section(el) { el.title=el.title.replace(/Expand/,'Collapse'); el.lastChild.style.display = 'none'; el.style.fontWeight='bold'; el.style.fontSize='125%'; el.nextSibling.style.display = 'inline'; } function toggle_section(el) { (el.title.match(/Expand/)) ? expand_section(el) : collapse_section(el); } function expand_all_sections(n) { var id = 'inner_block_' + n.toString(); var elp = document.getElementById(id); for (var j = 1; j < elp.childNodes.length; j++) { var el = elp.childNodes[j].firstChild; el.firstChild.title="Collapse section " + j; el.lastChild.style.display = 'inline'; el.firstChild.style.fontWeight='bold'; el.firstChild.style.fontSize='125%'; el.firstChild.lastChild.style.display = 'none'; } } function collapse_all_sections(n) { var id = 'inner_block_' + n.toString(); var elp = document.getElementById(id); for (var j = 1; j < elp.childNodes.length; j++) { var el = elp.childNodes[j].firstChild; el.firstChild.title="Expand section " + j; el.lastChild.style.display = 'none'; el.firstChild.style.fontWeight='normal'; el.firstChild.style.fontSize='100%'; el.firstChild.lastChild.style.display = 'inline'; } } function extract_block(str, block) { if (typeof block !='number') return ''; str=str.replace(/\\(begin|end)\s*{block}/g,'\\$1{pages}'); var result = str.split(/\\begin{pages}((\n|.)+?)\\end{pages}/)[1+3*block]; if (typeof result =='undefined') return ''; return result; } function extract_section(str, n) { var result = str.split(/(\\page\s*{[^}]*})/); if ( (2*n >= result.length) || (2*n < 1) ) return (''); return result[2*n-1] + result[2*n]; } function paging_html(string, size, original_source) { if (typeof original_source == 'undefined') original_source = ''; var arr = string.split(/\\page\s*/); var result = '
    ' + arr[0].toString().replace(/^\s+$/,'') + '
    '; for (i = 1; i < arr.length; i++) { var tab = bracket_substring( arr[i], 0 ); var str1 = tab[0]; var str2 = arr[i].substring( tab[2] +1 , arr[i].length ); var lsize = Math.round(size * 1.25); if (tab[0] != -1) { var with_margin = (extracting_arguments (str2, /(\\margin|\\marginpar)\s*{/) == ''); var str_top = '
    ' ; var evenness = (i %2 == 0) ? 'even' : 'odd'; str_top += '
    1) { str_top += 'title="Expand section '+i+'" style="position:relative" '; } else { str_top += 'title="Collapse section '+i+'" style="position:relative; font-weight:bold; font-size:125%; " '; } str_top += ' onclick=" var el=this; toggle_section(el);" >'; var ii = ((i<10) && (arr.length > 9) ) ? '  '+i : ''+i; if (arr.length > 2) str_top += ''+ ii +'' + ' '; str_top += '
    ' + str1 +'
    ' + '
    ' + '
    ' + '
    ' + '\n0) marginal_notes= '\n\n'+ marginal_notes; var str_margin = with_margin ? '' +'' + str_margin + big_paragraphs[j] + '\n'; } result = result + str_top + table_row + '
    ' : '
    ' + marginal_notes + '
    '; table_row = table_row + '\n
    '; result = result + '
    '; } else { result = result + arr[i]; } } return result; } function extract_url_title(str) { if (typeof str =='undefined') str = document.location.href; var title = str.replace(/\?.*/,''); if (title.substr(title.length-1)=='/') title=substr(title,0,title.length-1); title = title.replace(/.+\/([^\/]+)$/,'$1').replace(/\.[^\.]+$/,'').replace(/_/g,' '); return title; } function blocking_html (string, size, original_source) { var number_blocks = 0; string = string.replace (/\\begin{(block|pages)}((\n|.)+?)\\end{\1}/g, function (str, p1,p2, offset, s) { var str = '
    '; var title = extracting_arguments(p2,/\\title\s*{/); if (title =='') { title="Live notes"; }; p2 = remove_function_and_arguments(p2,'title'); str +='
    '; var sss=' 
    '; var pages_number = p2.split(/\\page\s*/).length -1; var exp_str = ' Expand'; var col_str = ' Collapse'; var expandAll = (pages_number > 1) ? exp_str : col_str; if (pages_number > 1) { sss +=' ' + expandAll + ' All
    '; } else {sss ='';} str+='
    ' + title + sss + '
    '; var p3 = extract_block( original_source,number_blocks); str += '
    '; str += latex2image(p3, size, 'pdf'); str += '
    '; str +='
    '; str +='
    ' + paging_html( p2, size, p3) + "
    "; number_blocks++; return str; } ); return string; } function remove_function_and_arguments(str,fun) { // \margin{...} should work recursively var reg_latex =new RegExp("\\\\" + fun + "\\s*{"); var br = reg_latex.source; br = br.charAt(br.length-1); var caught = str.match(reg_latex); if (caught == null) return(str) ; var p= str.indexOf(caught[0]); var left = str.substring(0,p); var r = str.substring(p+caught[0].length); var result = left; var tab =bracket_substring(br+r, 0, br ); if ( (tab[0] == -1) || (tab[1] == -1) || (tab[2] == -1) ) { return(str); } var str1 = tab[0]; var rstr = r.substring( tab[2] , r.length ).toString(); if (tab[0] != -1) { result = result + rstr; } else { result = result + r; } result = left + remove_function_and_arguments( result.substr(left.length), fun ); return result; } function nonmath_latex_layout_to_html(string, size) { if (typeof size !='number') size =15; parskip0 = '

    '; parskip1 = '

    '; parskip2 = '

    '; string = string.replace(/(\n|\r\n){3,}/g, parskip2).replace(/(\n|\r\n){2,}/g, parskip1).replace(/\\\\/g,parskip0); string = hyperlink_address (string); string = string.replace(/\\today/g, today_string() ) .replace(/\\now/g, today_string(true) ); string = string.replace(/\\smallskip/g, parskip0).replace(/\\medskip/g, parskip1).replace(/\\bigskip/g, parskip2); var l1='<'+'iframe frameborder="0" height="300" src="'; var l2 = '" style="'; var l3 ='" >Loading...'; string = styling_html(string,/\\iframe\s*{/, l1,l2,l3); l1='<'+'img class="image" src="'; l2 = '" alt="'; l3 ='" />'; string = styling_html(string,/\\img\s*{/, l1,l2,l3); return string; } function latex_layout_to_html (string, size, original_source) { if (typeof size !='number') size =15; string = questioning(string); string = blocking_html (string, size, original_source); string = styling_html(string, /\\div\s*{/,'
    ','
    '); string = styling_html(string, /\\span\s*{/,'',''); string = styling_html (string,/\\red\s*{/, '', ''); string = styling_html (string,/\\blue\s*{/, '', ''); string = styling_html (string,/\\green\s*{/, '', ''); string = styling_html (string,/\\cyan\s*{/, '', ''); string = styling_html (string,/\\hl\s*{/, '', ''); string = styling_html (string,/\\large\s*{/, '', ''); string = styling_html (string,/\\small\s*{/, '', ''); string = styling_html (string,/\\footnotesize\s*{/, '', ''); string = styling_html (string,/\\center\s*{/, '
    ', '
    '); string = styling_html (string,/\\flushright\s*{/, '
    ', '
    '); string = styling_html (string,/\\bf\s*{/, '', ''); string = styling_html (string,/\\textbf\s*{/, '', ''); string = styling_html (string,/\\texttt\s*{/, '', ''); string = styling_html (string,/\\emph\s*{/, '', ''); string = styling_html (string,/\\it\s*{/, '', ''); string = styling_html (string,/\\fcolorbox\s*{\s*cyan\s*}\s*{\s*white\s*}\s*{/, '
     ', ' 
    '); string = styling_html (string,/\\fcolorbox\s*{\s*red\s*}\s*{\s*white\s*}\s*{/, '
     ', ' 
    '); string = styling_html (string,/\\fcolorbox\s*{\s*black\s*}\s*{\s*white\s*}\s*{/, '
     ', ' 
    '); string = styling_html (string, /{[\s|\n]*(?:\\textbf|\\bf) [\s\n]*/,'',''); string = styling_html (string, /{[\s|\n]*\\it [\s\n]*/,'',''); string = styling_html (string, /\\caption\s*{/,'
    ','
    '); //\toggle{$=$}{$=x^2$} var l1= ''; var l2 =''); // var l1= '
    ×'; var l2 = ' - Dismiss' + '
    '; string = styling_html (string,/\\dismiss\s*{/,l1, l2); // var l = ''; var m =''; string = styling_html(string,/\\onclick\s*{/,l,m,r); var l = ''; var m =''; string = styling_html(string,/\\onmouseover\s*{/,l,m,r); //\expand{anchor}{This goes under the anchor when clicked} var h1 = ''; var h2 = '»

    '; string = styling_html(string,/\\expand\s*{/,h1,h2,h3); var l = '
    ' +'
    ' +'
    ' +'
    ' +'Mango-beta'; string=styling_html(string,/\\mangobox\s*{/,l,r); string = itemizing_html (string); string = styling_html (string,/(?:\\margin|\\marginpar)\s*{/, ''); string = statementing_html (string); return string; } function adjust_font_size(el) { el.style.fontSize= Math.min(100,Math.max(64,103-Math.floor(Math.pow(el.value.length,.7)))) + '%'; return false; } function odgadnij(str) // { str = ' ' + str + ' '; str = str.replace(/(\d)([a-zA-Z])/g,'$1 $2'); str = str.replace(/d([x|y|t|u]*)\/d([x|y|t|u])/g,'\\tfrac{d$1}{d$2}') str = str.replace(/[\.,;]$/,' $1'); str = styling_html(str, /lim(?:it)?\s*\(/, '\\lim_{', '}' ); str = styling_html(str, /lim(?:it)?\s*\[/, '\\lim_{', '}' ); str = str.replace( /lim(?:it)?\s*([a-z]+ *\-+>\S+)/g, '\\lim_{$1}' ); str = str.replace(/\\?(?:[sS]um|[sS]umm?ation)\s*from\s+(\S+)\s+to\s+(\S+)/g,'\\sum_{$1}^{$2}') .replace(/\\?(?:[pP]roduct)\s*from\s+(\S+)\s+to\s+(\S+)/g,'\\product_{$1}^{$2}') .replace(/((\n.+\|.+){2,})/g, function (temp_str, p1, offset, s) { p1 = '\\begin{tabular}{c|c}\n' + p1; p1 = p1.replace(/\n(.+)\|(.+)/g,'$1 & $2 \\\\\n') ; p1 = p1 + '\\end{tabular}'; return (p1); } ) .replace(/->/g,' \\to ') .replace(/%/g,' \\% ') .replace(/([^\\a-zA-Z])(oo|inf)([^a-zA-Z])/g,'$1\\infty$3') .replace(/([^\\a-zA-Z])(l?dots)([^a-zA-Z])/g,'$1\\$2$3') .replace(/([^\\a-zA-Z])(infty|infinity)([^a-zA-Z])/g,'$1\\infty $3') .replace(/<>/g,' \\not =') .replace(/([^\\a-zA-Z])red([^a-zA-Z])/g,'$1\\red $2') .replace(/([^\\a-zA-Z])green([^a-zA-Z])/g,'$1\\green $2') .replace(/([^\\a-zA-Z])blue([^a-zA-Z])/g,'$1\\blue $2') .replace(/([^\\a-zA-Z])black([^a-zA-Z])/g,'$1\\black $2') .replace(/([^\\a-zA-Z])yellow([^a-zA-Z])/g,'$1\\yellow $2') .replace(/([^\\a-zA-Z])[Mm]od([^a-zA-Z])/g,'$1\\mod $2') .replace(/([^\\a-zA-Z])not([^a-zA-Z])/g,'$1\\not $2') .replace(/>=/g,'\\ge ') .replace(/<=/g,'\\le ') .replace(/([^\\a-zA-Z])frac(?:tion)?([^a-zA-Z])/g,'$1\\frac $2') .replace(/([^\\a-zA-Z])sum(?:mation)?/g,'$1\\sum ') .replace(/([^\\a-zA-Z])lim(?:it)?/g,'$1\\lim ') .replace(/\s(to|arrow)/g,'\\to ') .replace(/([^\\a-zA-Z])int(?:egral)?([^a-zA-Z])/g,'$1\\int$2') .replace(/([^\\a-zA-Z])[pP][iI]([^a-zA-Z])/g,'$1\\pi $2') .replace(/([^\\a-zA-Z])E([^a-zA-Z])/g,'$1e $2') .replace(/([^\\a-zA-Z])([aA]lpha|[bB]eta|[gG]amma|[dD]elta|[eE]ta|[eE]psilon|[rR]ho|[tT]au|[tT]heta|[zZ]eta|[rR]ho|[oO]mega)([^a-zA-Z])/g,'$1\\$2$3') str=styling_html(str,/\\?(?:sqrt?|root)\s*\(/,'\\sqrt{', '}'); str=styling_html(str,/\\?(?:sqrt?|root)\s*\[/,'\\sqrt{', '}'); str=styling_html(str,/\\frac\s*\(/,'\\frac{', '}{','}'); str=styling_html(str,/\\frac\s*\[/,'\\frac{', '}{','}'); str = styling_html(str,/\^\s*sin\s*\(/,'^{sin(',')}'); str = styling_html(str,/\^\s*cos\s*\(/,'^{cos(',')}'); str = styling_html(str,/\^\s*(root|sqrt)\s*\(/,'^{sqrt(',')}'); str = styling_html(str,/\^\s*ln\s*\(/,'^{ln(',')}'); str= str.replace(/([\^\_])(\-?([a-zA-Z\\]+))/g,'$1{$2}') .replace(/([\^\_])(\-?(\d+(\.\d+)?|\d*\.\d+))/g,'$1{$2}'); str = str.replace(/_(\S+)\^/g, '_ $1 ^'); str = str.replace(/(\^|_)/g, function (temp, p1, offset, s) { return ( (p1=='^') ? '_' : '^' ); } ); str= add_braces_after(str); str = str.replace(/(\^|_)/g, function (temp, p1, offset, s) { return ( (p1=='^') ? '_' : '^' ); } ); str= add_braces_after(str); str = str .replace(/([^\\a-zA-Z])sqrt?([^a-zA-Z])/g,'$1\\sqrt $2') .replace(/([^\\a-zA-Z])cube\s+root([^a-zA-Z])/g,'$1\\sqrt[3] $2') .replace(/([^\\a-zA-Z])root([^a-zA-Z])/g,'$1\\sqrt $2') .replace(/([^\\a-zA-Z])[sS]in(e)?([x|y|t|\d]?)/g,'$1\\sin $3') .replace(/([^\\a-zA-Z])[sS]ec(ant)?([x|y|t|\d]?)/g,'$1\\sec $3') .replace(/([^\\a-zA-Z])[cC]sc(ant)?([x|y|t|\d]?)/g,'$1\\csc $3') .replace(/([^\\a-zA-Z])[cC]os(ine)?([x|y|t|\d]?)/g,'$1\\cos $3') .replace(/([^\\a-zA-Z])[tT]an(gent)?([x|y|t|\d]?)/g,'$1\\tan $3') .replace(/([^\\a-zA-Z])[cC]ot(angent)?([x|y|t|\d]?)/g,'$1\\cot $3') .replace(/( and | or | ?if )/g,'\\text{$1}') //.replace(/\[([^\[\]]+)\]\s*\/\s*\[([^\[\]]+)\]/g,'\\frac{$1}{$2}') //.replace(/\((.+)\)\s*\/\s*\((.+)\)/g,'\\frac{$1}{$2}') .replace(/([^\\])[lL]n([x|y|t|\d]?)/g,'$1\\ln $2') .replace(/([^\\])[lL]og([x|y|t|\d]?)/g,'$1\\log $2'); str= slash_to_frac(str); str=power_to_carrot(str); str= str.replace(/\*([^}])/g,' \\cdot $1') ; str = str.replace(/([\(\[])/g,'\\left $1') .replace(/(\)|\])/g,'\\right $1') str =str .replace(/([/\-\+\(\)\[\]\{\}])\s+([\\\/\-\+\(\)\[\]\{\}])/g,'$1$2') .replace(/([\da-z])\s+([\/\-\+\(\)\[\]\{\}])/g,'$1$2') .replace(/<(\S)/g,' < $1'); ; var l= "\\begin{pspicture*}(-10,-10)(10,10)\n\\pscurve[linecolor=red,showpoints=false]"; var r= "\n\\end{pspicture*}"; str=str.replace(/\\path\s*{([^}]+)}/g, function (s,p1,offset,s){ p1 = p1.replace(/;/,'\n\\pscurve[linecolor=blue,showpoints=false]'); p1 = p1.replace(/;/,'\n\\pscurve[linecolor=green,showpoints=false]'); p1 = p1.replace(/;/g,'\n\\pscurve[linecolor=black,showpoints=false]'); return '\\path{'+ p1 + '}' ; } ); str=styling_html(str,/\\(ps)?(path|curve)\s*{/,l, r ); var l= "\\begin{pspicture*}(-10,-10)(10,10)\n\\pspolygon[linecolor=red]"; var r= "\n\\end{pspicture*}"; str=str.replace(/\\polygon\s*{([^}]+)}/g, function (s,p1,offset,s){ p1 = p1.replace(/;/,'\n\\pspolygon[linecolor=blue]'); p1 = p1.replace(/;/,'\n\\pscurve[linecolor=green]'); p1 = p1.replace(/;/g,'\n\\pscurve[linecolor=black]'); return '\\path{'+ p1 + '}' ; } ); str=styling_html(str,/\\(ps)?polygon\s*{/, l , r ); return ( format_latex (naive_complete_braces (str)) ); } function orphaned_html_tags(str) { while (str != (str = str.replace(/<([a-zA-Z]+)\b[^>]* \/>/g, ""))); while (str != (str = str.replace(/<([a-zA-Z]+)[^>]*>((?:(?!<\/?\1\b[^>]*>)[\S\s])*)<\/\1>/g, "$2"))); return str.match(/<\/?\w+[^>]*>/g); } function remove_nested_tags(str, tag) { var opentag='<'+ tag +'[^>]*>'; var closetag='<\\/'+tag+'>'; var reg = RegExp ('('+opentag+'|'+closetag+')',"g"); var arr = str.split(reg); var trace = new Array(); var counter =0; for (var j=1;j < arr.length-1;j=j+2) { if (arr[j].match(opentag)) {counter=counter+1;} if (arr[j].match(closetag)) {counter=counter-1;} trace[j]=counter; } var result = (arr.length == 1) ? arr[0] : arr[0]+arr[1]; for (var j=2; j])\s*/g,'$1') .replace(/\s*(\\leq|\\ge)/g,'$1') .replace(/({|\[|\()\s+/g,'$1') .replace(/\s+(}|\]|\))/g,'$1') .replace(/(frac)\s+/g,'$1') .replace(/(\d) +([a-zA-Z][^a-zA-Z])/g,'$1$2') .replace(/([\.\;\,])([\+\^\_\*\-\/=])/g,'$1 $2') .replace(/(\S)AkorzenA/g,'$1 AkorzenA'); str =str.replace(/(sin|cos|tan|cot|ln|log|root|sqrt|\w[\)\]])\s*([\(\{\[]) */g,'$1$2') // .replace(/ *([\)\}\]])/g,'$1'); .replace(/(\s)([A-Z])(\s)/g,'$1AkorzenA$2ZkorzenZ$3') .replace(/(\s)([mM]u|[pP]hi|[eE]ta|[xyztuv])([\s,\.])/g,'$1AkorzenA$2ZkorzenZ$3') .replace(/(\s)([aA]lpha|[bB]eta|[gG]amma|[dD]elta|[tT]au|[tT]heta|[zZ]eta|[rR]ho|[oO]mega)/g,'$1AkorzenA$2ZkorzenZ') str= str .replace(/((?:\S+[\+\^\_\*\-\/=<>]\S+)|(?:^[\+\^\_\*\-\/=<>]\S+)|(?:\S+[\+\^\_\*\-\/=<>]$))/g, function (temp_str, p1, offset, s) { return ( ( (p1.indexOf('>') != -1 ) && (p1.indexOf('<') != -1 ) && (p1.indexOf('<>') == -1 ) || (p1.indexOf('\/>') != -1 ) || (p1.indexOf('<\/') != -1 ) || (p1.indexOf('http:\/\/') != -1 ) || (p1.match(/\.(com|edu|org|pl|de|fr|uk|au|kr|ru|biz|info)/)) ) ? p1 : 'AkorzenA' + p1 + 'ZkorzenZ' ); } ) .replace(/(\\?[\(\[\{])\s*AkorzenA/,'AkorzenA$1') .replace(/ZkorzenZ\s*(\\?[\)\]\}])/,'$1ZkorzenZ') .replace(/([\[\({]\S* *, *\S*[\]\)}])/g, 'AkorzenA$1ZkorzenZ') .replace(/(\s+)(\S*\[[xytuv]\]\S*)(\s+)/g,'$1AkorzenA$2ZkorzenZ$3') .replace(/(\s+)(\S*\([xytuv]\)\S*)(\s+)/g,'$1AkorzenA$2ZkorzenZ$3') .replace(/(\\?)(f\(\w+\)|[^a-z]pi|Pi| e| E| x\s?|root|lim|Lim|[^a-z]int|Int|[^a-z]ln|Ln|log|Log|[^a-z]sin|Sin|[^a-z]cos|Cos|sec|Sec|csc|Csc|[^a-z]tan|Tan|cot|Cot|plot *[\(\[]|graph *[\(\[])\s*AkorzenA/g,'AkorzenA$1$2 '); function swap_korzen_and_bracket(str,char) { for (var j=0; j < str.length; j=j+1) { if (str.charAt(j) == char) { var t=bracket_substring(str,j,char); if ( (typeof t[0]=='string') && (t[0].indexOf('ZkorzenZ') != -1) ) { t[0]=t[0].replace(/ZkorzenZ/,''); str = str.substring(0,t[1])+t[0]+str.substring(t[2])+'ZkorzenZ'; } } } return (str); } str=swap_korzen_and_bracket(str,'('); str=swap_korzen_and_bracket(str,'['); str=swap_korzen_and_bracket(str,'{'); str = str .replace(/ZkorzenZ *([\\\{\}\+\^\_\*\-\/=]+|kreskaDash) *AkorzenA/g,'$1') .replace(/kreskaDash/g,'-') .replace(/ZkorzenZ([\.\;\,}])/g,'$1ZkorzenZ') return (str); } /* looks for likely math formulas and returns str with dollars around math formulas or \begin{displaymath} and \end{displaymath} withing new math delimiters, the function adds \source{ } should act on strings that are not latex yet guess_what_is_math is @ Arek Goetz and cannot be used elsewhere */ function guess_what_is_math (str, add_source) { if (typeof add_source == 'undefined') add_source = true; str = p1_guess_what_is_math(str); str=styling_html(str, /lim\s*\(/, 'AkorzenAlim(', ')ZkorzenZ'); str=styling_html(str, /lim\s*\[/, 'AkorzenAlim[', ']ZkorzenZ'); str= str .replace(/AkorzenA((?:\n|.)*?)ZkorzenZ/g, function (temp_str, p1, offset, s) { return 'AkorzenA' + p1.replace(/\$/g,'') + 'ZkorzenZ'; } ) .replace(/kreskaDash/g,'-') //.replace(/([\.\;\,])ZkorzenZ/g,'ZkorzenZ$1') .replace(/([\s\)\]}])([\-\.]?(\d+(\w+)?(\.?\d+)?)|d[xyzutv]|([a-zA-Z]{1,4}[\(\[\{][xytuvabcdhz]{1,2}[\)\]\}]))\s/g, function (temp_str, p1,p2, offset, s) { return p1+ ' AkorzenA' + p2 + 'ZkorzenZ '; } ) .replace(/AkorzenA(http:\/\/\S+)ZkorzenZ/g, '$1') .replace(/\n{2,} *AkorzenA(.+)ZkorzenZ/g, function (s,p1,r,t) { return ( '\n\\begin{displaymath}\n' + p1.replace(/AkorzenA|ZkorzenZ/g,'') + '\n\\end{displaymath}' ) } ); str=str.replace(/AkorzenA/g,'').replace(/ZkorzenZ/g,''); str = remove_nested_tags(str, 'korzen'); str = str .replace(/|<\/korzen>/g, '$') // .replace(/\n\\end{displaymath} *\$([^\$]+)\$/g,'$1 \n\\end{displaymath}') str = str .replace(/\$\$/g,'') .replace(/\$ +\$/g,' ') .replace(/kreskaDash/g,'-').replace(/\$\s+\$/g,' '); str = str .replace(/\\begin{displaymath}\s*\n\s*((.|\n)+?)\n\\end{displaymath}/g, function (ss, p1, offset, s) { p1 = naive_complete_braces( p1 ); return '\\begin{displaymath}' + ( (add_source) ? '\n\\source{'+ p1 + '} \n' : '') + odgadnij(p1) + '\n\\end{displaymath}'; } ); str = str.replace(/\$((.|\n)+?)\$/g, function (ss, p1, offset, s) { p1 = naive_complete_braces( p1 ); return '' + ((add_source) ? '\\source{'+ p1 + '} ' : '') + odgadnij(p1) + ''; } ); str=str.replace(/|<\/korzen>/g, '$') return (str); } function nonmath (str) { // str = styling_html(str,/\\nonmath\s*{/,'\\begin{nonmath}','\\end{nonmath}'); arr = [''].concat(str.split(/\\begin\s*{nonmath}((?:\n|.)+?)\\end\s*{nonmath}/)); return (arr); } function split_math (str, guessing, add_source) { // if ((str == '') || (typeof str =='undefined')) return (['','']); if (typeof add_source == 'undefined') add_source = true; if (typeof guessing == 'undefined') guessing = true; str = ' ' + str; str = str.replace(/([^\\](\\\\)*)\\\$/g,'$1\\dollar'); var reg = '(?:\\\\begin\\s*{displaymath}(?:\\n|.)+?\\\\end\\s*{displaymath})'; reg = reg + '|' + '(?:\\$\\$(?:\\n|.)+?\\$\\$)'; reg = reg + '|' + '(?:\\\\\\[(?:\\n|.)+?\\\\\\])'; reg = reg + '|' + '(?:\\\\begin\\s*{equation}(?:\\n|.)+?\\\\end\\s*{equation})'; reg = reg + '|' + '(?:\\\\begin\\s*{equation\\*}(?:\\n|.)+?\\\\end\s*{equation\\*})'; reg = reg + '|' + '(?:\\\\begin\\s*{align}(?:\\n|.)+?\\\\end\\s*{align})'; reg = reg + '|' + '(?:\\\\begin\\s*{align\\*}(?:\\n|.)+?\\\\end\\s*{align\\*})'; reg = reg + '|' + '(?:\\\\begin\\s*{eqnarray}(?:\\n|.)+?\\\\end\\s*{eqnarray})'; reg = reg + '|' + '(?:\\\\begin\\s*{eqnarray\\*}(?:\\n|.)+?\\\\end\\s*{eqnarray\\*})'; reg = reg + '|' + '(?:\\\\begin\\s*{pspicture}(?:\\n|.)+?\\\\end\\s*{pspicture})'; reg = reg + '|' + '(?:\\\\begin\\s*{pspicture\\*}(?:\\n|.)+?\\\\end\\s*{pspicture\\*})'; reg = reg + '|' + '(?:\\$(?:\\n|.)+?\\$)'; reg ='(' + reg + ')'; reg = new RegExp (reg); var arr = str.split(reg); arr[0]=arr[0].substring(1,arr[0].length); if (guessing) { for (var i=0; i0) && str.charAt(i-1).match(/[^\+\-\*\/\%\^]/) )) && ( (bracket_substring(str,i,'(')[1] == -1) || (bracket_substring(str,i,'(')[2] == -1) ) && ( (bracket_substring(str,i,'[')[1] == -1) || (bracket_substring(str,i,'[')[2] == -1) ) && ( (bracket_substring(str,i,'{')[1] == -1) || (bracket_substring(str,i,'{')[2] == -1) ) ) { arr[arr.length]=str.substring(l,i).replace(/^\s+/,'').replace(/\s+$/,''); arr[arr.length]=c; l=i+1; } } arr[arr.length]=str.substring(l).replace(/^\s+/,'').replace(/\s+$/,''); return(arr); } function fun_split (str,lbr) { if (lbr=='{') rbr='}'; if (lbr=='[') rbr=']'; if (lbr=='(') rbr=')'; var tab = bracket_substring(str,str.indexOf(lbr),lbr) ; if (tab[0] ==-1) return; var fs = str.substring(0,tab[1]-1).match(/^\s*[a-zA-Z\\]+\d?\s*$/) ; if (fs == null) return; var rs = str.substring(tab[2]); rs = rs.substring(rs.indexOf(rbr)+1).match(/^\s*\w*\s*$/) ; if (rs == null) return; return ([fs+lbr,tab[0],rbr+rs]); } function slash_to_frac( str ) { if (str.indexOf('/') ==-1) return (str); var doing_coord = false; var s= new Array; s=['=' , ',' , '>' , '<', ' ']; str = str .replace(/(\W)\s*([^\w\\])/g,'$1$2') .replace(/(\w)\s*([^\w\\])/g,'$1$2') .replace(/(\W)\s*(\w)/g,'$1$2') .replace(/^\s+(.*)/,'$1').replace(/(.*)\s+$/,'$1') .replace(/(\d|\)|\]|})(\(|\[|{)/g,'$1 $2') .replace(/(\)|\]|})(\w|\(|\[|{)/g,'$1 $2'); for (var j=0; j 1 ) { str = ''; doing_coord = true; for (var i=0; i < coord.length; i=i+1) { str = str + slash_to_frac(coord[i]) +s[j]; } str = str.substring(0,str.length-1); } } if (doing_coord) { return (str);} var arr=split_mathematical_expression(str); arr.unshift(''); arr.push(''); for (var i=arr.length-1; i>0 ; i=i-1) { if (typeof fun_split(arr[i],'(') != 'undefined') { var tab=fun_split(arr[i],'('); arr[i] = tab[0]+slash_to_frac(tab[1])+tab[2]; } if (typeof fun_split(arr[i],'[') != 'undefined') { var tab=fun_split(arr[i],'['); arr[i] = tab[0]+slash_to_frac(tab[1])+tab[2]; } if (typeof fun_split(arr[i],'{') != 'undefined') { var tab=fun_split(arr[i],'{'); arr[i] = tab[0]+slash_to_frac(tab[1])+tab[2]; } var l=''; var r=''; if (arr[i]=='/') { r = arr[i+1]; l = arr[i-1]; arr[i+1]=''; arr[i-1]=''; var j=2; while ( (arr[i+j] == '^') && (i+j < arr.length-2) ) { r = r + arr[i+j] + arr[i+j+1]; arr[i+j]=''; arr[i+j+1]=''; j = j+2; } var k=2; while ( ( (arr[i-k] == '^') || (arr[i-k] == '/') ) && (i-k >0) ) { l = arr[i-k-1] + arr[i-k]+l ; arr[i-k]=''; arr[i-k-1]=''; k = k+2; } arr[i] = '\\frac{' + remove_unnecessary_brackets(l) + '}{' + remove_unnecessary_brackets(r) + '}'; } } str=arr.join(''); return (str); } function latex_to_plain_text (str) { str = str.replace(/\s+/g,' ').replace(/\\\\/g,'   ').replace(/~/g,' ') ; str = replace_function(str, '\\nonmath{#1}', ' #1 '); str = replace_function(str, '\\href{#1}{#2}', ' #2 '); str = replace_function(str, '\\img{#1}{#2}', ' [image: #2] '); str = replace_function(str, '\\toggle{#1}{#2}', ' #1 '); str = replace_function(str, '\\expand{#1}{#2}', ' #1 '); str = replace_function(str, '\\hover{#1}{#2}', ' #1 '); str = replace_function(str, '\\dismiss{#1}{#2}', ' #2 '); str = replace_function(str, '\\frac{#1}{#2}', '[#1]/[#2] '); str = replace_function(str, '\\tfrac{#1}{#2}', '[#1]/[#2] '); str = replace_function(str,'\\framebox{#1}', ' #1 '); str = replace_function(str,'\\boldsymbol{#1}', ' #1 '); str = replace_function(str,'\\textstyle{#1}', ' #1 '); str = replace_function(str,'\\displaystyle{#1}', ' #1 '); str = replace_function(str,'\\bf{#1}', ' #1 '); str = replace_function(str,'\\mathbf{#1}', ' #1 '); str = replace_function(str,'\\textbf{#1}', ' #1 '); str = replace_function(str,'\\texttt{#1}', ' #1 '); str = replace_function(str,'\\bf{#1}', ' #1 '); str = replace_function(str,'\\source{#1}', ' #1 '); str = replace_function(str,'\\emph{#1}', ' #1 '); str = styling_html(str,/\\href{/,' [','] ', ''); str = str .replace(/\\boldsymbol/g,'') .replace(/\\begin{pspicture}((.|\n)*?)\\end{pspicture}/g,'...illustration...') .replace(/\\begin{theorem}/g,' Theorem. ') .replace(/\\begin{solution}/g,' Solution. ') .replace(/[\$\n]/g,'') .replace(/\\ge(\W)/g,' greater or = $1') .replace(/\\le(\W)/g,' less or = $1') .replace(/\\item/g,' • ') .replace(/\\(\w+)/g,' $1 ') .replace(/\\[,;~]/g,' ') .replace(/(?:left|right|big)\s*([\(\[{}\]\)])/g,'$1') .replace(/infty/g,' infinity ') .replace(/lim\s*\_/g,' limit as ') .replace(/int\s*\_/g,' integral from ') .replace(/(begin|end)\s*{\s*(equation*?|align*?|displaymath|enumerate|itemize|description|theorem|lemma|solution)\*?\s*}/g,' ') .replace(/cdot/g,'*') .replace(/sqrt\s*{(\w)}/g,' root($1)') .replace(/sqrt\s*\[3\]/g,' cubic root of ') .replace(/sqrt\s*\[(\w)\]/g,' $1 th root of ') .replace(/sqrt/g,'root') .replace(/\[(d[a-z]?)\]\s*\/\s*\[(d[a-z])\]/g,'$1/$2') .replace(/\[([a-z])\]/g,'$1').replace(/\[([0-9]+)\]/g,'$1') .replace(/{/g,'(').replace(/}/g,')') .replace(/([\da-z\)\]])\s+([\\\/\-\+\)\]\}])/g,'$1$2') .replace(/([\\\/\-\+\(\[\{])\s+([\da-z\(\[])/g,'$1$2') .replace(/\.([A-Z])/g,'. $1'); str = remove_unnecessary_brackets(trim(str)); return( format_latex(str) ); } function latex_to_say(str) { var say = extracting_arguments(str,/\\say\s*{/); if (say !='') { str = say; } else { var lsource = extracting_arguments(str,/\\source\s*{/); if (lsource != '') { str = lsource ; } else { str = latex_to_plain_text(str); } } return str; } function latex_to_source(str) { var lsource = extracting_arguments(str,/\\source\s*{/); if (lsource != '') { str = lsource ; } return str; } function simplified_source (latex_str) { latex_str = format_latex(latex_str).replace(/^\$(\$[\s\S]+\$)\$$/,'$1'); var source = latex_to_source(latex_str); if (source != latex_str) return source; var reduced = trim(latex_to_plain_text(latex_str)); if ( format_latex(guess_what_is_math(reduced,false) .replace(/\s*\\(?:left|right|big)\s*\\?([\(\[{}\]\)])/g,'$1') .replace(/([\^_]){([a-z0-9])}/g,'$1$2')) == latex_str.replace(/\\tfrac/g,'\\frac') ) { return reduced; } else { return latex_str; } } function simplify_text(str) { var arr= split_to_nonmath_and_math( links_to_simplified_source (str), true); var result = ''; for (var i=0; i < arr.length; i=i+1) { if (i%2==0) { result=result + arr[i]; } else result=result + simplified_source(arr[i]); } return trim(result); } function texify_text(str, include_source) { if (typeof include_source == 'undefined') include_source = true; var arr= split_to_nonmath_and_math( str, true, include_source); var result = ''; for (var i=0; i < arr.length; i=i+1) { if (i%2==0) { result=result + arr[i]; } else result=result + format_latex(arr[i]); } return trim(result); } function encode_latex(str) { str = str.replace(/([\+\?&=\n\t%])/g, function(ss, p1, offset, s){ return encodeURIComponent(p1); } ).replace(/\s/g,'+') ; return (str); } function decode_latex(str) { try {var s = decodeURIComponent(str.replace(/\+/g,' ')); } catch(err) {return('not a valid coded latex');} return(s); } function links_to_simplified_source(str) { str = str.replace(/http:\/\/[\w\/\.]+latex[\w\/\.]*\?src=([^&]+)(&\S*)?size=\d\d?/g, function (ss, p1, offset, s) { var r= decode_latex( p1 ); var lsource = extracting_arguments(r,/\\source\s*{/); if (lsource == '') { r = r.replace(/\s*\\begin\s*{\s*displaymath\s*}\s*\\textstyle\s*{\s*([\s\S]+)\s*}\s*\\end\s*{\s*displaymath\s*}\s*/, function (ss, p1, offset, s){ return simplified_source('$'+trim(p1)+'$'); } ); r = r.replace(/\s*\\begin\s*{\s*displaymath\s*}\s*([\s\S]+)\s*\\end\s*{\s*displaymath\s*}/, function (ss, p1, offset, s) { var result = simplified_source('$'+trim(p1)+'$'); return (result.match(/^\$/)) ? '$'+result+'$' : '\n\n'+result+'\n\n'; } ); return r; } else {return lsource;} } ); return str; } function latex_to_links(string, size) { if (typeof size != 'number') size = 15 ; var done = false; string = ' ' + string; string = string.replace(/\$\$((?:\n|.)+?)\$\$/g, function (str, p1, offset, s) { return '\\begin{displaymath}' + p1 + '\\end{displaymath}' } ) string = string.replace(/\\begin\s*{displaymath}((?:\n|.)+?)\\end\s*{displaymath}/g, function (str, p1, offset, s) { done = true; return '
    '+latex2image('\\begin{displaymath}' + p1 + '\\end{displaymath}', size )+ '
    ' } ); if (done) return string; string = string.replace(/\\\[((?:\n|.)+?)\\\]/g, function (str, p1, offset, s) { done = true; return '
    '+latex2image('\\\[' + p1 + '\\\]', size )+'
    ' } ); if (done) return string; string = string.replace(/\\begin\s*{equation\}((?:\n|.)+?)\\end\s*{equation\}/g, function (str, p1, offset, s) { done = true; var p2 = p1.replace(/\\(?:label|tag)\{((?:.)+?)\}/g,'\\text{($1)~~}'); return '
    '+latex2image('\\begin{equation*}' + p2 + '\\end{equation*}', size )+'
    '; } ); if (done) return string; string = string.replace(/\\begin\s*{equation\*}((?:\n|.)+?)\\end\s*{equation\*\}/g, function (str, p1, offset, s) { done = true; return '
    '+latex2image('\\begin{equation*}' + p1 + '\\end{equation*}', size )+'
    '; } ); if (done) return string; string = string.replace(/\\begin\s*{align}((?:\n|.)+?)\\end\s*{align\}/g, function (str, p1, offset, s) { done = true; var p2 = p1.replace(/\\label/g,'\\text'); return '
    '+latex2image('\\begin{align*}'+ p2 + '\\end{align*}', size )+ '
    '; } ); if (done) return string; string = string.replace(/\\begin\s*{align\*\}((?:\n|.)+?)\\end\s*{align\*\}/g, function (str, p1, offset, s) { done =true; return '
    '+latex2image('\\begin{align*}'+ p1 + '\\end{align*}', size )+'
    '; } ); if (done) return string; string = string. replace(/\\begin\s*{eqnarray\}((?:\n|.)+?)\\end\s*{eqnarray\}/g, function (str, p1, offset, s) { done =true; var p2 = p1.replace(/\\label/g,'\\text'); return '
    '+latex2image('\\begin{eqnarray*}'+ p2 + '\\end{eqnarray*}', size )+'
    '; } ); if (done) return string; string = string. replace(/\\begin\s*{eqnarray\*\}((?:\n|.)+?)\\end\s*{eqnarray\*\}/g, function (str, p1, offset, s) { done=true; return '
    '+latex2image('\\begin{eqnarray*}'+ p1 + '\\end{eqnarray*}', size )+'
    '; } ); if (done) return string; string = string.replace(/\\begin\s*{pspicture\}((?:\n|.)+?)\\end\s*{pspicture\}/g, function (str, p1, offset, s) { done = true; return '
    '+latex2image('\\begin{pspicture}'+ p1 + '\\end{pspicture}', size )+'
    '; } ). replace(/\\begin\s*{pspicture\*\}((?:\n|.)+?)\\end\s*{pspicture\*\}/g, function (str, p1, offset, s) { done=true; return latex2image('\\begin{pspicture*}'+ p1 + '\\end{pspicture*}', size ); } ); if (done) return string; string = string.replace(/\$((?:\n|.)+?)\$/g, function (str, p1, offset, s) { var tem = (p1.indexOf('\\displaystyle') != -1 ) ? p1 : '\\textstyle{' + p1 + '}'; return latex2image('\\begin{displaymath} ' + tem + ' \\end{displaymath}', size) ; } ); return (trim(string)); } function colorize(str) { str = str.replace(/(\,|:)/g,'$1'); str = str.replace(/(;)/g,'$1'); str = str.replace(/(\.)/g,'$1'); sl=''; sr=''; str = styling_html(str,/root\s*\(/,sl+"root("+sr,sl+")"+sr); str = styling_html(str,/root\s*\[/,sl+"root["+sr,sl+"]"+sr); str = styling_html(str,/sqrt?\s*\(/,sl+"sqrt("+sr,sl+")"+sr); str = styling_html(str,/sqrt?\s*\[/,sl+"sqrt["+sr,sl+"]"+sr); str = styling_html(str,/sqrt?\s*{/,sl+"sqrt{"+sr,sl+"}"+sr); sl=''; sr=''; str = styling_html(str,/sin\s*\(/,sl+"sin("+sr,sl+")"+sr); str = styling_html(str,/cos\s*\(/,sl+"cos("+sr,sl+")"+sr); str = styling_html(str,/tan\s*\(/,sl+"tan("+sr,sl+")"+sr); str = styling_html(str,/cot\s*\(/,sl+"cot("+sr,sl+")"+sr); str = styling_html(str,/sec\s*\(/,sl+"sec("+sr,sl+")"+sr); str = styling_html(str,/csc\s*\(/,sl+"csc("+sr,sl+")"+sr); sl=''; sr=''; str = styling_html(str,/sin\s*\[/,sl+"sin["+sr,sl+"]"+sr); str = styling_html(str,/cos\s*\[/,sl+"cos["+sr,sl+"]"+sr); str = styling_html(str,/tan\s*\[/,sl+"tan["+sr,sl+"]"+sr); str = styling_html(str,/cot\s*\[/,sl+"cot["+sr,sl+"]"+sr); str = styling_html(str,/sec\s*\[/,sl+"sec["+sr,sl+"]"+sr); str = styling_html(str,/csc\s*\[/,sl+"csc["+sr,sl+"]"+sr); sl=''; sr=''; str = styling_html(str,/ln\s*\(/,sl+"ln("+sr,sl+")"+sr); str = styling_html(str,/log\s*\(/,sl+"log("+sr,sl+")"+sr); str = styling_html(str,/exp\s*\(/,sl+"exp("+sr,sl+")"+sr); sl=''; sr=''; str = styling_html(str,/ln\s*\[/,sl+"ln["+sr,sl+"]"+sr); str = styling_html(str,/log\s*\[/,sl+"log["+sr,sl+"]"+sr); str = styling_html(str,/exp\s*\[/,sl+"exp["+sr,sl+"]"+sr); sl=''; sr=''; str = styling_html(str,/\\frac\s*{/,sl+"\\frac{"+sr,sl+"}{"+sr,sl+"}"+sr); sl=''; sr=''; str = styling_html(str,/\(/,sl+"("+sr,sl+")"+sr); str = styling_html(str,/\[/,sl+"["+sr,sl+"]"+sr); str = styling_html(str,/{/,sl+"{"+sr,sl+"}"+sr); str = str.replace(/(\$)/g,'$1'); return (str); } function mango(str, size, loose) { if (typeof size != 'number') size=15; if (typeof loose =='undefined') loose = true; var arr= split_to_nonmath_and_math( links_to_simplified_source (str), loose ); var result = ''; for (var i=0; i < arr.length; i=i+1) { arr[i]=arr[i].replace(/\\dollar/g,'\\$'); if (i%2==0) { arr[i]=nonmath_latex_layout_to_html(arr[i], size); result=result + arr[i]; } else result=result + ''+latex_to_links(arr[i], size)+''; } result=latex_layout_to_html(result,size, str); return result; } function nformat_latex(str) { str=str.replace(/([^\n] *)(\\page\s*{[^}]*})/g,'$1\n$2'); str=str.replace(/(\\page\s*{[^}]*})( *[^\n])/g,'$1\n$2'); str=str.replace(/([^\n] *)(\\(?:begin|end)\s*{(?:displaymath|pspicture\*?|align\*?|theorem|lemma|proposition|solution|itemize|description|enumerate|pages|tabs)}|\\page\s*{[^}]*})/g,'$1\n$2'); str=str.replace(/(\\(?:begin|end)\s*{(?:displaymath|pspicture\*?|align\*?|theorem|lemma|proposition|solution|itemize|description|enumerate|pages|tabs)}|\\page\s*{[^}]*})( *[^\n])/g,'$1\n$2'); return str; } function format_latex( str ) { if (str.match(/pspicture/)) return str; str = trim( str.replace(/([\)\]}\w])\s*\\/g,'$1 \\') ) //.replace (/}([a-zA-Z\d])/g,'} $1') .replace(/([a-zA-Z\d])\s*\\/g,'$1 \\') .replace(/([^\s\-])([=<>])/g,'$1 $2').replace(/([=<>])(\S)/g,'$1 $2') .replace(/\s+([\^\_\/\*\-\+%])/g,'$1') .replace(/([\^\_\/\*\-\+%])\s+/g,'$1') .replace(/^\-\s(\w)/g,'-$1').replace(/([=<>\-\+%])\s\-\s(\w)/g,'$1 -$2') .replace(/\-\s*>\s*/g,'->') .replace(/([\(\[])\s([^\(\[])/g,'$1$2').replace(/([^\)\]])\s([\)\]])/g,'$1$2') .replace(/{ \\(^\\)/g,'{\\$1').replace(/(\W\w)\s*([\(\[])/g,'$1$2') //.replace(/(\-\+ \d+) ([a-z])/,'$1$2') .replace(/ *\$ */,'$') ; return (str); } function carrot_to_power( str ) { while ( ( str.indexOf('^') != -1 ) && (str != '^') ) { var coord = split_to_coordinates(str); if ( coord.length > 1 ) { str = ''; for (var i=0; i < coord.length; i=i+1) { str = str + carrot_to_power(coord[i]) +','; } str = str.substring(0,str.length-1); } if ( split_mathematical_expression(str).length == 1) { if ( str.match(/^([^\(]*\()((?:.|\n)*)(\)[^\)]*)$/) ) { str =str.replace(/^([^\(]*\()((?:.|\n)*)(\)[^\)]*)$/, function (s1,p1,p2,p3,offset,s) { return p1+carrot_to_power(p2)+p3; } ); } if (str.match(/^([^\[]*\[)((?:.|\n)*)(\][^\]]*)$/) ) { str =str.replace(/^([^\[]*\[)((?:.|\n)*)(\][^\]]*)$/, function (s1,p1,p2,p3,offset,s) { return p1+carrot_to_power(p2)+p3; } ); } if (str.match(/^([^\[]*\{)((?:.|\n)*)(\}[^\}]*)$/) ) { str =str.replace(/^([^\{]*\{)((?:.|\n)*)(\}[^\}]*)$/, function (s1,p1,p2,p3,offset,s) { return p1+carrot_to_power(p2)+p3; } ); } } var arr=split_mathematical_expression(str); str = ''; for (var i=0;i 0; i=i-1) { if (arr[i]=='^') { arr[i-1] = 'Math.pow('+remove_unnecessary_brackets(arr[i-1])+','+remove_unnecessary_brackets(arr[i+1])+')'; arr[i] = ''; arr[i+1] =''; } else if ( arr[i].indexOf('^') != -1) { arr[i]=carrot_to_power(arr[i]); } } str=arr.join(''); } return (str); } function power_to_carrot(str) { var reg_latex =new RegExp("pow(?:er)?\\s*\\("); var br = reg_latex.source; br = br.charAt(br.length-1); var caught = str.match(reg_latex); if (caught == null) return(str) ; var p= str.indexOf(caught[0]); var left = str.substring(0,p); var r = str.substring(p+caught[0].length); var result = left; var tab =bracket_substring(br+r, 0, br ); if ( (tab[0] == -1) || (tab[1] == -1) || (tab[2] == -1) ) { return(str); } var str1 = tab[0]; var t = split_to_coordinates(str1,','); if (t.length == 2) { if ( t[0].replace(/[\w\.\s]/g,'') != '' ) { t[0] = '('+t[0]+')'; } str1='{'+t[0]+'}^{'+t[1]+'}'; } var rstr = r.substring( tab[2] , r.length ).toString(); if (tab[0] != -1) { result = result + str1 + rstr; } else { result = result + r; } result = left + power_to_carrot(result.substr(left.length) ); return result; } function add_braces_after(str) { if (str.match(/\^\s*[^{}\)\]\s]/)) { var s= new Array; s=['=',',','>','<',' ','\n']; for (var j=0; j 1 ) { str = ''; for (var i=0; i < coord.length; i=i+1) { str = str + add_braces_after(coord[i]) +s[j]; } str = str.substring(0,str.length-1); } } if ( split_mathematical_expression(str).length == 1) { if ( str.match(/^([^\(]*\()((?:.|\n)*)(\)[^\)]*)$/) ) { str =str.replace(/^([^\(]*\()((?:.|\n)*)(\)[^\)]*)$/, function (s1,p1,p2,p3,offset,s) { return p1+add_braces_after(p2)+p3; } ); } if (str.match(/^([^\[]*\[)((?:.|\n)*)(\][^\]]*)$/) ) { str =str.replace(/^([^\[]*\[)((?:.|\n)*)(\][^\]]*)$/, function (s1,p1,p2,p3,offset,s) { return p1+add_braces_after(p2)+p3; } ); } if (str.match(/^([^\[]*\{)((?:.|\n)*)(\}[^\}]*)$/) ) { str =str.replace(/^([^\{]*\{)((?:.|\n)*)(\}[^\}]*)$/, function (s1,p1,p2,p3,offset,s) { return p1+add_braces_after(p2)+p3; } ); } } var arr = split_mathematical_expression(str); for (var i=0;i (a-b)*c^d or // [(a-b)*c^d] -> (a-b)*c^d var b=bracket_substring(str,0,'['); var p=bracket_substring(str,0,'('); if ( (str.length-b[1]-b[2] ==0) || (str.length-p[1]-p[2] ==0) ) { var t = str.substring(1,str.length-1); if (split_to_coordinates( t ).length == 1 ) str = t; } return (str); } function calculate(str, equal) { var original_string = str; if (original_string.match(/;|\\&/)) { return original_string; } //'x^2 when x=5', or 'x^6,x=2' str = str.replace(/\s*when/g,','); var coord = split_to_coordinates(str, ','); str = coord[0]; if (typeof equal == 'undefined') { equal = true; } var e_string = "Math.E"; var pi_string ="Math.PI"; var str = guess_mathematical_expression(str).toLowerCase().replace(/math\./g,''); if (str =='e') str=e_string; str= str.replace(/([\d\s\-\+\*\^\/\%])e$/g,'$1' + e_string) .replace(/^e([\d\s\-\+\*\^\/\%])/g, e_string + '$1') .replace(/([\d\s\-\+\*\^\/\(\)\%])e([\d\s\-\+\*\^\/\(\)\%])/g,'$1' + e_string + '$2') if (str =='pi') str=pi_string; str= str.replace(/([\d\s\-\+\*\^\/\%])pi$/g,'$1' + pi_string) .replace(/^pi([\d\s\-\+\*\^\/\%])?/g, pi_string + '$1') .replace(/([\d\s\-\+\*\^\/\(\)\%])pi([\d\s\-\+\*\^\/\(\)\%])/g,'$1' + pi_string + '$2') function cot(x) { return 1/Math.tan(x); } str=str .replace(/a(rc)?cos/g,'Math.acos') .replace(/a(rc)?sin/g,'Math.asin') .replace(/a(rc)?tan/g,'Math.atan') //.replace(/cot/g,'1/Math.tan') .replace(/\bsin/g,'Math.sin') .replace(/\bcos/g,'Math.cos') .replace(/\btan/g,'Math.tan') .replace(/sec/g,'Math.sec') .replace(/csc/g,'Math.csc') .replace(/exp/g,'Math.exp') .replace(/power/g,'Math.pow') .replace(/floor/g,'Math.floor') .replace(/abs/g,'Math.abs') .replace(/(ln|log)/g,'Math.log') .replace(/sqrt?/g,'Math.sqrt'); var str = carrot_to_power(str); str = str.replace(/\s/g,''); var tem = ''; try { for (var i=1;i= 100000000000000 ) ) { return original_string; } var equal_symbol = '='; if (equal) return ready_to_evaluate.replace(/Math\./g,'').toString() + equal_symbol + evaluated; return evaluated; } function format_calculated (str) { str = str . toString() .replace(/([\-\.\d]+)e\+(\d+)/, function (s,p1,p2,r,t) { if (parseFloat(p2)>14 ) return str; else return (p1+ '*10^'+ p2); } ) .replace(/([\-\.\d]+)e\-(\d+)/, function (s,p1,p2,r,t) { if (parseFloat(p2)>14 ) return "0"; else return (p1+ '*10^(-'+ p2+')'); } ) .replace(/(\d+)?\.(\d+)/g, function (s,p1,p2,t,v) { var z=(p1=='') ? 1 : 0; return p1+'.'+p2.substr(0,7-p1.length-z) } ); return (format_latex(str) ); } function graphable_dots (str,x_min,x_max,y_min,y_max,variable,steps) { //(x_max-x_min)/steps should be the minimum distance between two dots if (typeof variable == 'undefined') variable = 'x'; if (typeof x_min == 'undefined') x_min=-3; if (typeof x_max == 'undefined') x_max=3; if (typeof y_min == 'undefined') y_min=-3; if (typeof y_max == 'undefined') y_max=3; if (typeof steps == 'undefined') steps=100; var ok_arguments= new Array; var ok_values= new Array; { var sample =x_min+ (x_max-x_min)*i/steps; var tem = parseFloat ( calculate(str + ' when ' + variable + '=' + sample.toString() , false)); if ( ( typeof tem == 'number') && (tem <=y_max) && (tem >= y_min) ) { ok_arguments[ok_arguments.length] = sample; ok_values[ok_values.length] = tem; } } return (ok_arguments.length == 0)? '' : [ok_arguments, ok_values]; } function dec_round(a,n) { if (typeof a != 'number') return (NaN); if (typeof n =='undefined') n = 3; var p = (a==0) ? 0 : n - Math.round(Math.log(Math.abs(a))/Math.LN10 ); if ( Math.abs(a) > Math.pow(10,n)) return (Math.round(a)); return ( Math.round( Math.pow(10,p)* a)/Math.pow(10,p) ); } function xydots(x,y,x_min,x_max,y_min,y_max,size,scale,color,opacity,symbol,aspect_ratio,title) { if (typeof x == 'number') {x=[x];y=[y];} if (typeof x_min == 'undefined') x_min=-3; if (typeof x_max == 'undefined') x_max=3; if (typeof y_min == 'undefined') y_min=-3; if (typeof y_max == 'undefined') y_max=3; if (typeof scale == 'undefined') scale = 48; if (typeof color == 'undefined') color='#FF0000'; if (typeof aspect_ratio == 'undefined') aspect_ratio = 1; if (typeof opacity == 'undefined') opacity = .86; if (x.length >= 200) {opacity=.9*opacity;} if (( typeof symbol == 'undefined') || (symbol=='dot') ) symbol='•'; if (symbol =='x') symbol='×' ; if (symbol =='diamond') symbol='♦' ; var symbol_size= .61 ; if (typeof size == 'undefined') size=4; if (symbol=='•') size = 6 * size; var str = ''; var count = new Array; for (i=0;i0) count[i]++; count[j] = 0; } } } } var add_coord = (typeof title == 'undefined'); for (i=0;i=x_min) && (x[i]<=x_max) && (y[i]>=y_min) && (y[i] <=y_max)) { var multiple = (count[i] > 1) ? ' × ' + count[i] : ''; if (count[i]>0) { title = (add_coord) ? '('+ dec_round (x[i]) + ',' + dec_round(y[i]) + ')' + multiple : ''; var r = Math.round(10*size*Math.sqrt(count[i]))/10; var offsetx=(symbol !='•') ? .27 * (size - (size-r)) : .17* (size - (size-r)); var offsety=(symbol !='•') ? .27 *(size + .5*(size-r)) : .34* (size + .05 *(size-r)); var tx=Math.round(10 * scale * (x[i]-x_min)-10*(offsetx-1 ) )/10; var ty=Math.round(10 * scale* (y[i]-y_min)-10*(offsety-1) )/10; str = str + '
    ' + symbol + '
    '; } } } var width = scale *(x_max-x_min); var height = scale * (y_max-y_min); if ((x_min<=0)&&(x_max>=0)) { str ='
     
    ' + str; } if ((y_min<=0)&&(y_max>=0)) { str ='
     
    ' + str; var k=6; var got_tick = false; var label_html = ''; while ( (!got_tick) && (k>=-6) ) { if ((x_minMath.pow(10,k))) { str ='
    ' +'
    ' +str; label_html = '' + Math.pow(10,k).toString() +''; got_tick = true; } else k--; } } str = '
    \n' +label_html + '' + str + '' + '
    '; return str; } function nonmatched_elements(str) { str = ' ' + str.toLowerCase(); result = ''; str = str.replace(/(\\\\)*/g,''); str = str.replace(/[^\\]\\\'/g,''); if ( str.match(/\'/) && ( str.match(/\'/g).length % 2 == 1) ) {result = result + "'"; } str = str.replace(/[^\\]\\\"/g,''); if ( str.match(/\"/) && ( str.match(/\"/g).length % 2 == 1) ) {result = result + '"'; } str = str.replace(/[^\\]\\\$/g,''); if ( str.match(/\$/) && ( str.match(/\$/g).length % 2 == 1) ) {result = result + '$'; } str = str.replace(/\\[\(\)\[\]{}]/g, ''); var counter =0; tag_array = [ '\\begin{theorem}','\\end{theorem}', '\\begin{lemma}','\\end{lemma}', '\\begin{proposition}','\\end{proposition}', '\\begin{align}','\\end{align}', '\\begin{align\\*}','\\end{align\\*}', '\\begin{displaymode}','\\end{displaymode}', '\\begin{pspicture}','\\end{pspicture}', '\\begin{pspicture\\*}','\\end{pspicture\\*}', '\\begin{itemize}','\\end{itemize}', '\\begin{description}','\\end{description}', '\\begin{enumerate}','\\end{enumerate}', '\\begin{[^{}]*}','\\end{[^{}]*}', '\\begin{','\\end{', '{','}','[',']','(',')']; for (var i=0;i 0) { counter=counter-1; result = result + tag_array[i]; } while (counter < 0 ) { counter=counter+1; result = result + tag_array[i+1]; } result =result+ '\n'; } result =result .replace(/\n+/g,'\n') .replace(/^\n+/,''); result = result.replace(/\[\^{}\]\*/g,'...'); result = result.split(/\n/); result.sort(); result = result.join(', ').replace(/^, /,''); return (result); } function today_string(time) { if (typeof now != 'undefined') time = true; var currentTime = new Date(); var hours = currentTime.getHours(); var minutes = currentTime.getMinutes(); if (minutes < 10) minutes = '0'+ minutes; var day = currentTime.getDate(); var year = currentTime.getFullYear(); var month = 'January'; if (currentTime.getMonth() == 1) month ='February' ; if (currentTime.getMonth() == 2) month ='March' ; if (currentTime.getMonth() == 3) month ='April' ; if (currentTime.getMonth() == 4) month ='May' ; if (currentTime.getMonth() == 5) month ='June' ; if (currentTime.getMonth() == 6) month ='July' ; if (currentTime.getMonth() == 7) month ='August' ; if (currentTime.getMonth() == 8) month ='September' ; if (currentTime.getMonth() == 9) month ='October' ; if (currentTime.getMonth() == 10) month ='November' ; if (currentTime.getMonth() == 11) month ='December' ; return time ? (hours + ':' + minutes + ', ' + month + ' ' + day) : ( month + " " + day + ", " + year); } function mango_box(str,with_render) { var result = ''; if (typeof with_render =='undefined') with_render = false; var s = format_calculated(calculate(str)); if (str !=s) { result =colorize(s); if (s.match(/\/|\^|sqrt|root|sin|cos|tan|cot|int|lim|ln|log/) && with_render ) { result = result + '
    ' + mango( '$'+odgadnij(s) +'$', 15)+''; } } else { result=colorize(str); } return (result); } function tui(url) { url=url.replace(/size=(\d+)/, function (ss,p1,offset,s1) { return (p1 <= 24) ? 'size='+Math.round(1.6666*p1) : 'size='+Math.round(0.6*p1); } ) return url; } function random_integer(n) { return ( Math.min(n, Math.floor ( Math.random() * (n+1) ) ) ); } function random_permutation(n) { function sortNumber(a, b){return a - b}; var arr = new Array(n); var brr = new Array(n); for (i=0;i<"+"head><"+"/head>"; html_str = html_str + ""; html_str = html_str + s; html_str = html_str + "<"+"/body>"; return (html_str); } if (editable) str = wrap(str); var doc = el.contentDocument; if (doc == undefined || doc == null) doc = el.contentWindow.document; doc.open(); doc.write(str); doc.close(); } function getWindowHeight() { var windowHeight=0; if (typeof(window.innerHeight)=='number') { windowHeight=window.innerHeight; } else { if (document.documentElement&& document.documentElement.clientHeight) { windowHeight= document.documentElement.clientHeight; } else { if (document.body&&document.body.clientHeight) { windowHeight=document.body.clientHeight ; } } } return windowHeight; } function getWindowWidth() { var windowWidth=0; if (typeof(window.innerWidth)=='number') { windowWidth=window.innerWidth; } else { if (document.documentElement&& document.documentElement.clientWidth) { windowWidth= document.documentElement.clientWidth; } else { if (document.body&&document.body.clientWidth) { windowWidth=document.body.clientWidth ; } } } return windowWidth; } function getScroll() { var scrOfX = 0, scrOfY = 0; if( typeof( window.pageYOffset ) == 'number' ) { scrOfY = window.pageYOffset; scrOfX = window.pageXOffset; } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft; } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft; } return scrOfY; } function isIE() { return (navigator.appName == 'Microsoft Internet Explorer') ? 1 : 0; } function isSafari() { return ( navigator.vendor.indexOf("Apple") != -1 ) ? 1 : 0; } function pixels_to_bottom(elemID) { var offsetTrail = document.getElementById(elemID); var offsetLeft = 0; var offsetTop = 0; while (offsetTrail) { offsetLeft += offsetTrail.offsetLeft; offsetTop += offsetTrail.offsetTop; offsetTrail = offsetTrail.offsetParent; } if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") { offsetLeft += document.body.leftMargin; offsetTop += document.body.topMargin; } return getWindowHeight() - offsetTop - 1 - 4 * isIE(); } function pixels_to_right_margin(elemID) { var offsetTrail = document.getElementById(elemID); var offsetLeft = 0; var offsetTop = 0; while (offsetTrail) { offsetLeft += offsetTrail.offsetLeft; offsetTop += offsetTrail.offsetTop; offsetTrail = offsetTrail.offsetParent; } if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined") { offsetLeft += document.body.leftMargin; offsetTop += document.body.topMargin; } return getWindowWidth() - offsetLeft - 1; } url = document.location.href; xend = url.substring(7,url.length).indexOf("/")+7 ; var base_url = url.substring(0, xend); var ajax_get_error = false; function ajax_do (url) { if (url.substring(0, 4) != 'http') { url = base_url + url; } var jsel = document.createElement('SCRIPT'); jsel.type = 'text/javascript'; jsel.src = url; document.body.appendChild (jsel); return true; } function ajax_get (url, el) { if (typeof(el) == 'string') { el = document.getElementById(el); } if (el == null) { return false; } if (url.substring(0, 4) != 'http') { url = base_url +"/"+ url; } getfile_url = 'http://' + 'calculus.sfsu.edu' + '/javascript/getfile.php?el=' + encodeURIComponent(el.id) + '&random=' + Math.floor(Math.random()*100000000000) + '&url=' + encodeURIComponent(url ) ; ajax_do (getfile_url); return true; } function remove_element(id){ if (!document.getElementById) return; element = document.getElementById(id); parent = element.parentNode; parent.removeChild(element); } function toggle_element(el) { if (!document.getElementById) return; if (typeof el == 'string') { el = document.getElementById(el); } if (el.style.display=="none") el.style.display= "block"; else { el.style.display = 'none' ; } return (true) } function block_element(id) { if (!document.getElementById) return; var el = document.getElementById(id); return (el.style.display == "block"); } function delayed_inline_toggle(el, timing, timing1, inline) { if (typeof el == 'string') { el = document.getElementById(el); } function make_visible () { el.style.visibility = 'visible'; } function make_display_inline() { if ( (typeof inline == 'undefined') || (inline == null) ) inline = 'inline'; el.style.display = inline; } function make_display_none() { el.style.display = 'none'; el.style.visibility = 'visible'; } if ( (typeof timing == 'undefined') || (timing == null) ) timing = 900; if ( (typeof timing1 == 'undefined') || (timing1 == null) ) timing1 = 0; if (el.style.display == 'none') { el.style.visibility = 'hidden'; setTimeout(make_display_inline,timing1); setTimeout(make_visible, timing); } else { fade_element(el); setTimeout(make_display_none,timing+700); } } function color_red_green ( fraction ) { fraction = fraction.toString(); var r = Math.floor( 110 *(1- fraction)) + 145; var g = Math.floor( 110 * fraction) + 145; return ( '#' + r.toString(16) + g.toString(16) + '00' ).toUpperCase(); } function dark_color_red_green ( fraction ) { fraction = fraction.toString(); var r = Math.floor( 110 *(1- fraction)) + 86; var g = Math.floor( 110 * fraction) + 86; return ( '#' + r.toString(16) + g.toString(16) + '00' ).toUpperCase(); } //} //} //} url = document.location.href; xend = url.substring(7,url.length).indexOf("/")+7; var base_url = url.substring(0, xend); base_url = "http://" + "calculus.sfsu.edu"; function wrap_post_pdf (p1) { var result = ''; result = result + ' '; result = result + ''; result = result + 'Beta'; result = result + ''; return (result); } function latex2image(str, size, image_type) { if (typeof image_type != 'string') { var image_type = 'png'; } if (typeof size != 'number') { var size = 15; } var result; var string = str; if (image_type =='pdf') { string=string.replace(/]*href\s*=\s*['"]?([^'"\s>]+)['"]?[^>]*>((?:\n|.)+?)<\/a>/g,'\\href{$1}{$2}' ); string=string.replace(/]*src\s*=\s*['"]?([^'"\s>]+)['"]?[^>]*>((?:\n|.)*?)(<\/embed>)?/g,'\\href{$1}{embedded multimedia: $1}' ); string=string.replace(/]*src\s*=\s*['"]?([^'"\s>]+)['"]?[^>]*>((?:\n|.)*?)(<\/embed>)?/g,'\\href{$1}{embedded image: $1}' ); string = string.replace(/([^%\\])%([^%])/g,'$1\\%$2'); string=string.replace(/<(\w+)[^>]*>((\n|.)*?)<\/\1>/g,'' ); string=string.replace(/\\begin{pspicture}/g,' \\begin{center} \\begin{pspicture}') .replace(/\\end{pspicture}/g,'\\end{pspicture} \\end{center}') .replace(/\\begin{pspicture*}/g,' \\begin{center} \\begin{pspicture*}') .replace(/\\end{pspicture*}/g,'\\end{pspicture*} \\end{center}'); } else {string = (string.length > 2500) ? "string~longer~than~2500~characters" : string; } if (image_type == 'pdf') { result = wrap_post_pdf(string); } else { string = format_latex(string); var alt = encode_entities(latex_to_say(string).replace(/\s+/g,' ')); var source = simplified_source(string); var longdesc=encode_entities(source).replace(/(\n|\r\n){2,}$/g,'$1'); var title = extracting_arguments(str,/\\say\s*{/); string = encode_latex(string); var tsrc=base_url + "/latexrender?src=" + string + "&type=" + image_type + "&size=" + size; var ss=''+ alt +''; result = ss; } return result; } function render_textareas() { var els=document.getElementsByTagName("TEXTAREA"); for(var i=0;i