X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Fcontent_pres%2FboxPp.ml;h=bdd97a5e64aa5c3dbe6d275ab1ea0451ef3de5e3;hb=e085135177f7b3b74b410d47a4f3bca1784b60b1;hp=7a2fa9912f31144cb135e72441fe03f7b1bfd6fc;hpb=55b82bd235d82ff7f0a40d980effe1efde1f5073;p=helm.git diff --git a/helm/software/components/content_pres/boxPp.ml b/helm/software/components/content_pres/boxPp.ml index 7a2fa9912..bdd97a5e6 100644 --- a/helm/software/components/content_pres/boxPp.ml +++ b/helm/software/components/content_pres/boxPp.ml @@ -31,7 +31,7 @@ module Pres = Mpresentation let string_space = " " let string_space_len = String.length string_space -let string_indent = string_space +let string_indent = (* string_space *) "" let string_indent_len = String.length string_indent let string_ink = "##" let string_ink_len = String.length string_ink @@ -93,7 +93,7 @@ let fixed_rendering s = let s_len = String.length s in (fun _ -> s_len, [s]) -let render_to_strings size markup = +let render_to_strings ~map_unicode_to_tex choose_action size markup = let max_size = max_int in let rec aux_box = function @@ -101,7 +101,7 @@ let render_to_strings size markup = | Box.Space _ -> fixed_rendering string_space | Box.Ink _ -> fixed_rendering string_ink | Box.Action (_, []) -> assert false - | Box.Action (_, hd :: _) -> aux_box hd + | Box.Action (_, l) -> aux_box (choose_action l) | Box.Object (_, o) -> aux_mpres o | Box.H (attrs, children) -> let spacing = want_spacing attrs in @@ -185,6 +185,7 @@ let render_to_strings size markup = and aux_mpres = let text s = Pres.Mtext ([], s) in let mrow c = Pres.Mrow ([], c) in + let parentesize s = s in function | Pres.Mi (_, s) | Pres.Mn (_, s) @@ -193,11 +194,15 @@ let render_to_strings size markup = | Pres.Mgliph (_, s) -> fixed_rendering s | Pres.Mo (_, s) -> let s = - if String.length s > 1 then - (* heuristic to guess which operators need to be expanded in their - * TeX like format *) - Utf8Macro.tex_of_unicode s ^ " " - else s + if map_unicode_to_tex then begin + if String.length s = 1 && Char.code s.[0] < 128 then + s + else + match Utf8Macro.tex_of_unicode s with + | s::_ -> s ^ " " + | [] -> " " ^ s ^ " " + end else + s in fixed_rendering s | Pres.Mspace _ -> fixed_rendering string_space @@ -205,11 +210,11 @@ let render_to_strings size markup = let children' = List.map aux_mpres children in (fun size -> render_row size false children') | Pres.Mfrac (_, m, n) -> - aux_mpres (mrow [ text "\\frac("; text ")"; text "("; n; text ")" ]) - | Pres.Msqrt (_, m) -> aux_mpres (mrow [ text "\\sqrt("; m; text ")" ]) + aux_mpres (mrow [ text " \\frac "; parentesize m ; parentesize n]) + | Pres.Msqrt (_, m) -> aux_mpres (mrow [ text " \\sqrt "; parentesize m; ]) | Pres.Mroot (_, r, i) -> aux_mpres (mrow [ - text "\\root("; i; text ")"; text "\\of("; r; text ")" ]) + text " \\root "; parentesize i; text " \\of "; parentesize r ]) | Pres.Mstyle (_, m) | Pres.Merror (_, m) | Pres.Mpadded (_, m) @@ -218,13 +223,13 @@ let render_to_strings size markup = | Pres.Mfenced (_, children) -> aux_mpres (mrow children) | Pres.Maction (_, []) -> assert false | Pres.Msub (_, m, n) -> - aux_mpres (mrow [ text "("; m; text ")\\sub("; n; text ")" ]) + aux_mpres (mrow [ parentesize m; text " \\sub "; parentesize n ]) | Pres.Msup (_, m, n) -> - aux_mpres (mrow [ text "("; m; text ")\\sup("; n; text ")" ]) + aux_mpres (mrow [ parentesize m; text " \\sup "; parentesize n ]) | Pres.Munder (_, m, n) -> - aux_mpres (mrow [ text "("; m; text ")\\below("; n; text ")" ]) + aux_mpres (mrow [ parentesize m; text " \\below "; parentesize n ]) | Pres.Mover (_, m, n) -> - aux_mpres (mrow [ text "("; m; text ")\\above("; n; text ")" ]) + aux_mpres (mrow [ parentesize m; text " \\above "; parentesize n ]) | Pres.Msubsup _ | Pres.Munderover _ | Pres.Mtable _ -> @@ -236,6 +241,7 @@ let render_to_strings size markup = in snd (aux_mpres markup size) -let render_to_string size markup = - String.concat "\n" (render_to_strings size markup) +let render_to_string ~map_unicode_to_tex choose_action size markup = + String.concat "\n" + (render_to_strings ~map_unicode_to_tex choose_action size markup)