]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - math/render.ml
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / math / render.ml
index f16735554e915cf49ff80d578c9e8ba16a1f3b6d..5a02b6715bf2db0fe037e2a695d1951e876b633e 100644 (file)
@@ -1,7 +1,11 @@
+(* vim: set sw=8 ts=8 et: *)
+
 let cmd_dvips tmpprefix = "dvips -q -R -E " ^ tmpprefix ^ ".dvi -f >" ^ tmpprefix ^ ".ps"
 let cmd_latex tmpprefix = "latex " ^ tmpprefix ^ ".tex >/dev/null"
+
 (* Putting -transparent white in converts arguments will sort-of give you transperancy *)
 let cmd_convert tmpprefix finalpath = "convert -quality 100 -density 120 " ^ tmpprefix ^ ".ps " ^ finalpath ^ " >/dev/null 2>/dev/null"
+
 (* Putting -bg Transparent in dvipng's arguments will give full-alpha transparency *)
 (* Note that IE have problems with such PNGs and need an additional javascript snippet *)
 (* Putting -bg transparent in dvipng's arguments will give binary transparency *)
@@ -15,26 +19,40 @@ let render tmppath finalpath outtex md5 backcolor =
     let unlink_all () =
       begin
         (* Commenting this block out will aid in debugging *)
-       Sys.remove (tmpprefix ^ ".dvi");
-       Sys.remove (tmpprefix ^ ".aux");
-       Sys.remove (tmpprefix ^ ".log");
+        Sys.remove (tmpprefix ^ ".dvi");
+        Sys.remove (tmpprefix ^ ".aux");
+        Sys.remove (tmpprefix ^ ".log");
         Sys.remove (tmpprefix ^ ".tex");
-       if Sys.file_exists (tmpprefix ^ ".ps")
-       then Sys.remove (tmpprefix ^ ".ps");
+        if Sys.file_exists (tmpprefix ^ ".ps")
+        then Sys.remove (tmpprefix ^ ".ps");
       end in
+
     let f = (Util.open_out_unless_exists (tmpprefix ^ ".tex")) in
       begin
-       output_string f (Texutil.get_preface ());
-       output_string f outtex;
-       output_string f (Texutil.get_footer ());
-       close_out f;
-       if Util.run_in_other_directory tmppath (cmd_latex tmpprefix0) != 0
-       then (unlink_all (); raise (ExternalCommandFailure "latex"))
-       else if (Sys.command (cmd_dvipng tmpprefix (finalpath^"/"^md5^".png") backcolor) != 0)
-       then (if (Sys.command (cmd_dvips tmpprefix) != 0)
-       then (unlink_all (); raise (ExternalCommandFailure "dvips"))
-       else if (Sys.command (cmd_convert tmpprefix (finalpath^"/"^md5^".png")) != 0)
-       then (unlink_all (); raise (ExternalCommandFailure "convert"))
-       else unlink_all ())
-       else unlink_all ()
+        (* Assemble final output in file 'f' *)
+        output_string f (Texutil.get_preface ());
+        output_string f outtex;
+        output_string f (Texutil.get_footer ());
+        close_out f;
+
+        (* TODO: document *)
+        if Util.run_in_other_directory tmppath (cmd_latex tmpprefix0) != 0
+          then (
+            unlink_all (); raise (ExternalCommandFailure "latex")
+        ) else if (Sys.command (cmd_dvipng tmpprefix (finalpath^"/"^md5^".png") backcolor) != 0)
+          then (
+            if (Sys.command (cmd_dvips tmpprefix) != 0)
+              then (
+                unlink_all ();
+                raise (ExternalCommandFailure "dvips")
+            ) else if (Sys.command (cmd_convert tmpprefix (finalpath^"/"^md5^".png")) != 0)
+              then ( 
+                unlink_all ();
+                raise (ExternalCommandFailure "convert")
+            ) else (
+                unlink_all ()
+            )
+        ) else (
+            unlink_all ()
+        )
       end