def convert_to_png_blahtex(kind, tex)
begin
FileUtils::mkdir_p MaRuKu::Globals[:html_png_dir]
md5sum = Digest::MD5.hexdigest(tex+" params: ")
result_file = File.join(MaRuKu::Globals[:html_png_dir], md5sum+".txt")
if not File.exists?(result_file)
tmp_in = Tempfile.new('maruku_blahtex')
f = tmp_in.open
f.write tex
f.close
resolution = get_setting(:html_png_resolution)
options = "--png --use-preview-package --shell-dvipng '/usr/bin/dvipng -D #{resolution}' "
options += ("--temp-directory '%s' " % MaRuKu::Globals[:html_png_dir])
options += ("--png-directory '%s'" % MaRuKu::Globals[:html_png_dir])
cmd = "blahtex #{options} < #{tmp_in.path} > #{result_file}"
system cmd
tmp_in.delete
end
result = File.read(result_file)
if result.nil? || result.empty?
raise "Blahtex error: empty output"
end
doc = Document.new(result, {:respect_whitespace =>:all})
png = doc.root.elements[1]
if png.name != 'png'
raise "Blahtex error: \n#{doc}"
end
depth = png.elements['depth'] || (raise "No depth element in:\n #{doc}")
height = png.elements['height'] || (raise "No height element in:\n #{doc}")
md5 = png.elements['md5'] || (raise "No md5 element in:\n #{doc}")
depth = depth.text.to_f
height = height.text.to_f
md5 = md5.text
dir_url = MaRuKu::Globals[:html_png_url]
return PNG.new("#{dir_url}#{md5}.png", depth, height)
rescue Exception => e
maruku_error "Error: #{e}"
end
nil
end