Class Generators::TexParser
In: generators/xhtml_generator.rb
Parent: HyperlinkHtml

Note that Japanese and English are described in parallel.

TeX の数式を MathML に変換

TeX で記述された数式を MathML に変換します. インラインで表示したい場合, TeX の数式を以下のように $ … $ でくくって 記述してください. $ の 前後には半角空白を一文字以上入れて下さい.

  インラインで表示する数式は $ f(x) = x^2 + 1 $ のように記述します.
  ($ の前後に空白をお忘れなく).

ブロックで表示する場合, 以下のように \[ と \] とでくくって記述してください. \[, \] は必ず行頭に記述してください.

  \[
     \sum_{i=1}^nf_n(x)
  \]

TeX の数式から MathML 変換には Ruby 用 MathML ライブラリのバージョン 0.5 を使用しています. このライブラリはひらくの工房 にて公開されています. 使用できる TeX コマンドの詳細に関しても こちらのサイトを参照してください.

作成されたドキュメントを閲覧する際には MathML に対応した ブラウザを使用する必要が あります. MathML 日本語情報MathML Software - Browsers などを参照してください.

TeX is converted to MathML

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.5 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.

Methods

Public Class methods

[Source]

    # File generators/xhtml_generator.rb, line 75
75:     def initialize(*args)
76:       super(*args)
77:     end

Public Instance methods

[Source]

    # 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:       location = file_name
90:       location += "#"+class_or_method if class_or_method
91:     end

TEXBLOCK pattern \[…\] is converted to MathML format when —mathml option is given.

[Source]

     # File generators/xhtml_generator.rb, line 123
123:     def handle_special_TEXBLOCK(special)
124:       text = special.text
125:       return text unless Options.instance.mathml
126:       text.sub!(/^\\\[/, '')
127:       text.sub!(/\\\]$/, '')
128:       tex = MathMLWrapper.new
129:       mathml, stat = tex.parse(text, true)
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 mathml
135:     end

TEXINLINE pattern $…$ is converted to MathML format when —mathml option is given.

[Source]

     # File generators/xhtml_generator.rb, line 96
 96:     def handle_special_TEXINLINE(special)
 97:       text = special.text
 98:       return text unless Options.instance.mathml
 99:       raw_text = text.scan(/^.*?\$/).to_s.sub(/\$$/, '')
100:       text.sub!(/^.*?\$/, '')
101:       text.sub!(/\$$/, '')
102:       tex = MathMLWrapper.new
103:       mathml, stat = tex.parse(text)
104:       if !stat.zero?
105:         $stderr.puts "Warning: in #{file_location}, following TeX commands can not be converted to MathML\n\n",
106:         "    #{text}\n\n"
107:       end
108:       return raw_text + mathml
109:     end

TEXINLINEDELIMITER pattern "\$" is converted to single dollar "$" when —mathml option is given.

[Source]

     # File generators/xhtml_generator.rb, line 114
114:     def handle_special_TEXINLINEDELIMITER(special)
115:       text = special.text
116:       return text unless Options.instance.mathml
117:       return text.gsub(/\\\$/, '$')
118:     end

[Validate]