2 ||M|| This file is part of HELM, an Hypertextual, Electronic
3 ||A|| Library of Mathematics, developed at the Computer Science
4 ||T|| Department, University of Bologna, Italy.
6 ||T|| HELM is free software; you can redistribute it and/or
7 ||A|| modify it under the terms of the GNU General Public License
8 \ / version 2 or (at your option) any later version.
9 \ / This software is distributed as is, NO WARRANTY.
10 V_______________________________________________________________ *)
20 module E = NCicEnvironment
26 let status = new P.status
28 (* internal functions *******************************************************)
30 let rec segments_of_string ss l s =
31 match try Some (S.index s '/') with Not_found -> None with
33 | Some i -> segments_of_string (S.sub s 0 i :: ss) (l-i-1) (S.sub s (i+1) (l-i-1))
35 let segments_of_uri u =
36 let s = U.string_of_uri u in
37 let s = F.chop_extension s in
39 let i = S.index s ':' in
40 let s = S.sub s (i+2) (l-i-2) in
41 segments_of_string [] (l-i-2) s
43 let rec mk_string sep r = function
45 | s :: ss -> mk_string sep (s ^ sep ^ r) ss
50 failwith ("MaTeX: malformed term: " ^ s)
52 let not_supported () =
53 failwith "MaTeX: object not supported"
55 let proc_sort = function
56 | C.Prop -> [T.Macro "Prop"]
57 | C.Type [`Type, u] -> [T.Macro "Type"; T.arg (U.string_of_uri u)]
58 | C.Type [`CProp, u] -> [T.Macro "Crop"; T.arg (U.string_of_uri u)]
59 | C.Type _ -> malformed "1"
61 let proc_gref r = T.Macro "GRef"
63 let rec proc_term c = function
66 | C.Implicit _ -> malformed "2"
68 let name = L.nth c (m-1) in
69 [T.Macro "LRef"; T.arg name]
71 let riss = L.rev_map (proc_term c) ts in
72 T.Macro "Appl" :: T.mk_rev_args riss
75 let is_w = proc_term c w in
76 let is_t = proc_term (s::c) t in
77 T.Macro "Prod" :: T.arg s :: T.Group is_w :: is_t
78 | C.Lambda (s, w, t) ->
80 let is_w = proc_term c w in
81 let is_t = proc_term (s::c) t in
82 T.Macro "Abst" :: T.arg s :: T.Group is_w :: is_t
83 | C.LetIn (s, w, v, t) ->
85 let is_w = proc_term c w in
86 let is_v = proc_term c v in
87 let is_t = proc_term (s::c) t in
88 T.Macro "Abbr" :: T.arg s :: T.Group is_w :: T.Group is_v :: is_t
93 | C.Match (w, u, v, ts) ->
94 let is_w = [proc_gref w] in
95 let is_u = proc_term c u in
96 let is_v = proc_term c v in
97 let riss = L.rev_map (proc_term c) ts in
98 T.Macro "Case" :: T.Group is_w :: T.Group is_u :: T.Group is_v :: T.mk_rev_args riss
100 let proc_term c t = try proc_term c t with
103 | Invalid_argument "List.nth" -> malformed "3"
106 open_out (F.concat !G.out_dir (s ^ T.file_ext))
109 let ss = segments_of_uri u in
110 let _, _, _, _, obj = E.get_checked_obj status u in
112 | C.Constant (_, _, None, u, _) -> not_supported ()
113 | C.Constant (_, _, Some t, u, _) ->
114 let name = mk_string "." "body" ss in
115 let och = open_out_tex name in
116 O.out_text och (proc_term [] t);
117 O.out_text och T.newline;
119 let name = mk_string "." "type" ss in
120 let och = open_out_tex name in
121 O.out_text och (proc_term [] u);
122 O.out_text och T.newline;
124 | C.Fixpoint (_, _, _) -> not_supported ()
125 | C.Inductive (_, _, _, _) -> not_supported ()
127 (* interface functions ******************************************************)
129 let process = proc_obj