1 (* Copyright (C) 2000, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 (**************************************************************************)
30 (* Andrea Asperti <asperti@cs.unibo.it> *)
33 (**************************************************************************)
41 | Mtext 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
69 and row = Mtr of attr * mtd list
71 and mtd = Mtd of attr * mpres
73 and attr = (string option * string * string) list
76 let smallskip = Mspace([None,"width","0.1cm"]);;
77 let indentation = Mspace([None,"width","0.3cm"]);;
80 Mrow([],[indentation;elem]);;
82 let standard_tbl_attr =
83 [None,"align","baseline 1";None,"equalrows","false";None,"columnalign","left"]
86 let two_rows_table attr a b =
87 Mtable(attr@standard_tbl_attr,
89 Mtr([],[Mtd([],b)])]);;
91 let two_rows_table_with_brackets attr a b op =
92 (* only the open bracket is added; the closed bracket must be in b *)
93 Mtable(attr@standard_tbl_attr,
94 [Mtr([],[Mtd([],Mrow([],[Mtext([],"(");a]))]);
95 Mtr([],[Mtd([],Mrow([],[indentation;op;b]))])]);;
97 let two_rows_table_without_brackets attr a b op =
98 Mtable(attr@standard_tbl_attr,
100 Mtr([],[Mtd([],Mrow([],[indentation;op;b]))])]);;
102 let row_with_brackets attr a b op =
103 (* by analogy with two_rows_table_with_brackets we only add the
105 Mrow(attr,[Mtext([],"(");a;op;b])
107 let row_without_brackets attr a b op =
113 let rec print_mpres =
114 let module X = Xml in
116 Mi (attr,s) -> X.xml_nempty ~prefix "mi" attr (X.xml_cdata s)
117 | Mn (attr,s) -> X.xml_nempty ~prefix "mn" attr (X.xml_cdata s)
118 | Mo (attr,s) -> X.xml_nempty ~prefix "mo" attr (X.xml_cdata s)
119 | Mtext (attr,s) -> X.xml_nempty ~prefix "mtext" attr (X.xml_cdata s)
120 | Mspace attr -> X.xml_empty ~prefix "mspace" attr
121 | Ms (attr,s) -> X.xml_nempty ~prefix "ms" attr (X.xml_cdata s)
122 | Mgliph (attr,s) -> X.xml_nempty ~prefix "mgliph" attr (X.xml_cdata s)
123 (* General Layout Schemata *)
125 X.xml_nempty ~prefix "mrow" attr
126 [< (List.fold_right (fun x i -> [< (print_mpres x) ; i >]) l [<>])
128 | Mfrac (attr,m1,m2) ->
129 X.xml_nempty ~prefix "mfrac" attr
134 X.xml_nempty ~prefix "msqrt" attr [< print_mpres m >]
135 | Mroot (attr,m1,m2) ->
136 X.xml_nempty ~prefix "mroot" attr
141 X.xml_nempty ~prefix "mstyle" attr [< print_mpres m >]
143 X.xml_nempty ~prefix "merror" attr [< print_mpres m >]
144 | Mpadded (attr,m) ->
145 X.xml_nempty ~prefix "mpadded" attr [< print_mpres m >]
146 | Mphantom (attr,m) ->
147 X.xml_nempty ~prefix "mphantom" attr [< print_mpres m >]
148 | Mfenced (attr,l) ->
149 X.xml_nempty ~prefix "mfenced" attr
150 [< (List.fold_right (fun x i -> [< (print_mpres x) ; i >]) l [<>])
152 | Menclose (attr,m) ->
153 X.xml_nempty ~prefix "menclose" attr [< print_mpres m >]
154 (* Script and Limit Schemata *)
155 | Msub (attr,m1,m2) ->
156 X.xml_nempty ~prefix "msub" attr
160 | Msup (attr,m1,m2) ->
161 X.xml_nempty ~prefix "msup" attr
165 | Msubsup (attr,m1,m2,m3) ->
166 X.xml_nempty ~prefix "msubsup" attr
171 | Munder (attr,m1,m2) ->
172 X.xml_nempty ~prefix "munder" attr
176 | Mover (attr,m1,m2) ->
177 X.xml_nempty ~prefix "mover" attr
181 | Munderover (attr,m1,m2,m3) ->
182 X.xml_nempty ~prefix "munderover" attr
187 (* | Multiscripts of ??? NOT IMPLEMEMENTED *)
188 (* Tables and Matrices *)
189 | Mtable (attr, rl) ->
190 X.xml_nempty ~prefix "mtable" attr
191 [< (List.fold_right (fun x i -> [< (print_mrow x) ; i >]) rl [<>])
193 (* Enlivening Expressions *)
194 | Maction (attr, l) ->
195 X.xml_nempty ~prefix "maction" attr
196 [< (List.fold_right (fun x i -> [< (print_mpres x) ; i >]) l [<>])
200 let module X = Xml in
203 X.xml_nempty ~prefix "mtr" attr
204 [< (List.fold_right (fun x i -> [< (print_mtd x) ; i >]) l [<>])
208 let module X = Xml in
210 Mtd (attr,m) -> X.xml_nempty ~prefix "mtd" attr [< (print_mpres m) ; X.xml_nempty ~prefix "mphantom" [] (X.xml_nempty ~prefix "mtext" [] (X.xml_cdata "(")) >]
213 let print_mpres pres =
214 [< Xml.xml_cdata "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" ;
216 Xml.xml_nempty ~prefix "math"
217 [Some "xmlns","m","http://www.w3.org/1998/Math/MathML" ;
218 Some "xmlns","helm","http://www.cs.unibo.it/helm" ;
219 Some "xmlns","xlink","http://www.w3.org/1999/xlink"
220 ] (Xml.xml_nempty ~prefix "mstyle" [None, "mathvariant", "normal"; None, "rowspacing", "0.6ex"] (print_mpres pres))