mathml.ml 877 B

123456789101112131415161718192021
  1. open Tex
  2. open Render_info
  3. type t = TREE_MN of string | TREE_MO of string | TREE_MI of string
  4. let rec make_mathml_tree = function
  5. TREE_MN a::otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MN,b))::itr -> make_mathml_tree(TREE_MN (a^b)::otr,itr)
  6. | otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MN,a))::itr -> make_mathml_tree(TREE_MN a::otr,itr)
  7. | otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MO,a))::itr -> make_mathml_tree(TREE_MO a::otr,itr)
  8. | otr,TEX_LITERAL(MHTMLABLEC(_,_,_,MI,a))::itr -> make_mathml_tree(TREE_MI a::otr,itr)
  9. | otr,TEX_CURLY(crl)::itr -> make_mathml_tree(otr,crl@itr)
  10. | otr,[] -> List.rev otr
  11. | _ -> failwith "failed to render mathml"
  12. let render_mathml_tree = function
  13. TREE_MN s -> "<mn>"^s^"</mn>"
  14. | TREE_MI s -> "<mi>"^s^"</mi>"
  15. | TREE_MO s -> "<mo>"^s^"</mo>"
  16. let render tree = try Some (Util.mapjoin render_mathml_tree (make_mathml_tree ([],tree))) with _ -> None