diff --git a/filter/tex/filter.php b/filter/tex/filter.php index 7e1bfb7ea1b..873194d8819 100644 --- a/filter/tex/filter.php +++ b/filter/tex/filter.php @@ -165,7 +165,7 @@ class tex_filter extends moodle_text_filter { $texcache->timemodified = time(); $DB->insert_record("cache_filters", $texcache, false); } - $filename = $md5 . ".gif"; + $filename = $md5 . ".{$CFG->filter_tex_convertformat}"; $text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align, $alt), $text); } return $text; diff --git a/filter/tex/filtersettings.php b/filter/tex/filtersettings.php index 417ab400eda..24d8e773627 100644 --- a/filter/tex/filtersettings.php +++ b/filter/tex/filtersettings.php @@ -37,6 +37,12 @@ $items[] = new admin_setting_configexecutable('filter_tex_pathlatex', get_string $items[] = new admin_setting_configexecutable('filter_tex_pathdvips', get_string('pathdvips', 'admin'), '', $default_filter_tex_pathdvips); $items[] = new admin_setting_configexecutable('filter_tex_pathconvert', get_string('pathconvert', 'admin'), '', $default_filter_tex_pathconvert); +// Even if we offer GIF and PNG formats here, in the update callback we check whether +// all the paths actually point to executables. If they don't, we force the setting +// to GIF, as that's the only format mimeTeX can produce. +$formats = array('gif' => 'GIF', 'png' => 'PNG'); +$items[] = new admin_setting_configselect('filter_tex_convertformat', get_string('convertformat', 'admin'), get_string('configconvertformat', 'admin'), 'gif', $formats); + foreach ($items as $item) { $item->set_updatedcallback('filter_tex_updatedcallback'); $settings->add($item); diff --git a/filter/tex/latex.php b/filter/tex/latex.php index 36d4c2e1125..4deb513b164 100644 --- a/filter/tex/latex.php +++ b/filter/tex/latex.php @@ -82,11 +82,11 @@ } /** - * Render TeX string into gif + * Render TeX string into gif/png * @param string $formula TeX formula * @param string $filename base of filename for output (no extension) * @param int $fontsize font size - * @param int $density density value for .ps to .gif conversion + * @param int $density density value for .ps to .gif/.png conversion * @param string $background background color (e.g, #FFFFFF). * @param file $log valid open file handle for optional logging (debugging only) * @return bool true if successful @@ -106,7 +106,7 @@ $tex = "{$this->temp_dir}/$filename.tex"; $dvi = "{$this->temp_dir}/$filename.dvi"; $ps = "{$this->temp_dir}/$filename.ps"; - $gif = "{$this->temp_dir}/$filename.gif"; + $img = "{$this->temp_dir}/$filename.{$CFG->filter_tex_convertformat}"; // turn the latex doc into a .tex file in the temp area $fh = fopen( $tex, 'w' ); @@ -126,30 +126,32 @@ return false; } - // run convert on document (.ps to .gif) + // run convert on document (.ps to .gif/.png) if ($background) { $bg_opt = "-transparent \"$background\""; // Makes transparent background } else { $bg_opt = ""; } - $command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps $gif"; + $command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps $img"; if ($this->execute($command, $log )) { return false; } - return $gif; + return $img; } /** * Delete files created in temporary area - * Don't forget to copy the final gif before calling this + * Don't forget to copy the final gif/png before calling this * @param string $filename file base (no extension) */ function clean_up( $filename ) { + global $CFG; + unlink( "{$this->temp_dir}/$filename.tex" ); unlink( "{$this->temp_dir}/$filename.dvi" ); unlink( "{$this->temp_dir}/$filename.ps" ); - unlink( "{$this->temp_dir}/$filename.gif" ); + unlink( "{$this->temp_dir}/$filename.{$CFG->filter_tex_convertformat}" ); unlink( "{$this->temp_dir}/$filename.aux" ); unlink( "{$this->temp_dir}/$filename.log" ); return; diff --git a/filter/tex/lib.php b/filter/tex/lib.php index 8d8fc83238d..a2cb6d1cc4a 100644 --- a/filter/tex/lib.php +++ b/filter/tex/lib.php @@ -84,6 +84,13 @@ function filter_tex_updatedcallback($name) { $DB->delete_records('cache_filters', array('filter'=>'tex')); $DB->delete_records('cache_filters', array('filter'=>'algebra')); + + if (!(is_file($CFG->filter_tex_pathlatex) && is_executable($CFG->filter_tex_pathlatex) && + is_file($CFG->filter_tex_pathdvips) && is_executable($CFG->filter_tex_pathdvips) && + is_file($CFG->filter_tex_pathconvert) && is_executable($CFG->filter_tex_pathconvert))) { + // LaTeX, dvips or convert are not available, and mimetex can only produce GIFs so... + set_config('filter_tex_convertformat', 'gif'); + } } diff --git a/filter/tex/pix.php b/filter/tex/pix.php index bbfe1c8fbc1..c01e884827c 100644 --- a/filter/tex/pix.php +++ b/filter/tex/pix.php @@ -32,7 +32,7 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching } if (!file_exists($pathname)) { - $md5 = str_replace('.gif','',$image); + $md5 = str_replace(".{$CFG->filter_tex_convertformat}",'',$image); if ($texcache = $DB->get_record('cache_filters', array('filter'=>'tex', 'md5key'=>$md5))) { if (!file_exists($CFG->dataroot.'/filter/tex')) { make_upload_directory('filter/tex'); diff --git a/filter/tex/texdebug.php b/filter/tex/texdebug.php index 094f4980b2e..eace9122bb0 100644 --- a/filter/tex/texdebug.php +++ b/filter/tex/texdebug.php @@ -117,6 +117,7 @@ return; } + $texexp = stripslashes($texexp); $image = md5($texexp) . ".gif"; $filetype = 'image/gif'; if (!file_exists("$CFG->dataroot/filter/tex")) { @@ -211,7 +212,7 @@ $tex = "$latex->temp_dir/$md5.tex"; $dvi = "$latex->temp_dir/$md5.dvi"; $ps = "$latex->temp_dir/$md5.ps"; - $gif = "$latex->temp_dir/$md5.gif"; + $img = "$latex->temp_dir/$md5.{$CFG->filter_tex_convertformat}"; // put the expression as a file into the temp area $expression = html_entity_decode($expression); @@ -233,13 +234,13 @@ $output .= execute($cmd); // step 3: convert command - $cmd = "$CFG->filter_tex_pathconvert -density 240 -trim $ps $gif "; + $cmd = "$CFG->filter_tex_pathconvert -density 240 -trim $ps $img "; $output .= execute($cmd); if (!$graphic) { echo($output); } else { - send_file($gif, "$md5.gif"); + send_file($img, "$md5.{$CFG->filter_tex_convertformat}"); } } @@ -280,13 +281,13 @@ target="inlineframe">
The following tests are available: