|
Sunday, 19 November 2006 08:00 |
Mediawiki itself has a Math.php file used to generate math formula, but the installation is a little bit complicated:
- First of all, we need to install ocaml and LaTex.
- And then enter the math directory, make to compile texvc.
- Finally modify the LocalSettings.php file, set $wgUseTeX to true;
For the guys do not have their own server (like me), it is difficult to install ocaml and LaTex. So let me introduce my method: using mimetex to display math fomular:
mimetex is a CGI program which generate formula using tex syntax, the installation is much simpler than ocaml and Latex. I would not talk about the installation of mimetex here, since this tutorial focus of mediawiki. I will assume you have a mimetex.cgi file already, and let's start the modification of mediawiki:
- First of all, enter the math directory, backup math.php file.
- upload our math.php file ( the file is given at the end of this tutorial)
- Open the Localsettings.php file, change the setting:
$wgUseTeX = true;
$wgMathPath = "MIMETEX URL";
- The "MIMETEX URL" above is the location of your mimetex.cgi program, for my website, it looks like "http://www.bytea.net/cgi-bin/mimetex.cgi"
Ok now let's have a look at the math.php file:
For the guys using php4.x, the whole math.php looks lie:
<?php function renderMath( $tex ){ global $wgMathPath; $url = htmlspecialchars( "$wgMathPath?$tex"); $alt = trim(str_replace("\n", ' ', htmlspecialchars( $tex ))); return "<img class='tex' src=\"$url\" alt=\"$alt\" />"; } ?>
For the guys using php5.x, the whole math.php looks lie:
<?php class MathRenderer { public static function renderMath( $tex ) { global $wgMathPath; $url = htmlspecialchars( "$wgMathPath?$tex"); $alt = trim(str_replace("\n", ' ', htmlspecialchars( $tex ))); return "<img class='tex' src=\"$url\" alt=\"$alt\" />"; } } ?>
Done! Now if you want to write a formula in mediawiki, just use the tag <math>FORMULA</math>.
And the FORMULA above is tex syntax. Besides math formula, mimetex could also display lots of other things, FYI: mimetex's tutorial.
Notice that this tutorial is just for your reference, I am not responsible for any bug and any damage it may cause.
Of course I am appreciate you could tell me any bug or suggestion
|