Class MathMLWrapper
In: markup/simple_markup/mathml_wrapper.rb
Parent: Object

This class is MathML module wrapper. If MathML module can not be loaded, methods in this module return raw argument without modification.

Methods

new   parse  

Constants

MACRO_PATH = "mathml/macro"   $LOAD_PATH/MACRO_PATH/* files are parsed as TeX macro

Public Class methods

[Source]

    # File markup/simple_markup/mathml_wrapper.rb, line 12
12:   def initialize
13:     @load_error_flag = false
14:     begin
15:       require "mathml"
16:       if !@@macro_input_flag
17:         @@mathml_formula_macro = MathML::LaTeX::Parser.new
18:         @@macro_input_flag = true
19:         $LOAD_PATH.each{ |lpath|
20:           macro_files = Dir::glob(File.join(lpath, MACRO_PATH, "*"))
21:           macro_files.each{ |mfile|
22:             if File.file?(mfile)
23:               File.open(mfile, "r" ) { |io|
24:                 io.each{ |line|
25:                   begin
26:                     @@mathml_formula_macro.macro.parse(line)
27:                   rescue MathML::LaTeX::ParseError
28:                     macroerrormsg = $!.to_s
29:                   rescue
30:                     macroerrormsg = $!.to_s
31:                   end
32:                   if macroerrormsg
33:                     $stderr.puts "Warning: in #{mfile}, following TeX macro causes #{macroerrormsg.to_s}\n\n",
34:                     "    #{line}\n\n"
35:                   end
36:                 }
37:               }
38:             end
39:           }
40:         }
41:       end
42:     rescue LoadError
43:       @load_error_flag = true
44:     end
45:   end

Public Instance methods

[Source]

    # File markup/simple_markup/mathml_wrapper.rb, line 46
46:   def parse(formula, block=false)
47:     return formula if @load_error_flag
48:     mathml_formula = @@mathml_formula_macro
49:     begin
50:       mathml_formula_str = mathml_formula.parse(formula, block).to_s
51:     rescue MathML::LaTeX::ParseError
52:       return formula, 1
53:     rescue
54:       return formula, 1
55:     end
56:     return mathml_formula_str, 0
57:   end

[Validate]