$eqAbbrev $affe"); $affe -= 1; } } } function tex($label, $texFormula) { //variables global $ImgCacheUrl, $eqCount, $eqArray; // put the label into the array that holds all the labels ... :) ... god, that sounds stupid // increment the label counter $label = trim($label); $eqArray[$eqCount] = $label; $eqCount++; // create image name based on md5-sum of latex expression $imgN = md5($texFormula).".png"; $texFormula = trim($texFormula); makePng($texFormula, $imgN); // write html return Keep("
\"$texFormula\" ($eqCount)
"); } function inline($texString) { // variables global $ImgCacheUrl; // create image name based on md5-sum of latex expression $imgN = md5($texString).".png"; $texString = trim($texString); makePng($texString, $imgN); // write html return Keep("\"$texString\""); } // clean work.* stuff out off latex dir function cleanUp($patternStr) { foreach(glob($patternStr) as $fn) { unlink($fn); } } // create png function makePng($tex, $imgname) { global $dvipngPath,$latexPath, $ImgCacheDir; $tex = str_replace('$','\$',$tex); # Prevent user from leaving math mode $tex = str_replace('/','\slash{}',$tex); # Prevent user from open files... $tex = preg_replace('/{([^ ]+})/','{\nothing{}$1',$tex); # Obvuscate potential filenames // template for tex file $texString = "\documentclass[a4paper,12pt]{article} \\newcommand{\\nothing}{} \\pagestyle{empty} \\begin{document} $$tex$ \\end{document}"; // check if image already exists, if not create it if (!file_exists("$ImgCacheDir/$imgname")) { // create tex template touch("$ImgCacheDir/work.tex"); if ($fp = fopen("$ImgCacheDir/work.tex", "w+")) { fwrite($fp,$texString); //create dvi exec("cd $ImgCacheDir && $latexPath work.tex"); // create png exec("cd $ImgCacheDir && $dvipngPath -T tight -bg Transparent -D 100 -o $imgname work.dvi"); fclose($fp); // clean up cleanUp("$ImgCacheDir/work.*"); } else { echo "something has gone wrong, do you have correct permissions to $ImgCacheDir"; } } } ?>