2 // This function fetches math. images from the data directory
3 // If not, it obtains the corresponding TeX expression from the cache_tex db table
4 // and uses mimeTeX to create the image file
6 $nomoodlecookie = true; // Because it interferes with caching
8 require_once("../../config.php");
10 if (empty($CFG->textfilters
)) {
11 error ('Filter not enabled!');
13 $filters = explode(',', $CFG->textfilters
);
14 if (array_search('filter/tex', $filters) === FALSE) {
15 error ('Filter not enabled!');
19 $CFG->texfilterdir
= "filter/tex";
20 $CFG->teximagedir
= "filter/tex";
22 error_reporting(E_ALL
);
23 $texexp = urldecode($_SERVER['QUERY_STRING']);
24 $texexp = str_replace('formdata=','',$texexp);
27 //$texexp = stripslashes($texexp);
29 $image = md5($texexp) . ".gif";
30 $filetype = 'image/gif';
31 if (!file_exists("$CFG->dataroot/$CFG->teximagedir")) {
32 make_upload_directory($CFG->teximagedir
);
34 $pathname = "$CFG->dataroot/$CFG->teximagedir/$image";
35 $texexp = escapeshellarg($texexp);
39 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.linux -e $pathname -- $texexp" );
44 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.exe -e $pathname -- $texexp");
47 system("$CFG->dirroot/$CFG->texfilterdir/mimetex.darwin -e $pathname -- $texexp" );
50 if (file_exists($pathname)) {
51 $lastmodified = filemtime($pathname);
52 header("Last-Modified: " . gmdate("D, d M Y H:i:s", $lastmodified) . " GMT");
53 header("Expires: " . gmdate("D, d M Y H:i:s", time() +
$lifetime) . " GMT");
54 header("Cache-control: max_age = $lifetime"); // a day
56 header("Content-disposition: inline; filename=$image");
57 header("Content-length: ".filesize($pathname));
58 header("Content-type: $filetype");
59 readfile("$pathname");
61 echo "Image not found!";
69 <head
><title
>mimeTeX Previewer
</title
></head
>
71 <p
>Now enter your own expression
or use the sample provided
,
72 press the Submit button
, and mimeTeX
's rendering should be
73 displayed in the little window immediately below it.
75 <form action="texed.php" method="get"
77 <input type="text" name="formdata" size="50"
78 value="\Large f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt" />
79 <input type="submit" />
81 <iframe name="inlineframe" align="middle" width="80%" height="100">
82 <p>Something is wrong...</p>