Extension:Math/高度な設定

This page is a translated version of the page Extension:Math/advancedSettings and the translation is 64% complete.
Outdated translations are marked like this.

数式拡張機能は Mathoid その他のバックエンドを利用し、数式のレンダリングをサポートします。 この拡張機能で現在、何ができるかについては数式の表示にまとめてあります。

設定

サーバ側で MathJax を使用して変換

MW 1.23以降は Mathoid サーバで MathJax を使いサーバ側の texvc 入力を MathML+SVG 画像生成に変換できます。 Mathoid は将来的にウィキペディアで用いられる画像生成モードです。 それに関して、以下の設定が推奨されます。

// ensure 'mathml'; is added to the $wgMathValidModes array;
$wgMathValidModes[] = 'mathml';

// Set Mathoid as default rendering option;
$wgDefaultUserOptions['math'] = 'mathml';

Mathoid を確認し、自分専用の Mathoid サーバ上で実行する手順を探します。 MathML 画像生成モードを有効に設定後、データベース更新スクリプトをもう一度実行し、必要なテーブルを作成します。

サーバ側で LaTeXML を使用して変換

LaTeX 画像生成の便利なオプションとして LaTeXML ウェブサービスを利用します。このサービスは LaTeX を高画質 MathML に変換します。

設定 (MW 1.22) 1.23以降のほぼすべての設定が有効です
// Enable LaTeXML as rendering option
$wgUseLaTeXML = true; // this became an unused setting around 1.23
設定 (MW 1.23 以降)
$wgMathValidModes[] = 'latexml'; // adding LaTeXML as rendering option
// Set LaTeXML as default rendering option;
$wgDefaultUserOptions['math'] = 'latexml';
// Specify the path to your LaTeXML instance that converts the \TeX commands to MathML (optional)
$wgLaTeXMLUrl = 'http://example.com/';

LaTeXML を自分戦丁野サーバにインストールする短いガイドはこちらを参照してください: Install LaTeXML

LaTeXML 画像生成モードを有効に設定後、データベース更新スクリプトを毛一度実行し、必要なテーブルを作成します。

Historical note

texvc used to be a rendering option before version 1.32. It is now completely replaced by Mathoid, but the subset of AMS-LaTeX it supports remains the basis of this extension.

すべての環境設定一覧

require_once "$IP/extensions/Math/Math.php";を呼び出した後、LocalSettings.phpに以下の変数を定義します。

これらの設定について個別のページでは非推奨になったと表示されます。原因はバージョン1.18でこの拡張機能がコアのmediawikiから分離されたことですが、もしこの拡張機能をインストール済の場合、左記に関わらずこれらの設定は有効です。
設定名 既定値 説明
$wgUseTeX true 後方互換性グローバル; もう何も実行しません。
$wgTexvc dirname( __FILE__ ) . '/math/texvc' texvc バイナリの場所 (Removed in MW 1.32 due to texvc being gone.)
$wgTexvcBackgroundColor 'transparent' Texvc 背景色; \special 関数に用いられる LaTeX 色彩フォーマットを使います。背景色を透明にするには 'Transparent' 値をアルファ透明に、または 'transparent'をバイナリ透明に設定します。 (Removed in MW 1.32 due to texvc being gone.)
$wgMathCheckFiles true 通常、数式画像を作成するには書き込み先のディレクトリが存在すること、生成されたファイルがそれらを再度起動する必要があるときにまだ存在していることを、二重に確認します。

こうすると、パーミッションの問題が発生したときに使えるエラーメッセージの表示と、失われた画像を自動的に再構成することができます。

大型のサイトで NFS 流量が多い場合、この方法では遅く断片化する可能性があるため、場合によって、これを false に設定して短絡したいと感じます。

