1 let cmd_dvips tmpprefix
= "dvips -R -E " ^ tmpprefix ^
".dvi -f >" ^ tmpprefix ^
".ps"
2 let cmd_latex tmpprefix
= "latex " ^ tmpprefix ^
".tex >/dev/null"
3 (* Putting -transparent white in converts arguments will sort-of give you transperancy *)
4 let cmd_convert tmpprefix finalpath
= "convert -quality 100 -density 120 " ^ tmpprefix ^
".ps " ^ finalpath ^
" >/dev/null 2>/dev/null"
6 exception ExternalCommandFailure
of string
8 let render tmppath finalpath outtex md5
=
9 let tmpprefix0 = (string_of_int
(Unix.getpid
()))^
"_"^md5
in
10 let tmpprefix = (tmppath^
"/"^
tmpprefix0) in
13 (* Commenting this block out will aid in debugging *)
14 Sys.remove
(tmpprefix ^
".dvi");
15 Sys.remove
(tmpprefix ^
".aux");
16 Sys.remove
(tmpprefix ^
".log");
17 Sys.remove
(tmpprefix ^
".tex");
18 Sys.remove
(tmpprefix ^
".ps");
20 let f = (Util.open_out_unless_exists
(tmpprefix ^
".tex")) in
22 output_string
f (Texutil.get_preface
());
23 output_string
f outtex
;
24 output_string
f (Texutil.get_footer
());
26 if Util.run_in_other_directory tmppath
(cmd_latex tmpprefix0) != 0
27 then (unlink_all (); raise
(ExternalCommandFailure
"latex"))
28 else if (Sys.command
(cmd_dvips tmpprefix) != 0)
29 then (unlink_all (); raise
(ExternalCommandFailure
"dvips"))
30 else if (Sys.command
(cmd_convert tmpprefix (finalpath^
"/"^md5^
".png")) != 0)
31 then (unlink_all (); raise
(ExternalCommandFailure
"convert"))