コード例 #1
0
ファイル: algebradebug.php プロジェクト: r007/PMoodle
function tex2image($texexp, $md5, $return = false)
{
    global $CFG;
    if (!$texexp) {
        echo 'No tex expresion specified';
        return;
    }
    $texexp = '\\Large ' . $texexp;
    $image = $md5 . ".gif";
    $filetype = 'image/gif';
    if (!file_exists("{$CFG->dataroot}/filter/algebra")) {
        make_upload_directory("filter/algebra");
    }
    $pathname = "{$CFG->dataroot}/filter/algebra/{$image}";
    if (file_exists($pathname)) {
        unlink($pathname);
    }
    $commandpath = tex_filter_get_executable(true);
    $cmd = tex_filter_get_cmd($pathname, $texexp);
    system($cmd, $status);
    if ($return) {
        return $image;
    }
    if (file_exists($pathname)) {
        send_file($pathname, $image);
    } else {
        $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!";
    }
}
コード例 #2
0
ファイル: pix.php プロジェクト: edwinphillips/moodle-485cb39
        $latex = new latex();
        $density = $CFG->filter_tex_density;
        $background = $CFG->filter_tex_latexbackground;
        $texexp = html_entity_decode($texcache->rawtext);
        $latex_path = $latex->render($texexp, $md5, 12, $density, $background);
        if ($latex_path) {
            copy($latex_path, $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 = tex_filter_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/tex/texdebug.php\">debugging script</a>";
    } else {
        echo "Image not found!<br />";
        echo "Please try the <a href=\"{$CFG->wwwroot}/filter/tex/texdebug.php\">debugging script</a><br />";
        echo "Please turn on debug mode in site configuration to see more info here.";