利用者:Kanjy/LaTeXEnv1.js
注意: 保存した後、ブラウザのキャッシュをクリアする必要があります。Mozilla / Firefox / Safari: [Shift] を押しながら [再読み込み] をクリック、または [Shift]-[Ctrl]-[R] (Macでは [Cmd]-[Shift]-[R]); IE: [Ctrl] を押しながら [更新] をクリック、または [Ctrl]-[F5]; Konqueror: [再読み込み] をクリック、または [F5]; Opera: 「ツール」→「設定」からキャッシュをクリア。
// 編集ツールバーの数式ボタンに、簡易な LaTeX 環境マークアップ入力支援機能を追加する
var insertMath = function(){insertTags("\x3cmath\x3e", "\x3c/math\x3e", "数式");};
function insertLaTeXEnv()
{
var envName = prompt("数式に挿入する環境名は?", "cases");
if (!envName) {
insertMath();
return true;
}
var envArg = "", sampleText = "";
if (envName == "array") {
envArg = "{lcr}";
sampleText = "\n2^{8} & = & 256\\\\\n2^{16} & = & 65536\n";
} else if (envName == "alignat") {
envArg = "{2}";
sampleText = "\ny & = (a + b)(a - b)\\\\\n & = a^2 - b^2\n";
} else if (envName.indexOf("matrix") != -1) {
sampleText = "\nx & y\\\\\nz & w\n";
} else {
sampleText = "\nx + y = 3\\\\\nx + 2y = 4\n";
}
var tagOpen = "\\begin{" + envName + "}" + envArg;
var tagClose = "\\end{" + envName + "}\n";
insertTags(tagOpen, tagClose, sampleText);
return true;
}
function installLaTeXEnv() {
var button = document.getElementById("mw-editbutton-math");
if (button) {
insertMath = button.onclick;
button.onclick = insertLaTeXEnv;
}
return true;
}
hookEvent("load", installLaTeXEnv);