Class | Generators::TexParser |
In: |
generators/xhtml_generator.rb
|
Parent: | HyperlinkHtml |
Note that Japanese and English are described in parallel.
TeX で記述された数式を MathML に変換します. インラインで表示したい場合, TeX の数式を以下のように $ … $ でくくって 記述してください. $ の 前後には半角空白を一文字以上入れて下さい. (なお, "$Id: xhtml_generator.rb,v 1.9 2006/11/15 15:51:45 morikawa Exp $" や "$Log: xhtml_generator.rb,v $ (なお, "$Id: … $" や "Revision 1.9 2006/11/15 15:51:45 morikawa (なお, "$Id: … $" や "* The format of CVS keywords, that is "$Id: … $" or (なお, "$Id: … $" や " "$Log: … $" etc. is ignored. (なお, "$Id: … $" や " (なお, "$Id: … $" や "* "$Id: … $" や "$Log: … $" といった, CVS のキーワードとして (なお, "$Id: … $" や " 用いられている書き方は数式として扱わない. (なお, "$Id: … $" や "" といった, 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: xhtml_generator.rb,v 1.9 2006/11/15 15:51:45 morikawa Exp $" or "$Log: xhtml_generator.rb,v $ "Revision 1.9 2006/11/15 15:51:45 morikawa "* The format of CVS keywords, that is "$Id: … $" or " "$Log: … $" etc. is ignored. " "* "$Id: … $" や "$Log: … $" といった, CVS のキーワードとして " 用いられている書き方は数式として扱わない. "" 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 110 110: def initialize(*args) 111: super(*args) 112: end
# File generators/xhtml_generator.rb, line 114 114: def file_location 115: if @context.context.parent 116: class_or_method = @context.context.name 117: end 118: context = @context.context 119: while context.parent 120: context = context.parent 121: end 122: file_name = context.file_relative_name 123: 124: if class_or_method 125: location += "#"+class_or_method 126: else 127: location = file_name 128: end 129: end
TEXBLOCK pattern \[…\] is converted to MathML format when —mathml option is given.
# File generators/xhtml_generator.rb, line 162 162: def handle_special_TEXBLOCK(special) 163: text = special.text 164: return text unless Options.instance.mathml 165: text.sub!(/^\\\[/, '') 166: text.sub!(/\\\]$/, '') 167: tex = MathMLWrapper.new 168: mathml, stat = tex.parse(text, true) 169: if !stat.zero? 170: $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n", 171: " #{text}\n\n" 172: end 173: return mathml 174: end
TEXINLINE pattern $…$ is converted to MathML format when —mathml option is given.
# File generators/xhtml_generator.rb, line 134 134: def handle_special_TEXINLINE(special) 135: text = special.text 136: return text unless Options.instance.mathml 137: raw_text = text.scan(/^.*?\$/).to_s.sub(/\$$/, '') 138: return text if text =~ /^.*?\$[A-Z]\w+:/ # CVS keywords are skipped 139: text.sub!(/^.*?\$/, '') 140: text.sub!(/\$$/, '') 141: tex = MathMLWrapper.new 142: mathml, stat = tex.parse(text) 143: if !stat.zero? 144: $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n", 145: " #{text}\n\n" 146: end 147: return raw_text + mathml 148: end
TEXINLINEDELIMITER pattern "\$" is converted to single dollar "$" when —mathml option is given.
# File generators/xhtml_generator.rb, line 153 153: def handle_special_TEXINLINEDELIMITER(special) 154: text = special.text 155: return text unless Options.instance.mathml 156: return text.gsub(/\\\$/, '$') 157: end