1 (* vim: set sw=8 ts=8 et: *)
3 let cmd_dvips tmpprefix
= "dvips -q -R -E " ^ tmpprefix ^
".dvi -f >" ^ tmpprefix ^
".ps"
4 let cmd_latex tmpprefix
= "latex " ^ tmpprefix ^
".tex >/dev/null"
6 (* Putting -transparent white in converts arguments will sort-of give you transperancy *)
7 let cmd_convert tmpprefix finalpath
= "convert -quality 100 -density 120 " ^ tmpprefix ^
".ps " ^ finalpath ^
" >/dev/null 2>/dev/null"
9 (* Putting -bg Transparent in dvipng's arguments will give full-alpha transparency *)
10 (* Note that IE have problems with such PNGs and need an additional javascript snippet *)
11 (* Putting -bg transparent in dvipng's arguments will give binary transparency *)
12 let cmd_dvipng tmpprefix finalpath backcolor
= "dvipng -bg \'" ^ backcolor ^
"\' -gamma 1.5 -D 120 -T tight --strict " ^ tmpprefix ^
".dvi -o " ^ finalpath ^
" >/dev/null 2>/dev/null"
14 exception ExternalCommandFailure
of string
16 let render tmppath finalpath outtex md5 backcolor
=
17 let tmpprefix0 = (string_of_int
(Unix.getpid
()))^
"_"^md5
in
18 let tmpprefix = (tmppath^
"/"^
tmpprefix0) in
21 (* Commenting this block out will aid in debugging *)
22 Sys.remove
(tmpprefix ^
".dvi");
23 Sys.remove
(tmpprefix ^
".aux");
24 Sys.remove
(tmpprefix ^
".log");
25 Sys.remove
(tmpprefix ^
".tex");
26 if Sys.file_exists
(tmpprefix ^
".ps")
27 then Sys.remove
(tmpprefix ^
".ps");
30 let f = (Util.open_out_unless_exists
(tmpprefix ^
".tex")) in
32 (* Assemble final output in file 'f' *)
33 output_string
f (Texutil.get_preface
());
34 output_string
f outtex
;
35 output_string
f (Texutil.get_footer
());
39 if Util.run_in_other_directory tmppath
(cmd_latex tmpprefix0) != 0
41 unlink_all (); raise
(ExternalCommandFailure
"latex")
42 ) else if (Sys.command
(cmd_dvipng tmpprefix (finalpath^
"/"^md5^
".png") backcolor
) != 0)
44 if (Sys.command
(cmd_dvips tmpprefix) != 0)
47 raise
(ExternalCommandFailure
"dvips")
48 ) else if (Sys.command
(cmd_convert tmpprefix (finalpath^
"/"^md5^
".png")) != 0)
51 raise
(ExternalCommandFailure
"convert")