Math/math/texvc.ml
Brion Vibber c4d9349786 Initial stab at breaking math/texvc out to Math extension.
* (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.
2011-04-09 00:39:40 +00:00

59 lines
2.0 KiB
OCaml

(* vim: set sw=8 ts=8 et: *)
exception LexerException of string
(* *)
let lexer_token_safe lexbuf =
try Lexer.token lexbuf
with Failure s -> raise (LexerException s)
(* *)
let render tmppath finalpath tree backcolor =
let outtex = Util.mapjoin Texutil.render_tex tree in
let md5 = Digest.to_hex (Digest.string outtex) in
begin
let mathml = Mathml.render tree
and html = Html.render tree
in print_string (match (html,!Html.conservativeness,mathml) with
None,_,None -> "+" ^ md5
| Some h,Html.CONSERVATIVE,None -> "c" ^ md5 ^ h
| Some h,Html.MODERATE,None -> "m" ^ md5 ^ h
| Some h,Html.LIBERAL,None -> "l" ^ md5 ^ h
| Some h,Html.CONSERVATIVE,Some m -> "C" ^ md5 ^ h ^ "\000" ^ m
| Some h,Html.MODERATE,Some m -> "M" ^ md5 ^ h ^ "\000" ^ m
| Some h,Html.LIBERAL,Some m -> "L" ^ md5 ^ h ^ "\000" ^ m
| None,_,Some m -> "X" ^ md5 ^ m
);
Render.render tmppath finalpath outtex md5 backcolor
end
(* TODO: document
* Arguments:
* 1st :
* 2nd :
* 3rd :
* 4th : encoding (Default: UTF-8)
* 5th : color (Default: rgb 1.0 1.0 1.0)
*
* Output one character:
* S : Parsing error
* E : Lexer exception raised
* F : TeX function not recognized
* - : Generic/Default failure code. Might be an invalid argument,
* output file already exist, a problem with an external
* command ...
* *)
let _ =
Texutil.set_encoding (try Sys.argv.(4) with _ -> "UTF-8");
try render Sys.argv.(1) Sys.argv.(2) (
Parser.tex_expr lexer_token_safe (
Lexing.from_string Sys.argv.(3))
) (try Sys.argv.(5) with _ -> "rgb 1.0 1.0 1.0")
with Parsing.Parse_error -> print_string "S"
| LexerException _ -> print_string "E"
| Texutil.Illegal_tex_function s -> print_string ("F" ^ s)
| Util.FileAlreadyExists -> print_string "-"
| Invalid_argument _ -> print_string "-"
| Failure _ -> print_string "-"
| Render.ExternalCommandFailure s -> ()
| _ -> print_string "-"