]> git.mjollnir.org Git - moodle.git/commitdiff
Yip's additions for Greek letters and bug fixes
authorfiedorow <fiedorow>
Fri, 20 Feb 2004 19:24:36 +0000 (19:24 +0000)
committerfiedorow <fiedorow>
Fri, 20 Feb 2004 19:24:36 +0000 (19:24 +0000)
filter/algebra/AlgParser.pm
filter/algebra/algebradebug.php
filter/algebra/filter.php

index d63da86d115dbfb2d393d022dfede6f4b565eaa3..3fedb19e16ee2a16ffffd702aee86ca11c2234c1 100755 (executable)
@@ -42,7 +42,7 @@ $binoper1 = '[-+=><%!#]';
 $openparen = '[{(\\[]';
 $closeparen = '[})\\]]';
 $varname = '[A-Za-z](?:_[0-9]+)?';
-$specialvalue = '(?:e|pi|da|db|dc|de|df|dg|dh|di|dj|dk|dl|dm|dn|do|dp|dq|dr|ds|dt|du|dv|dw|dx|dy|dz|infty)';
+$specialvalue = '(?:e|pi|da|db|dc|de|df|dg|dh|di|dj|dk|dl|dm|dn|do|dp|dq|dr|ds|dt|du|dv|dw|dx|dy|dz|infty|alpha|bita|gamma|zita|thita|iota|kappa|lambda|mu|nu|xi|rho|sigma|tau|phi|chi|psi|omega|zepslon|zdelta|xeta|zupslon)';
 $numberplain = '(?:\d+(?:\.\d*)?|\.\d+)';
 $numberE = '(?:' . $numberplain . 'E[-+]?\d+)';
 $number = '(?:' . $numberE . '|' . $numberplain . ')';
index 27fcaf7d50973e01ae0b90ec25012a5fbe080f55..5de73001984826b2737827046fb13b5faefa1bd4 100644 (file)
@@ -12,8 +12,8 @@
     $CFG->algebrafilterdir = "filter/algebra";
     $CFG->algebraimagedir = "filter/algebra";
 
-    error_reporting(E_ALL);
     $query = urldecode($_SERVER['QUERY_STRING']);
