diff --git a/.upgradenotes/MDL-85233-2025122207154958.yml b/.upgradenotes/MDL-85233-2025122207154958.yml new file mode 100644 index 00000000000..92cfd1f14da --- /dev/null +++ b/.upgradenotes/MDL-85233-2025122207154958.yml @@ -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 diff --git a/public/filter/algebra/algebradebug.php b/public/filter/algebra/algebradebug.php index 047bf873ce8..690ff9c3066 100644 --- a/public/filter/algebra/algebradebug.php +++ b/public/filter/algebra/algebradebug.php @@ -1,7 +1,7 @@ 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` . "
\n"; - echo "The shell command
$cmd
returned status = $status
\n"; - if ($status == 4) { - echo "Status corresponds to illegal instruction
\n"; - } else if ($status == 11) { - echo "Status corresponds to bus error
\n"; - } else if ($status == 22) { - echo "Status corresponds to abnormal termination
\n"; - } - if (file_exists($commandpath)) { - echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "
"; - echo "The file permissions are: " . decoct(fileperms($commandpath)) . "
"; - if (function_exists("md5_file")) { - echo "The md5 checksum of the file is " . md5_file($commandpath) . "
"; - } else { - $handle = fopen($commandpath,"rb"); - $contents = fread($handle,16384); - fclose($handle); - echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "
"; - } - } else { - echo "mimetex executable $commandpath not found!
"; - } - echo "Image not found!"; + echo "Image not found!
"; + 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.

    @@ -334,12 +315,11 @@ on the algebra2tex.pl script. In that case change permissions accordingly a bug in the algebra filter. Post the original algebraic expression and the bad TeX translation in the Mathematics Tools forum in the Using Moodle course on moodle.org. -
  1. 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 -http://www.forkosh.com/mimetex.zip. Lastly check the execute permissions -on your mimetex binary, as outlined in item 2 above.
  2. +
  3. 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.
diff --git a/public/filter/algebra/classes/text_filter.php b/public/filter/algebra/classes/text_filter.php index 63a6064db61..56effeb3dce 100644 --- a/public/filter/algebra/classes/text_filter.php +++ b/public/filter/algebra/classes/text_filter.php @@ -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 ... 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 john@forkosh.com. 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); diff --git a/public/filter/algebra/db/upgrade.php b/public/filter/algebra/db/upgrade.php new file mode 100644 index 00000000000..0857a3bf117 --- /dev/null +++ b/public/filter/algebra/db/upgrade.php @@ -0,0 +1,46 @@ +. + +/** + * Algebra filter upgrade code. + * + * @package filter_algebra + * @copyright 2025 Yusuf Wibisono + * @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; +} diff --git a/public/filter/algebra/lang/en/filter_algebra.php b/public/filter/algebra/lang/en/filter_algebra.php index 1d9ad59994d..8a7a8ac64cd 100644 --- a/public/filter/algebra/lang/en/filter_algebra.php +++ b/public/filter/algebra/lang/en/filter_algebra.php @@ -1,5 +1,4 @@ latex and dvips are present in addition to convert or dvisvgm, select the preferred image type (convert produces PNG or GIF; dvisvgm produces SVG).'; +$string['convertformat'] = 'Output image format'; +$string['filtername'] = 'Algebra notation'; +$string['latexpreamble'] = 'LaTeX preamble'; +$string['latexsettings'] = 'LaTeX renderer Settings'; +$string['pathconvert'] = 'Path of convert binary'; +$string['pathdvips'] = 'Path of dvips binary'; +$string['pathdvisvgm'] = 'Path of dvisvgm binary'; +$string['pathlatex'] = 'Path of latex binary'; $string['privacy:metadata'] = 'The Algebra notation plugin does not store any personal data.'; diff --git a/public/filter/algebra/lib.php b/public/filter/algebra/lib.php new file mode 100644 index 00000000000..c3781706436 --- /dev/null +++ b/public/filter/algebra/lib.php @@ -0,0 +1,75 @@ +. + +/** + * Algebra filter library functions. + * + * @package filter_algebra + * @copyright 2025 Yusuf Wibisono + * @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'); + } +} diff --git a/public/filter/algebra/pix.php b/public/filter/algebra/pix.php index e9663636673..ff230b8845d 100644 --- a/public/filter/algebra/pix.php +++ b/public/filter/algebra/pix.php @@ -1,7 +1,7 @@ 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
$cmd
returned status = $status
\n"; echo "Image not found!
"; echo "Please try the wwwroot/filter/algebra/algebradebug.php\">debugging script"; } else { diff --git a/public/filter/algebra/settings.php b/public/filter/algebra/settings.php new file mode 100644 index 00000000000..7bdcf1d74a3 --- /dev/null +++ b/public/filter/algebra/settings.php @@ -0,0 +1,125 @@ +. + +/** + * Algebra filter settings + * + * @package filter_algebra + * @copyright 2025 Yusuf Wibisono + * @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); + } +} diff --git a/public/filter/algebra/version.php b/public/filter/algebra/version.php index 3ddf82dbf5a..253dd2cc149 100644 --- a/public/filter/algebra/version.php +++ b/public/filter/algebra/version.php @@ -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]; diff --git a/public/filter/tex/README.mimetex b/public/filter/tex/README.mimetex deleted file mode 100644 index dbfc250cc18..00000000000 --- a/public/filter/tex/README.mimetex +++ /dev/null @@ -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 - john@forkosh.com 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 tag in your document wherever you want to - see the corresponding LaTeX expression. For example, - - generates and displays the corresponding gif image on-the-fly, - wherever you put that 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 - 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 =========================== - diff --git a/public/filter/tex/classes/text_filter.php b/public/filter/tex/classes/text_filter.php index 99800ef57df..421bba9b27c 100644 --- a/public/filter/tex/classes/text_filter.php +++ b/public/filter/tex/classes/text_filter.php @@ -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 ... tags to gif images using - * mimetex.cgi obtained from http: *www.forkosh.com/mimetex.html authored by - * John Forkosh john@forkosh.com. 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 ... tags to PNG, GIF, or SVG images using + * LaTeX tools (latex, dvips, convert/dvisvgm). * * @package filter_tex * @subpackage tex diff --git a/public/filter/tex/db/upgrade.php b/public/filter/tex/db/upgrade.php index ca4ca8e3a60..448907440cf 100644 --- a/public/filter/tex/db/upgrade.php +++ b/public/filter/tex/db/upgrade.php @@ -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; } diff --git a/public/filter/tex/lang/en/filter_tex.php b/public/filter/tex/lang/en/filter_tex.php index a4fdb121e74..fcba826e99a 100644 --- a/public/filter/tex/lang/en/filter_tex.php +++ b/public/filter/tex/lang/en/filter_tex.php @@ -23,16 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['configconvertformat'] = 'If latex and dvips are present in addition to convert or dvisvgm, select the preferred image type (convert produces GIF or PNG; dvisvgm produces SVG). Otherwise mimeTeX will be used to to create GIF images.'; +$string['configconvertformat'] = 'If latex and dvips are present in addition to convert or dvisvgm, select the preferred image type (convert produces PNG or GIF; dvisvgm 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 convert binary'; $string['pathdvips'] = 'Path of dvips binary'; $string['pathdvisvgm'] = 'Path of dvisvgm binary'; $string['pathlatex'] = 'Path of latex binary'; -$string['pathmimetex'] = 'Path of mimetex 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'; diff --git a/public/filter/tex/latex.php b/public/filter/tex/latex.php index e7cf8259784..08d57ace5c7 100644 --- a/public/filter/tex/latex.php +++ b/public/filter/tex/latex.php @@ -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 )) { diff --git a/public/filter/tex/lib.php b/public/filter/tex/lib.php index a1d296ab9e4..fa4258ad258 100644 --- a/public/filter/tex/lib.php +++ b/public/filter/tex/lib.php @@ -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'); } } diff --git a/public/filter/tex/mimetex.darwin b/public/filter/tex/mimetex.darwin deleted file mode 100755 index 3d8d7ed65f9..00000000000 Binary files a/public/filter/tex/mimetex.darwin and /dev/null differ diff --git a/public/filter/tex/mimetex.exe b/public/filter/tex/mimetex.exe deleted file mode 100755 index c495a4b3cc2..00000000000 Binary files a/public/filter/tex/mimetex.exe and /dev/null differ diff --git a/public/filter/tex/mimetex.freebsd b/public/filter/tex/mimetex.freebsd deleted file mode 100755 index 936a19fe148..00000000000 Binary files a/public/filter/tex/mimetex.freebsd and /dev/null differ diff --git a/public/filter/tex/mimetex.linux b/public/filter/tex/mimetex.linux deleted file mode 100755 index 8b2eb74d43d..00000000000 Binary files a/public/filter/tex/mimetex.linux and /dev/null differ diff --git a/public/filter/tex/mimetex.linux.aarch64 b/public/filter/tex/mimetex.linux.aarch64 deleted file mode 100755 index 5408d704ac3..00000000000 Binary files a/public/filter/tex/mimetex.linux.aarch64 and /dev/null differ diff --git a/public/filter/tex/pix.php b/public/filter/tex/pix.php index e4697cf48ff..c7b0ca35930 100644 --- a/public/filter/tex/pix.php +++ b/public/filter/tex/pix.php @@ -1,7 +1,7 @@ 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
$cmd
returned status = $status
\n"; echo "Image not found!
"; echo "Please try the wwwroot/filter/tex/texdebug.php\">debugging script"; } else { diff --git a/public/filter/tex/readme_moodle.txt b/public/filter/tex/readme_moodle.txt deleted file mode 100644 index 941aaae966c..00000000000 --- a/public/filter/tex/readme_moodle.txt +++ /dev/null @@ -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 diff --git a/public/filter/tex/settings.php b/public/filter/tex/settings.php index e0d5ddce68f..b577bba320b 100644 --- a/public/filter/tex/settings.php +++ b/public/filter/tex/settings.php @@ -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'); diff --git a/public/filter/tex/texdebug.php b/public/filter/tex/texdebug.php index 25481b3101e..d3ed8edf98c 100644 --- a/public/filter/tex/texdebug.php +++ b/public/filter/tex/texdebug.php @@ -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 "\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` . "
\n"; - echo "The shell command
$cmd
returned status = $status
\n"; - if ($status == 4) { - echo "Status corresponds to illegal instruction
\n"; - } else if ($status == 11) { - echo "Status corresponds to bus error
\n"; - } else if ($status == 22) { - echo "Status corresponds to abnormal termination
\n"; - } - if (file_exists($commandpath)) { - echo "File size of mimetex executable $commandpath is " . filesize($commandpath) . "
"; - echo "The file permissions are: " . decoct(fileperms($commandpath)) . "
"; - if (function_exists("md5_file")) { - echo "The md5 checksum of the file is " . md5_file($commandpath) . "
"; - } else { - $handle = fopen($commandpath,"rb"); - $contents = fread($handle,16384); - fclose($handle); - echo "The md5 checksum of the first 16384 bytes is " . md5($contents) . "
"; - } - } else { - echo "mimetex executable $commandpath not found!
"; - } - 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 "

