Bug#7252: Patch to enable dvipng support in math rendering
authorDomas Mituzas <midom@users.mediawiki.org>
Sun, 10 Sep 2006 06:25:48 +0000 (06:25 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Sun, 10 Sep 2006 06:25:48 +0000 (06:25 +0000)
(If used on Wikimedia environment, dvipng package from http://dammit.lt/tech/packages/ should be installed on FC3 boxes)

math/README
math/render.ml

index d36e09c..818ce6b 100644 (file)
@@ -1,7 +1,7 @@
 == About texvc ==
 
 texvc takes LaTeX-compatible equations and produces formatted output in
 == About texvc ==
 
 texvc takes LaTeX-compatible equations and produces formatted output in
-HTML, MathML, and (via LaTeX/dvips/ImageMagick) rasterized PNG images.
+HTML, MathML, and (via LaTeX/dvipng) rasterized PNG images.
 Input data is parsed and scrutinized for safety, and the output includes
 an estimate of whether the code is simple enough that HTML rendering will
 look acceptable.
 Input data is parsed and scrutinized for safety, and the output includes
 an estimate of whether the code is simple enough that HTML rendering will
 look acceptable.
@@ -21,8 +21,8 @@ from http://caml.inria.fr/ if your system doesn't have it available.
 
 The makefile requires GNU make.
 
 
 The makefile requires GNU make.
 
-Rasterization is done via LaTeX, dvips, and ImageMagick. These need
-to be installed and in the PATH: latex, dvips, convert
+Rasterization is done via LaTeX, dvipng. These need
+to be installed and in the PATH: latex, dvipng
 
 AMS* packages for LaTeX also need to be installed. Without AMS* some
 equations will render correctly while others won't render.
 
 AMS* packages for LaTeX also need to be installed. Without AMS* some
 equations will render correctly while others won't render.
@@ -115,7 +115,6 @@ which is basically:
 2. texvc does its magic, which is basically to check for invalid latex code.
 3. texvc takes the user input if valid and creates a latex file containing it, see
    get_preface in texutil.ml
 2. texvc does its magic, which is basically to check for invalid latex code.
 3. texvc takes the user input if valid and creates a latex file containing it, see
    get_preface in texutil.ml
-4. latex(1) gets called to create a .dvi file, then a .ps file is created from the
-   .dvi file using dvips(1), and finally convert(1) creates a .png file from
-   the .ps file. See render.ml for this process (commenting out the removal of
+4. dvipng(1) gets called to create a .png file
+   See render.ml for this process (commenting out the removal of
    the temporary file is useful for debugging).
    the temporary file is useful for debugging).
index f070a91..864681e 100644 (file)
@@ -2,6 +2,10 @@ let cmd_dvips tmpprefix = "dvips -R -E " ^ tmpprefix ^ ".dvi -f >" ^ tmpprefix ^
 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"
 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 *)
+let cmd_dvipng tmpprefix finalpath = "dvipng -gamma 1.5 -D 120 -T tight --strict " ^ tmpprefix ^ ".dvi -o " ^ finalpath ^ " >/dev/null 2>/dev/null"
 
 exception ExternalCommandFailure of string
 
 
 exception ExternalCommandFailure of string
 
@@ -25,9 +29,11 @@ let render tmppath finalpath outtex md5 =
        close_out f;
        if Util.run_in_other_directory tmppath (cmd_latex tmpprefix0) != 0
        then (unlink_all (); raise (ExternalCommandFailure "latex"))
        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_dvips tmpprefix) != 0)
+       else if (Sys.command (cmd_dvipng tmpprefix (finalpath^"/"^md5^".png")) != 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"))
        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
        else unlink_all ()
       end