def convert_to_mathml_blahtex(kind, tex)
@@BlahtexCache = PStore.new(get_setting(:latex_cache_file))
begin
@@BlahtexCache.transaction do
if @@BlahtexCache[tex].nil?
tmp_in = Tempfile.new('maruku_blahtex')
f = tmp_in.open
f.write tex
f.close
tmp_out = Tempfile.new('maruku_blahtex')
options = "--mathml"
cmd = "blahtex #{options} < #{tmp_in.path} > #{tmp_out.path}"
system cmd
tmp_in.delete
result = nil
File.open(tmp_out.path) do |f| result=f.read end
puts result
@@BlahtexCache[tex] = result
end
blahtex = @@BlahtexCache[tex]
doc = Document.new(blahtex, {:respect_whitespace =>:all})
mathml = doc.root.elements['mathml']
if not mathml
maruku_error "Blahtex error: \n#{doc}"
return nil
else
return mathml
end
end
rescue Exception => e
maruku_error "Error: #{e}"
end
nil
end