diff --git a/filter/tex/latex.php b/filter/tex/latex.php index fe0baf99795..6504610c0fb 100644 --- a/filter/tex/latex.php +++ b/filter/tex/latex.php @@ -108,14 +108,16 @@ fclose( $fh ); // run latex on document - $command = "{$CFG->filter_tex_pathlatex} --interaction=nonstopmode --halt-on-error $tex"; + $pathlatex = escapeshellarg(trim($CFG->filter_tex_pathlatex, " '\"")); + $command = "{$pathlatex} --interaction=nonstopmode --halt-on-error $tex"; chdir( $this->temp_dir ); if ($this->execute($command, $log)) { // It allways False on Windows // return false; } // run dvips (.dvi to .ps) - $command = "{$CFG->filter_tex_pathdvips} -E $dvi -o $ps"; + $pathdvips = escapeshellarg(trim($CFG->filter_tex_pathdvips, " '\"")); + $command = "{$pathdvips} -E $dvi -o $ps"; if ($this->execute($command, $log )) { return false; } @@ -126,7 +128,8 @@ } else { $bg_opt = ""; } - $command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps $img"; + $pathconvert = escapeshellarg(trim($CFG->filter_tex_pathconvert, " '\"")); + $command = "{$pathconvert} -density $density -trim $bg_opt $ps $img"; if ($this->execute($command, $log )) { return false; } diff --git a/filter/tex/lib.php b/filter/tex/lib.php index c6b5989fb93..46529031c5a 100644 --- a/filter/tex/lib.php +++ b/filter/tex/lib.php @@ -116,9 +116,13 @@ function filter_tex_updatedcallback($name) { return; } - 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))) { + $pathlatex = trim($CFG->filter_tex_pathlatex, " '\""); + $pathdvips = trim($CFG->filter_tex_pathdvips, " '\""); + $pathconvert = trim($CFG->filter_tex_pathconvert, " '\""); + + if (!(is_file($pathlatex) && is_executable($pathlatex) && + is_file($pathdvips) && is_executable($pathdvips) && + is_file($pathconvert) && is_executable($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/settings.php b/filter/tex/settings.php index c0244e88bb1..ecedc11ba77 100644 --- a/filter/tex/settings.php +++ b/filter/tex/settings.php @@ -50,9 +50,9 @@ if ($ADMIN->fulltree) { } else if (PHP_OS=='WINNT' or PHP_OS=='WIN32' or PHP_OS=='Windows') { // note: you need Ghostscript installed (standard), miktex (standard) // and ImageMagick (install at c:\ImageMagick) - $default_filter_tex_pathlatex = "\"c:\\texmf\\miktex\\bin\\latex.exe\" "; - $default_filter_tex_pathdvips = "\"c:\\texmf\\miktex\\bin\\dvips.exe\" "; - $default_filter_tex_pathconvert = "\"c:\\imagemagick\\convert.exe\" "; + $default_filter_tex_pathlatex = "c:\\texmf\\miktex\\bin\\latex.exe"; + $default_filter_tex_pathdvips = "c:\\texmf\\miktex\\bin\\dvips.exe"; + $default_filter_tex_pathconvert = "c:\\imagemagick\\convert.exe"; } else { $default_filter_tex_pathlatex = ''; @@ -60,6 +60,16 @@ if ($ADMIN->fulltree) { $default_filter_tex_pathconvert = ''; } + $pathlatex = $CFG->filter_tex_pathlatex; + $pathdvips = $CFG->filter_tex_pathdvips; + $pathconvert = $CFG->filter_tex_pathconvert; + if (strrpos($pathlatex . $pathdvips . $pathconvert, '"') or + strrpos($pathlatex . $pathdvips . $pathconvert, "'")) { + set_config('filter_tex_pathlatex', trim($pathlatex, " '\"")); + set_config('filter_tex_pathdvips', trim($pathdvips, " '\"")); + set_config('filter_tex_pathconvert', trim($pathconvert, " '\"")); + } + $items[] = new admin_setting_configexecutable('filter_tex_pathlatex', get_string('pathlatex', 'admin'), '', $default_filter_tex_pathlatex); $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); @@ -74,4 +84,4 @@ if ($ADMIN->fulltree) { $item->set_updatedcallback('filter_tex_updatedcallback'); $settings->add($item); } -} \ No newline at end of file +} diff --git a/filter/tex/texdebug.php b/filter/tex/texdebug.php index 0817d7e65ec..1e49e8ab59c 100644 --- a/filter/tex/texdebug.php +++ b/filter/tex/texdebug.php @@ -200,27 +200,33 @@ // first check if it is likely to work at all $output .= "