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

MATHML_NAME = "mathml"   Mathml library name
MACRO_PATH = "#{MATHML_NAME}/macro"   $LOAD_PATH/MACRO_PATH/* files are parsed as TeX macro

Public Class methods

[Source]

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

Public Instance methods

[Source]

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

[Validate]