Class | Generators::TexParser |
In: |
generators/xhtml_generator.rb
|
Parent: | HyperlinkHtml |
Note that Japanese and English are described in parallel.
TeX で記述された数式を MathML に変換します. インラインで表示したい場合, TeX の数式を以下のように $ … $ でくくって 記述してください. $ の 前後には半角空白を一文字以上入れて下さい.
インラインで表示する数式は $ f(x) = x^2 + 1 $ のように記述します. ($ の前後に空白をお忘れなく).
ブロックで表示する場合, 以下のように \[ と \] とでくくって記述してください. \[, \] は必ず行頭に記述してください.
\[ \sum_{i=1}^nf_n(x) \]
TeX の数式から MathML 変換には Ruby 用 MathML ライブラリのバージョン 0.5a を使用しています. このライブラリはひらくの工房 にて公開されています. 使用できる 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 "$".
Inline formula is $ f(x) = x^2 + 1 $ .
When block display, TeX formula should be bundled by \[ … \] as follows. Describe \[ and \] at the head of line.
\[ \sum_{i=1}^nf_n(x) \]
MathML library for Ruby version 0.5a 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 79 79: def file_location 80: if @context.context.parent 81: class_or_method = @context.context.name 82: end 83: context = @context.context 84: while context.parent 85: context = context.parent 86: end 87: file_name = context.file_relative_name 88: 89: if class_or_method 90: location += "#"+class_or_method 91: else 92: location = file_name 93: end 94: end
TEXBLOCK pattern \[…\] is converted to MathML format when —mathml option is given.
# File generators/xhtml_generator.rb, line 126 126: def handle_special_TEXBLOCK(special) 127: text = special.text 128: return text unless Options.instance.mathml 129: text.sub!(/^\\\[/, '') 130: text.sub!(/\\\]$/, '') 131: tex = MathMLWrapper.new 132: mathml, stat = tex.parse(text, true) 133: if !stat.zero? 134: $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n", 135: " #{text}\n\n" 136: end 137: return mathml 138: end
TEXINLINE pattern $…$ is converted to MathML format when —mathml option is given.
# File generators/xhtml_generator.rb, line 99 99: def handle_special_TEXINLINE(special) 100: text = special.text 101: return text unless Options.instance.mathml 102: raw_text = text.scan(/^.*?\$/).to_s.sub(/\$$/, '') 103: text.sub!(/^.*?\$/, '') 104: text.sub!(/\$$/, '') 105: tex = MathMLWrapper.new 106: mathml, stat = tex.parse(text) 107: if !stat.zero? 108: $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n", 109: " #{text}\n\n" 110: end 111: return raw_text + mathml 112: end
TEXINLINEDELIMITER pattern "\$" is converted to single dollar "$" when —mathml option is given.
# File generators/xhtml_generator.rb, line 117 117: def handle_special_TEXINLINEDELIMITER(special) 118: text = special.text 119: return text unless Options.instance.mathml 120: return text.gsub(/\\\$/, '$') 121: end