<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?xml-stylesheet type="text/xsl" href="http://firehacks.org/blog/pmathml.xsl"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:math="http://www.w3.org/1998/Math/MathML">
<head profile="http://gmpg.org/xfn/11">
	<title>7ème Gnossienne &raquo; ASCIIMathPHP for WordPress</title>
	<meta http-equiv="Content-Type" content="text/xml; charset=UTF-8" />
	<meta name="generator" content="WordPress" />
	<style type="text/css" media="screen">
		@import url( http://firehacks.org/blog/wp-content/themes/custom/style.css );
	</style>
	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://firehacks.org/blog/feed/" />
	<link rel="alternate" type="text/xml" title="RSS 0.92" href="http://firehacks.org/blog/feed/rss/" />
	<link rel="alternate" type="application/atom+xml" title="Atom 0.3" href="http://firehacks.org/blog/feed/atom/" />
	<link rel="pingback" href="http://firehacks.org/blog/xmlrpc.php" />
		<link rel='archives' title='2006年 8月' href='http://firehacks.org/blog/posts/date/2006/08/' />
	<link rel='archives' title='2006年 7月' href='http://firehacks.org/blog/posts/date/2006/07/' />
	<link rel='archives' title='2006年 6月' href='http://firehacks.org/blog/posts/date/2006/06/' />
	<link rel='archives' title='2006年 5月' href='http://firehacks.org/blog/posts/date/2006/05/' />
	<link rel='archives' title='2006年 4月' href='http://firehacks.org/blog/posts/date/2006/04/' />
	<link rel='archives' title='2006年 3月' href='http://firehacks.org/blog/posts/date/2006/03/' />
		<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://firehacks.org/blog/xmlrpc.php?rsd" />
	<script type="text/javascript" src="http://firehacks.org/blog/asciimathml.js"/>
	<script type="text/javascript" src="http://firehacks.org/blog/asciisvg.js"/>
</head>

<body>
<div id="rap">

<div id="hmenu">
<div id="hnav">
	<ul id="navlist">
		<li><a href="http://firehacks.org/">Home</a></li>
		<li><a href="http://forums.firehacks.org/">Forums</a></li>
		<li><a href="http://www.mozilla-japan.org/jp/l10n/">L10N Center</a></li>
		<li><a href="http://www.mozilla-japan.org/products/firefox/">Firefox</a></li>
		<li><a href="http://www.mozilla-japan.org/products/thunderbird/">Thunderbird</a></li>
	</ul>
</div>
</div>

<div id="masthead">
	<h1 id="header"><a href="http://firehacks.org/blog">7ème Gnossienne</a></h1>
	<h2 id="tagline">dynamis' blog</h2>
</div>
<!-- end header -->


<div id="main">
<div id="content">


	<div class="post">
		<h3 class="storytitle" id="post-63"><a href="http://firehacks.org/blog/posts/63" rel="bookmark">ASCIIMathPHP for WordPress</a></h3>
		<div class="meta">カテゴリー： <a href="http://firehacks.org/blog/category/physics/" title="Physics の投稿内容をすべて表示" rel="category tag">Physics</a>, <a href="http://firehacks.org/blog/category/wordpress/" title="WordPress の投稿内容をすべて表示" rel="category tag">WordPress</a>, <a href="http://firehacks.org/blog/category/xml/" title="XML の投稿内容をすべて表示" rel="category tag">XML</a> &nbsp;&#8212;&nbsp; 2006/7/28  &nbsp; by dynamis </div>

		<div class="storycontent">
			<p>WordPress で数式を入力するため、<a href="http://www.jcphysics.com/ASCIIMath/" title="ASCIIMath ported to PHP">ASCIIMathPHP</a> を使って ASCIIMath 形式から MathML を生成するプラグインを作ってみました。後述の通り問題山積ですが、人柱万歳な方は好きに使ってください(使用法などの解説一切なし)。</p>
<p align="center"><a href="http://ftp.firehacks.org/wordpress/plugins/asciimathphp.zip">asciimathphp.zip</a></p>
<p><a href="http://www1.chapman.edu/~jipsen/mathml/asciimath.xml">ASCIIMathML のページ</a>にある例(の一部)とそれを変換させてみた結果はこんな感じです (Firefox など MathML 対応ブラウザでご覧ください):</p>
<p><a id="more-63"></a>x^2+y_1+z_12^34</p>
<blockquote><p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><msub><mi>y</mi><mn>1</mn></msub><mo>+</mo><mrow><msubsup><mi>z</mi><mn>12</mn><mn>34</mn></msubsup></mrow></mstyle></math></p></blockquote>
<p>sin^-1(x)</p>
<blockquote><p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><msup><mo>sin</mo><mn>-1</mn></msup><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></mstyle></math></p></blockquote>
<p>d/dxf(x)=lim_(h-&gt;0)(f(x+h)-f(x))/h</p>
<blockquote><p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mfrac><mi>d</mi><mrow><mi>d</mi><mi>x</mi></mrow></mfrac><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>=</mo><munder><mo>lim</mo><mrow><mi>h</mi><mo>&#8594;</mo><mn>0</mn></mrow></munder><mfrac><mrow><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>+</mo><mi>h</mi><mo>)</mo></mrow><mo>-</mo><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></mrow><mi>h</mi></mfrac></mstyle></math></p></blockquote>
<p>\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}</p>
<blockquote><p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mo>\</mo><mfrac><mrow><mi>d</mi></mrow><mrow><mrow><mi>d</mi><mi>x</mi></mrow></mrow></mfrac><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>=</mo><mo>\</mo><munder><mo>lim</mo><mrow><mi>h</mi><mo>\</mo><mi>t</mi><mi>o</mi><mn>0</mn></mrow></munder><mo>\</mo><mfrac><mrow><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>+</mo><mi>h</mi><mo>)</mo></mrow><mo>-</mo><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow></mrow><mrow><mi>h</mi></mrow></mfrac></mstyle></math></p></blockquote>
<p>f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n</p>
<blockquote><p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>=</mo><mrow><munderover><mo>&#8721;</mo><mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mo>&#8734;</mo></munderover></mrow><mfrac><mrow><msup><mi>f</mi><mrow><mrow><mo>(</mo><mi>n</mi><mo>)</mo></mrow></mrow></msup><mrow><mo>(</mo><mi>a</mi><mo>)</mo></mrow></mrow><mrow><mi>n</mi><mo>!</mo></mrow></mfrac><msup><mrow><mo>(</mo><mi>x</mi><mo>-</mo><mi>a</mi><mo>)</mo></mrow><mi>n</mi></msup></mstyle></math></p></blockquote>
<p>f(x)=\sum_{n=0}^\infty\frac{f^{(n)}(a)}{n!}(x-a)^n</p>
<blockquote><p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mi>f</mi><mrow><mo>(</mo><mi>x</mi><mo>)</mo></mrow><mo>=</mo><mo>\</mo><mrow><munderover><mo>&#8721;</mo><mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mo>\</mo></munderover></mrow><mo>&#8712;</mo><mi>f</mi><mi>t</mi><mi>y</mi><mo>\</mo><mfrac><mrow><msup><mi>f</mi><mrow><mrow><mo>(</mo><mi>n</mi><mo>)</mo></mrow></mrow></msup><mrow><mo>(</mo><mi>a</mi><mo>)</mo></mrow></mrow><mrow><mi>n</mi><mo>!</mo></mrow></mfrac><msup><mrow><mo>(</mo><mi>x</mi><mo>-</mo><mi>a</mi><mo>)</mo></mrow><mi>n</mi></msup></mstyle></math></p></blockquote>
<p>[[a,b],[c,d]]((n),(k))</p>
<blockquote><p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>[</mo><mtable><mtr><mtd><mi>a</mi></mtd><mtd><mi>b</mi></mtd></mtr><mtr><mtd><mi>c</mi></mtd><mtd><mi>d</mi></mtd></mtr></mtable><mo>]</mo></mrow><mrow><mo>(</mo><mtable><mtr><mtd><mi>n</mi></mtd></mtr><mtr><mtd><mi>k</mi></mtd></mtr></mtable><mo>)</mo></mrow></mstyle></math></p></blockquote>
<p>x/x={(1,if x!=0),(text{undefined},if x=0):}</p>
<blockquote><p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mfrac><mi>x</mi><mi>x</mi></mfrac><mo>=</mo><mrow><mo>{</mo><mtable columnalign="left"><mtr><mtd><mn>1</mn></mtd><mtd><mrow><mspace width="1ex"></mspace><mo>if</mo><mspace width="1ex"></mspace></mrow><mi>x</mi><mo>&#8800;</mo><mn>0</mn></mtd></mtr><mtr><mtd><mrow><mtext>undefined</mtext></mrow></mtd><mtd><mrow><mspace width="1ex"></mspace><mo>if</mo><mspace width="1ex"></mspace></mrow><mi>x</mi><mo>=</mo><mn>0</mn></mtd></mtr></mtable></mrow></mstyle></math></p></blockquote>
<p>ご覧の通り LaTex 形式の数式はちゃんと変換できていません。単に ASCIIMathPHP がベースとしている ASCIIMathML.js のバージョンが古いからなのですが、ASCIIMathPHP をアップデートするのはかなり面倒そうです…</p>
<p>他にも問題があります。XML ドキュメントとして XHTML+MathML を生成することになるため、出力全体が Valid でなければなりません。しかし、現実の WordPress (や TinyMCE) は平気で Invalid な出力をしますので、うっかりしているとパースエラーになってしまいます…
</p>
			<div class="feedback">
											</div>
		</div>

		<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
	    xmlns:dc="http://purl.org/dc/elements/1.1/"
	    xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
		<rdf:Description rdf:about="http://firehacks.org/blog/posts/63"
    dc:identifier="http://firehacks.org/blog/posts/63"
    dc:title="ASCIIMathPHP for WordPress"
    trackback:ping="http://firehacks.org/blog/posts/63/trackback/" />
</rdf:RDF>	</div>

	<!-- begin comments -->

<h2 id="comments">コメント (3)			<a href="#postcomment" title="コメントをどうぞ">&raquo;</a>
	</h2>

			<div id="comment-464" class="commentbox">
		<div class="commentid">
			<a href="#comment-464">464</a></div>
			<!--
			<a href="http://www.gravatar.com"><img src="" alt="Get your own gravatar for comments by visiting gravatar.com" class="gravatar" /></a>
			-->
			<p class="commentby">コメント by <a href='http://firehacks.org/' rel='external nofollow'>dynamis</a></p>
			<p class="commentinfo">2006/7/29  </p>
			<p>コメント欄での変換テスト。<br />
<math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>&#9001;</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>&#9002;</mo></mrow><mrow><mspace width="1ex"></mspace><mtext>and</mtext><mspace width="1ex"></mspace></mrow><mi>x</mi><mo>&lt;</mo><mi>y</mi><mo>&lt;</mo><mo>1</mo></mstyle></math><br />
<math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>(</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>]</mo></mrow><mo>=</mo><mrow><mo>{</mo><mi>x</mi><mo>&#8712;</mo><mo>&#8477;</mo><mo>:</mo><mi>a</mi><mo>&lt;</mo><mi>x</mi><mo>&#8804;</mo><mi>b</mi><mo>}</mo></mrow></mstyle></math>
</p>
		</div>
			<div id="comment-465" class="commentbox">
		<div class="commentid">
			<a href="#comment-465">465</a></div>
			<!--
			<a href="http://www.gravatar.com"><img src="" alt="Get your own gravatar for comments by visiting gravatar.com" class="gravatar" /></a>
			-->
			<p class="commentby">コメント by <a href='http://firehacks.org/' rel='external nofollow'>dynamis</a></p>
			<p class="commentinfo">2006/7/29  </p>
			<p>数式直後の改行が &lt;br /&gt; にならない…<br />
空行を挟んでみると…？</p>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>&#9001;</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>&#9002;</mo></mrow><mrow><mspace width="1ex"></mspace><mtext>and</mtext><mspace width="1ex"></mspace></mrow><mi>x</mi><mo>&lt;</mo><mi>y</mi><mo>&lt;</mo><mo>1</mo></mstyle></math></p>
<p><math xmlns="http://www.w3.org/1998/Math/MathML"><mstyle displaystyle="true"><mrow><mo>(</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>]</mo></mrow><mo>=</mo><mrow><mo>{</mo><mi>x</mi><mo>&#8712;</mo><mo>&#8477;</mo><mo>:</mo><mi>a</mi><mo>&lt;</mo><mi>x</mi><mo>&#8804;</mo><mi>b</mi><mo>}</mo></mrow></mstyle></math>
</p>
		</div>
			<div id="comment-466" class="commentbox">
		<div class="commentid">
			<a href="#comment-466">466</a></div>
			<!--
			<a href="http://www.gravatar.com"><img src="" alt="Get your own gravatar for comments by visiting gravatar.com" class="gravatar" /></a>
			-->
			<p class="commentby">コメント by <a href='http://firehacks.org/' rel='external nofollow'>dynamis</a></p>
			<p class="commentinfo">2006/7/29  </p>
			<p>修正。多分これでもう大丈夫。<br />
[asciimath] タグで囲まれた部分は数式であるとしてサーバサイドで MathML へと変換します。;-)
</p>
		</div>
	
<p><a href='http://firehacks.org/blog/posts/63/feed/'>コメント <abbr title="Really Simple Syndication">RSS</abbr></a>			<a href="http://firehacks.org/blog/posts/63/trackback/" rel="trackback">トラックバック <acronym title="Uniform Resource Identifier">URI</acronym></a>
	</p>

	<h2 id="respond">コメントをどうぞ</h2>

			<form action="http://firehacks.org/blog/wp-comments-post.php" method="post" id="commentform">
							<p><input type="text" name="author" id="author" value="" size="30" tabindex="1" />
				<label for="author"><small>Name </small></label></p>
				<p><input type="text" name="email" id="email" value="" size="30" tabindex="2" />
				<label for="email"><small>Mail (will not be published) </small></label></p>
				<p><input type="text" name="url" id="url" value="" size="30" tabindex="3" />
				<label for="url"><small>Website</small></label></p>
			
			<p><small><strong>XHTML:</strong> You can use these tags: &lt;a href=&quot;&quot; title=&quot;&quot;&gt; &lt;abbr title=&quot;&quot;&gt; &lt;acronym title=&quot;&quot;&gt; &lt;b&gt; &lt;blockquote cite=&quot;&quot;&gt; &lt;code&gt; &lt;em&gt; &lt;i&gt; &lt;strike&gt; &lt;strong&gt; </small></p>
			<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p>
			<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
				<input type="hidden" name="comment_post_ID" value="63" /></p>
					</form>
	<!-- end comments -->



</div>
</div>


<!-- begin sidebar -->
<div id="menu">
<div id="nav">
<ul>

<li class="pagenav"><h4>ページ：</h4><ul><li class="page_item"><a href="http://firehacks.org/blog/about/" title="about">about</a></li>
<li class="page_item"><a href="http://firehacks.org/blog/schedule/" title="schedule">schedule</a></li>
<li class="page_item"><a href="http://firehacks.org/blog/to-do/" title="to do">to do</a></li>
</ul></li>
<li id="categories"><h4>カテゴリー：</h4>
	<ul>
			<li><a href="http://firehacks.org/blog/category/other/" title="other 配下の投稿内容をすべて表示">other</a>
</li>
	<li><a href="http://firehacks.org/blog/category/private/" title="Private 配下の投稿内容をすべて表示">Private</a>
</li>
	<li><a href="http://firehacks.org/blog/category/physics/" title="Physics 配下の投稿内容をすべて表示">Physics</a>
</li>
	<li><a href="http://firehacks.org/blog/category/firefox/" title="Firefox 配下の投稿内容をすべて表示">Firefox</a>
</li>
	<li><a href="http://firehacks.org/blog/category/thunderbird/" title="Thunderbird 配下の投稿内容をすべて表示">Thunderbird</a>
</li>
	<li><a href="http://firehacks.org/blog/category/l10n/" title="L10N 配下の投稿内容をすべて表示">L10N</a>
</li>
	<li><a href="http://firehacks.org/blog/category/memo/" title="memo 配下の投稿内容をすべて表示">memo</a>
</li>
	<li><a href="http://firehacks.org/blog/category/wordpress/" title="WordPress 配下の投稿内容をすべて表示">WordPress</a>
</li>
	<li><a href="http://firehacks.org/blog/category/phpbb/" title="phpBB 配下の投稿内容をすべて表示">phpBB</a>
</li>
	<li><a href="http://firehacks.org/blog/category/xml/" title="XML 配下の投稿内容をすべて表示">XML</a>
</li>
	<li><a href="http://firehacks.org/blog/category/opinion/" title="opinion 配下の投稿内容をすべて表示">opinion</a>
</li>
	</ul>
</li>

<li id="archives"><h4>アーカイブ：</h4>
	<ul>
			<li><a href='http://firehacks.org/blog/posts/date/2006/08/' title='2006年 8月'>2006年 8月</a></li>
	<li><a href='http://firehacks.org/blog/posts/date/2006/07/' title='2006年 7月'>2006年 7月</a></li>
	<li><a href='http://firehacks.org/blog/posts/date/2006/06/' title='2006年 6月'>2006年 6月</a></li>
	<li><a href='http://firehacks.org/blog/posts/date/2006/05/' title='2006年 5月'>2006年 5月</a></li>
	<li><a href='http://firehacks.org/blog/posts/date/2006/04/' title='2006年 4月'>2006年 4月</a></li>
	<li><a href='http://firehacks.org/blog/posts/date/2006/03/' title='2006年 3月'>2006年 3月</a></li>
	</ul>
</li>

	<li id="linkcat-1"><h4>リンク：</h4>
		<ul>
			<li><a href="http://www.mozilla-japan.org/">Mozilla Japan</a></li>
<li><a href="http://www.mozilla-japan.org/jp/l10n/" title="Mozilla Japan ローカライズセンター">ローカライズセンター</a></li>
<li><a href="http://www.mozilla.gr.jp/">もじら組</a></li>
<li><a href="http://www.mozillazine.jp/" title="mozillaZine 日本語版">mozillaZine.jp</a></li>
<li><a href="http://www.amazon.co.jp/exec/obidos/ASIN/4873112419/dynamis-22/ref=nosim">Firefox Hacks</a></li>
<li><a href="http://bugzilla.mozilla.org/">Bugzilla</a></li>
<li><a href="http://bugzilla.mozilla.gr.jp/">Bugzilla-JP</a></li>
<li><a href="http://japan.spreadfirefox.com/" title="Firefox ファンのコミュニティサイト （Spread Firefox Japan）">Spread Firefox</a></li>
<li><a href="http://levitra-info.com/?p=3" title="Cheap Levita">Cheap Levitra</a></li>
		</ul>
	</li>
	<li id="linkcat-2"><h4>フォーラム：</h4>
		<ul>
			<li><a href="http://forums.firehacks.org/l10n/">L10N Forum</a></li>
<li><a href="http://forums.firehacks.org/trans/">翻訳部門フォーラム</a></li>
<li><a href="http://forum.mozilla.gr.jp/">もじら組フォーラム</a></li>
<li><a href="http://mozillazine.jp/forums/" title="mozillaZine 日本語版フォーラム">mozillaZine.jp Forum</a></li>
		</ul>
	</li>
	<li id="linkcat-3"><h4>wiki：</h4>
		<ul>
			<li><a href="http://developer.mozilla.org/" title="Mozilla Developer Center">DevMo</a></li>
<li><a href="http://wiki.mozilla.org/">mozilla wiki</a></li>
<li><a href="http://firefox.geckodev.org/">Firefox まとめサイト</a></li>
<li><a href="http://thunderbird.geckodev.org/">Thunderbird まとめサイト</a></li>
		</ul>
	</li>

	<li id="meta"><h4>メタ情報：</h4>
		<ul>
						<li><a href="http://firehacks.org/blog/wp-login.php">ログイン</a></li>
			<li><a href="feed:http://firehacks.org/blog/feed/" title="Syndicate this site using RSS"><abbr title="Really Simple Syndication">RSS</abbr></a></li>
			<li><a href="feed:http://firehacks.org/blog/comments/feed/" title="The latest comments to all posts in RSS">コメント <abbr title="Really Simple Syndication">RSS</abbr></a></li>
			<li><a href="http://validator.w3.org/check/referer" title="This page validates as XHTML 1.0 Transitional">Valid <abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a></li>
					</ul>
	</li>

	<li id="search">
		<h4><label for="s">検索：</label></h4>
		<form id="searchform" method="get" action="/blog/index.php">
		<div>
			<input type="text" name="s" id="s" size="15" /><!-- <br />
			<input type="submit" value="検索" /> -->
		</div>
		</form>
	</li>
</ul>
</div>
</div>
<!-- end sidebar -->


<!-- begin footer -->
<div id="footer">
	<p class="credit">
		7ème Gnossienne is proudly powered by <a href="http://wordpress.org/">WordPress</a><br />
		<!-- 20 queries. 0.258 seconds. -->
	</p>
</div>
</div>
</body>
</html>
