Welcome to bytea
当前位置: Home 学习资料 网站制作 Mediawiki用mimetex显示数学公式 今天是...date...

登录bbs

用户名
密码

bytea统计

Members : 43193
Content : 340
Web Links : 69
Mediawiki用mimetex显示数学公式 PDF Print E-mail
Sunday, 19 November 2006 08:00
Mediawiki自带了一个Math.php用来显示数学公式,不过安装比较麻烦:
  1. 需要先安装ocamlLaTex
  2. 然后进入math目录make,编译texvc
  3. 最后在LocalSettings.php文件里,把$wgUseTeX 设置为 true;
这里需要的ocaml和LaTex对于没有自己服务器的人来说都比较难安装。下面介绍我的方法,用mimetex来显示数学公式:

mimetex是一个CGI程序,根据tex语法来生成数学公式,他不需要像ocamlLatex那样在服务器端安装。mimetex的设置这里就不罗嗦了,本文主要说的是mediawiki的修改。假设你已经有了mimetex.cgi程序,下面开始修改mediawiki:
  1. 首先进入include目录,备份math.php文件,
  2. 上传自己的math.php文件(下面会说怎么写)
  3. 修改mediawiki根目录下的Localsettings.php文件:
    $wgUseTeX             = true;
    $wgMathPath         = "MIMETEX URL";
  4. 上面的"MIMETEX URL"是你的mimetex的位置,比如本站的是http://www.bytea.net/cgi-bin/mimetex.cgi
下面说说math.php文件:
对于php4.x的同学,整个math.php文件是这样:

<?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\" />";
}
?>

对于php5.x的同学,整个math.php文件是这样:

<?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\" />";
    }
}
?>

好了,完成了,以后要在mediawiki中写公式,只要<math>公式</math>就可以了。
公式”是tex格式的,当然除了公式,mimetex还可以显示很多其他的图案,大家可以参考mimetex的tutorial

注意:本文仅供参考,我不为修改后造成的任何bug及其带来的损失负责。
当然如果有bug请留言或到bbs告诉我
Comments (3)Add Comment
請教一些問題, 謝謝!
written by josephchang888, December 12, 2006
版主, 您好!

1. 在下終於將 mimetex 的程式碼, 在 Winxp 下 comlipe 完成, 產生 mimetex.cgi

2. 在 WinXP下, 我使用 XAMPP 1.55(PHP5/MySQL5), 免安裝版來架站, 也順利安裝好mediawiki 1.82

3. 可是依照版主的說明, 含實際上有些出入, 所以http://localhost/mimetex.cgi?方式可以產生數學公式的 gif, 但是 mediawiki 內, 則無法正常顯示.

4. midiawiki/include 目錄下有 math.php, 但是在 mediawiki/mapth 目錄下則沒有 math.php?

5. 是完全取代原有的 math.php, 還是加入到 math.php 後面?
report abuse
vote down
vote up
Votes: +0
...
written by zijie, December 13, 2006
sorry,是我的疏忽,应该是替换include目录下 的math.php文件。原文已修正。
report abuse
vote down
vote up
Votes: +1
...
written by giantlab, June 05, 2009
博主你好,我在linux上安装了mimetex,在终 下执行./mimetex "x^2 y^2" 也能象官网上那样正确显示,可是在浏览 里输入http://localhost/cgi-bin/mimetex.cgi?x^2 y^2后,就会弹出一个要我下载文件的对话 ,当然下载下来的文件是.cgi,很不解,我认为mimetex. cgi应该编译成功了,而且权限也改了,但 什么还出现这种情况,在浏览器里面怎 也显示不出图片来?
report abuse
vote down
vote up
Votes: +0

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

security code
Write the displayed characters


busy
 

支持本站:



Connect with me via QQ:38074 or e-mail:

©2006 bytea.net All Copyrights Reserved.

本站备案编号:保密^_^

RSS:  

开启背景音乐