Permalink
Browse files

various improvements: better debugging, image positioning, XHTML vali…

…dation
  • Loading branch information...
1 parent f352814 commit d7e3f044c19ac2455626b602f57442da8ea75f0d fiedorow committed Feb 10, 2005
Showing with 42 additions and 8 deletions.
  1. +26 −0 filter/algebra/algebradebug.php
  2. +12 −4 filter/algebra/filter.php
  3. +4 −4 filter/algebra/pix.php
@@ -90,9 +90,35 @@ function algebra2tex($algebra) {
if ( (PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows") ) {
$algebra = "\"". str_replace('"','\"',$algebra) . "\"";
+ $cmd = "cd $CFG->dirroot\\$CFG->algebrafilterdirwin & algebra2tex.pl x/2";
+ $test = `$cmd`;
+ if ($test != '\frac{x}{2}') {
+ echo "There is a problem with either Perl or the script algebra2tex.pl<br>";
+ $ecmd = $cmd . " 2>&1";
+ echo `$ecmd` . "<br>\n";
+ echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
+ $commandpath = "$CFG->dirroot\\$CFG->algebrafilterdirwin\\algebra2tex.pl";
+ if (file_exists($commandpath)) {
+ echo "The file permissions of algebra2tex.pl are: " . decoct(fileperms($commandpath)) . "<br>";
+ }
+ die;
+ }
$cmd = "cd $CFG->dirroot\\$CFG->algebrafilterdirwin & algebra2tex.pl $algebra";
} else {
$algebra = escapeshellarg($algebra);
+ $cmd = "cd $CFG->dirroot/$CFG->algebrafilterdir; ./algebra2tex.pl x/2";
+ $test = `$cmd`;
+ if ($test != '\frac{x}{2}') {
+ echo "There is a problem with either Perl or the script algebra2tex.pl<br>";
+ $ecmd = $cmd . " 2>&1";
+ echo `$ecmd` . "<br>\n";
+ echo "The shell command<br>$cmd<br>returned status = $status<br>\n";
+ $commandpath = "$CFG->dirroot/$CFG->algebrafilterdir/algebra2tex.pl";
+ if (file_exists($commandpath)) {
+ echo "The file permissions of algebra2tex.pl are: " . decoct(fileperms($commandpath)) . "<br>";
+ }
+ die;
+ }
$cmd = "cd $CFG->dirroot/$CFG->algebrafilterdir; ./algebra2tex.pl $algebra";
}
$texexp = `$cmd`;
View
@@ -46,7 +46,7 @@
$CFG->algebrafilterdirwin = "filter\\algebra";
}
-function string_file_picture_algebra($imagefile, $tex= "", $height="", $width="") {
+function string_file_picture_algebra($imagefile, $tex= "", $height="", $width="", $align="middle") {
// Given the path to a picture file in a course, or a URL,
// this function includes the picture in the page.
global $CFG;
@@ -72,7 +72,7 @@ function string_file_picture_algebra($imagefile, $tex= "", $height="", $width=""
} else {
$output .= "<a target=\"popup\" title=\"TeX\" href=";
$output .= "\"$CFG->wwwroot/$CFG->texfilterdir/displaytex.php?";
- $output .= urlencode($tex) . "\" onClick=\"return openpopup('/$CFG->texfilterdir/displaytex.php?";
+ $output .= urlencode($tex) . "\" onclick=\"return openpopup('/$CFG->texfilterdir/displaytex.php?";
$output .= urlencode($tex) . "', 'popup', 'menubar=0,location=0,scrollbars,";
$output .= "resizable,width=300,height=240', 0);\">";
}
@@ -82,7 +82,7 @@ function string_file_picture_algebra($imagefile, $tex= "", $height="", $width=""
} else {
$output .= "$CFG->wwwroot/$CFG->algebrafilterdir/pix.php?file=$imagefile";
}
- $output .= "\" />";
+ $output .= "\" style=\"vertical-align:$align\" />";
$output .= "</a>";
} else {
$output .= "Error: must pass URL or course";
@@ -136,6 +136,14 @@ function algebra_filter ($courseid, $text) {
$algebra = $matches[1][$i] . $matches[2][$i];
$algebra = str_replace('<nolink>','',$algebra);
$algebra = str_replace('</nolink>','',$algebra);
+ $align = "middle";
+ if (preg_match('/^align=bottom /',$algebra)) {
+ $align = "text-bottom";
+ $algebra = preg_replace('/^align=bottom /','',$algebra);
+ } else if (preg_match('/^align=top /',$algebra)) {
+ $align = "text-top";
+ $algebra = preg_replace('/^align=top /','',$algebra);
+ }
$md5 = md5($algebra);
$filename = $md5 . ".gif";
if (! $texcache = get_record("cache_filters","filter","algebra", "md5key", $md5)) {
@@ -221,7 +229,7 @@ function algebra_filter ($courseid, $text) {
$texcache->rawtext = addslashes($texexp);
$texcache->timemodified = time();
insert_record("cache_filters",$texcache);
- $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp), $text);
+ $text = str_replace( $matches[0][$i], string_file_picture_algebra($filename, $texexp, '', '', $align), $text);
} else {
$text = str_replace( $matches[0][$i],"<b>Undetermined error:</b> ",$text);
}
View
@@ -46,20 +46,20 @@
$texexp = str_replace('"','\"',$texexp);
$cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex.exe";
$cmd = str_replace(' ','^ ',$cmd);
- $cmd .= " ++ -e \"$pathname\" \"$texexp\"";
+ $cmd .= " ++ -e \"$pathname\" -- \"$texexp\"";
} else if (is_executable("$CFG->dirroot/$CFG->texfilterdir/mimetex")) { /// Use the custom binary
- $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname ". escapeshellarg($texexp);
+ $cmd = "$CFG->dirroot/$CFG->texfilterdir/mimetex -e $pathname -- ". escapeshellarg($texexp);
} else { /// Auto-detect the right TeX binary
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 "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: /// Nothing was found, so tell them how to fix it.

0 comments on commit d7e3f04

Please sign in to comment.