mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-40939 tex filter: Changes to the TeX notation plugin
- Added configurable setting for path to mimetex binary - Moved language strings from lang/en/admin.php to lang/en/filter_tex.php - Config settings now stored in table config_plugins and retrieved through get_config - Added upgrade step to move TeX settings to the config_plugins table and delete settings from the config table AMOS BEGIN MOV [configconvertformat,core_admin],[configconvertformat,filter_tex] MOV [convertformat,core_admin],[convertformat,filter_tex] MOV [latexpreamble,core_admin],[latexpreamble,filter_tex] MOV [latexsettings,core_admin],[latexsettings,filter_tex] MOV [pathconvert,core_admin],[pathconvert,filter_tex] MOV [pathdvips,core_admin],[pathdvips,filter_tex] MOV [pathlatex,core_admin],[pathlatex,filter_tex] AMOS END
This commit is contained in:
parent
56cc9b387e
commit
7a3723219c
@ -44,6 +44,22 @@ function xmldb_filter_tex_upgrade($oldversion) {
|
||||
// Moodle v2.5.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2013050101) {
|
||||
$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, 2013050101, '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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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 = 2013050100; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2013050101; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2013050100; // Requires this Moodle version
|
||||
$plugin->component = 'filter_tex'; // Full name of the plugin (used for diagnostics)
|
||||
|
@ -150,7 +150,6 @@ $string['configcalendarexportsalt'] = 'This random text is used for improving of
|
||||
$string['configclamactlikevirus'] = 'Treat files like viruses';
|
||||
$string['configclamdonothing'] = 'Treat files as OK';
|
||||
$string['configclamfailureonupload'] = 'If you have configured clam to scan uploaded files, but it is configured incorrectly or fails to run for some unknown reason, how should it behave? If you choose \'Treat files like viruses\', they\'ll be moved into the quarantine area, or deleted. If you choose \'Treat files as OK\', the files will be moved to the destination directory like normal. Either way, admins will be alerted that clam has failed. If you choose \'Treat files like viruses\' and for some reason clam fails to run (usually because you have entered an invalid pathtoclam), ALL files that are uploaded will be moved to the given quarantine area, or deleted. Be careful with this setting.';
|
||||
$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['configcookiehttponly'] = 'Enables new PHP 5.2.0 feature - browsers are instructed to send cookie with real http requests only, cookies should not be accessible by scripting languages. This is not supported in all browsers and it may not be fully compatible with current code. It helps to prevent some types of XSS attacks.';
|
||||
$string['configcookiesecure'] = 'If server is accepting only https connections it is recommended to enable sending of secure cookies. If enabled please make sure that web server is not accepting http:// or set up permanent redirection to https:// address. When <em>wwwroot</em> address does not start with https:// this setting is turned off automatically.';
|
||||
$string['configcountry'] = 'If you set a country here, then this country will be selected by default on new user accounts. To force users to choose a country, just leave this unset.';
|
||||
@ -354,7 +353,6 @@ $string['configyuicomboloading'] = 'This options enables combined file loading o
|
||||
$string['confirmation'] = 'Confirmation';
|
||||
$string['confirmdeletecomments'] = 'You are about to delete comments, are you sure?';
|
||||
$string['confirmed'] = 'Confirmed';
|
||||
$string['convertformat'] = '<i>convert</i> output format';
|
||||
$string['cookiehttponly'] = 'Only http cookies';
|
||||
$string['cookiesecure'] = 'Secure cookies only';
|
||||
$string['country'] = 'Default country';
|
||||
@ -618,8 +616,6 @@ $string['langmenu'] = 'Display language menu';
|
||||
$string['langpackwillbeupdated'] = 'NOTE: Moodle will try to download updates for your language packs during the upgrade.';
|
||||
$string['langstringcache'] = 'Cache all language strings';
|
||||
$string['languagesettings'] = 'Language settings';
|
||||
$string['latexpreamble'] = 'LaTeX preamble';
|
||||
$string['latexsettings'] = 'LaTeX renderer Settings';
|
||||
$string['latinexcelexport'] = 'Excel encoding';
|
||||
$string['legacyfilesinnewcourses'] = 'Legacy course files in new courses';
|
||||
$string['legacyfilesinnewcourses_help'] = 'By default legacy course files areas are available only in upgraded courses. Please note some features like single activity backup/restore are not compatible with this settings.';
|
||||
@ -778,9 +774,6 @@ $string['order2'] = 'Second';
|
||||
$string['order3'] = 'Third';
|
||||
$string['order4'] = 'Fourth';
|
||||
$string['passwordpolicy'] = 'Password policy';
|
||||
$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['pathtoclam'] = 'clam AV path';
|
||||
$string['pathtodot'] = 'Path to dot';
|
||||
$string['pathtodot_help'] = 'Path to dot. Probably something like /usr/bin/dot. To be able to generate graphics from DOT files, you must have installed the dot executable and point to it here. Note that, for now, this only used by the profiling features (Development->Profiling) built into Moodle.';
|
||||
|
Loading…
x
Reference in New Issue
Block a user