$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 $useMethod, $dvipngPath,$dvipsPath, $convertPath, $latexPath, $ImgCacheDir; $tex = str_replace('<','<',$tex); $tex = str_replace('>','>',$tex); $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); # Obfuscate potential filenames // template for tex file $texString = "\documentclass[12pt]{article} \\usepackage{amssymb,amsmath,amscd,concmath} \\newcommand{\\nothing}{} \\pagestyle{empty} \\begin{document} \\begin{align*}$tex\\end{align*} \\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 switch ($useMethod) { case "dvips-convert": // first dvips then convert $cmd = "cd $ImgCacheDir && ".$dvipsPath." -D 400 -E work.dvi -o work.ps"; exec( $cmd ); //$cmd = "cd $ImgCacheDir && ".$convertPath." -density 100 -trim -transparent \"#FFFFFF\" work.ps ".$imgname; $cmd = "cd $ImgCacheDir && ".$convertPath." -density 100 -trim \"#FFFFFF\" work.ps ".$imgname; exec( $cmd ); break; case "dvipng": exec("cd $ImgCacheDir && $dvipngPath -T tight -bg Transparent -D 100 -o $imgname work.dvi"); break; } fclose($fp); // clean up cleanUp("$ImgCacheDir/work.*"); } else { echo "something has gone wrong, do you have correct permissions to $ImgCacheDir"; } } } ?>