サマリ | LaTeXのインストールなしでLaTeX数式を表示させるプラグイン |
---|---|
リビジョン | 1.0 |
対応バージョン | 1.4.7 |
投稿者 | abicky |
投稿日 | 2010-04-18 (日) 10:41:04 |
PukiWikiでTeXの数式を表示するためのプラグイン.
ref.inc.phpをベースに作成しました.なので強制的にGPLライセンスになるのかと思って一応GPLということにしておきます.
#tex($数式$ [,options] [,parameters]) &tex($数式$ [,options] [,parameters]); options left: 左寄せ(デフォルト) center: 中央揃え right: 右寄せ around: 回り込み link: 元ファイルへのリンクを貼る url: Google Chart API のURLを表示する noimg: 画像を展開しない zoom: 縦横比を保持する(拡大率の小さい方に合わせる) parameters WIDTHxHEIGHT: WIDTH px,HEIGHT pxにする ※WIDTH, HEIGHT は数値 NUM%: NUM%のサイズにする ※NUM は数値 #RRGGBB: 数式の色を16進数で指定(デフォルトは#000000) bg#RRGGBBAA: 背景色を16進数で指定.AAは不透過度(デフォルトは#ffffff00) TITLE: タイトルをTITLEにする
こちらを御覧下さい
LaTeXのようにドルマークで挟んだり,\[ \]などで挟んだりすることで数式を書きたい場合は以下のような変更を加えることで実現できます.
※この記法でオプションは使えません
$converters = array( 'plugin', // Inline plugins 'TeX', // LaTeX Mathematical Expression 'note', // Footnotes 'url', // URLs 'url_interwiki', // URLs (interwiki definition) 'mailto', // mailto: URL schemes 'interwikiname', // InterWikiNames 'autolink', // AutoLinks 'bracketname', // BracketNames 'wikiname', // WikiNames 'autolink_a', // AutoLinks(alphabet) );
// LaTeX Mathematical Expression class Link_TeX extends Link_plugin { function Link_plugin($start) { parent::Link_plugin($start); } function get_pattern() { $this->pattern = '(?<!\\\\)\$((.+?))(?<!\\\\)\$'; return $this->pattern; } function get_count() { return 2; } function set($arr, $page) { list($all, $this->plain, $this->param) = $this->splice($arr); $matches = array(); return parent::setParam($page, 'tex', '', 'plugin'); } }
$retval .= array_shift($arr) . array_shift($this->result); ↓ $retval .= str_replace('\$', '$', array_shift($arr)) . array_shift($this->result);※ドルマークを表示させる場合は\$と表記します
// LaTeX Mathematical Expression if (substr($line, 0, 2) == '\[') { if (strpos($line, '\]') === false){ while (! empty($lines)) { $next_line = preg_replace("/[\r\n]*$/", '', array_shift($lines)); $line .= $next_line; if (strpos($next_line, '\]') !== false) break; } } $this->last = & $this->last->add(TeX($this, $line)); continue; } else if (substr($line, 0, 6) == '\begin'){ if (strpos($line, '\end') === false){ while (! empty($lines)) { $next_line = preg_replace("/[\r\n]*$/", '', array_shift($lines)); $line .= $next_line; if (strpos($line, '\end') !== false) break; } } $this->last = & $this->last->add(TeX($this, $line)); continue; }
function & TeX(& $root, $text) { if(exist_plugin_convert('tex')) return new Div(array('', 'tex', $text)); else return new Paragraph($text); }
不具合や感想などがあればこちらで投稿お願いします.