Exemplo n.º 1
0
        $density = get_config('filter_texwjax', 'density');
        $background = get_config('filter_texwjax', 'latexbackground');
        $texexp = $texcache->rawtext;
        // the entities are now decoded before inserting to DB
        $lateximage = $latex->render($texexp, $image, 12, $density, $background);
        if ($lateximage) {
            copy($lateximage, $pathname);
            $latex->clean_up($md5);
        } else {
            // failing that, use mimetex
            $texexp = $texcache->rawtext;
            $texexp = str_replace('&lt;', '<', $texexp);
            $texexp = str_replace('&gt;', '>', $texexp);
            $texexp = preg_replace('!\\r\\n?!', ' ', $texexp);
            $texexp = '\\Large ' . $texexp;
            $cmd = filter_texwjax_get_cmd($pathname, $texexp);
            system($cmd, $status);
        }
    }
}
if (file_exists($pathname)) {
    send_file($pathname, $image);
} else {
    if (debugging()) {
        echo "The shell command<br />{$cmd}<br />returned status = {$status}<br />\n";
        echo "Image not found!<br />";
        echo "Please try the <a href=\"{$CFG->wwwroot}/filter/texwjax/texdebug.php\">debugging script</a>";
    } else {
        echo "Image not found!<br />";
        echo "Please try the <a href=\"{$CFG->wwwroot}/filter/texwjax/texdebug.php\">debugging script</a><br />";
        echo "Please turn on debug mode in site configuration to see more info here.";
function tex2image($texexp, $return = false)
{
    global $CFG;
    if (!$texexp) {
        echo 'No tex expresion specified';
        return;
    }
    $image = md5($texexp) . ".gif";
    $filetype = 'image/gif';
    if (!file_exists("{$CFG->dataroot}/filter/tex")) {
        make_upload_directory("filter/tex");
    }
    $pathname = "{$CFG->dataroot}/filter/tex/{$image}";
    if (file_exists($pathname)) {
        unlink($pathname);
    }
    $texexp = '\\Large ' . $texexp;
    $commandpath = filter_texwjax_get_executable(true);
    $cmd = filter_texwjax_get_cmd($pathname, $texexp);
    system($cmd, $status);
    if ($return) {
        return $image;
    }
    if (file_exists($pathname)) {
        send_file($pathname, $image);
    } else {
        if (debugging()) {
            $ecmd = "{$cmd} 2>&1";
            echo `{$ecmd}` . "<br />\n";
            echo "The shell command<br />{$cmd}<br />returned status = {$status}<br />\n";
            if ($status == 4) {
                echo "Status corresponds to illegal instruction<br />\n";
            } else {
                if ($status == 11) {
                    echo "Status corresponds to bus error<br />\n";
                } else {
                    if ($status == 22) {
                        echo "Status corresponds to abnormal termination<br />\n";
                    }
                }
            }
            if (file_exists($commandpath)) {
                echo "File size of mimetex executable  {$commandpath} is " . filesize($commandpath) . "<br />";
                echo "The file permissions are: " . decoct(fileperms($commandpath)) . "<br />";
                if (function_exists("md5_file")) {
                    echo "The md5 checksum of the file is " . md5_file($commandpath) . "<br />";
                } else {
                    $handle = fopen($commandpath, "rb");
                    $contents = fread($handle, 16384);
                    fclose($handle);
                    echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br />";
                }
            } else {
                echo "mimetex executable {$commandpath} not found!<br />";
            }
            echo "Image not found!";
        } else {
            echo "Can not output detailed information due to security concerns, please turn on debug mode first.";
        }
    }
}