Class | Generators::TexParser |
In: |
generators/xhtml_generator.rb
|
Parent: | HyperlinkHtml |
Note that Japanese and English are described in parallel.
TeX で記述された数式を MathML に変換します. インラインで表示したい場合, TeX の数式を以下のように $ … $ でくくって 記述してください. $ の 前後には半角空白を一文字以上入れて下さい. (なお, "$ID: … $" や "$LOG: … $ といった, CVS のキーワードとして 用いられている書き方は数式として扱われません.)
インラインで表示する数式は $ f(x) = x^2 + 1 $ のように記述します. ($ の前後に空白をお忘れなく).
ブロックで表示する場合, 以下のように \[ と \] とでくくって記述してください. \[, は必ず行頭に記述してください.
\[ \sum_{i=1}^nf_n(x) \]
数式を複数行で表示する場合には, 改行する部分に "\] \[" を記述してください.
\[ d\zeta/dt + J(\psi,\zeta) = Ra \; dT/dx + \nabla\zeta, \] \[ dT/dt + J(\psi,T) - d\psi/dx = \nabla T, \] \[ \nabla\psi = \zeta \]
TeX の数式から MathML 変換には Ruby 用 MathML ライブラリのバージョン 0.6b を使用しています. このライブラリはひらくの工房 にて公開されています. 使用できる TeX コマンドの詳細に関しても こちらのサイトを参照してください.
作成されたドキュメントを閲覧する際には MathML に対応した ブラウザを使用する必要が あります. MathML 日本語情報 や MathML Software - Browsers などを参照してください.
TeX formula is converted to MathML. When inline display, TeX formula should be bundled by $ … $ as follows. One or more normal-width blank is necessary before and behind "$". (The format of CVS keywords, that is "$ID: … $" or "$LOG: … $ etc. is ignored.)
Inline formula is $ f(x) = x^2 + 1 $ .
When block display, TeX formula should be bundled by \[ … \] as follows. Describe \[ at the head of line.
\[ \sum_{i=1}^nf_n(x) \]
To write equations across multiple lines, describe "\] \[" as follows.
\[ d\zeta/dt + J(\psi,\zeta) = Ra \; dT/dx + \nabla\zeta, \] \[ dT/dt + J(\psi,T) - d\psi/dx = \nabla T, \] \[ \nabla\psi = \zeta \]
MathML library for Ruby version 0.6b is needed to convert TeX formula to MathML. This library is available from Bottega of Hiraku (JAPANESE only). See this site about available TeX commands.
When you browse generated documents, you need to use browers that can handle MathML. See MathML Software - Browsers, etc.
# File generators/xhtml_generator.rb, line 101 101: def file_location 102: if @context.context.parent 103: class_or_method = @context.context.name 104: end 105: context = @context.context 106: while context.parent 107: context = context.parent 108: end 109: file_name = context.file_relative_name 110: 111: if class_or_method 112: location += "#"+class_or_method 113: else 114: location = file_name 115: end 116: end
TEXBLOCK pattern \[…\] is converted to MathML format when —mathml option is given.
# File generators/xhtml_generator.rb, line 149 149: def handle_special_TEXBLOCK(special) 150: text = special.text 151: return text unless Options.instance.mathml 152: text.sub!(/^\\\[/, '') 153: text.sub!(/\\\]$/, '') 154: tex = MathMLWrapper.new 155: mathml, stat = tex.parse(text, true) 156: if !stat.zero? 157: $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n", 158: " #{text}\n\n" 159: end 160: return mathml 161: end
TEXINLINE pattern $…$ is converted to MathML format when —mathml option is given.
# File generators/xhtml_generator.rb, line 121 121: def handle_special_TEXINLINE(special) 122: text = special.text 123: return text unless Options.instance.mathml 124: raw_text = text.scan(/^.*?\$/).to_s.sub(/\$$/, '') 125: return text if text =~ /^.*?\$[A-Z]\w+:/ # CVS keywords are skipped 126: text.sub!(/^.*?\$/, '') 127: text.sub!(/\$$/, '') 128: tex = MathMLWrapper.new 129: mathml, stat = tex.parse(text) 130: if !stat.zero? 131: $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n", 132: " #{text}\n\n" 133: end 134: return raw_text + mathml 135: end
TEXINLINEDELIMITER pattern "\$" is converted to single dollar "$" when —mathml option is given.
# File generators/xhtml_generator.rb, line 140 140: def handle_special_TEXINLINEDELIMITER(special) 141: text = special.text 142: return text unless Options.instance.mathml 143: return text.gsub(/\\\$/, '$') 144: end