+    error_reporting(E_ALL);
 
     if ($query) {
       $output = $query;
@@ -60,7 +60,7 @@
       if (strpos($query,'ShowImage')) {
        $output = algebra2tex($algebra);
         $output = refineTeX($output);
-        tex2image($output);
+        tex2image($output, $md5);
       } else {   
         outputText($output);
       }
@@ -74,7 +74,15 @@ function algebra2tex($algebra) {
   $algebra = str_replace('<>','#',$algebra);
   $algebra = str_replace('<=','%',$algebra);
   $algebra = str_replace('>=','!',$algebra);
+  $algebra = str_replace('delta','zdelta',$algebra);
+  $algebra = str_replace('beta','bita',$algebra);
+  $algebra = str_replace('theta','thita',$algebra);
+  $algebra = str_replace('zeta','zita',$algebra);
+  $algebra = str_replace('eta','xeta',$algebra);
+  $algebra = str_replace('epsilon','zepslon',$algebra);
+  $algebra = str_replace('upsilon','zupslon',$algebra);
   $algebra = preg_replace('!\r\n?!',' ',$algebra);
+
   if ( (PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows") ) {
     $algebra = "\"". str_replace('"','\"',$algebra) . "\"";
     $cmd  = "cd $CFG->dirroot/$CFG->algebrafilterdir & algebra2tex.pl $algebra";
@@ -94,6 +102,28 @@ function refineTeX($texexp) {
   $texexp = str_replace('\right}','}',$texexp);
   $texexp = str_replace('\fun',' ',$texexp);
   $texexp = str_replace('infty','\infty',$texexp);
+  $texexp = str_replace('alpha','\alpha',$texexp);
+  $texexp = str_replace('gamma','\gamma',$texexp);
+  $texexp = str_replace('iota','\iota',$texexp);
+  $texexp = str_replace('kappa','\kappa',$texexp);
+  $texexp = str_replace('lambda','\lambda',$texexp);
+  $texexp = str_replace('mu','\mu',$texexp);
+  $texexp = str_replace('nu','\nu',$texexp);
+  $texexp = str_replace('xi','\xi',$texexp);
+  $texexp = str_replace('rho','\rho',$texexp);
+  $texexp = str_replace('sigma','\sigma',$texexp);
+  $texexp = str_replace('tau','\tau',$texexp);
+  $texexp = str_replace('phi','\phi',$texexp);
+  $texexp = str_replace('chi','\chi',$texexp);
+  $texexp = str_replace('psi','\psi',$texexp);
+  $texexp = str_replace('omega','\omega',$texexp);
+  $texexp = str_replace('zdelta','\delta',$texexp);
+  $texexp = str_replace('bita','\beta',$texexp);
+  $texexp = str_replace('thita','\theta',$texexp);
+  $texexp = str_replace('zita','\zeta',$texexp);
+  $texexp = str_replace('xeta','\eta',$texexp);
+  $texexp = str_replace('zepslon','\epsilon',$texexp);
+  $texexp = str_replace('zupslon','\upsilon',$texexp);
   $texexp = str_replace('\mbox{logten}','\mbox{log}_{10}',$texexp);
   $texexp = str_replace('\mbox{acos}','\mbox{cos}^{-1}',$texexp);
   $texexp = str_replace('\mbox{asin}','\mbox{sin}^{-1}',$texexp);
@@ -107,7 +137,6 @@ function refineTeX($texexp) {
   $texexp = str_replace('\mbox{asech}','\mbox{sech}^{-1}',$texexp);
   $texexp = str_replace('\mbox{acsch}','\mbox{csch}^{-1}',$texexp);
   $texexp = str_replace('\mbox{acoth}','\mbox{coth}^{-1}',$texexp);
-  $texexp = preg_replace('/\\\frac{(.+?)}{\\\left\((.+?)\\\right\)}/s','\frac{'."\$1}{\$2}",$texexp);
   $texexp = preg_replace('/\\\sqrt{(.+?),(.+?)}/s','\sqrt['. "\$2]{\$1}",$texexp);
   $texexp = preg_replace('/\\\mbox{abs}\\\left\((.+?)\\\right\)/s',"|\$1|",$texexp);
   $texexp = preg_replace('/\\\log\\\left\((.+?),(.+?)\\\right\)/s','\log_{'. "\$2}\\left(\$1\\right)",$texexp);
@@ -132,12 +161,12 @@ function outputText($texexp) {
   echo "</pre></body></html>\n";
 }
 
-function tex2image($texexp) {
+function tex2image($texexp, $md5) {
   global $CFG;
   if ($texexp) {
        $texexp = '\Large ' . $texexp;
        $lifetime = 86400;
-       $image  = md5($texexp) . ".gif";
+       $image  = $md5 . ".gif";
        $filetype = 'image/gif';
        if (!file_exists("$CFG->dataroot/$CFG->algebraimagedir")) {
           make_upload_directory($CFG->algebraimagedir);
index 510151c2ed98b2436054a3e87322c3b658a82046..22b6b4baefc3fef7fb92c3ee893f06c6a8c274d6 100644 (file)
@@ -138,6 +138,13 @@ function algebra_filter ($courseid, $text) {
            $algebra = str_replace('<>','#',$algebra);
            $algebra = str_replace('<=','%',$algebra);
            $algebra = str_replace('>=','!',$algebra);
+           $algebra = str_replace('delta','zdelta',$algebra);
+           $algebra = str_replace('beta','bita',$algebra);
+           $algebra = str_replace('theta','thita',$algebra);
+           $algebra = str_replace('zeta','zita',$algebra);
+           $algebra = str_replace('eta','xeta',$algebra);
+           $algebra = str_replace('epsilon','zepslon',$algebra);
+           $algebra = str_replace('upsilon','zupslon',$algebra);
            $algebra = preg_replace('!\r\n?!',' ',$algebra);
            if ( (PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows") ) {
               $algebra = "\"". str_replace('"','\"',$algebra) . "\"";
@@ -157,6 +164,28 @@ function algebra_filter ($courseid, $text) {
               $texexp = str_replace('\right}','}',$texexp);
               $texexp = str_replace('\fun',' ',$texexp);
               $texexp = str_replace('infty','\infty',$texexp);
+             $texexp = str_replace('alpha','\alpha',$texexp);  
+             $texexp = str_replace('gamma','\gamma',$texexp); 
+             $texexp = str_replace('iota','\iota',$texexp);
+             $texexp = str_replace('kappa','\kappa',$texexp);
+             $texexp = str_replace('lambda','\lambda',$texexp);
+             $texexp = str_replace('mu','\mu',$texexp);
+             $texexp = str_replace('nu','\nu',$texexp);
+             $texexp = str_replace('xi','\xi',$texexp);
+             $texexp = str_replace('rho','\rho',$texexp);
+             $texexp = str_replace('sigma','\sigma',$texexp);
+             $texexp = str_replace('tau','\tau',$texexp);
+             $texexp = str_replace('phi','\phi',$texexp);
+             $texexp = str_replace('chi','\chi',$texexp);
+             $texexp = str_replace('psi','\psi',$texexp);
+             $texexp = str_replace('omega','\omega',$texexp);
+             $texexp = str_replace('zdelta','\delta',$texexp);
+             $texexp = str_replace('bita','\beta',$texexp);
+             $texexp = str_replace('thita','\theta',$texexp);
+             $texexp = str_replace('zita','\zeta',$texexp);
+             $texexp = str_replace('xeta','\eta',$texexp);
+             $texexp = str_replace('zepslon','\epsilon',$texexp);
+             $texexp = str_replace('zupslon','\upsilon',$texexp);
               $texexp = str_replace('\mbox{logten}','\mbox{log}_{10}',$texexp);
               $texexp = str_replace('\mbox{acos}','\mbox{cos}^{-1}',$texexp);
               $texexp = str_replace('\mbox{asin}','\mbox{sin}^{-1}',$texexp);
@@ -170,7 +199,7 @@ function algebra_filter ($courseid, $text) {
               $texexp = str_replace('\mbox{asech}','\mbox{sech}^{-1}',$texexp);
               $texexp = str_replace('\mbox{acsch}','\mbox{csch}^{-1}',$texexp);
               $texexp = str_replace('\mbox{acoth}','\mbox{coth}^{-1}',$texexp);
-              $texexp = preg_replace('/\\\frac{(.+?)}{\\\left\((.+?)\\\right\)}/s','\frac{'."\$1}{\$2}",$texexp);
+              //$texexp = preg_replace('/\\\frac{(.+?)}{\\\left\((.+?)\\\right\)}/s','\frac{'."\$1}{\$2}",$texexp);
              $texexp = preg_replace('/\\\sqrt{(.+?),(.+?)}/s','\sqrt['. "\$2]{\$1}",$texexp);
              $texexp = preg_replace('/\\\mbox{abs}\\\left\((.+?)\\\right\)/s',"|\$1|",$texexp);
               $texexp = preg_replace('/\\\log\\\left\((.+?),(.+?)\\\right\)/s','\log_{'. "\$2}\\left(\$1\\right)",$texexp);