MDL-85233 filter: Remove MimeTeX support and use LaTeX for TeX/algebra
This commit removes MimeTeX support from both filter_tex and filter_algebra, requiring LaTeX tools (latex, dvips, convert/dvisvgm) for rendering. It also makes filter_algebra fully independent from filter_tex with its own configuration settings
This commit is contained in:
committed by
yusufwib01
parent
b3cd83bd48
commit
5b96820437
@@ -0,0 +1,9 @@
|
||||
issueNumber: MDL-85233
|
||||
notes:
|
||||
core_filters:
|
||||
- message: >-
|
||||
MimeTeX support has been removed from both `filter_tex` and
|
||||
`filter_algebra`. These filters now depend on LaTeX tools (`latex`,
|
||||
`dvips`, and `convert`/`dvisvgm`), and as a result, the `pathmimetex`
|
||||
setting has been removed.
|
||||
type: removed
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
// This function fetches math. images from the data directory
|
||||
// If not, it obtains the corresponding TeX expression from the cache_tex db table
|
||||
// and uses mimeTeX to create the image file
|
||||
// If not, it obtains the corresponding TeX expression from the cache_filters db table
|
||||
// and uses LaTeX to create the image file.
|
||||
|
||||
require_once("../../config.php");
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->dirroot.'/filter/tex/lib.php');
|
||||
require_once($CFG->dirroot . '/filter/algebra/lib.php');
|
||||
require_once($CFG->dirroot . '/filter/tex/latex.php');
|
||||
|
||||
$action = optional_param('action', '', PARAM_ALPHANUM);
|
||||
$algebra = optional_param('algebra', '', PARAM_RAW);
|
||||
@@ -203,9 +205,8 @@ function tex2image($texexp, $md5, $return=false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$texexp = '\Large ' . $texexp;
|
||||
$image = $md5 . ".gif";
|
||||
$filetype = 'image/gif';
|
||||
$convertformat = get_config('filter_algebra', 'convertformat');
|
||||
$image = $md5 . ".{$convertformat}";
|
||||
if (!file_exists("$CFG->dataroot/filter/algebra")) {
|
||||
make_upload_directory("filter/algebra");
|
||||
}
|
||||
@@ -213,42 +214,22 @@ function tex2image($texexp, $md5, $return=false) {
|
||||
if (file_exists($pathname)) {
|
||||
unlink($pathname);
|
||||
}
|
||||
$commandpath = filter_tex_get_executable(true);
|
||||
$cmd = filter_tex_get_cmd($pathname, $texexp);
|
||||
system($cmd, $status);
|
||||
|
||||
// Render with LaTeX.
|
||||
$latex = new latex('filter_algebra');
|
||||
$density = get_config('filter_algebra', 'density');
|
||||
$background = get_config('filter_algebra', 'latexbackground');
|
||||
$lateximage = $latex->render($texexp, $image, 12, $density, $background);
|
||||
|
||||
if ($return) {
|
||||
return $image;
|
||||
}
|
||||
if (file_exists($pathname)) {
|
||||
if ($lateximage) {
|
||||
copy($lateximage, $pathname);
|
||||
send_file($pathname, $image);
|
||||
|
||||
} else {
|
||||
$ecmd = "$cmd 2>&1";
|
||||
echo `$ecmd` . "<br />\n";
|
||||
echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
|
||||
if ($status == 4) {
|
||||
echo "Status corresponds to illegal instruction<br />\n";
|
||||
} else if ($status == 11) {
|
||||
echo "Status corresponds to bus error<br />\n";
|
||||
} else if ($status == 22) {
|
||||
echo "Status corresponds to abnormal termination<br />\n";
|
||||
}
|
||||
if (file_exists($commandpath)) {
|
||||
echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "<br />";
|
||||
echo "The file permissions are: " . decoct(fileperms($commandpath)) . "<br />";
|
||||
if (function_exists("md5_file")) {
|
||||
echo "The md5 checksum of the file is " . md5_file($commandpath) . "<br />";
|
||||
} else {
|
||||
$handle = fopen($commandpath,"rb");
|
||||
$contents = fread($handle,16384);
|
||||
fclose($handle);
|
||||
echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br />";
|
||||
}
|
||||
} else {
|
||||
echo "mimetex executable $commandpath not found!<br />";
|
||||
}
|
||||
echo "Image not found!";
|
||||
echo "Image not found!<br />";
|
||||
echo "Please check that LaTeX tools are properly configured in the filter settings.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +295,7 @@ looks for the TeX translation in the Moodle database in the table cache_filters
|
||||
in the field rawtext. If not found, it passes the algebraic expression to the
|
||||
Perl script algebra2tex.pl, which also uses the Perl library AlgParser.pm.
|
||||
It then saves the TeX translation in the database for subsequent uses and
|
||||
passes the TeX to the mimetex executable to be converted to a gif image.
|
||||
passes the TeX to the LaTeX renderer to be converted to a png/gif/svg image.
|
||||
Here are a few common things that can go wrong and some suggestions on how
|
||||
you might try to fix them.</p>
|
||||
<ol>
|
||||
@@ -334,12 +315,11 @@ on the algebra2tex.pl script. In that case change permissions accordingly</li>
|
||||
a bug in the algebra filter. Post the original algebraic expression and the
|
||||
bad TeX translation in the <a href="http://moodle.org/mod/forum/view.php?id=752">
|
||||
Mathematics Tools</a> forum in the Using Moodle course on moodle.org.</li>
|
||||
<li>The TeX to gif image conversion process does not work. If your server is
|
||||
running Unix, a likely cause is that the mimetex binary you are using is
|
||||
incompatible with your operating system. You can try compiling it from the
|
||||
C sources downloaded from <a href="http://www.forkosh.com/mimetex.zip">
|
||||
http://www.forkosh.com/mimetex.zip</a>. Lastly check the execute permissions
|
||||
on your mimetex binary, as outlined in item 2 above.</li>
|
||||
<li>The TeX to png/gif/svg image conversion process does not work. This requires
|
||||
LaTeX tools to be properly installed and configured. Check that the paths
|
||||
to latex, dvips, convert/dvisvgm are correctly set in the filter_algebra
|
||||
settings. Make sure that you have all the packages installed. Lastly check
|
||||
the execute permissions on your LaTeX binaries, as outlined in item 2 above.</li>
|
||||
</ol>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -19,25 +19,18 @@ namespace filter_algebra;
|
||||
use core\context\system as context_system;
|
||||
use core\output\actions\popup_action;
|
||||
use core\url;
|
||||
use core_useragent;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Moodle - Filter for converting simple calculator-type algebraic expressions to cached gif images
|
||||
* Moodle - Filter for converting simple calculator-type algebraic expressions to cached images
|
||||
*
|
||||
* NOTE: This Moodle text filter converts algebraic expressions delimited
|
||||
* by either @@...@@ or by <algebra...>...</algebra> tags
|
||||
* first converts it to TeX using WeBWorK algebra parser Perl library
|
||||
* AlgParser.pm, part of the WeBWorK distribution obtained from
|
||||
* http://webhost.math.rochester.edu/downloadwebwork/
|
||||
* then converts the TeX to gif images using
|
||||
* mimetex.cgi obtained from http://www.forkosh.com/mimetex.html authored by
|
||||
* John Forkosh [email protected]. The mimetex.cgi ELF binary compiled for Linux i386
|
||||
* as well as AlgParser.pm are included with this distribution.
|
||||
* Note that there may be patent restrictions on the production of gif images
|
||||
* in Canada and some parts of Western Europe and Japan until July 2004.
|
||||
* -------------------------------------------------------------------------
|
||||
* You will then need to edit your moodle/config.php to invoke mathml_filter.php
|
||||
* -------------------------------------------------------------------------
|
||||
* then converts the TeX to PNG or SVG images using LaTeX tools.
|
||||
*
|
||||
* @package filter_algebra
|
||||
* @subpackage algebra
|
||||
@@ -92,7 +85,11 @@ class text_filter extends \core_filters\text_filter {
|
||||
}
|
||||
|
||||
$md5 = md5($algebra);
|
||||
$filename = $md5 . ".gif";
|
||||
$convertformat = get_config('filter_algebra', 'convertformat');
|
||||
if ($convertformat == 'svg' && !core_useragent::supports_svg()) {
|
||||
$convertformat = 'png';
|
||||
}
|
||||
$filename = $md5 . ".{$convertformat}";
|
||||
if (! $texcache = $DB->get_record("cache_filters", ["filter" => "algebra", "md5key" => $md5])) {
|
||||
$algebra = str_replace('<', '<', $algebra);
|
||||
$algebra = str_replace('>', '>', $algebra);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Algebra filter upgrade code.
|
||||
*
|
||||
* @package filter_algebra
|
||||
* @copyright 2025 Yusuf Wibisono <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* Upgrade function for the algebra filter.
|
||||
*
|
||||
* @param int $oldversion the version we are upgrading from
|
||||
* @return bool result
|
||||
*/
|
||||
function xmldb_filter_algebra_upgrade($oldversion) {
|
||||
|
||||
if ($oldversion < 2025122200) {
|
||||
global $OUTPUT;
|
||||
|
||||
// Show notification if filter_algebra is enabled.
|
||||
if (filter_is_enabled('algebra')) {
|
||||
echo $OUTPUT->notification(get_string('mimetexdeprecated', 'admin', ['plugin_name' => 'filter_algebra']), 'info');
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2025122200, 'filter', 'algebra');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -23,6 +22,14 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['filtername'] = 'Algebra notation';
|
||||
$string['algebraicexpression'] = 'Algebraic expression';
|
||||
$string['configconvertformat'] = 'If <i>latex</i> and <i>dvips</i> are present in addition to <i>convert</i> or <i>dvisvgm</i>, select the preferred image type (<i>convert</i> produces PNG or GIF; <i>dvisvgm</i> produces SVG).';
|
||||
$string['convertformat'] = 'Output image format';
|
||||
$string['filtername'] = 'Algebra notation';
|
||||
$string['latexpreamble'] = 'LaTeX preamble';
|
||||
$string['latexsettings'] = 'LaTeX renderer Settings';
|
||||
$string['pathconvert'] = 'Path of <i>convert</i> binary';
|
||||
$string['pathdvips'] = 'Path of <i>dvips</i> binary';
|
||||
$string['pathdvisvgm'] = 'Path of <i>dvisvgm</i> binary';
|
||||
$string['pathlatex'] = 'Path of <i>latex</i> binary';
|
||||
$string['privacy:metadata'] = 'The Algebra notation plugin does not store any personal data.';
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Algebra filter library functions.
|
||||
*
|
||||
* @package filter_algebra
|
||||
* @copyright 2025 Yusuf Wibisono <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Purge all caches when settings changed.
|
||||
*
|
||||
* @param string $name The name of the setting that was changed.
|
||||
*/
|
||||
function filter_algebra_updatedcallback($name) {
|
||||
global $CFG, $DB;
|
||||
reset_text_filters_cache();
|
||||
|
||||
if (file_exists("$CFG->dataroot/filter/algebra")) {
|
||||
remove_dir("$CFG->dataroot/filter/algebra");
|
||||
}
|
||||
if (file_exists("$CFG->tempdir/latex")) {
|
||||
remove_dir("$CFG->tempdir/latex");
|
||||
}
|
||||
|
||||
$DB->delete_records('cache_filters', ['filter' => 'algebra']);
|
||||
|
||||
$pathlatex = get_config('filter_algebra', 'pathlatex');
|
||||
if ($pathlatex === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$pathlatex = trim($pathlatex, " '\"");
|
||||
$pathdvips = trim(get_config('filter_algebra', 'pathdvips'), " '\"");
|
||||
$pathconvert = trim(get_config('filter_algebra', 'pathconvert'), " '\"");
|
||||
$pathdvisvgm = trim(get_config('filter_algebra', 'pathdvisvgm'), " '\"");
|
||||
|
||||
$supportedformats = [];
|
||||
if (
|
||||
(is_file($pathlatex) && is_executable($pathlatex)) &&
|
||||
(is_file($pathdvips) && is_executable($pathdvips))
|
||||
) {
|
||||
if (is_file($pathconvert) && is_executable($pathconvert)) {
|
||||
$supportedformats[] = 'png';
|
||||
$supportedformats[] = 'gif';
|
||||
}
|
||||
if (is_file($pathdvisvgm) && is_executable($pathdvisvgm)) {
|
||||
$supportedformats[] = 'svg';
|
||||
}
|
||||
}
|
||||
// If no formats are supported, default to PNG (even if tools aren't available, admin can configure later).
|
||||
if (empty($supportedformats)) {
|
||||
$supportedformats[] = 'png';
|
||||
}
|
||||
if (!in_array(get_config('filter_algebra', 'convertformat'), $supportedformats)) {
|
||||
set_config('convertformat', $supportedformats[0], 'filter_algebra');
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
// This function fetches math. images from the data directory
|
||||
// If not, it obtains the corresponding TeX expression from the cache_tex db table
|
||||
// and uses mimeTeX to create the image file
|
||||
// If not, it obtains the corresponding TeX expression from the cache_filters db table
|
||||
// and uses LaTeX to create the image file.
|
||||
|
||||
// disable moodle specific debug messages and any errors in output
|
||||
define('NO_DEBUG_DISPLAY', true);
|
||||
@@ -15,9 +15,7 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
||||
|
||||
require_once($CFG->libdir.'/filelib.php');
|
||||
require_once($CFG->dirroot.'/filter/tex/lib.php');
|
||||
|
||||
$cmd = ''; // Initialise these variables
|
||||
$status = '';
|
||||
require_once($CFG->dirroot . '/filter/tex/latex.php');
|
||||
|
||||
$relativepath = get_file_argument();
|
||||
|
||||
@@ -31,27 +29,35 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
||||
}
|
||||
|
||||
if (!file_exists($pathname)) {
|
||||
$md5 = str_replace('.gif','',$image);
|
||||
$convertformat = get_config('filter_algebra', 'convertformat');
|
||||
if (strpos($image, '.png')) {
|
||||
$convertformat = 'png';
|
||||
}
|
||||
$md5 = str_replace(".{$convertformat}", '', $image);
|
||||
if ($texcache = $DB->get_record('cache_filters', array('filter'=>'algebra', 'md5key'=>$md5))) {
|
||||
if (!file_exists($CFG->dataroot.'/filter/algebra')) {
|
||||
make_upload_directory('filter/algebra');
|
||||
}
|
||||
|
||||
// Render with LaTeX.
|
||||
$latex = new latex('filter_algebra');
|
||||
$density = get_config('filter_algebra', 'density');
|
||||
$background = get_config('filter_algebra', 'latexbackground');
|
||||
$texexp = $texcache->rawtext;
|
||||
$texexp = str_replace('<','<',$texexp);
|
||||
$texexp = str_replace('>','>',$texexp);
|
||||
$texexp = preg_replace('!\r\n?!',' ',$texexp);
|
||||
$texexp = '\Large ' . $texexp;
|
||||
$cmd = filter_tex_get_cmd($pathname, $texexp);
|
||||
system($cmd, $status);
|
||||
$lateximage = $latex->render($texexp, $image, 12, $density, $background);
|
||||
if ($lateximage) {
|
||||
copy($lateximage, $pathname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists($pathname)) {
|
||||
send_file($pathname, $image);
|
||||
send_file($pathname, $image, YEARSECS, 0, false, false, '', false, [
|
||||
'cacheability' => 'public',
|
||||
'immutable' => true,
|
||||
]);
|
||||
} else {
|
||||
if (debugging()) {
|
||||
echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
|
||||
echo "Image not found!<br />";
|
||||
echo "Please try the <a href=\"$CFG->wwwroot/filter/algebra/algebradebug.php\">debugging script</a>";
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Algebra filter settings
|
||||
*
|
||||
* @package filter_algebra
|
||||
* @copyright 2025 Yusuf Wibisono <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
if ($ADMIN->fulltree) {
|
||||
require_once($CFG->dirroot . '/filter/algebra/lib.php');
|
||||
|
||||
$items = [];
|
||||
$items[] = new admin_setting_heading('filter_algebra/latexheading', get_string('latexsettings', 'filter_algebra'), '');
|
||||
$items[] = new admin_setting_configtextarea(
|
||||
'filter_algebra/latexpreamble',
|
||||
get_string('latexpreamble', 'filter_algebra'),
|
||||
'',
|
||||
"\\usepackage[latin1]{inputenc}\n\\usepackage{amsmath}\n" .
|
||||
"\\usepackage{amsfonts}\n\\RequirePackage{amsmath,amssymb,latexsym}\n"
|
||||
);
|
||||
$items[] = new admin_setting_configtext(
|
||||
'filter_algebra/latexbackground',
|
||||
get_string('backgroundcolour', 'admin'),
|
||||
'',
|
||||
'#FFFFFF'
|
||||
);
|
||||
$items[] = new admin_setting_configtext('filter_algebra/density', get_string('density', 'admin'), '', '120', PARAM_INT);
|
||||
|
||||
$defaultfilteralgebrapathlatex = '';
|
||||
$defaultfilteralgebrapathdvips = '';
|
||||
$defaultfilteralgebrapathdvisvgm = '';
|
||||
$defaultfilteralgebrapathconvert = '';
|
||||
if (PHP_OS == 'Linux') {
|
||||
$defaultfilteralgebrapathlatex = "/usr/bin/latex";
|
||||
$defaultfilteralgebrapathdvips = "/usr/bin/dvips";
|
||||
$defaultfilteralgebrapathdvisvgm = "/usr/bin/dvisvgm";
|
||||
$defaultfilteralgebrapathconvert = "/usr/bin/convert";
|
||||
} else if (PHP_OS == 'Darwin') {
|
||||
// Most likely needs a fink install (fink.sf.net).
|
||||
$defaultfilteralgebrapathlatex = "/sw/bin/latex";
|
||||
$defaultfilteralgebrapathdvips = "/sw/bin/dvips";
|
||||
$defaultfilteralgebrapathdvisvgm = "/usr/bin/dvisvgm";
|
||||
$defaultfilteralgebrapathconvert = "/sw/bin/convert";
|
||||
} else if (PHP_OS == 'WINNT' || PHP_OS == 'WIN32' || PHP_OS == 'Windows') {
|
||||
// Note: you need Ghostscript installed (standard), miktex (standard)
|
||||
// and ImageMagick (install at c:\ImageMagick).
|
||||
$defaultfilteralgebrapathlatex = "c:\\texmf\\miktex\\bin\\latex.exe";
|
||||
$defaultfilteralgebrapathdvips = "c:\\texmf\\miktex\\bin\\dvips.exe";
|
||||
$defaultfilteralgebrapathdvisvgm = "c:\\texmf\\miktex\\bin\\dvisvgm.exe";
|
||||
$defaultfilteralgebrapathconvert = "c:\\imagemagick\\convert.exe";
|
||||
}
|
||||
|
||||
$pathlatex = get_config('filter_algebra', 'pathlatex');
|
||||
$pathdvips = get_config('filter_algebra', 'pathdvips');
|
||||
$pathconvert = get_config('filter_algebra', 'pathconvert');
|
||||
$pathdvisvgm = get_config('filter_algebra', 'pathdvisvgm');
|
||||
if (
|
||||
strrpos($pathlatex . $pathdvips . $pathconvert . $pathdvisvgm, '"') ||
|
||||
strrpos($pathlatex . $pathdvips . $pathconvert . $pathdvisvgm, "'")
|
||||
) {
|
||||
set_config('pathlatex', trim($pathlatex, " '\""), 'filter_algebra');
|
||||
set_config('pathdvips', trim($pathdvips, " '\""), 'filter_algebra');
|
||||
set_config('pathconvert', trim($pathconvert, " '\""), 'filter_algebra');
|
||||
set_config('pathdvisvgm', trim($pathdvisvgm, " '\""), 'filter_algebra');
|
||||
}
|
||||
|
||||
$items[] = new admin_setting_configexecutable(
|
||||
'filter_algebra/pathlatex',
|
||||
get_string('pathlatex', 'filter_algebra'),
|
||||
'',
|
||||
$defaultfilteralgebrapathlatex
|
||||
);
|
||||
$items[] = new admin_setting_configexecutable(
|
||||
'filter_algebra/pathdvips',
|
||||
get_string('pathdvips', 'filter_algebra'),
|
||||
'',
|
||||
$defaultfilteralgebrapathdvips
|
||||
);
|
||||
$items[] = new admin_setting_configexecutable(
|
||||
'filter_algebra/pathconvert',
|
||||
get_string('pathconvert', 'filter_algebra'),
|
||||
'',
|
||||
$defaultfilteralgebrapathconvert
|
||||
);
|
||||
$items[] = new admin_setting_configexecutable(
|
||||
'filter_algebra/pathdvisvgm',
|
||||
get_string('pathdvisvgm', 'filter_algebra'),
|
||||
'',
|
||||
$defaultfilteralgebrapathdvisvgm
|
||||
);
|
||||
|
||||
// The update callback checks whether required paths actually point to executables.
|
||||
// If they don't, we force the setting to PNG as the default fallback format.
|
||||
$formats = ['png' => 'PNG', 'gif' => 'GIF', 'svg' => 'SVG'];
|
||||
$items[] = new admin_setting_configselect(
|
||||
'filter_algebra/convertformat',
|
||||
get_string('convertformat', 'filter_algebra'),
|
||||
get_string('configconvertformat', 'filter_algebra'),
|
||||
'png',
|
||||
$formats
|
||||
);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->set_updatedcallback('filter_algebra_updatedcallback');
|
||||
$settings->add($item);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2025100600; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2025122200; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2025092600; // Requires this Moodle version.
|
||||
$plugin->component = 'filter_algebra'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->dependencies = ['filter_tex' => 2025122200];
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
March 31, 2012 Version 1.74
|
||||
|
||||
m i m e T e X R e a d m e F i l e
|
||||
|
||||
Copyright(c) 2002-2012, John Forkosh Associates, Inc. All rights reserved.
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
by: John Forkosh
|
||||
[email protected] www.forkosh.com
|
||||
|
||||
This file is part of mimeTeX, which is free software.
|
||||
You may redistribute and/or modify it under the terms
|
||||
of the GNU General Public License, version 3 or later,
|
||||
as published by the Free Software Foundation. See
|
||||
http://www.gnu.org/licenses/gpl.html
|
||||
|
||||
MimeTeX is discussed and illustrated online at
|
||||
its homepage
|
||||
http://www.forkosh.com/mimetex.html
|
||||
Or you can follow the Quick Start instructions below
|
||||
(or the more detailed instructions in Section III)
|
||||
to immediately install mimeTeX on your own machine.
|
||||
Then point your browser to
|
||||
http://www.yourdomain.com/mimetex.html
|
||||
for a demo/tutorial and reference.
|
||||
Installation problems? Point your browser to
|
||||
mimeTeX's homepage
|
||||
http://www.forkosh.com/mimetex.html
|
||||
then click its "full mimeTeX manual" link and see
|
||||
Section II.
|
||||
|
||||
|
||||
I. QUICK START
|
||||
------------------------------------------------------------------------
|
||||
To compile and install mimeTeX
|
||||
* unzip mimetex.zip in any convenient working directory
|
||||
* to produce an executable that emits anti-aliased
|
||||
gif images (recommended)
|
||||
cc -DAA mimetex.c gifsave.c -lm -o mimetex.cgi
|
||||
-or- for gif images without anti-aliasing
|
||||
cc -DGIF mimetex.c gifsave.c -lm -o mimetex.cgi
|
||||
-or- to produce an executable that emits mime xbitmaps
|
||||
cc -DXBITMAP mimetex.c -lm -o mimetex.cgi
|
||||
(For Windows, see "Compile Notes" in Section III below.)
|
||||
* mv mimetex.cgi to your server's cgi-bin/ directory
|
||||
* mv mimetex.html to your server's htdocs/ directory
|
||||
* if the relative path from htdocs to cgi-bin isn't
|
||||
../cgi-bin then edit mimetex.html and change the
|
||||
few dozen occurrences as necessary.
|
||||
Then, to quickly learn more about mimeTeX
|
||||
* point your browser to www.yourdomain.com/mimetex.html
|
||||
Any problems with the above?
|
||||
* read the more detailed instructions below,
|
||||
or see http://www.forkosh.com/mimetex.html
|
||||
|
||||
|
||||
II. INTRODUCTION
|
||||
------------------------------------------------------------------------
|
||||
MimeTeX, licensed under the gpl, lets you easily embed LaTeX math in
|
||||
your html pages. It parses a LaTeX math expression and immediately
|
||||
emits the corresponding gif image, rather than the usual TeX dvi.
|
||||
And mimeTeX is an entirely separate little program that doesn't
|
||||
use TeX or its fonts in any way. It's just one cgi that you put in
|
||||
your site's cgi-bin/ directory, with no other dependencies.
|
||||
So mimeTeX is very easy to install. And it's equally easy to use.
|
||||
Just place an html <img> tag in your document wherever you want to
|
||||
see the corresponding LaTeX expression. For example,
|
||||
<img src="../cgi-bin/mimetex.cgi?f(x)=\int_{-\infty}^x~e^{-t^2}dt"
|
||||
border=0 align=absmiddle>
|
||||
generates and displays the corresponding gif image on-the-fly,
|
||||
wherever you put that <img> tag. MimeTeX doesn't need intermediate
|
||||
dvi-to-gif conversion, and it doesn't clutter your filesystem with
|
||||
separate little gif files for each converted expression. (Optional
|
||||
image caching does store gif files, and subsequently reads them as
|
||||
needed, rather than re-rendering the same images every time a page
|
||||
is reloaded.)
|
||||
|
||||
|
||||
III. COMPILATION AND INSTALLATION
|
||||
------------------------------------------------------------------------
|
||||
I've built and run mimeTeX under Linux and NetBSD using gcc.
|
||||
The source code is ansi-standard C, and should compile
|
||||
and execute under all environments without any change whatsoever.
|
||||
Build instructions below are for Unix. Modify them as necessary
|
||||
for your particular situation. Note the -DWINDOWS switch if
|
||||
applicable.
|
||||
|
||||
Unzip mimetex.zip in any convenient working directory.
|
||||
Your working directory should now contain
|
||||
mimetex.zip your gnu zipped mimeTeX distribution containing...
|
||||
README this file (see mimetex.html for demo/tutorial)
|
||||
COPYING GPL license, under which you may use mimeTeX
|
||||
mimetex.c mimeTeX source program and all required functions
|
||||
mimetex.h header file for mimetex.c (and for gfuntype.c)
|
||||
gfuntype.c parses output from gftype -i and writes bitmap data
|
||||
texfonts.h output from several gfuntype runs, needed by mimetex.c
|
||||
gifsave.c gif library by Sverre H. Huseby <[email protected]>
|
||||
mimetex.html sample html document, mimeTeX demo and tutorial
|
||||
Note: all files in mimetex.zip use Unix line termination,
|
||||
i.e., linefeeds (without carriage returns) signal line endings.
|
||||
Conversion for Windows, Macs, VMS, etc, can usually be accomplished
|
||||
with unzip's -a option, i.e., unzip -a mimetex.zip
|
||||
|
||||
Now, to compile a mimeTeX executable that emits anti-aliased gif
|
||||
images (recommended for most uses), type the command
|
||||
cc -DAA mimetex.c gifsave.c -lm -o mimetex.cgi
|
||||
|
||||
Or, for an executable that emits gif images without
|
||||
anti-aliasing,
|
||||
cc -DGIF mimetex.c gifsave.c -lm -o mimetex.cgi
|
||||
|
||||
Alternatively, to compile a mimeTeX executable that emits
|
||||
mime xbitmaps, just type the command
|
||||
cc -DXBITMAP mimetex.c -lm -o mimetex.cgi
|
||||
|
||||
Compile Notes:
|
||||
* If (and only if) you're compiling a Windows executable
|
||||
with the -DAA or -DGIF option (but not -DXBITMAP), then
|
||||
add -DWINDOWS also. For example,
|
||||
cc -DAA -DWINDOWS mimetex.c gifsave.c -lm -o mimetex.cgi
|
||||
The above Unix-like syntax works with MinGW (http://www.mingw.org)
|
||||
and djgpp (http://www.delorie.com/djgpp/) Windows compilers, but
|
||||
probably not with most others, where it's only intended as a
|
||||
"template".
|
||||
* Several additional command-line options that you may find
|
||||
useful are discussed in Section IId (href="#options")
|
||||
of your mimetex.html page.
|
||||
|
||||
That's all there is to building mimeTeX. You can now test your
|
||||
mimetex.cgi executable from the Unix command line by typing, e.g.,
|
||||
./mimetex.cgi "x^2+y^2"
|
||||
which should emit two ascii rasters something like the following
|
||||
Ascii dump of bitmap image... Hex dump of colormap indexes...
|
||||
........**..................**.. .......1**1................1**1.
|
||||
.......*..*.....*..........*..*. .......*23*.....*..........*23*.
|
||||
..........*.....*.............*. ..........*.....*.............*.
|
||||
.***......*.....*....**.*.....*. .***1....2*.....*....**3*....2*.
|
||||
.**.*....*......*....**.*....*.. .**.*...1*......*....**.*...1*..
|
||||
..*.....*.*..******...*.*...*.*. ..*....2*.*..******...*.*..2*.*.
|
||||
**.*...****.....*....*.*...****. **.*...****.....*....*.*2..****.
|
||||
****............*.....**........ ****............*....1**........
|
||||
................*......*........ ................*......*........
|
||||
................*....**......... ................*....**1........
|
||||
The 5 colormap indexes denote rgb...
|
||||
.-->255 1-->196 2-->186 3-->177 *-->0
|
||||
The right-hand illustration shows asterisks in the same positions as
|
||||
the left-hand one, along with anti-aliased grayscale colormap indexes
|
||||
assigned to neighboring pixels, and with the rgb value for each
|
||||
index. Just typing ./mimetex.cgi without an argument should produce
|
||||
ascii rasters for the default expression f(x)=x^2. If you see the
|
||||
two ascii rasters then your binary's good, so mv it to your server's
|
||||
cgi-bin/ directory and set permissions as necessary.
|
||||
|
||||
Once mimetex.cgi is working, mv it to your server's cgi-bin/ directory
|
||||
(wherever cgi programs are expected), and chmod/chown it as necessary.
|
||||
Then mv mimetex.html to your server's htdocs/ directory. Now point
|
||||
your browser to www.yourdomain.com/mimetex.html and you should see
|
||||
your mimeTeX user's manual reference page.
|
||||
|
||||
Install Notes:
|
||||
* These two directories are typically of the form
|
||||
somewhere/www/cgi-bin/ and somewhere/www/htdocs/
|
||||
so I set up mimtex.html to access mimetex.cgi from
|
||||
the relative path ../cgi-bin/ If your directories
|
||||
are non-conforming, you may have to edit the few dozen
|
||||
occurrences of ../cgi-bin/mimetex.cgi in mimetex.html
|
||||
Sometimes a suitable symlink works. If not, you'll
|
||||
have to edit. In that case, globally changing
|
||||
../cgi-bin/mimetex.cgi often works.
|
||||
* Either way, once mimetex.html displays properly, you can
|
||||
assume everything is working, and can begin authoring html
|
||||
documents using mimetex.cgi to render your own math.
|
||||
|
||||
|
||||
IV. REVISION HISTORY
|
||||
------------------------------------------------------------------------
|
||||
A more detailed account of mimeTeX's revision history
|
||||
is maintained at http://www.forkosh.com/mimetexchangelog.html
|
||||
---
|
||||
03/31/12 J.Forkosh version 1.74 released.
|
||||
08/24/11 J.Forkosh version 1.72 released.
|
||||
09/06/08 J.Forkosh version 1.70 released.
|
||||
11/30/04 J.Forkosh version 1.60 released
|
||||
10/02/04 J.Forkosh version 1.50 released on CTAN with various new
|
||||
features and fixes, and updated documentation.
|
||||
07/18/04 J.Forkosh version 1.40 re-released on CTAN with minor
|
||||
changes, e.g., \mathbb font and nested \array's
|
||||
now supported.
|
||||
03/21/04 J.Forkosh version 1.40 released on CTAN, with improved
|
||||
LaTeX compatibility, various new features and
|
||||
fixes, including fix to work under Windows.
|
||||
12/21/03 J.Forkosh version 1.30 released on CTAN, with improved
|
||||
LaTeX compatibility and anti-aliasing, various new
|
||||
features, and thoroughly updated documentation.
|
||||
10/17/03 J.Forkosh version 1.20 released on CTAN, adding picture
|
||||
environment and various other changes (e.g.,
|
||||
more delimiters arbitrarily sized) and fixes.
|
||||
07/29/03 J.Forkosh version 1.10 released on CTAN, completely replacing
|
||||
mimeTeX's original built-in fonts with thinner and
|
||||
more pleasing fonts, and adding one larger size.
|
||||
06/27/03 J.Forkosh version 1.01 released on CTAN, adding lowpass
|
||||
anti-aliasing for gifs, and http_referer checks,
|
||||
and fixing a few very obscure bugs.
|
||||
12/11/02 J.Forkosh version 1.00 released on CTAN, fixing \array bug
|
||||
and adding various new features.
|
||||
10/31/02 J.Forkosh version 0.99 released on CTAN
|
||||
09/18/02 J.Forkosh internal beta test release
|
||||
|
||||
|
||||
V. CONCLUDING REMARKS
|
||||
------------------------------------------------------------------------
|
||||
I hope you find mimeTeX useful. If so, a contribution to your
|
||||
country's TeX Users Group, or to the GNU project, is suggested,
|
||||
especially if you're a company that's currently profitable.
|
||||
========================= END-OF-FILE README ===========================
|
||||
|
||||
@@ -24,15 +24,11 @@ use core_useragent;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Moodle - Filter for converting TeX expressions to cached gif images
|
||||
* Moodle - Filter for converting TeX expressions to cached images
|
||||
*
|
||||
* This Moodle text filter converts TeX expressions delimited
|
||||
* by either $$...$$ or by <tex...>...</tex> tags to gif images using
|
||||
* mimetex.cgi obtained from http: *www.forkosh.com/mimetex.html authored by
|
||||
* John Forkosh [email protected]. Several binaries of this areincluded with
|
||||
* this distribution.
|
||||
* Note that there may be patent restrictions on the production of gif images
|
||||
* in Canada and some parts of Western Europe and Japan until July 2004.
|
||||
* by either $$...$$ or by <tex...>...</tex> tags to PNG, GIF, or SVG images using
|
||||
* LaTeX tools (latex, dvips, convert/dvisvgm).
|
||||
*
|
||||
* @package filter_tex
|
||||
* @subpackage tex
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Upgrade function for the tex filter.
|
||||
*
|
||||
* @param int $oldversion the version we are upgrading from
|
||||
* @return bool result
|
||||
*/
|
||||
@@ -40,5 +42,20 @@ function xmldb_filter_tex_upgrade($oldversion) {
|
||||
// Automatically generated Moodle v5.1.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2025122200) {
|
||||
global $OUTPUT;
|
||||
|
||||
// Remove MimeTeX configuration setting as MimeTeX support has been removed.
|
||||
unset_config('pathmimetex', 'filter_tex');
|
||||
|
||||
// Show notification if filter_tex is enabled.
|
||||
if (filter_is_enabled('tex')) {
|
||||
echo $OUTPUT->notification(get_string('mimetexdeprecated', 'admin', ['plugin_name' => 'filter_tex']), 'info');
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_plugin_savepoint(true, 2025122200, 'filter', 'tex');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -23,16 +23,14 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['configconvertformat'] = 'If <i>latex</i> and <i>dvips</i> are present in addition to <i>convert</i> or <i>dvisvgm</i>, select the preferred image type (<i>convert</i> produces GIF or PNG; <i>dvisvgm</i> produces SVG). Otherwise <i>mimeTeX</i> will be used to to create GIF images.';
|
||||
$string['configconvertformat'] = 'If <i>latex</i> and <i>dvips</i> are present in addition to <i>convert</i> or <i>dvisvgm</i>, select the preferred image type (<i>convert</i> produces PNG or GIF; <i>dvisvgm</i> produces SVG).';
|
||||
$string['convertformat'] = 'Output image format';
|
||||
$string['filtername'] = 'TeX notation';
|
||||
$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['pathdvisvgm'] = 'Path of <i>dvisvgm</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';
|
||||
$string['privacy:metadata'] = 'The TeX notation plugin does not store any personal data.';
|
||||
$string['source'] = 'TeX source';
|
||||
|
||||
+17
-11
@@ -13,14 +13,20 @@
|
||||
/** @var bool To store value of supported_platform. */
|
||||
protected $supported_platform;
|
||||
|
||||
/** @var string Plugin name to use for configuration (e.g., 'filter_tex' or 'filter_algebra') */
|
||||
protected $pluginname;
|
||||
|
||||
/**
|
||||
* Constructor - create temporary directories and build paths to
|
||||
* external 'helper' binaries.
|
||||
* Other platforms could/should be added
|
||||
*
|
||||
* @param string $pluginname Plugin name to use for configuration (default: 'filter_tex')
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct($pluginname = 'filter_tex') {
|
||||
// Construct directory structure.
|
||||
$this->temp_dir = make_request_directory();
|
||||
$this->pluginname = $pluginname;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +46,7 @@
|
||||
function construct_latex_document($formula, $fontsize = 12) {
|
||||
// $fontsize don't affects to formula's size. $density can change size
|
||||
$doc = "\\documentclass[{$fontsize}pt]{article}\n";
|
||||
$doc .= get_config('filter_tex', 'latexpreamble');
|
||||
$doc .= get_config($this->pluginname, 'latexpreamble');
|
||||
$doc .= "\\pagestyle{empty}\n";
|
||||
$doc .= "\\begin{document}\n";
|
||||
if (preg_match("/^[[:space:]]*\\\\begin\\{(gather|align|alignat|multline).?\\}/i", $formula)) {
|
||||
@@ -76,21 +82,21 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* Render TeX string into gif/png
|
||||
* Render TeX string into PNG, GIF, or SVG
|
||||
* @param string $formula TeX formula
|
||||
* @param string $filename filename for output (including extension)
|
||||
* @param int $fontsize font size
|
||||
* @param int $density density value for .ps to .gif/.png conversion
|
||||
* @param int $density density value for .ps to .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
|
||||
* @return string|false path to image file if successful, false otherwise
|
||||
*/
|
||||
function render($formula, $filename, $fontsize=12, $density=240, $background='', $log=null ) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
// quick check - will this work?
|
||||
$pathlatex = get_config('filter_tex', 'pathlatex');
|
||||
$pathlatex = get_config($this->pluginname, 'pathlatex');
|
||||
if (empty($pathlatex)) {
|
||||
return false;
|
||||
}
|
||||
@@ -99,7 +105,7 @@
|
||||
$doc = $this->construct_latex_document( $formula, $fontsize );
|
||||
|
||||
// construct some file paths
|
||||
$convertformat = get_config('filter_tex', 'convertformat');
|
||||
$convertformat = get_config($this->pluginname, 'convertformat');
|
||||
if (!strpos($filename, ".{$convertformat}")) {
|
||||
$convertformat = 'png';
|
||||
}
|
||||
@@ -125,23 +131,23 @@
|
||||
}
|
||||
|
||||
// run dvips (.dvi to .ps)
|
||||
$pathdvips = escapeshellarg(trim(get_config('filter_tex', 'pathdvips'), " '\""));
|
||||
$pathdvips = escapeshellarg(trim(get_config($this->pluginname, 'pathdvips'), " '\""));
|
||||
$command = "$pathdvips -q -E $dvi -o $ps";
|
||||
if ($this->execute($command, $log )) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Run convert on document (.ps to .gif/.png) or run dvisvgm (.ps to .svg).
|
||||
// Run convert on document (.ps to .png/.gif) or run dvisvgm (.ps to .svg).
|
||||
if ($background) {
|
||||
$bg_opt = "-transparent \"$background\""; // Makes transparent background
|
||||
} else {
|
||||
$bg_opt = "";
|
||||
}
|
||||
if ($convertformat == 'svg') {
|
||||
$pathdvisvgm = escapeshellarg(trim(get_config('filter_tex', 'pathdvisvgm'), " '\""));
|
||||
$pathdvisvgm = escapeshellarg(trim(get_config($this->pluginname, 'pathdvisvgm'), " '\""));
|
||||
$command = "$pathdvisvgm -E $ps -o $img";
|
||||
} else {
|
||||
$pathconvert = escapeshellarg(trim(get_config('filter_tex', 'pathconvert'), " '\""));
|
||||
$pathconvert = escapeshellarg(trim(get_config($this->pluginname, 'pathconvert'), " '\""));
|
||||
$command = "$pathconvert -density $density -trim $bg_opt $ps $img";
|
||||
}
|
||||
if ($this->execute($command, $log )) {
|
||||
|
||||
@@ -26,44 +26,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
function filter_tex_get_executable($debug=false) {
|
||||
global $CFG;
|
||||
|
||||
if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
|
||||
return "$CFG->dirroot/filter/tex/mimetex.exe";
|
||||
}
|
||||
|
||||
if ($pathmimetex = get_config('filter_tex', 'pathmimetex')) {
|
||||
if (is_executable($pathmimetex)) {
|
||||
return $pathmimetex;
|
||||
} else {
|
||||
throw new \moodle_exception('mimetexnotexecutable', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
$custom_commandpath = "$CFG->dirroot/filter/tex/mimetex";
|
||||
if (file_exists($custom_commandpath)) {
|
||||
if (is_executable($custom_commandpath)) {
|
||||
return $custom_commandpath;
|
||||
} else {
|
||||
throw new \moodle_exception('mimetexnotexecutable', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
switch (PHP_OS) {
|
||||
case "Darwin": return "$CFG->dirroot/filter/tex/mimetex.darwin";
|
||||
case "FreeBSD": return "$CFG->dirroot/filter/tex/mimetex.freebsd";
|
||||
case "Linux":
|
||||
if (php_uname('m') == 'aarch64') {
|
||||
return "$CFG->dirroot/filter/tex/mimetex.linux.aarch64";
|
||||
}
|
||||
|
||||
return "$CFG->dirroot/filter/tex/mimetex.linux";
|
||||
}
|
||||
|
||||
throw new \moodle_exception('mimetexisnotexist', 'error');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the formula expression against the list of denied keywords.
|
||||
*
|
||||
@@ -129,20 +91,6 @@ function filter_tex_sanitize_formula(string $texexp): string {
|
||||
return $texexp;
|
||||
}
|
||||
|
||||
function filter_tex_get_cmd($pathname, $texexp) {
|
||||
$texexp = filter_tex_sanitize_formula($texexp);
|
||||
$texexp = escapeshellarg($texexp);
|
||||
$executable = filter_tex_get_executable(false);
|
||||
|
||||
if ((PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
|
||||
$executable = str_replace(' ', '^ ', $executable);
|
||||
return "$executable ++ -e \"$pathname\" -- $texexp";
|
||||
|
||||
} else {
|
||||
return "\"$executable\" -e \"$pathname\" -- $texexp";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purge all caches when settings changed.
|
||||
*/
|
||||
@@ -153,15 +101,11 @@ function filter_tex_updatedcallback($name) {
|
||||
if (file_exists("$CFG->dataroot/filter/tex")) {
|
||||
remove_dir("$CFG->dataroot/filter/tex");
|
||||
}
|
||||
if (file_exists("$CFG->dataroot/filter/algebra")) {
|
||||
remove_dir("$CFG->dataroot/filter/algebra");
|
||||
}
|
||||
if (file_exists("$CFG->tempdir/latex")) {
|
||||
remove_dir("$CFG->tempdir/latex");
|
||||
}
|
||||
|
||||
$DB->delete_records('cache_filters', array('filter'=>'tex'));
|
||||
$DB->delete_records('cache_filters', array('filter'=>'algebra'));
|
||||
|
||||
$pathlatex = get_config('filter_tex', 'pathlatex');
|
||||
if ($pathlatex === false) {
|
||||
@@ -174,18 +118,23 @@ function filter_tex_updatedcallback($name) {
|
||||
$pathconvert = trim(get_config('filter_tex', 'pathconvert'), " '\"");
|
||||
$pathdvisvgm = trim(get_config('filter_tex', 'pathdvisvgm'), " '\"");
|
||||
|
||||
$supportedformats = array('gif');
|
||||
$supportedformats = [];
|
||||
if ((is_file($pathlatex) && is_executable($pathlatex)) &&
|
||||
(is_file($pathdvips) && is_executable($pathdvips))) {
|
||||
if (is_file($pathconvert) && is_executable($pathconvert)) {
|
||||
$supportedformats[] = 'png';
|
||||
$supportedformats[] = 'gif';
|
||||
}
|
||||
if (is_file($pathdvisvgm) && is_executable($pathdvisvgm)) {
|
||||
$supportedformats[] = 'svg';
|
||||
}
|
||||
}
|
||||
// If no formats are supported, default to PNG (even if tools aren't available, admin can configure later).
|
||||
if (empty($supportedformats)) {
|
||||
$supportedformats[] = 'png';
|
||||
}
|
||||
if (!in_array(get_config('filter_tex', 'convertformat'), $supportedformats)) {
|
||||
set_config('convertformat', array_pop($supportedformats), 'filter_tex');
|
||||
set_config('convertformat', $supportedformats[0], 'filter_tex');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
// This function fetches math. images from the data directory
|
||||
// If not, it obtains the corresponding TeX expression from the cache_tex db table
|
||||
// and uses mimeTeX to create the image file
|
||||
// and uses LaTeX to create the image file.
|
||||
|
||||
// disable moodle specific debug messages and any errors in output
|
||||
define('NO_DEBUG_DISPLAY', true);
|
||||
@@ -17,9 +17,6 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
||||
require_once($CFG->dirroot.'/filter/tex/lib.php');
|
||||
require_once($CFG->dirroot.'/filter/tex/latex.php');
|
||||
|
||||
$cmd = ''; // Initialise these variables
|
||||
$status = '';
|
||||
|
||||
$relativepath = get_file_argument();
|
||||
|
||||
$args = explode('/', trim($relativepath, '/'));
|
||||
@@ -42,7 +39,7 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
||||
make_upload_directory('filter/tex');
|
||||
}
|
||||
|
||||
// try and render with latex first
|
||||
// Render with LaTeX.
|
||||
$latex = new latex();
|
||||
$density = get_config('filter_tex', 'density');
|
||||
$background = get_config('filter_tex', 'latexbackground');
|
||||
@@ -50,15 +47,6 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
||||
$lateximage = $latex->render($texexp, $image, 12, $density, $background);
|
||||
if ($lateximage) {
|
||||
copy($lateximage, $pathname);
|
||||
} else {
|
||||
// failing that, use mimetex
|
||||
$texexp = $texcache->rawtext;
|
||||
$texexp = str_replace('<', '<', $texexp);
|
||||
$texexp = str_replace('>', '>', $texexp);
|
||||
$texexp = preg_replace('!\r\n?!', ' ', $texexp);
|
||||
$texexp = '\Large '.$texexp;
|
||||
$cmd = filter_tex_get_cmd($pathname, $texexp);
|
||||
system($cmd, $status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +58,6 @@ define('NO_MOODLE_COOKIES', true); // Because it interferes with caching
|
||||
]);
|
||||
} else {
|
||||
if (debugging()) {
|
||||
echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
|
||||
echo "Image not found!<br />";
|
||||
echo "Please try the <a href=\"$CFG->wwwroot/filter/tex/texdebug.php\">debugging script</a>";
|
||||
} else {
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
Description of mimeTeX v 1.77 import into Moodle
|
||||
|
||||
Compiling mimeTeX:
|
||||
|
||||
Windows
|
||||
=======
|
||||
1/ get "Automated MinGW-w64 Installer" from https://sourceforge.net/projects/mingw-w64/
|
||||
2/ install mingw
|
||||
3/ go into directory with extracted source files
|
||||
4/ execute "set path=%path%;c:\mingw-w64\bin"
|
||||
5/ execute "c:\mingw\bin\gcc -DAA -DWINDOWS mimetex.c gifsave.c -lm -o mimetex.exe"
|
||||
|
||||
Linux
|
||||
=====
|
||||
1/ install gcc
|
||||
2/ go into directory with extracted source files
|
||||
3/ execute "cc -DAA mimetex.c gifsave.c -lm -o mimetex.linux"
|
||||
|
||||
Linux aarch64
|
||||
=====
|
||||
1/ install gcc
|
||||
2/ go into directory with extracted source files
|
||||
3/ execute "cc -DAA mimetex.c gifsave.c -lm -o mimetex.linux.aarch64"
|
||||
|
||||
FreeBSD
|
||||
=======
|
||||
1/ go into directory with extracted source files
|
||||
2/ execute "cc -DAA mimetex.c gifsave.c -lm -o mimetex.freebsd"
|
||||
|
||||
Apple OSX
|
||||
=========
|
||||
1/ install XCode and command line tools
|
||||
2/ go into directory with extracted source files
|
||||
3/ execute "cc -DAA -arch i386 -arch x86_64 -mmacosx-version-min=10.5 mimetex.c gifsave.c -lm -o mimetex.darwin"
|
||||
|
||||
|
||||
Petr Skoda
|
||||
Sujith Haridasan
|
||||
@@ -77,13 +77,17 @@ if ($ADMIN->fulltree) {
|
||||
$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/pathdvisvgm', get_string('pathdvisvgm', 'filter_tex'), '', $default_filter_tex_pathdvisvgm);
|
||||
$items[] = new admin_setting_configexecutable('filter_tex/pathmimetex', get_string('pathmimetex', 'filter_tex'), get_string('pathmimetexdesc', 'filter_tex'), '');
|
||||
|
||||
// Even if we offer GIF, PNG and SVG formats here, in the update callback we check whether
|
||||
// required 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', 'svg' => 'SVG');
|
||||
$items[] = new admin_setting_configselect('filter_tex/convertformat', get_string('convertformat', 'filter_tex'), get_string('configconvertformat', 'filter_tex'), 'gif', $formats);
|
||||
// The update callback checks whether required paths actually point to executables.
|
||||
// If they don't, we force the setting to PNG as the default fallback format.
|
||||
$formats = ['png' => 'PNG', 'gif' => 'GIF', 'svg' => 'SVG'];
|
||||
$items[] = new admin_setting_configselect(
|
||||
'filter_tex/convertformat',
|
||||
get_string('convertformat', 'filter_tex'),
|
||||
get_string('configconvertformat', 'filter_tex'),
|
||||
'png',
|
||||
$formats
|
||||
);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->set_updatedcallback('filter_tex_updatedcallback');
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
/**
|
||||
* This function fetches math. images from the data directory
|
||||
* If not, it obtains the corresponding TeX expression from the cache_tex db table
|
||||
* and uses mimeTeX to create the image file
|
||||
* and uses LaTeX to create the image file
|
||||
*
|
||||
* @package filter
|
||||
* @subpackage tex
|
||||
@@ -84,11 +84,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Action: Show Image
|
||||
if ($action=='ShowImageMimetex') {
|
||||
tex2image($texexp);
|
||||
}
|
||||
|
||||
// Action: Check Slasharguments
|
||||
if ($action=='SlashArguments') {
|
||||
slasharguments($texexp);
|
||||
@@ -132,68 +127,6 @@
|
||||
echo "</pre></body></html>\n";
|
||||
}
|
||||
|
||||
function tex2image($texexp, $return=false) {
|
||||
global $CFG;
|
||||
|
||||
if (!$texexp) {
|
||||
echo 'No tex expresion specified';
|
||||
return;
|
||||
}
|
||||
|
||||
$image = md5($texexp) . ".gif";
|
||||
$filetype = 'image/gif';
|
||||
if (!file_exists("$CFG->dataroot/filter/tex")) {
|
||||
make_upload_directory("filter/tex");
|
||||
}
|
||||
$pathname = "$CFG->dataroot/filter/tex/$image";
|
||||
if (file_exists($pathname)) {
|
||||
unlink($pathname);
|
||||
}
|
||||
|
||||
$texexp = '\Large '.$texexp;
|
||||
$commandpath = filter_tex_get_executable(true);
|
||||
$cmd = filter_tex_get_cmd($pathname, $texexp);
|
||||
system($cmd, $status);
|
||||
|
||||
if ($return) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
if (file_exists($pathname)) {
|
||||
send_file($pathname, $image);
|
||||
|
||||
} else if (debugging()) {
|
||||
$ecmd = "$cmd 2>&1";
|
||||
echo `$ecmd` . "<br />\n";
|
||||
echo "The shell command<br />$cmd<br />returned status = $status<br />\n";
|
||||
if ($status == 4) {
|
||||
echo "Status corresponds to illegal instruction<br />\n";
|
||||
} else if ($status == 11) {
|
||||
echo "Status corresponds to bus error<br />\n";
|
||||
} else if ($status == 22) {
|
||||
echo "Status corresponds to abnormal termination<br />\n";
|
||||
}
|
||||
if (file_exists($commandpath)) {
|
||||
echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "<br />";
|
||||
echo "The file permissions are: " . decoct(fileperms($commandpath)) . "<br />";
|
||||
if (function_exists("md5_file")) {
|
||||
echo "The md5 checksum of the file is " . md5_file($commandpath) . "<br />";
|
||||
} else {
|
||||
$handle = fopen($commandpath,"rb");
|
||||
$contents = fread($handle,16384);
|
||||
fclose($handle);
|
||||
echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "<br />";
|
||||
}
|
||||
} else {
|
||||
echo "mimetex executable $commandpath not found!<br />";
|
||||
}
|
||||
echo "Image not found!";
|
||||
} else {
|
||||
echo "Can not output detailed information due to security concerns, please turn on debug mode first.";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// test Tex/Ghostscript output - command execution only
|
||||
function TexOutput($expression, $graphic=false) {
|
||||
global $CFG;
|
||||
@@ -296,7 +229,9 @@
|
||||
function slasharguments($texexp) {
|
||||
global $CFG;
|
||||
$admin = $CFG->wwwroot.'/'.$CFG->admin.'/settings.php?section=http';
|
||||
$image = tex2image($texexp,true);
|
||||
$md5 = md5($texexp);
|
||||
$convertformat = get_config('filter_tex', 'convertformat');
|
||||
$image = $md5 . ".{$convertformat}";
|
||||
echo "<p>If the following image displays correctly, set your ";
|
||||
echo "<a href=\"$admin\" target=\"_blank\">Administration->Server->HTTP</a> ";
|
||||
echo "setting for slasharguments to file.php/1/pic.jpg: ";
|
||||
@@ -329,9 +264,7 @@
|
||||
<label for="ShowDB">See the cache_filters database entry for this expression (if any).</label></li>
|
||||
<li><input type="radio" name="action" value="DeleteDB" id="DeleteDB" />
|
||||
<label for="DeleteDB">Delete the cache_filters database entry for this expression (if any).</label></li>
|
||||
<li><input type="radio" name="action" value="ShowImageMimetex" id="ShowImageMimetex" checked="checked" />
|
||||
<label for="ShowImageMimetex">Show a graphic image of the algebraic expression rendered with mimetex.</label></li>
|
||||
<li><input type="radio" name="action" value="ShowImageTex" id="ShowImageTex" />
|
||||
<li><input type="radio" name="action" value="ShowImageTex" id="ShowImageTex" checked="checked" />
|
||||
<label for="ShowImageTex">Show a graphic image of the algebraic expression rendered with Tex/Ghostscript.</label></li>
|
||||
<li><input type="radio" name="action" value="ShowOutputTex" id="ShowOutputTex" />
|
||||
<label for="ShowOutputTex">Show command execution output from the algebraic expression rendered with Tex/Ghostscript.</label></li>
|
||||
@@ -355,10 +288,9 @@ searches the database cache_filters table to see if this TeX expression had been
|
||||
processed before. If not, it adds a DB entry for that expression. It then
|
||||
replaces the TeX expression by an <img src=".../filter/tex/pix.php...">
|
||||
tag. The filter/tex/pix.php script then searches the database to find an
|
||||
appropriate gif/png/svg image file for that expression and to create one if it doesn't exist.
|
||||
It will then use either the LaTex/Ghostscript renderer (using external executables
|
||||
on your system) or the bundled Mimetex executable. The full Latex/Ghostscript
|
||||
renderer produces better results and is tried first.
|
||||
appropriate png/gif/svg image file for that expression and to create one if it doesn't exist.
|
||||
It uses the LaTeX/Ghostscript renderer (using external executables on your system)
|
||||
to produce the images.
|
||||
Here are a few common things that can go wrong and some suggestions on how
|
||||
you might try to fix them.</p>
|
||||
<ol>
|
||||
@@ -366,21 +298,16 @@ you might try to fix them.</p>
|
||||
process this expression. Then the database entry for that expression contains
|
||||
a bad TeX expression in the rawtext field (usually blank). You can fix this
|
||||
by clicking on "Delete DB Entry"</li>
|
||||
<li>The TeX to gif/png/svg image conversion process does not work.
|
||||
If paths are specified in the filter configuation screen for the three
|
||||
executables these will be tried first. Note that they still must be correctly
|
||||
<li>The TeX to png/gif/svg image conversion process does not work.
|
||||
If paths are specified in the filter configuration screen for the LaTeX
|
||||
executables these will be used. Note that they must be correctly
|
||||
installed and have the correct permissions. In particular make sure that you
|
||||
have all the packages installed (e.g., on Debian/Ubuntu you need to install
|
||||
the 'tetex-extra' package). Running the 'show command execution' test should
|
||||
give a big clue.
|
||||
If this fails or is not available, the Mimetex executable is tried. If this
|
||||
fails a likely cause is that the mimetex binary you are using is
|
||||
incompatible with your operating system. You can try compiling it from the
|
||||
C sources downloaded from <a href="http://www.forkosh.com/mimetex.zip">
|
||||
http://www.forkosh.com/mimetex.zip</a>.
|
||||
Another possible problem which may affect
|
||||
both Unix and Windows servers is that the web server doesn't have execute permission
|
||||
on the mimetex binary. In that case change permissions accordingly</li>
|
||||
on the LaTeX binaries. In that case change permissions accordingly</li>
|
||||
</ol>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<libraries>
|
||||
<library>
|
||||
<location>mimetex.*</location>
|
||||
<name>mimeTeX</name>
|
||||
<description>Compiled C program to convert TeX into GIFs</description>
|
||||
<version>1.77</version>
|
||||
<license>GPL</license>
|
||||
<licenseversion>3.0+</licenseversion>
|
||||
<repository>https://github.com/icaoberg/mimetex</repository>
|
||||
<copyrights>
|
||||
<copyright>2002-2004 John Forkosh Associates, Inc</copyright>
|
||||
</copyrights>
|
||||
<upgradable>false</upgradable>
|
||||
</library>
|
||||
</libraries>
|
||||
@@ -25,6 +25,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2025100600; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2025122200; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2025092600; // Requires this Moodle version.
|
||||
$plugin->component = 'filter_tex'; // Full name of the plugin (used for diagnostics)
|
||||
|
||||
@@ -926,6 +926,7 @@ $string['messagingdefaultpressenter'] = 'Use enter to send enabled by default';
|
||||
$string['messagingdeletereadnotificationsdelay'] = 'Delete read notifications';
|
||||
$string['messagingdeleteallnotificationsdelay'] = 'Delete all notifications';
|
||||
$string['messagingssettings'] = 'Messaging settings';
|
||||
$string['mimetexdeprecated'] = 'Since MimeTeX is no longer supported, please update your {$a->plugin_name} settings to use LaTeX instead. For best results, we recommend using MathJax to render math formulas.';
|
||||
$string['minpassworddigits'] = 'Digits';
|
||||
$string['minpasswordlength'] = 'Password length';
|
||||
$string['minpasswordlower'] = 'Lowercase letters';
|
||||
|
||||
@@ -411,8 +411,6 @@ $string['maxareabytes'] = 'The file is larger than the space remaining in this a
|
||||
$string['maxdraftitemids'] = 'Your file uploads are temporarily limited after you uploaded a high volume of files. Please wait then try again.';
|
||||
$string['messageundeliveredbynotificationsettings'] = 'The message could not be sent because personal messages between users (in Notification settings) has been disabled by a site administrator.';
|
||||
$string['messagingdisable'] = 'Messaging is disabled on this site';
|
||||
$string['mimetexisnotexist'] = 'Your system is not configured to run mimeTeX. You need to obtain the C source from <a href="https://www.forkosh.com/mimetex.zip">https://www.forkosh.com/mimetex.zip</a>, compile it and put the executable into your moodle/filter/tex/ directory.';
|
||||
$string['mimetexnotexecutable'] = 'Custom mimetex is not executable!';
|
||||
$string['missingcategoryrole'] = 'Could not assign role to user: missing role for category.';
|
||||
$string['missingfield'] = 'Field "{$a}" is missing';
|
||||
$string['missingkeyinsql'] = 'ERROR: missing param "{$a}" in query';
|
||||
|
||||
@@ -172,16 +172,11 @@ final class admintree_test extends \advanced_testcase {
|
||||
$this->assertMatchesRegularExpression('/class="text-danger"/', $result);
|
||||
|
||||
// Check for a file which is not executable.
|
||||
$result = $executable->output_html($CFG->dirroot . '/filter/tex/readme_moodle.txt');
|
||||
$result = $executable->output_html($CFG->dirroot . '/lib/upgrade.txt');
|
||||
$this->assertMatchesRegularExpression('/class="text-danger"/', $result);
|
||||
|
||||
// Check for an executable file.
|
||||
if ($CFG->ostype == 'WINDOWS') {
|
||||
$filetocheck = 'mimetex.exe';
|
||||
} else {
|
||||
$filetocheck = 'mimetex.darwin';
|
||||
}
|
||||
$result = $executable->output_html($CFG->dirroot . '/filter/tex/' . $filetocheck);
|
||||
// Check for an executable file using PHP_BINARY (the current PHP executable).
|
||||
$result = $executable->output_html(PHP_BINARY);
|
||||
$this->assertMatchesRegularExpression('/class="text-success"/', $result);
|
||||
|
||||
// Check for no file specified.
|
||||
|
||||
Reference in New Issue
Block a user