Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / filter / tex / texed.php
blob5ff4c0bd42d580a5f87e7679020af521b9ecf6c3
1 <?PHP // $Id$
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");
9 require_once($CFG->dirroot.'/filter/tex/lib.php');
11 if (empty($CFG->textfilters)) {
12 error ('Filter not enabled!');
13 } else {
14 $filters = explode(',', $CFG->textfilters);
15 if (array_search('filter/tex', $filters) === FALSE) {
16 error ('Filter not enabled!');
20 error_reporting(E_ALL);
21 $texexp = urldecode($_SERVER['QUERY_STRING']);
22 $texexp = str_replace('formdata=','',$texexp);
24 if ($texexp) {
25 $image = md5($texexp) . ".gif";
26 $filetype = 'image/gif';
27 if (!file_exists("$CFG->dataroot/filter/tex")) {
28 make_upload_directory("filter/tex");
31 $texexp = str_replace('&lt;','<',$texexp);
32 $texexp = str_replace('&gt;','>',$texexp);
33 $texexp = preg_replace('!\r\n?!',' ',$texexp);
34 $cmd = tex_filter_get_cmd($pathname, $texexp);
35 system($cmd, $status);
37 if (file_exists($pathname)) {
38 send_file($pathname, $image);
39 } else {
40 echo "Image not found!";
42 exit;
43 } else {
44 echo "No tex expresion specified";
49 <html>
50 <head><title>mimeTeX Previewer</title></head>
51 <body>
52 <p>Now enter your own expression or use the sample provided,
53 press the Submit button, and mimeTeX's rendering should be
54 displayed in the little window immediately below it.
55 <center>
56 <form action="texed.php" method="get"
57 target="inlineframe">
58 <input type="text" name="formdata" size="50"
59 value="\Large f(x)=\Bigint_{-\infty}^x~e^{-t^2}dt" />
60 <input type="submit" />
61 </form> <br /> <br />
62 <iframe name="inlineframe" align="middle" width="80%" height="100">
63 &lt;p&gt;Something is wrong...&lt;/p&gt;
64 </iframe>
65 </center> <br />
66 </body>
67 </html>