$wgMathPath false 数式ディレクトリの URL パス。既定では以下のとおり。 "{$wgUploadPath }/math".
$wgMathDirectory false 数式ディレクトリのファイルシステムのパス。既定では以下のとおり。 "{$wgUploadDirectory }/math".
$wgUseMathJax false MathJax を画像生成のオプションとして有効化。
$wgMathJaxUrl '$IP/extensions/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML' もし既定のパーサをhttp://cdn.mathjax.org/で使用しない場合の、MathJax のURL。
$wgMathValidModes [ 'png', 'source', 'mathml' ] サーバで許可されたモードを定義。
$wgMathMathMLUrl 'https://mathoid-beta.wmflabs.org' mathoid サーバのURL。
$wgMathMathMLTimeout 20 数式をレンダリングするために MathML に送信した HTTP リクエストのタイムアウト (秒単位)。
$wgMathLaTeXMLUrl 'https://latexml.formulasearchengine.com/convert' LaTeXML の使用。

自分専用のサーバを使いたい、あるいは使う必要がある場合は、インストール手順に従い$wgMathLaTeXMLUrlをオーバーライドします : [1]

負荷が重いと予想される場合は、複数のサーバを指定してください。その場合、画像生成のプロセスごとにどれかひとつのサーバが選択されます。配列内にサーバの一覧を指定します。例: $wgMathLaTeXMLUrl = [ 'http://latexml.example.com/convert', 'http://latexml2.example.com/convert' ];

$wgMathLaTeXMLTimeout 240 数式をレンダリングするために LaTeXML に送信した HTTP リクエストのタイムアウト (秒単位)。
$wgMathDefaultLaTeXMLSetting
[
	'format' => 'xhtml',
	'whatsin' => 'math',
	'whatsout' => 'math',
	'pmml',
	'cmml',
	'mathtex',
	'nodefaultresources',
	'preload' => [
		'LaTeX.pool',
		'article.cls',
		'amsmath.sty',
		'amsthm.sty',
		'amstext.sty',
		'amssymb.sty',
		'eucal.sty',
		'[dvipsnames]xcolor.sty',
		'url.sty',
		'hyperref.sty',
		'[ids]latexml.sty',
		'texvc'
	],
	'linelength': 90
}
LaTeXML レンダラー設定の詳細。
$wgMathDisableTexFilter 'new' Texフィルタを無効にするオプションについて。「true」に設定した状態でLaTeX表示があると、セキュリティ上の弱点になる可能性があります。「false」に設定すると、TeXコマンドのサブセットのみ有効になります。 詳細はヘルプ:数式の書き方を参照してください。
$wgMathEnableExperimentalInputFormats false 実験的な MathML および AsciiMath 用入力フォーマットのサポートを有効にする

Alternate rendering

CSS for visual rendering of MathML

MathML は既定ではアクセシビリティのツールからしか見えない設定です。しかしながら以下の MediaWiki スタイルシートを指定し、強制的にレンダリングを視覚化できます: However, you can force visual rendering with the following MediaWiki stylesheets:

.mwe-math-mathml-a11y {
    clip: auto !important;
    overflow: visible !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
    opacity: 1 !important;
}
.mwe-math-fallback-image-inline,
.mwe-math-fallback-image-display {
    display: none !important;
}

すると MathML 数式の書式も自由に変更可能で、たとえば数式用フォントの設定ができます。

.mw-body, mtext {
    font-family: Latin Modern Roman;
}
math {
    font-family: Latin Modern Math;
}
本文のフォントもすべて統一するには.mw-body,の設定を追加します。 もし本文フォントを変更したくない場合は、この.mw-body,の部分は変更しません。 もちろん忘れずにカンマを除去してください。

Userscript renderers

It is also possible to use other client-side renderers, according to the comments of phab:T99369. None of these options should be actually deployed for general users; they are just for side-stepping parts of the current pipeline for experimentation.

  • JS script for client-side MathJax, interpreting math code directly: phab:T99369#1482730.
  • JS script for client-side MathJax, interpreting MathML: phab:T99369#1484437.
  • JS script for client-side KaTeX, interpreting either TeX code embedded in MathML, or raw "text mode" TeX code: phab:T99369#1484437.

CSS for dark background

The Extension always renders formulae in black text by default, which can throw off users and wikis running a dark background color. A skin author can add the following code to invert the lightness of formula images using CSS filters:

.mwe-math-fallback-image-inline,
.mwe-math-fallback-image-display {
    filter: hue-rotate(180deg) invert(1);
}
The hue-rotate keeps the hues roughly constant, so that colors remain somewhat useful. This solution is nowhere near being final. See the linked task and other tickets linked to it for more information.