18: def initialize
19:
20: err_count = 0
21: if !@@mathml_required
22: MATHML_NAME.each{ |ml|
23: begin
24: require ml
25: @@macro_path = File.join(ml, MACRO_REL_PATH)
26: rescue LoadError
27: err_count = err_count + 1
28: end
29: }
30: if err_count < MATHML_NAME.size
31: @@mathml_required = true
32: else
33: raise LoadError,
34: " Error: \"#{MATHML_NAME.join('" or "')}\" library is not found\n" +
35: " in $LOAD_PATH=[#{$LOAD_PATH.join(',')}]\n\n"
36: end
37: end
38:
39: if (@@mathml_required && !@@macro_input_flag)
40: @@mathml_formula_macro = MathML::LaTeX::Parser.new
41: @@macro_input_flag = true
42: $LOAD_PATH.each{ |lpath|
43: macro_files = Dir::glob(File.join(lpath, @@macro_path, "*"))
44: macro_files.each{ |mfile|
45: if File.file?(mfile)
46: File.open(mfile, "r" ) { |io|
47: io.each{ |line|
48: begin
49: @@mathml_formula_macro.macro.parse(line)
50: rescue MathML::LaTeX::ParseError
51: macroerrormsg = $!.to_s
52: rescue
53: macroerrormsg = $!.to_s
54: end
55: if macroerrormsg
56: $stderr.puts "Warning: in #{mfile}, following TeX macro causes #{macroerrormsg.to_s}\n\n",
57: " #{line}\n\n"
58: end
59: }
60: }
61: end
62: }
63: }
64: end
65:
66: end