-let box_of mathonly kind attrs children =
- if mathonly then Mpresentation.Mrow (attrs, children)
- else
- match kind with
- | CicNotationPt.H when List.for_all genuine_math children ->
- Mpresentation.Mrow (attrs, children)
- | CicNotationPt.H ->
- mpres_of_box (Box.H (attrs, List.map box_of_mpres children))
- | CicNotationPt.V ->
- mpres_of_box (Box.V (attrs, List.map box_of_mpres children))
- | CicNotationPt.HV ->
- mpres_of_box (Box.HV (attrs, List.map box_of_mpres children))
- | CicNotationPt.HOV ->
- mpres_of_box (Box.HOV (attrs, List.map box_of_mpres children))
-
-let open_paren = Mpresentation.Mo ([], "(")
-let closed_paren = Mpresentation.Mo ([], ")")
-let open_box_paren = Box.Text ([], "(")
-let closed_box_paren = Box.Text ([], ")")
+let rec eligible_math =
+ function
+ | Mpresentation.Mobject ([], Box.Object ([], mpres)) -> eligible_math mpres
+ | Mpresentation.Mobject ([], _) -> false
+ | _ -> true
+
+let rec promote_to_math =
+ function
+ | Mpresentation.Mobject ([], Box.Object ([], mpres)) -> promote_to_math mpres
+ | math -> math
+
+let small_skip =
+ Mpresentation.Mspace (RenderingAttrs.small_skip_attributes `MathML)
+
+let rec add_mpres_attributes new_attr = function
+ | Mpresentation.Mobject (attr, box) ->
+ Mpresentation.Mobject (attr, add_box_attributes new_attr box)
+ | mpres ->
+ Mpresentation.set_attr (new_attr @ Mpresentation.get_attr mpres) mpres
+and add_box_attributes new_attr = function
+ | Box.Object (attr, mpres) ->
+ Box.Object (attr, add_mpres_attributes new_attr mpres)
+ | box -> Box.set_attr (new_attr @ Box.get_attr box) box
+
+let box_of mathonly spec attrs children =
+ match children with
+ | [t] -> add_mpres_attributes attrs t
+ | _ ->
+ let kind, spacing, indent = spec in
+ let dress children =
+ if spacing then
+ CicNotationUtil.dress small_skip children
+ else
+ children
+ in
+ if mathonly then Mpresentation.Mrow (attrs, dress children)
+ else
+ let attrs' =
+ (if spacing then RenderingAttrs.spacing_attributes `BoxML else [])
+ @ (if indent then RenderingAttrs.indent_attributes `BoxML else [])
+ @ attrs
+ in
+ match kind with
+ | Ast.H ->
+ if List.for_all eligible_math children then
+ Mpresentation.Mrow (attrs',
+ dress (List.map promote_to_math children))
+ else
+ mpres_of_box (Box.H (attrs',
+ List.map box_of_mpres children))
+(* | Ast.H when List.for_all genuine_math children ->
+ Mpresentation.Mrow (attrs', dress children) *)
+ | Ast.V ->
+ mpres_of_box (Box.V (attrs',
+ List.map box_of_mpres children))
+ | Ast.HV ->
+ mpres_of_box (Box.HV (attrs',
+ List.map box_of_mpres children))
+ | Ast.HOV ->
+ mpres_of_box (Box.HOV (attrs',
+ List.map box_of_mpres children))
+
+let open_paren = Mpresentation.Mo ([], "(")
+let closed_paren = Mpresentation.Mo ([], ")")
+let open_brace = Mpresentation.Mo ([], "{")
+let closed_brace = Mpresentation.Mo ([], "}")
+let hidden_substs = Mpresentation.Mtext ([], "{...}")
+let open_box_paren = Box.Text ([], "(")
+let closed_box_paren = Box.Text ([], ")")
+let semicolon = Mpresentation.Mo ([], ";")
+let toggle_action children =
+ Mpresentation.Maction ([None, "actiontype", "toggle"], children)