function tex2image($texexp, $md5) {
global $CFG;
+ $error_message1 = "Your system is not configured to run mimeTeX. ";
+ $error_message1 .= "You need to download the appropriate<br> executable ";
+ $error_message1 .= "from <a href=\"http://moodle.org/download/mimetex/\">";
+ $error_message1 .= "http://moodle.org/download/mimetex/</a>, or obtain the ";
+ $error_message1 .= "C source<br> from <a href=\"http://www.forkosh.com/mimetex.zip\">";
+ $error_message1 .= "http://www.forkosh.com/mimetex.zip</a>, compile it and ";
+ $error_message1 .= "put the executable into your<br> moodle/filter/tex/ directory. ";
+ $error_message1 .= "You also need to edit your moodle/filter/algebra/pix.php file<br>";
+ $error_message1 .= ' by adding the line<br><pre> case "' . PHP_OS . "\":\n";
+ $error_message1 .= " \$cmd = \"\\\\\"\$CFG->dirroot/\$CFG->texfilterdir/";
+ $error_message1 .= 'mimetex.' . strtolower(PHP_OS) . "\\\\\" -e \\\\\"\$pathname\\\\\" \". escapeshellarg(\$texexp);";
+ $error_message1 .= "</pre>You also need to add this to your algebradebug.php file.";
+
if ($texexp) {
$texexp = '\Large ' . $texexp;
$lifetime = 86400;
if (file_exists($pathname)) {
unlink($pathname);
}
- $windows = 0;
+ $commandpath = "";
+ $cmd = "";
switch (PHP_OS) {
case "Linux":
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp);
+ $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.linux";
+ $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp);
break;
case "WINNT":
case "WIN32":
case "Windows":
- $windows = 1;
- $texexp = str_replace('"','\"',$texexp);
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
+ $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
+ $texexp = str_replace('"','\"',$texexp);
+ $cmd = str_replace(' ','^ ',$commandpath);
+ $cmd .= " ++ -e \"$pathname\" \"$texexp\"";
break;
case "Darwin":
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
+ $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin";
+ $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
break;
}
+ if (!$cmd) {
+ error($error_message1);
+ }
system($cmd, $status);
}
if ($texexp && file_exists($pathname)) {
header("Content-type: $filetype");
readfile("$pathname");
} else {
- if (!$windows) {
- $ecmd = "$cmd 2>&1";
- echo `$ecmd` . "<br>\n";
- }
+ $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 == 22) {
echo "Status corresponds to abnormal termination<br>\n";
}
+ if (file_exists($commandpath)) {
+ echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "<br>";
+ $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!";
}
}
<html>
<head><title>Algebra Filter Debugger</title></head>
<body>
-<?PHP
- require_once("../../config.php");
- $filename = "$CFG->dirroot/filter/algebra/pix.php";
- $PHP_OS = PHP_OS;
- $handle = fopen($filename,"r");
- $contents = fread($handle, filesize($filename));
- fclose($handle);
- if (!strpos($contents,'case "'. $PHP_OS . '":')) {
- echo "<b>WARNING!</b> case \"$PHP_OS\": NOT found in pix.php!!!<br><br>";
- }
-?>
<p>Please enter an algebraic expression <b>without</b> any surrounding @@ into
the text box below. (Click <a href="#help">here for help.</a>)
<form action="algebradebug.php" method="get"
$texexp = '\Large ' . $texexp;
switch (PHP_OS) {
case "Linux":
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp);
+ $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp);
break;
case "WINNT":
case "WIN32":
case "Windows":
$texexp = str_replace('"','\"',$texexp);
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
+ $cmd = str_replace(' ','^ ',$cmd);
+ $cmd .= " ++ -e \"$pathname\" \"$texexp\"";
break;
case "Darwin":
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
- break;
- default: /// To allow drop-in binaries for other platforms
- if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {
- echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
- echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
- echo "and that it has the right permissions set on it as executable program.\n\n";
- echo "You can get the latest binaries for your ".PHP_OS." platform from: \n\n";
- echo " http://moodle.org/download/mimetex/";
- exit;
- }
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp);
+ $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
break;
+ default: /// To allow drop-in binaries for other platforms
+ if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {
+ echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
+ echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
+ echo "and that it has the right permissions set on it as executable program.\n\n";
+ echo "You can get the latest binaries for your ".PHP_OS." platform from: \n\n";
+ echo " http://moodle.org/download/mimetex/";
+ exit;
+ }
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp);
+ break;
}
- system($cmd, $status);
+ system($cmd, $status);
}
}
readfile("$pathname");
} else {
echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
- echo "Image not found!";
+ echo "Image not found!<br>";
+ echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a>";
}
exit;
$texexp = '\Large ' . $texexp;
switch (PHP_OS) {
case "Linux":
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp);
+ $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp);
break;
case "WINNT":
case "WIN32":
case "Windows":
$texexp = str_replace('"','\"',$texexp);
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
+ $cmd = str_replace(' ','^ ',$cmd);
+ $cmd .= " ++ -e \"$pathname\" \"$texexp\"";
break;
case "Darwin":
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
+ $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
break;
- default: /// To allow drop-in binaries for other platforms
+ default: /// To allow drop-in binaries for other platforms
if (!is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) {
echo "Make sure you have an appropriate MimeTeX binary here:\n\n";
echo " $CFG->dirroot/$CFG->texfilterdir/mimetex\n\n";
readfile("$pathname");
} else {
echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
- echo "Image not found!";
+ echo "Image not found!<br>";
+ echo "Please try the <a href=\"$CFG->wwwroot/filter/tex/texdebug.php\">debugging script</a>";
}
exit;
function tex2image($texexp) {
global $CFG;
+ $error_message1 = "Your system is not configured to run mimeTeX. ";
+ $error_message1 .= "You need to download the appropriate<br> executable ";
+ $error_message1 .= "from <a href=\"http://moodle.org/download/mimetex/\">";
+ $error_message1 .= "http://moodle.org/download/mimetex/</a>, or obtain the ";
+ $error_message1 .= "C source<br> from <a href=\"http://www.forkosh.com/mimetex.zip\">";
+ $error_message1 .= "http://www.forkosh.com/mimetex.zip</a>, compile it and ";
+ $error_message1 .= "put the executable into your<br> moodle/filter/tex/ directory. ";
+ $error_message1 .= "You also need to edit your moodle/filter/tex/pix.php file<br>";
+ $error_message1 .= ' by adding the line<br><pre> case "' . PHP_OS . "\":\n";
+ $error_message1 .= " \$cmd = \"\\\\\"\$CFG->dirroot/\$CFG->texfilterdir/";
+ $error_message1 .= 'mimetex.' . strtolower(PHP_OS) . "\\\\\" -e \\\\\"\$pathname\\\\\" \". escapeshellarg(\$texexp);";
+ $error_message1 .= "</pre>You also need to add this to your texdebug.php file.";
+
if ($texexp) {
$texexp = '\Large ' . $texexp;
$lifetime = 86400;
if (file_exists($pathname)) {
unlink($pathname);
}
- $windows = 0;
+ $commandpath = "";
+ $cmd = "";
switch (PHP_OS) {
case "Linux":
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname ". escapeshellarg($texexp);
+ $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.linux";
+ $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.linux\" -e \"$pathname\" ". escapeshellarg($texexp);
break;
case "WINNT":
case "WIN32":
case "Windows":
- $windows = 1;
- $texexp = str_replace('"','\"',$texexp);
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname \"$texexp\"";
+ $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
+ $texexp = str_replace('"','\"',$texexp);
+ $cmd = str_replace(' ','^ ',$commandpath);
+ $cmd .= " ++ -e \"$pathname\" \"$texexp\"";
break;
case "Darwin":
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname ". escapeshellarg($texexp);
+ $commandpath="$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin";
+ $cmd = "\"$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin\" -e \"$pathname\" ". escapeshellarg($texexp);
break;
}
+ if (!$cmd) {
+ error($error_message1);
+ }
system($cmd, $status);
}
if ($texexp && file_exists($pathname)) {
header("Content-type: $filetype");
readfile("$pathname");
} else {
- if (!$windows) {
- $ecmd = "$cmd 2>&1";
- echo `$ecmd` . "<br>\n";
- }
+ $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 == 22) {
echo "Status corresponds to abnormal termination<br>\n";
}
+ if (file_exists($commandpath)) {
+ echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "<br>";
+ $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!";
}
}
<html>
<head><title>TeX Filter Debugger</title></head>
<body>
-<?PHP
- require_once("../../config.php");
- $filename = "$CFG->dirroot/filter/tex/pix.php";
- $PHP_OS = PHP_OS;
- $handle = fopen($filename,"r");
- $contents = fread($handle, filesize($filename));
- fclose($handle);
- if (!strpos($contents,'case "'. $PHP_OS . '":')) {
- echo "<b>WARNING!</b> case \"$PHP_OS\": NOT found in pix.php!!!<br><br>";
- }
-?>
<p>Please enter an algebraic expression <b>without</b> any surrounding $$ into
the text box below. (Click <a href="#help">here for help.</a>)
<form action="texdebug.php" method="get"
target="inlineframe">
<center>
<input type="text" name="tex" size=50
- value="\Large f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
+ value="f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt">
</center>
<ol>
<li>First click on this button <input type="submit" name="ShowDB" value="Show DB Entry">