最近はいろいろな方法があるようであるが...
ここでは簡単な方法を使う。ただし Mac が必要。iDraw.app (Graphics) を使う1。
iDraw は TeX で生成された PDF を文字単位の構成要素にまで細分化し、編集可能にする。従って、一部分だけを選択して SVG ファイルを作り出すことが可能である。これは他の方法に比べて、大量の数式を扱いたいときに有利に働く。
以下のサンプル(Plain TeX で書かれている)
$$a\int_0^{\pi\over 2} \sqrt{\cos^2 \theta + \lambda^2 \sin^2 \theta} \, {\tt d} \theta$$
\medskip
where
$\lambda = b/a$
\end
から生成された PDF ファイルの一部を抜き取って作成された SVG による数式を次に示す。LaTeX の方が好みなら、もちろん LaTeX を使ってもよい。
Italic を指定しても、数式に使われる変数のフォントにはならない: Italic (小文字 a に注目する)
残念ながら、本文中に TeX フォントを使うよい方法が存在しない。
いや、そうでもない。次のように TeX フォントが使える。(これは cmmi フォント)
<style type="text/css">
@font-face {
font-family: 'cmmi10';
src: url('texfonts/cmmi10.woff') format('woff');
font-weight: normal;
font-style: normal; }
</style>
が必要。
うーん、記号文字が化けている。もとのHTMLコードは
<div style="font-family:cmmi10; font-size:100%; line-height:120%"> abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 .,:;!?&‘“’” </div>だったのよね。従って、λ=b/a は
<span style=font-family:cmmi10;">λ</span>=<span style=font-family:cmmi10;">b</span>/<span style=font-family:cmmi10;">a</span>と書けば λ=b/a となるが、非常に面倒臭い。さらにギリシャ文字のラムダは(Safari 以外は)正確には cmmi フォントにはなっていない。文字化けしない、ちゃんとしたcmmiフォントはないのか?
そうは言っても、この問題は原理的な困難を伴う。そもそも cmmi には '=' も ':' も '!' などは存在しないのである。cmmi の文字テーブル(0 ~ 127)は ASCII と全く異なる。例えばギリシャ文字を含む。ここで行われたことは、
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789 .,:;!?&‘“’”
それではギリシャ文字や特殊記号は文字コード "" で書いたらどうか?
残念ながら、それも上手くは行かない。"" で X ≦ 32 は捨てられてしまう。
上の SVG の取り込みは
<object type="image/svg+xml" data="a1.svg" height="16px"></object>でやったのであるが、
こんなのはどうか?
これは style の position を使って、
<object type="image/svg+xml" data="a1.svg" height="16px" style="position:relative; top:5px"></object>で書いている。
2次方程式の例
<math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>a</mi> <msup><mi>x</mi><mn>2</mn></msup> <mo>+</mo> <mi>b</mi> <mi>x</mi> <mo>+</mo> <mi>c</mi> <mo>=</mo> <mn>0</mn> <mspace width="1em"/> <mtext>(</mtext> <mi>a</mi> <mo>≠</mo> <mn>0</mn> <mtext>)</mtext> </math>Safari の結果を画像で示す
いろいろなブラウザで試してみよう。
このブラウザの結果:
結果の評価
| name | 評価 |
|---|---|
| Safari | 満点 |
| Firefox | ほぼ良好 (Tex の Math Font になっていない1。x を見よ) |
| Opera | フォントがダメ |
| Chrome | フォントがダメ、肩付がダメ |
<mi>x</mi><msup><mn>2</mn></msup>
<msup><mi>x</mi><mn>2</mn></msup>
さて MathML を使ってλ=b/aを書くととなる。
この HTML コードは
<math xmlns="http://www.w3.org/1998/Math/MathML"> <mi>λ</mi><mo>=</mo><mi>b</mi><mo>/</mo><mi>a</mi> </math>である。もちろん、Safari 以外では正しいフォントにはならない。Safari においてもラムダは cmmi から少しだけ外れている。
総評: まだ青い果実。青いまま枯れるかも...(次の MathJax を見よ)
<head> ~~~~ </head>
<script async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"> </script>と書けばよい。また数式ラベルを扱いたい場合には
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }
});
</script>
の追加が必要である。
inline 数式は
\( .... \)
\[ .... \]
.... の部分に TeX 形式の数式を書く。
以下はサンプルである。
\( ax^2 + bx + c \ \) (\(a \neq 0\))
\(\lambda = a/b \)
\( a\int_0^{\pi\over 2} \sqrt{\cos^2 \theta + \lambda^2 \sin^2 \theta} \, {\tt d} \theta \)
\[ a\int_0^{\pi\over 2} \sqrt{\cos^2 \theta + \lambda^2 \sin^2 \theta} \, {\tt d} \theta \]
\begin{equation} x^2 - 6x + 1 = 0 \label{eq:foo} \end{equation} \begin{eqnarray*} 2x_1 + x_2 & = & 5 \\ 2x_2 & = & 2 \end{eqnarray*}
これらは次の HTML コードで
<p>
\( ax^2 + bx + c \ \) (\(a \neq 0\))
<p>
\(\lambda = a/b \)
<p>
\( a\int_0^{\pi\over 2} \sqrt{\cos^2 \theta + \lambda^2 \sin^2 \theta} \, {\tt d} \theta \)
<p>
\[ a\int_0^{\pi\over 2} \sqrt{\cos^2 \theta + \lambda^2 \sin^2 \theta} \, {\tt d} \theta \]
<p>
\begin{equation}
x^2 - 6x + 1 = 0 \label{eq:foo}
\end{equation}
\begin{eqnarray*}
2x_1 + x_2 & = & 5 \\
2x_2 & = & 2
\end{eqnarray*}
で生成されている。 TeX でおなじみの数式表現である。 \label{eq:foo}
\ref{eq:foo}
TeX のルール通り、
inline 数式を
$ .... $
$$ .... $$
$" を他の意味で使うことがあるから。
Computer Modern Font
Text Font
| type face | control | font name | abbreviation |
|---|---|---|---|
| Roman | \rm | Computer Modern Roman | cmr |
| Slanted | \sl | Computer Modern Slanted Italic | cmsl |
| Italic | \it | Computer Modern Text Italic | cmti |
| Typewriter | \tt | Computer Modern Typewriter Type | cmtt |
| Bold | \bf | Computer Modern Bold Extended | cmbx |
| font name | abbreviation |
|---|---|
| Computer Modern Math Italic | cmmi |
| Computer Modern Math Symbol | cmsy |
| Computer Modern Math Extension | cmex |