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: if $DEBUG_RDOC
48: puts \
49: "\n##### Debug messages about \"#{__FILE__}\" #####",
50: " \"#{mfile}\" is loading as a TeX macro file.",
51: " Following macros have been included."
52: end
53: io.each{ |line|
54: line.chomp!
55: macroerrormsg = nil
56: begin
57: @@mathml_formula_macro.macro.parse(line)
58: rescue MathML::LaTeX::ParseError
59: macroerrormsg = $!.to_s
60: rescue
61: macroerrormsg = $!.to_s
62: end
63: if macroerrormsg
64: $stderr.puts "Warning: in #{mfile}, following TeX macro causes #{macroerrormsg.to_s}\n\n",
65: " #{line}\n\n"
66: else
67: if $DEBUG_RDOC && !(line.empty?) && !(line =~ /\s*\%/)
68: puts " #{line}"
69: end
70: end
71: }
72: }
73: end
74: }
75: }
76: end
77:
78: end