1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MediaWikiで数式を表示させるプラグインを導入する

Last updated at Posted at 2016-11-15

MediaWikiで数式を表示させるためにMathプラグインを導入する方法についてのメモです。
わりと大変でした。

Mathプラグインのインストール

https://www.mediawiki.org/wiki/Extension:Math の指示にあるようにtarボールをダウンロードしてwikiのフォルダにあるextensionsのなかに解凍します。
これは簡単です。

Mathoidのインストール

Mathプラグインだけでは数式を描画できるわけではないようで、別途数式を描画するためのソフトが必要になります。

代表的なものはTeXでしょうが、どうも今はMathoidというものが推奨されているようなので、これをインストールします。

Mathoidはサーバーとして動作し、MediaWikiのほうからはcurlでアクセスして情報を取得するようです。

Mathoidはnode.jsで動くものなので、node.jsがない場合はインストールしておきます。

Mathoidのインストール作業は次の通り:

$ mkdir methoid-server
$ cd methoid-server
$ npm install methoid
$ cd node_modules/mathoid
$ cp config.dev.yaml config.yaml
$ vim config.yaml #設定を編集。

設定の編集に関してはコメントによればよいでしょうが、一箇所
module: ./app.js
という行に関してはどうもこれでは一階層上を参照してしまうらしく、
module: ./mathoid/app.js
と修正する必要があります。

あとは
$ ./server.js
でmathoidのサーバーが起動します。

$ curl -d 'q=E=mc^2' http://localhost:10044
でそれらしい結果が返ってきていれば成功です。

永続的に起動しておくために公式サイトではscreenを使った方法が紹介されていますが、折角node.jsを使っているので、foreverを使えばよいのではないでしょうか:

$ npm install -g forever
$ forever start ./server.js

LocalSettings.phpの編集

MediaWikiのLocalSettings.phpの末尾に次のように追記します:

LocalSettings.php
wfLoadExtension( 'Math' );
$wgMathValidModes[] = 'mathml';
$wgDefaultUserOptions['math'] = 'mathml';
$wgMathFullRestbaseURL = 'https://api.formulasearchengine.com/';
$wgMathMathMLUrl = 'http://localhost:10044/'; # IP of Mathoid server

その他

基本的には以上なのですが、私の環境では500エラーが出て動きませんでした。エラーの原因はphp5からcurlを使うための拡張がインストールされていなかったことで、
$ sudo apt-get install php5-curl
で入れるとエラーが出ずに動くようになりました(環境はdebianです)。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?