]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - math/texvc.ml
MediaWiki 1.17.0
[autoinstalls/mediawiki.git] / math / texvc.ml
1 (* vim: set sw=8 ts=8 et: *)
2 exception LexerException of string
3
4 (* *)
5 let lexer_token_safe lexbuf =
6     try Lexer.token lexbuf
7     with Failure s -> raise (LexerException s)
8
9 (* *)
10 let render tmppath finalpath tree backcolor =
11     let outtex = Util.mapjoin Texutil.render_tex tree in
12     let md5 = Digest.to_hex (Digest.string outtex) in
13     begin
14         let mathml = Mathml.render tree
15         and html = Html.render tree
16         in print_string (match (html,!Html.conservativeness,mathml) with
17             None,_,None -> "+" ^ md5 
18           | Some h,Html.CONSERVATIVE,None -> "c" ^ md5  ^ h
19           | Some h,Html.MODERATE,None -> "m" ^ md5  ^ h
20           | Some h,Html.LIBERAL,None -> "l" ^ md5  ^ h
21           | Some h,Html.CONSERVATIVE,Some m -> "C" ^ md5  ^ h ^ "\000" ^ m
22           | Some h,Html.MODERATE,Some m -> "M" ^ md5  ^ h ^ "\000" ^ m
23           | Some h,Html.LIBERAL,Some m -> "L" ^ md5 ^ h ^ "\000" ^ m
24           | None,_,Some m -> "X" ^ md5   ^ m
25         );
26         Render.render tmppath finalpath outtex md5 backcolor
27     end
28
29 (* TODO: document
30  * Arguments:
31  * 1st :  
32  * 2nd :
33  * 3rd :
34  * 4th : encoding (Default: UTF-8)
35  * 5th : color (Default: rgb 1.0 1.0 1.0)
36  *
37  * Output one character:
38  *  S : Parsing error
39  *  E : Lexer exception raised
40  *  F : TeX function not recognized
41  *  - : Generic/Default failure code. Might be an invalid argument,
42  *      output file already exist, a problem with an external
43  *      command ...
44  * *)
45 let _ =
46     Texutil.set_encoding (try Sys.argv.(4) with _ -> "UTF-8");
47     try render Sys.argv.(1) Sys.argv.(2) (
48         Parser.tex_expr lexer_token_safe (
49             Lexing.from_string Sys.argv.(3))
50         ) (try Sys.argv.(5) with _ -> "rgb 1.0 1.0 1.0")
51     with Parsing.Parse_error -> print_string "S"
52        | LexerException _ -> print_string "E"
53        | Texutil.Illegal_tex_function s -> print_string ("F" ^ s)
54        | Util.FileAlreadyExists -> print_string "-"
55        | Invalid_argument _ -> print_string "-"
56        | Failure _ -> print_string "-"
57        | Render.ExternalCommandFailure s -> ()
58        | _ -> print_string "-"