If the following image displays correctly, set your "; echo "Administration->Server->HTTP "; echo "setting for slasharguments to file.php/1/pic.jpg: "; @@ -329,9 +264,7 @@

  • -
  • -
  • -
  • +
  • @@ -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.

      @@ -366,21 +298,16 @@ you might try to fix them.

      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" -
    1. 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 +
    2. 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 -http://www.forkosh.com/mimetex.zip. 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
    3. +on the LaTeX binaries. In that case change permissions accordingly
    diff --git a/public/filter/tex/thirdpartylibs.xml b/public/filter/tex/thirdpartylibs.xml deleted file mode 100644 index 79b12f865c8..00000000000 --- a/public/filter/tex/thirdpartylibs.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - mimetex.* - mimeTeX - Compiled C program to convert TeX into GIFs - 1.77 - GPL - 3.0+ - https://github.com/icaoberg/mimetex - - 2002-2004 John Forkosh Associates, Inc - - false - - diff --git a/public/filter/tex/version.php b/public/filter/tex/version.php index a25ea0bd141..4dbac98cb72 100644 --- a/public/filter/tex/version.php +++ b/public/filter/tex/version.php @@ -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) diff --git a/public/lang/en/admin.php b/public/lang/en/admin.php index c3f4aab139d..911b4865e35 100644 --- a/public/lang/en/admin.php +++ b/public/lang/en/admin.php @@ -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'; diff --git a/public/lang/en/error.php b/public/lang/en/error.php index 78bab35f806..61887881ded 100644 --- a/public/lang/en/error.php +++ b/public/lang/en/error.php @@ -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 https://www.forkosh.com/mimetex.zip, 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'; diff --git a/public/lib/tests/admintree_test.php b/public/lib/tests/admintree_test.php index a2512e11ec5..25d38165547 100644 --- a/public/lib/tests/admintree_test.php +++ b/public/lib/tests/admintree_test.php @@ -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.