履歴: ソフトウェア/pukiwiki/数式プラグイン
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 24 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2018/7/2 18:40:57 | ソフトウェア/pukiwiki/数式プラグイン 最新版 | 32,412 | +1 | -1 | 表示 | 差分 | — |
| 2018/7/2 18:40:57 | ソフトウェア/pukiwiki/数式プラグイン | 32,418 | +1 | -2 | 表示 | 差分 | 選択 |
| 2018/7/2 9:40:57 | ソフトウェア/pukiwiki/数式プラグイン | 32,350 | +2 | -1 | 表示 | 差分 | 選択 |
| 2018/7/2 9:40:57 | ソフトウェア/pukiwiki/数式プラグイン | 32,343 | +6 | -0 | 表示 | 差分 | 選択 |
| 2015/4/22 6:16:43 | ソフトウェア/pukiwiki/数式プラグイン | 32,243 | +8 | -0 | 表示 | 差分 | 選択 |
| 2015/4/22 6:16:43 | ソフトウェア/pukiwiki/数式プラグイン | 32,016 | +1 | -1 | 表示 | 差分 | 選択 |
| 2015/4/22 6:16:43 | ソフトウェア/pukiwiki/数式プラグイン | 32,015 | +7 | -0 | 表示 | 差分 | 選択 |
| 2014/6/13 11:14:29 | ソフトウェア/pukiwiki/数式プラグイン | 31,871 | +14 | -3 | 表示 | 差分 | 選択 |
| 2014/5/2 7:19:58 | ソフトウェア/pukiwiki/数式プラグイン | 31,715 | +5 | -5 | 表示 | 差分 | 選択 |
| 2014/5/2 7:19:58 | ソフトウェア/pukiwiki/数式プラグイン | 31,674 | +9 | -0 | 表示 | 差分 | 選択 |
| 2014/4/14 9:38:39 | ソフトウェア/pukiwiki/数式プラグイン | 31,511 | +442 | -6 | 表示 | 差分 | 選択 |
| 2014/4/12 12:14:30 | ソフトウェア/pukiwiki/数式プラグイン | 19,364 | +17 | -1 | 表示 | 差分 | 選択 |
| 2014/4/11 14:35:22 | ソフトウェア/pukiwiki/数式プラグイン | 19,069 | +181 | -0 | 表示 | 差分 | 選択 |
| 2013/4/11 0:02:52 | ソフトウェア/pukiwiki/数式プラグイン | 12,851 | +0 | -8 | 表示 | 差分 | 選択 |
| 2013/4/11 0:02:52 | ソフトウェア/pukiwiki/数式プラグイン | 12,983 | +8 | -0 | 表示 | 差分 | 選択 |
| 2013/4/8 3:28:03 | ソフトウェア/pukiwiki/数式プラグイン | 12,851 | +99 | -1 | 表示 | 差分 | 選択 |
| 2013/4/4 11:23:29 | ソフトウェア/pukiwiki/数式プラグイン | 10,537 | +4 | -2 | 表示 | 差分 | 選択 |
| 2013/4/4 11:23:29 | ソフトウェア/pukiwiki/数式プラグイン | 10,449 | +21 | -0 | 表示 | 差分 | 選択 |
| 2013/3/10 2:41:01 | ソフトウェア/pukiwiki/数式プラグイン | 10,041 | +10 | -0 | 表示 | 差分 | 選択 |
| 2011/10/22 15:45:46 | ソフトウェア/pukiwiki/数式プラグイン | 9,833 | +0 | -8 | 表示 | 差分 | 選択 |
| 2011/10/21 6:52:51 | ソフトウェア/pukiwiki/数式プラグイン | 9,966 | +8 | -0 | 表示 | 差分 | 選択 |
| 2011/5/19 11:09:24 | ソフトウェア/pukiwiki/数式プラグイン | 9,833 | +8 | -0 | 表示 | 差分 | 選択 |
| 2011/5/4 3:50:36 | ソフトウェア/pukiwiki/数式プラグイン | 9,676 | +78 | -28 | 表示 | 表示中 | 選択 |
| 2011/5/4 3:02:07 | ソフトウェア/pukiwiki/数式プラグイン | 8,128 | — | — | 表示 | — | 基準 |
基準: ソフトウェア/pukiwiki/数式プラグイン (2011/5/4 3:02:07) → 比較: ソフトウェア/pukiwiki/数式プラグイン (2011/5/4 3:50:36)
@@ -1,17 +1,68 @@
[[公開メモ]]
- LANG:php
+#contents
+
+* pukiwiki 用の数式プラグイン [#w6180144]
+
+pukiwiki に TeX で書いた数式を入れられるようにするプラグインです。
+
+特に、数式をインライン svg として表示できるようにしたので、
+対応するブラウザでは拡大時や印刷時に高い品質が得られます。
+
+現在、ユーザーエージェントに Mozilla/5 を含む場合にのみ、
+インライン svg で数式を表示するようになっています。
+
+それ以外では png ファイルとして数式を表示します。
+
+* 使用例 [#s60f1fc1]
+
+ &math(y=ax^2+bx+c);
+
+&math(y=ax^2+bx+c);
+
+ &math(x=\frac{-b\pm\sqrt{b^2-4ac}}{2a});
+
+&math(x=\frac{-b\pm\sqrt{b^2-4ac}}{2a});
+
+ &math(\left\{\begin{array}{c@{\ }l@{\ \ \ \ \ \ \ \ \ \ \ \ }l}\displaystyle
+ \ROT\bm E+\frac{\PD \bm B}{\PD t}&=\bm 0&\MARU{1}\vspace{2mm}
+ \\\DIV \bm B &= 0&\MARU{2}\vspace{2mm}\\\displaystyle\frac{1}{\mu_0}\ROT \bm B
+ -\varepsilon_0 \frac{\PD \bm E}{\PD t} &= \bm i&\MARU{3}\vspace{2mm}\\
+ \varepsilon_0\DIV \bm E &= \rho&\MARU{4}\\\end{array}\right .);
+
+&math(\left\{\begin{array}{c@{\ }l@{\ \ \ \ \ \ \ \ \ \ \ \ }l}\displaystyle \ROT\bm E+\frac{\PD \bm B}{\PD t}&=\bm 0&\MARU{1}\vspace{2mm}\\\DIV \bm B &= 0&\MARU{2}\vspace{2mm}\\\displaystyle\frac{1}{\mu_0}\ROT \bm B-\varepsilon_0 \frac{\PD \bm E}{\PD t} &= \bm i&\MARU{3}\vspace{2mm}\\\varepsilon_0\DIV \bm E &= \rho&\MARU{4}\\\end{array}\right .);
+
+※長い数式も1行で書かなければならないのがつらいところ
+
+ &math(\left\{\begin{array}{c@{}c@{}c@{}c@{}c@{}c@{}c}
+ a_{11}x_1&+&a_{12}x_2&+\cdots+&a_{1n}x_n&=&b_1 \\ a_{21}x_1&+
+ &a_{22}x_2&+\cdots+&a_{2n}x_n&=&b_2 \\ \vdots&&\vdots&&\vdots
+ &&\vdots\\ a_{m1}x_1&+&a_{m2}x_2&+\cdots+&a_{mn}x_n&=&b_m \\
+ \end{array}\right .);
+
+&math(\left\{\begin{array}{c@{}c@{}c@{}c@{}c@{}c@{}c} a_{11}x_1&+&a_{12}x_2&+\cdots+&a_{1n}x_n&=&b_1 \\ a_{21}x_1&+&a_{22}x_2&+\cdots+&a_{2n}x_n&=&b_2 \\ \vdots&&\vdots&&\vdots&&\vdots\\ a_{m1}x_1&+&a_{m2}x_2&+\cdots+&a_{mn}x_n&=&b_m \\ \end{array}\right .);
+
+* ソースコード [#p0757512]
+
+math.inc.php
+
+ LANG:php(linenumber)
<?php
//
// pukiwiki用 数式プラグイン (math.inc.php)
// Copywrite 2011 Osamu Takeuchi <osamu@big.jp>
//
+ // [履歴]
+ // 2011.05.04 初期リリース
+ //
// [インストール]
- // ソースファイルを (pukiwiki)/plugin/ ディレクトリにコピーする
+ // ソースファイルを (pukiwiki)/plugin/math.inc.php として保存
//
// [設定]
// MATHIMG_DIR に画像ファイルが作成される
- // 標準では (pukiwiki)/mathimg に画像ファイルが作成される
+ // 標準では (pukiwiki)/mathimg に画像ファイルが作成される
+ // function user_macros() に TeX マクロを記述できる
+ // function use_svg() でインライン svg を使うかどうかを判断する
//
// [使い方]
// &math(y=ax^2+bx+c); のように、&math(); 中に TeX ソース形式で
@@ -39,7 +90,6 @@
\newcommand{\DIV}[0]{{\rm div}\,}
\newcommand{\GRAD}[0]{{\rm grad}\,}
';
-
}
function math2tex($math){
@@ -89,12 +139,15 @@
{
$xmm = new MinMax();
$ymm = new MinMax();
- $converted = array();
- while(!feof($srch)) {
+ $converted = array();
+ while(!feof($srch)) {
$line = fgets($srch);
- if (preg_match("/<g transform=\"[^\"]+\" (.*)/", $line, $matches)) {
- $converted[] = "<g {$matches[1]}>";
+ if (preg_match("/<g /", $line, $matches)) {
+ $converted[] = preg_replace("/ transform=\"[^\"]*\"/", "", $line);
} else
+ if (preg_match("/<\/g>/", $line, $matches)) {
+ $converted[] = $line;
+ } else
if (preg_match("/<line (.*)/", $line, $matches)) {
$params = $matches[1];
if (preg_match("/x1=\"([^\"]+)\"/", $params, $matches))
@@ -140,15 +193,15 @@
$converted[] = $line;
}
}
- return array( $xmm, $ymm, implode($converted) );
+ return array( $xmm, $ymm, implode($converted) );
}
function format_svg($math, $srch)
{
list( $xmm, $ymm, $converted ) = calc_bounding_box($math, $srch);
- $margin= 0.02;
- $scale= 1.35;
+ $margin= 0.02;
+ $scale= 1.35;
$math_encoded = htmlspecialchars($math);
$width = ( $xmm->max() - $xmm->min() + $margin*2 ) * $scale;
@@ -156,20 +209,13 @@
$transx = - ( $xmm->min() - $margin );
$transy = - ( $ymm->max() + $margin );
return
- "<svg width=\"{$width}\" height=\"{$height}\" " .
- "xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" " .
- "style=\"vertical-align:middle;\" >\n" .
+ "<svg width=\"{$width}\" height=\"{$height}\" " .
+ "xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" " .
+ "style=\"vertical-align:middle;\" >\n" .
"<title>{$math_encoded}</title>\n" .
- "<g transform=\"scale({$scale},-{$scale}) translate({$transx}, " .
- "{$transy})\" stroke=\"black\" stroke-linecap=\"butt\" " .
- "stroke-linejoin=\"miter\" stroke-miterlimit=\"10.433\" " .
- "stroke-dasharray=\"none\" stroke-dashoffset=\"0\" stroke-opacity=\"1\" " .
- "fill=\"none\" fill-rule=\"even-odd\" fill-opacity=\"1\" font-style=\"normal\" " .
- "font-variant=\"normal\" font-weight=\"normal\" font-stretch=\"normal\" " .
- "font-size-adjust=\"none\" letter-spacing=\"normal\" word-spacing=\"normal\" " .
- "text-anchor=\"start\">\n" .
- "{$converted}\n" .
- "</g></svg>\n";
+ "<g transform=\"scale({$scale},-{$scale}) translate({$transx}, {$transy})\">\n" .
+ "{$converted}\n" .
+ "</g></svg>\n";
}
function create_image_files($math, $image_dir, $image_png, $image_svg)
@@ -201,11 +247,11 @@
$svgh = fopen($image_svg, "w");
fwrite($svgh, $svg);
fclose($svgh);
- } catch(Exception $e) {
- # cleanup temporary files
- # system("rm " . $tmp_any);
+ } catch(Exception $e) {
+ # cleanup temporary files
+ system("rm " . $tmp_any);
throw $e;
- }
+ }
}
function math2html($math)
@@ -254,3 +300,7 @@
}
?>
+
+* コメント [#od7d9c0b]
+
+#article_kcaptcha