mediawiki-extensions-Math/texvccheck/texvccheck.ml
Physikerwelt 4c9dc2f08e Breakdown of texvc
texvc had several tasks in the past:

1 checking the input
2 convert MediaWiki custom syntax to standard LaTeX
3 run LaTeX
4 convert dvi2png

This change provides a simplified version that performs
only steps 1+2. This is required to avoid security problems
with tools like MathJax, especially if these tools are
run at the server-side.

Bug: 54624
Change-Id: I1650e6ec2ccefff6335fbc36bbe8ca8f59db0faa
2013-12-14 18:34:15 +00:00

39 lines
1 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 tree =
let outtex = Util.mapjoin Texutil.render_tex tree in
begin
print_string ("+" ^ outtex);
end
(* TODO: document
* Arguments:
* 1st : tex input string
*
* Output one character:
* E : Lexer exception raised
* F : TeX function not recognized
* - : Generic/Default failure code. Might be an invalid argument,
* S : Parsing error
* output file already exist, a problem with an external
* command ...
*)
let _ =
try render (
Parser.tex_expr lexer_token_safe (
Lexing.from_string Sys.argv.(1))
)
with Parsing.Parse_error -> print_string "S"
| LexerException _ -> print_string "E"
| Texutil.Illegal_tex_function s -> print_string ("F" ^ s)
| Invalid_argument _ -> print_string "-"
| Failure _ -> print_string "-"
| _ -> print_string "-"