2023-02-27  2024-09-18    181 字  1 分钟

https://www.mediawiki.org/wiki/MediaWiki_and_LaTeX_on_a_host_with_shell_access

安装TexLive,使用 which latex 和 which dvipng 检查是否安装

按照注释中操作

 1<?php
 2# Place this file in extension directory as Mtag.php
 3# Add the following line to LocalSettings.php:
 4# include './extensions/Mtag.php';
 5# Mediawiki will render as LaTeX the code within <m> </m> tags.
 6
 7$wgExtensionFunctions[] = "wfMtag";
 8
 9function wfMtag() {
10    global $wgParser;
11    $wgParser->setHook( "m", "returnMtagged" );
12}
13
14function returnMtagged( $code, $argv) {
15# if you have mathtex.cgi installed:
16    $txt='<img src="/cgi-bin/mathtex.cgi?'.$code.'">';
17# OR if you want to temporarily test a public mathtex.cgi:
18#    $txt='<img src="http://www.forkosh.com/mathtex.cgi?'.$code.'">';
19
20    return $txt;
21}
22?>

下载并解压 Mathtex.zip

https://via.akvicor.com/file?f=1241

 1# 编译
 2cc mathtex.c -DLATEX=\"$(which latex)\"  -DDVIPNG=\"$(which dvipng)\" -o mathtex.cgi
 3# 移动cgi文件
 4mv mathtex.cgi /var/www/mediawiki/cgi-bin
 5cd /var/www/mediawiki/cgi-bin
 6# 更改权限
 7chmod 775 mathtex.cgi
 8chown caddy:caddy mathtex.cgi
 9# 测试
10./mathtex.cgi "x^2+y^2" –m 9 –o test

配置于wiki

LocalSettings.php

1include './extensions/Mtag.php';
2$wgTrustedMathMimetexUrl = 'https://wiki.akvicor.com/cgi-bin/mathtex.cgi?';

除另有声明外本博客文章均采用 知识共享 (Creative Commons) 署名 4.0 国际许可协议 进行许可转载请注明原作者与文章出处