利用外链CGI为Mediawiki添加数学公式支持
来自KlniuWiki
方法一:修改Math.php
修改includes/Math.php,将里面的renderMath函数注释掉:
public static function renderMath( $tex, $params=array() ) { global $wgUser; $math = new MathRenderer( $tex, $params ); $math->setOutputMode( $wgUser->getOption('math')); return $math->render(); }
加一个新的:
public static function renderMath( $tex, $params=array() ) { return '<img class="tex" src="http://www.forkosh.dreamhost.com/mathtex.cgi?' . rawurlencode($tex) . '" alt="LaTeX: ' . htmlspecialchars($tex) . '">'; }
其中的http://www.forkosh.dreamhost.com/mathtex.cgi 可以换成任意mathTeX web services。
在mathTeX manual里就提到几个:
http://www.forkosh.dreamhost.com/mathtex.cgi http://www.cyberroadie.org/cgi-bin/mathtex.cgi http://www.problem-solving.be/cgi-bin/mathtex.cgi
最后,记得在LocalSettings.php里启用Tex:
$wgUseTeX = true;
方法二:自定义标签(如<tex>)
如果想使用math标签,就把上述链接中说的
$wgParser->setHook("tex", "render_Mimetex");
改为
$wgParser->setHook("math", "render_Mimetex");
再把 includes/parser/parser.php中的
case 'math':
...
注释掉。
注:mathTex和mineText是一个作者John Forkosh写的:
If latex is installed on your server then see mathTeX, the successor to mimeTeX. It's based on real LaTeX and renders higher quality images than mimeTeX. If latex is not available on your server, continue using mimeTeX.
参见
- 利用外链CGI为Mediawiki添加数学公式支持. Smilingpoplar. 2008-12-11.