From 5b9682043704fc477bd3d6cd526068b73dd3cd36 Mon Sep 17 00:00:00 2001
From: Yusuf Wibisono
Date: Tue, 23 Dec 2025 02:58:03 +0700
Subject: [PATCH] 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
---
.upgradenotes/MDL-85233-2025122207154958.yml | 9 +
public/filter/algebra/algebradebug.php | 64 ++---
public/filter/algebra/classes/text_filter.php | 19 +-
public/filter/algebra/db/upgrade.php | 46 ++++
.../filter/algebra/lang/en/filter_algebra.php | 11 +-
public/filter/algebra/lib.php | 75 ++++++
public/filter/algebra/pix.php | 34 +--
public/filter/algebra/settings.php | 125 ++++++++++
public/filter/algebra/version.php | 3 +-
public/filter/tex/README.mimetex | 218 ------------------
public/filter/tex/classes/text_filter.php | 10 +-
public/filter/tex/db/upgrade.php | 17 ++
public/filter/tex/lang/en/filter_tex.php | 8 +-
public/filter/tex/latex.php | 28 ++-
public/filter/tex/lib.php | 65 +-----
public/filter/tex/mimetex.darwin | Bin 2917455 -> 0 bytes
public/filter/tex/mimetex.exe | Bin 1423360 -> 0 bytes
public/filter/tex/mimetex.freebsd | Bin 1418816 -> 0 bytes
public/filter/tex/mimetex.linux | Bin 1751184 -> 0 bytes
public/filter/tex/mimetex.linux.aarch64 | Bin 1786568 -> 0 bytes
public/filter/tex/pix.php | 17 +-
public/filter/tex/readme_moodle.txt | 38 ---
public/filter/tex/settings.php | 16 +-
public/filter/tex/texdebug.php | 97 +-------
public/filter/tex/thirdpartylibs.xml | 16 --
public/filter/tex/version.php | 2 +-
public/lang/en/admin.php | 1 +
public/lang/en/error.php | 2 -
public/lib/tests/admintree_test.php | 11 +-
29 files changed, 392 insertions(+), 540 deletions(-)
create mode 100644 .upgradenotes/MDL-85233-2025122207154958.yml
create mode 100644 public/filter/algebra/db/upgrade.php
create mode 100644 public/filter/algebra/lib.php
create mode 100644 public/filter/algebra/settings.php
delete mode 100644 public/filter/tex/README.mimetex
delete mode 100755 public/filter/tex/mimetex.darwin
delete mode 100755 public/filter/tex/mimetex.exe
delete mode 100755 public/filter/tex/mimetex.freebsd
delete mode 100755 public/filter/tex/mimetex.linux
delete mode 100755 public/filter/tex/mimetex.linux.aarch64
delete mode 100644 public/filter/tex/readme_moodle.txt
delete mode 100644 public/filter/tex/thirdpartylibs.xml
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.
-- 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.
+- 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.