]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/cic_transformations/mpresentation.ml
Several changes (the beginning of a new era???)
[helm.git] / helm / ocaml / cic_transformations / mpresentation.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (**************************************************************************)
27 (*                                                                        *)
28 (*                           PROJECT HELM                                 *)
29 (*                                                                        *)
30 (*                Andrea Asperti <asperti@cs.unibo.it>                    *)
31 (*                             16/62003                                   *)
32 (*                                                                        *)
33 (**************************************************************************)
34
35 type 
36   mpres = 
37   (* token elements *)
38     Mi of attr * string
39   | Mn of attr * string
40   | Mo of attr * string
41   | Mtext of attr * string
42   | Mspace of attr
43   | Ms of attr * string
44   | Mgliph of attr * string
45   (* General Layout Schemata *)
46   | Mrow of attr * mpres list
47   | Mfrac of attr * mpres * mpres
48   | Msqrt of attr * mpres
49   | Mroot of attr * mpres * mpres
50   | Mstyle of attr * mpres
51   | Merror of attr * mpres
52   | Mpadded of attr * mpres
53   | Mphantom of attr * mpres
54   | Mfenced of attr * mpres list
55   | Menclose of attr * mpres
56   (* Script and Limit Schemata *)
57   | Msub of attr * mpres * mpres
58   | Msup of attr * mpres * mpres
59   | Msubsup of attr * mpres * mpres *mpres 
60   | Munder of attr * mpres * mpres
61   | Mover of attr * mpres * mpres
62   | Munderover of attr * mpres * mpres *mpres 
63 (* | Multiscripts of ???  NOT IMPLEMEMENTED *)
64   (* Tables and Matrices *)
65   | Mtable of attr * row list
66   (* Enlivening Expressions *)
67   | Maction of attr * mpres list
68
69 and
70
71   row = Mtr of attr * mtd list
72
73 and 
74
75   mtd = Mtd of attr * mpres
76
77 and
78   
79   attr = (string * string) list
80
81 ;;
82
83 let smallskip = Mspace([("width","0.1cm")]);;
84 let indentation = Mspace([("width","0.3cm")]);;
85
86 let indented elem =
87   Mrow([],[indentation;elem]);;
88
89 let standard_tbl_attr = 
90   [("align","baseline 1");("equalrows","false");("columnalign","left")];;
91
92 let two_rows_table attr a b =
93   Mtable(attr@standard_tbl_attr,
94     [Mtr([],[Mtd([],a)]);
95      Mtr([],[Mtd([],b)])]);;
96
97 let two_rows_table_with_brackets attr a b op =
98   (* only the open bracket is added; the closed bracket must be in b *)
99   Mtable(attr@standard_tbl_attr,
100     [Mtr([],[Mtd([],Mrow([],[Mtext([],"(");a]))]);
101      Mtr([],[Mtd([],Mrow([],[indentation;op;smallskip;b]))])]);;
102
103 let two_rows_table_without_brackets attr a b op =
104   Mtable(attr@standard_tbl_attr,
105     [Mtr([],[Mtd([],a)]);
106      Mtr([],[Mtd([],Mrow([],[indentation;op;smallskip;b]))])]);;
107
108 let row_with_brackets attr a b op =
109   (* by analogy with two_rows_table_with_brackets we only add the
110      open brackets *)
111   Mrow(attr,[Mtext([],"(");a;smallskip;op;smallskip;b])
112
113 let row_without_brackets attr a b op =
114   Mrow(attr,[a;smallskip;op;smallskip;b])
115  
116 let rec print_mpres =
117  let module X = Xml in
118     function
119     Mi (attr,s) -> X.xml_nempty "mi" attr (X.xml_cdata s)
120   | Mn (attr,s) -> X.xml_nempty "mn" attr (X.xml_cdata s)
121   | Mo (attr,s) -> X.xml_nempty "mo" attr (X.xml_cdata s)
122   | Mtext (attr,s) -> X.xml_nempty "mtext" attr (X.xml_cdata s)
123   | Mspace attr -> X.xml_empty "mspace" attr
124   | Ms (attr,s) -> X.xml_nempty "ms" attr (X.xml_cdata s)
125   | Mgliph (attr,s) -> X.xml_nempty "mgliph" attr (X.xml_cdata s)
126   (* General Layout Schemata *)
127   | Mrow (attr,l) ->
128       X.xml_nempty "mrow" attr 
129          [< (List.fold_right (fun x i -> [< (print_mpres x) ; i >]) l [<>])
130           >]
131   | Mfrac (attr,m1,m2) ->
132        X.xml_nempty "mfrac" attr 
133          [< print_mpres m1;
134             print_mpres m2
135          >]
136   | Msqrt (attr,m) ->
137        X.xml_nempty "msqrt" attr [< print_mpres m >]
138   | Mroot  (attr,m1,m2) ->
139        X.xml_nempty "mroot" attr 
140          [< print_mpres m1;
141             print_mpres m2
142          >]
143   | Mstyle (attr,m) ->
144        X.xml_nempty "mstyle" attr [< print_mpres m >]
145   | Merror (attr,m) ->
146        X.xml_nempty "merror" attr [< print_mpres m >]
147   | Mpadded (attr,m) ->
148        X.xml_nempty "mpadded" attr [< print_mpres m >]
149   | Mphantom (attr,m) ->
150        X.xml_nempty "mphantom" attr [< print_mpres m >]
151   | Mfenced (attr,l) ->
152       X.xml_nempty "mfenced" attr 
153          [< (List.fold_right (fun x i -> [< (print_mpres x) ; i >]) l [<>])
154           >]
155   | Menclose (attr,m) ->
156       X.xml_nempty "menclose" attr [< print_mpres m >]
157   (* Script and Limit Schemata *)
158   | Msub (attr,m1,m2) ->
159       X.xml_nempty "msub" attr 
160          [< print_mpres m1;
161             print_mpres m2
162          >]
163   | Msup (attr,m1,m2) ->
164       X.xml_nempty "msup" attr 
165          [< print_mpres m1;
166             print_mpres m2
167          >]
168   | Msubsup (attr,m1,m2,m3) ->
169       X.xml_nempty "msubsup" attr 
170          [< print_mpres m1;
171             print_mpres m2;
172             print_mpres m3
173          >]
174   | Munder (attr,m1,m2) ->
175       X.xml_nempty "munder" attr 
176          [< print_mpres m1;
177             print_mpres m2
178          >]
179   | Mover (attr,m1,m2) ->
180       X.xml_nempty "mover" attr 
181          [< print_mpres m1;
182             print_mpres m2
183          >]
184   | Munderover (attr,m1,m2,m3) ->
185       X.xml_nempty "munderover" attr 
186          [< print_mpres m1;
187             print_mpres m2;
188             print_mpres m3
189          >]
190 (* | Multiscripts of ???  NOT IMPLEMEMENTED *)
191   (* Tables and Matrices *)
192   | Mtable (attr, rl) ->
193       X.xml_nempty "mtable" attr 
194          [< (List.fold_right (fun x i -> [< (print_mrow x) ; i >]) rl [<>])
195           >]
196   (* Enlivening Expressions *)
197   | Maction (attr, l) ->
198       X.xml_nempty "maction" attr 
199          [< (List.fold_right (fun x i -> [< (print_mpres x) ; i >]) l [<>])
200           >]
201
202 and print_mrow =
203  let module X = Xml in
204  function 
205     Mtr (attr, l) -> 
206       X.xml_nempty "mtr" attr 
207          [< (List.fold_right (fun x i -> [< (print_mtd x) ; i >]) l [<>])
208           >]
209
210 and print_mtd =
211   let module X = Xml in
212   function 
213      Mtd (attr,m) -> X.xml_nempty "mtd" attr (print_mpres m)
214 ;;
215
216
217
218