mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-15 19:50:16 +00:00
c4d9349786
* (bug 14202) $wgUseTeX has been superseded by the Math extension. To re-enable math conversion after upgrading, obtain the Math extension from SVN or from http://www.mediawiki.org/wiki/Extension:Math and add to LocalSettings.php: require_once "$IP/extensions/Math/Math.php"; This is an initial stab, and a few things remain to be cleaned up: * messages need to be moved from core to extension * MW_MATH_* constants should be moved to the extension from core * old back-compat math names interfaces using those constants should be removed from message files * classic edit toolbar's math button should be added from the extension (or else dropped) -- currently there's not a clean hook, but could do it by JS * couple of things like the 'armourMath' function on Language & LanguageConverter may want to be redone just as an unconditional, if that's simpler. Setting $wgUseTeX alone will no longer have any affect. The var's still there for the moment as a few bits still need to be fully moved out from core.
59 lines
2.4 KiB
OCaml
59 lines
2.4 KiB
OCaml
(* 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 *)
|
|
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"
|
|
|
|
exception ExternalCommandFailure of string
|
|
|
|
let render tmppath finalpath outtex md5 backcolor =
|
|
let tmpprefix0 = (string_of_int (Unix.getpid ()))^"_"^md5 in
|
|
let tmpprefix = (tmppath^"/"^tmpprefix0) in
|
|
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 ^ ".tex");
|
|
if Sys.file_exists (tmpprefix ^ ".ps")
|
|
then Sys.remove (tmpprefix ^ ".ps");
|
|
end in
|
|
|
|
let f = (Util.open_out_unless_exists (tmpprefix ^ ".tex")) in
|
|
begin
|
|
(* 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
|