mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Merge branch 'MDL-40939-master' of https://github.com/timgus/moodle
Conflicts: filter/tex/version.php lang/en/admin.php
This commit is contained in:
commit
13410584be
10 changed files with 90 additions and 47 deletions
|
@ -48,5 +48,22 @@ function xmldb_filter_tex_upgrade($oldversion) {
|
|||
// Moodle v2.6.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2013120300) {
|
||||
$settings = array(
|
||||
'density', 'latexbackground', 'convertformat', 'pathlatex',
|
||||
'convertformat', 'pathconvert', 'pathdvips', 'latexpreamble');
|
||||
|
||||
// Move tex settings to config_pluins and delete entries from the config table.
|
||||
foreach ($settings as $setting) {
|
||||
$existingkey = 'filter_tex_'.$setting;
|
||||
if (array_key_exists($existingkey, $CFG)) {
|
||||
set_config($setting, $CFG->{$existingkey}, 'filter_tex');
|
||||
unset_config($existingkey);
|
||||
}
|
||||
}
|
||||
|
||||
upgrade_plugin_savepoint(true, 2013120300, 'filter', 'tex');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -181,7 +181,8 @@ class filter_tex extends moodle_text_filter {
|
|||
$texcache->timemodified = time();
|
||||
$DB->insert_record("cache_filters", $texcache, false);
|
||||
}
|
||||
$filename = $md5 . ".{$CFG->filter_tex_convertformat}";
|
||||
$convertformat = get_config('filter_tex', 'convertformat');
|
||||
$filename = $md5.".{$convertformat}";
|
||||
$text = str_replace( $matches[0][$i], filter_text_image($filename, $texexp, 0, 0, $align, $alt), $text);
|
||||
}
|
||||
return $text;
|
||||
|
|
|
@ -23,5 +23,14 @@
|
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['configconvertformat'] = 'If <i>latex</i>, <i>dvips</i> and <i>convert</i> are available, the images are created using the specified format. If it is not, mimeTeX will be used and it will create GIF images.';
|
||||
$string['convertformat'] = '<i>Convert</i> output format';
|
||||
$string['latexpreamble'] = 'LaTeX preamble';
|
||||
$string['latexsettings'] = 'LaTeX renderer Settings';
|
||||
$string['filtername'] = 'TeX notation';
|
||||
$string['pathconvert'] = 'Path of <i>convert</i> binary';
|
||||
$string['pathdvips'] = 'Path of <i>dvips</i> binary';
|
||||
$string['pathlatex'] = 'Path of <i>latex</i> binary';
|
||||
$string['pathmimetex'] = 'Path of <i>mimetex</i> binary';
|
||||
$string['pathmimetexdesc'] = 'Moodle will use its own mimetex binary unless another valid path is specified.';
|
||||
$string['source'] = 'TeX source';
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
// $fontsize don't affects to formula's size. $density can change size
|
||||
$doc = "\\documentclass[{$fontsize}pt]{article}\n";
|
||||
$doc .= $CFG->filter_tex_latexpreamble;
|
||||
$doc .= get_config('filter_tex', 'latexpreamble');
|
||||
$doc .= "\\pagestyle{empty}\n";
|
||||
$doc .= "\\begin{document}\n";
|
||||
//dlnsk $doc .= "$ {$formula} $\n";
|
||||
|
@ -90,7 +90,8 @@
|
|||
global $CFG;
|
||||
|
||||
// quick check - will this work?
|
||||
if (empty($CFG->filter_tex_pathlatex)) {
|
||||
$pathlatex = get_config('filter_tex', 'pathlatex');
|
||||
if (empty($pathlatex)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -100,7 +101,8 @@
|
|||
$tex = "{$this->temp_dir}/$filename.tex";
|
||||
$dvi = "{$this->temp_dir}/$filename.dvi";
|
||||
$ps = "{$this->temp_dir}/$filename.ps";
|
||||
$img = "{$this->temp_dir}/$filename.{$CFG->filter_tex_convertformat}";
|
||||
$convertformat = get_config('filter_tex', 'convertformat');
|
||||
$img = "{$this->temp_dir}/$filename.{$convertformat}";
|
||||
|
||||
// turn the latex doc into a .tex file in the temp area
|
||||
$fh = fopen( $tex, 'w' );
|
||||
|
@ -108,14 +110,15 @@
|
|||
fclose( $fh );
|
||||
|
||||
// run latex on document
|
||||
$command = "{$CFG->filter_tex_pathlatex} --interaction=nonstopmode --halt-on-error $tex";
|
||||
$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 = get_config('filter_tex', 'pathdvips');
|
||||
$command = "{$pathdvips} -E $dvi -o $ps";
|
||||
if ($this->execute($command, $log )) {
|
||||
return false;
|
||||
}
|
||||
|
@ -126,7 +129,8 @@
|
|||
} else {
|
||||
$bg_opt = "";
|
||||
}
|
||||
$command = "{$CFG->filter_tex_pathconvert} -density $density -trim $bg_opt $ps $img";
|
||||
$pathconvert = get_config('filter_tex', 'pathconvert');
|
||||
$command = "{$pathconvert} -density $density -trim $bg_opt $ps $img";
|
||||
if ($this->execute($command, $log )) {
|
||||
return false;
|
||||
}
|
||||
|
@ -145,7 +149,8 @@
|
|||
unlink( "{$this->temp_dir}/$filename.tex" );
|
||||
unlink( "{$this->temp_dir}/$filename.dvi" );
|
||||
unlink( "{$this->temp_dir}/$filename.ps" );
|
||||
unlink( "{$this->temp_dir}/$filename.{$CFG->filter_tex_convertformat}" );
|
||||
$convertformat = get_config('filter_tex', 'convertformat');
|
||||
unlink( "{$this->temp_dir}/$filename.{$convertformat}" );
|
||||
unlink( "{$this->temp_dir}/$filename.aux" );
|
||||
unlink( "{$this->temp_dir}/$filename.log" );
|
||||
return;
|
||||
|
|
|
@ -42,6 +42,14 @@ function filter_tex_get_executable($debug=false) {
|
|||
return "$CFG->dirroot/filter/tex/mimetex.exe";
|
||||
}
|
||||
|
||||
if ($pathmimetex = get_config('filter_tex', 'pathmimetex')) {
|
||||
if (is_executable($pathmimetex)) {
|
||||
return $pathmimetex;
|
||||
} else {
|
||||
print_error('mimetexnotexecutable', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
$custom_commandpath = "$CFG->dirroot/filter/tex/mimetex";
|
||||
if (file_exists($custom_commandpath)) {
|
||||
if (is_executable($custom_commandpath)) {
|
||||
|
@ -111,16 +119,20 @@ function filter_tex_updatedcallback($name) {
|
|||
$DB->delete_records('cache_filters', array('filter'=>'tex'));
|
||||
$DB->delete_records('cache_filters', array('filter'=>'algebra'));
|
||||
|
||||
if (!isset($CFG->filter_tex_pathlatex)) {
|
||||
$pathlatex = get_config('filter_tex', 'pathlatex');
|
||||
if ($pathlatex === false) {
|
||||
// detailed settings not present yet
|
||||
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))) {
|
||||
$pathdvips = get_config('filter_tex', 'pathdvips');
|
||||
$pathconvert = get_config('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');
|
||||
set_config('convertformat', 'gif', 'filter_tex');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,8 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
|||
}
|
||||
|
||||
if (!file_exists($pathname)) {
|
||||
$md5 = str_replace(".{$CFG->filter_tex_convertformat}",'',$image);
|
||||
$convertformat = get_config('filter_tex', 'convertformat');
|
||||
$md5 = str_replace(".{$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');
|
||||
|
@ -40,8 +41,8 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
|||
|
||||
// try and render with latex first
|
||||
$latex = new latex();
|
||||
$density = $CFG->filter_tex_density;
|
||||
$background = $CFG->filter_tex_latexbackground;
|
||||
$density = get_config('filter_tex', 'density');
|
||||
$background = get_config('filter_tex', 'latexbackground');
|
||||
$texexp = $texcache->rawtext; // the entities are now decoded before inserting to DB
|
||||
$latex_path = $latex->render($texexp, $md5, 12, $density, $background);
|
||||
if ($latex_path) {
|
||||
|
|
|
@ -30,11 +30,11 @@ if ($ADMIN->fulltree) {
|
|||
require_once($CFG->dirroot.'/filter/tex/lib.php');
|
||||
|
||||
$items = array();
|
||||
$items[] = new admin_setting_heading('filter_tex_latexheading', get_string('latexsettings', 'admin'), '');
|
||||
$items[] = new admin_setting_configtextarea('filter_tex_latexpreamble', get_string('latexpreamble','admin'),
|
||||
$items[] = new admin_setting_heading('filter_tex/latexheading', get_string('latexsettings', 'filter_tex'), '');
|
||||
$items[] = new admin_setting_configtextarea('filter_tex/latexpreamble', get_string('latexpreamble','filter_tex'),
|
||||
'', "\\usepackage[latin1]{inputenc}\n\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\RequirePackage{amsmath,amssymb,latexsym}\n");
|
||||
$items[] = new admin_setting_configtext('filter_tex_latexbackground', get_string('backgroundcolour', 'admin'), '', '#FFFFFF');
|
||||
$items[] = new admin_setting_configtext('filter_tex_density', get_string('density', 'admin'), '', '120', PARAM_INT);
|
||||
$items[] = new admin_setting_configtext('filter_tex/latexbackground', get_string('backgroundcolour', 'admin'), '', '#FFFFFF');
|
||||
$items[] = new admin_setting_configtext('filter_tex/density', get_string('density', 'admin'), '', '120', PARAM_INT);
|
||||
|
||||
if (PHP_OS=='Linux') {
|
||||
$default_filter_tex_pathlatex = "/usr/bin/latex";
|
||||
|
@ -60,18 +60,19 @@ if ($ADMIN->fulltree) {
|
|||
$default_filter_tex_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);
|
||||
$items[] = new admin_setting_configexecutable('filter_tex/pathlatex', get_string('pathlatex', 'filter_tex'), '', $default_filter_tex_pathlatex);
|
||||
$items[] = new admin_setting_configexecutable('filter_tex/pathdvips', get_string('pathdvips', 'filter_tex'), '', $default_filter_tex_pathdvips);
|
||||
$items[] = new admin_setting_configexecutable('filter_tex/pathconvert', get_string('pathconvert', 'filter_tex'), '', $default_filter_tex_pathconvert);
|
||||
$items[] = new admin_setting_configexecutable('filter_tex/pathmimetex', get_string('pathmimetex', 'filter_tex'), get_string('pathmimetexdesc', 'filter_tex'), '');
|
||||
|
||||
// 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);
|
||||
$items[] = new admin_setting_configselect('filter_tex/convertformat', get_string('convertformat', 'filter_tex'), get_string('configconvertformat', 'filter_tex'), 'gif', $formats);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->set_updatedcallback('filter_tex_updatedcallback');
|
||||
$settings->add($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -200,26 +200,29 @@
|
|||
// first check if it is likely to work at all
|
||||
$output .= "<h3>Checking executables</h3>\n";
|
||||
$executables_exist = true;
|
||||
if (is_file($CFG->filter_tex_pathlatex)) {
|
||||
$output .= "latex executable ($CFG->filter_tex_pathlatex) is readable<br />\n";
|
||||
$pathlatex = get_config('filter_tex', 'pathlatex');
|
||||
if (is_file($pathlatex)) {
|
||||
$output .= "latex executable ($pathlatex) is readable<br />\n";
|
||||
}
|
||||
else {
|
||||
$executables_exist = false;
|
||||
$output .= "<b>Error:</b> latex executable ($CFG->filter_tex_pathlatex) is not readable<br />\n";
|
||||
$output .= "<b>Error:</b> latex executable ($pathlatex) is not readable<br />\n";
|
||||
}
|
||||
if (is_file($CFG->filter_tex_pathdvips)) {
|
||||
$output .= "dvips executable ($CFG->filter_tex_pathdvips) is readable<br />\n";
|
||||
$pathdvips = get_config('filter_tex', 'pathdvips');
|
||||
if (is_file($pathdvips)) {
|
||||
$output .= "dvips executable ($pathdvips) is readable<br />\n";
|
||||
}
|
||||
else {
|
||||
$executables_exist = false;
|
||||
$output .= "<b>Error:</b> dvips executable ($CFG->filter_tex_pathdvips) is not readable<br />\n";
|
||||
$output .= "<b>Error:</b> dvips executable ($pathdvips) is not readable<br />\n";
|
||||
}
|
||||
if (is_file($CFG->filter_tex_pathconvert)) {
|
||||
$output .= "convert executable ($CFG->filter_tex_pathconvert) is readable<br />\n";
|
||||
$pathconvert = get_config('filter_tex', 'pathconvert');
|
||||
if (is_file($pathconvert)) {
|
||||
$output .= "convert executable ($pathconvert) is readable<br />\n";
|
||||
}
|
||||
else {
|
||||
$executables_exist = false;
|
||||
$output .= "<b>Error:</b> convert executable ($CFG->filter_tex_pathconvert) is not readable<br />\n";
|
||||
$output .= "<b>Error:</b> convert executable ($pathconvert) is not readable<br />\n";
|
||||
}
|
||||
|
||||
// knowing that it might work..
|
||||
|
@ -230,7 +233,8 @@
|
|||
$tex = "$latex->temp_dir/$md5.tex";
|
||||
$dvi = "$latex->temp_dir/$md5.dvi";
|
||||
$ps = "$latex->temp_dir/$md5.ps";
|
||||
$img = "$latex->temp_dir/$md5.{$CFG->filter_tex_convertformat}";
|
||||
$convertformat = get_config('filter_tex', 'convertformat');
|
||||
$img = "$latex->temp_dir/$md5.{$convertformat}";
|
||||
|
||||
// put the expression as a file into the temp area
|
||||
$expression = html_entity_decode($expression);
|
||||
|
@ -244,21 +248,21 @@
|
|||
chdir($latex->temp_dir);
|
||||
|
||||
// step 1: latex command
|
||||
$cmd = "$CFG->filter_tex_pathlatex --interaction=nonstopmode --halt-on-error $tex";
|
||||
$cmd = "$pathlatex --interaction=nonstopmode --halt-on-error $tex";
|
||||
$output .= execute($cmd);
|
||||
|
||||
// step 2: dvips command
|
||||
$cmd = "$CFG->filter_tex_pathdvips -E $dvi -o $ps";
|
||||
$cmd = "$pathdvips -E $dvi -o $ps";
|
||||
$output .= execute($cmd);
|
||||
|
||||
// step 3: convert command
|
||||
$cmd = "$CFG->filter_tex_pathconvert -density 240 -trim $ps $img ";
|
||||
$cmd = "$pathconvert -density 240 -trim $ps $img ";
|
||||
$output .= execute($cmd);
|
||||
|
||||
if (!$graphic) {
|
||||
echo $output;
|
||||
} else if (file_exists($img)){
|
||||
send_file($img, "$md5.{$CFG->filter_tex_convertformat}");
|
||||
send_file($img, "$md5.{$convertformat}");
|
||||
} else {
|
||||
echo "Error creating image, see command execution output for more details.";
|
||||
}
|
||||
|
|
|
@ -25,6 +25,6 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2013110500; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2013120300; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2013110500; // Requires this Moodle version
|
||||
$plugin->component = 'filter_tex'; // Full name of the plugin (used for diagnostics)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue