From e248a905b49e6ee1dff3b4e317cd0c8120080891 Mon Sep 17 00:00:00 2001 From: moodler Date: Fri, 30 Jan 2004 08:50:53 +0000 Subject: [PATCH] Whoops ... forgot to check this in --- filter/texh/texh.php | 131 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 filter/texh/texh.php diff --git a/filter/texh/texh.php b/filter/texh/texh.php new file mode 100644 index 0000000000..771d8a2cff --- /dev/null +++ b/filter/texh/texh.php @@ -0,0 +1,131 @@ + tags into images, using HeVeA // +// // +// Copyright (C) 2001-2003 Bruno Vernier bruno@vsbeducation.ca // +// // +// This program 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 2 of the License, or // +// (at your option) any later version. // +// // +// This program 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: // +// // +// http://www.gnu.org/copyleft/gpl.html // +// // +/////////////////////////////////////////////////////////////////////////// + +//------------------------------------------------------------------------- +// +// README PREREQUISITES: +// +// 1: install HeVeA on your server http://pauillac.inria.fr/~maranget/hevea/ +// (debian and rpm available) (it is a TeX to HTML/MathML filter) +// +// 2: must include this file "texh.php" in the filters in config.php +// +// 3: must include TEX in the legal tags list in lib/weblib.php +// CAVEAT: if above not yet done, gets converted to <TEX> +// and can only be fixed by editing in HTML conversion mode +// +// 4: if you are using Windows then the hevea.bat file that comes with the +// windows distribution needs to have the line +// if "%1"=="" goto syn +// removed. +// +//------------------------------------------------------------------------- + +/// These lines are important - the variable must match the name +/// of the actual function below + + $textfilter_function='texh_filter'; + + if (function_exists($textfilter_function)) { + return; + } + + +function texh_pipe_cmd($cmd, $text) { + // general function for external system calls to $cmd, piping in $text, retrieving output + // taken mostly from a php tutorial on php.net website (modified slightly) + $spec = array( + 0 => array("pipe", "r"), // stdin + 1 => array("pipe", "w"), // stdout + ); + $process = proc_open($cmd , $spec, $pipes); + $output=""; + if (is_resource($process)) { + fwrite($pipes[0], $text); + fclose($pipes[0]); + while (!feof($pipes[1])) { + $buffer = fgets($pipes[1], 1024); + $output .= $buffer; + } + fclose($pipes[1]); + proc_close($process); + } + return $output; +} + +function texh_filter ($courseid, $text) { + // TeX conversion with $$ tex code $$ + // written by Bruno Vernier (c) 2004 GPL + + /// Do a quick check using stripos to avoid unnecessary work + if (!(stripos($text, ' some general TeX expression + preg_match_all('/(.+?)<\/tex>/is', $text, $matches); + for ($i=0; $i + -- 2.39.5