lib/mathematical/render.rb in mathematical-0.1.2 vs lib/mathematical/render.rb in mathematical-0.2.0
- old
+ new
@@ -9,18 +9,12 @@
:zoom => 1.0,
:base64 => false
}
def initialize(opts = {})
- raise(TypeError, "opts must be a hash!") unless opts.is_a? Hash
-
@config = DEFAULT_OPTS.merge(opts)
- begin
- @processer = Mathematical::Process.new(@config)
- rescue TypeError => e # some error in the C code
- raise
- end
+ @processer = Mathematical::Process.new(@config)
end
def render(maths)
raise(TypeError, "text must be a string!") unless maths.is_a? String
raise(ArgumentError, "text must be in itex format (`$...$` or `$$...$$`)!") unless maths =~ /\A\${1,2}/
@@ -30,10 +24,10 @@
begin
raise RuntimeError unless @processer.process(maths, tempfile.path)
svg_content = File.open(tempfile.path, 'r') { |image_file| image_file.read }
svg_content = svg_content[xml_header.length..-1] # remove starting <?xml...> tag
@config[:base64] ? svg_to_base64(svg_content) : svg_content
- rescue RuntimeError => e # an error in the C code, probably a bad TeX parse
+ rescue ParseError, DocumentCreationError, DocumentReadError => e # an error in the C code, probably a bad TeX parse
$stderr.puts "#{e.message}: #{maths}"
maths
end
end