diff options
Diffstat (limited to 'ocamldoc/odoc_latex.ml')
-rw-r--r-- | ocamldoc/odoc_latex.ml | 692 |
1 files changed, 352 insertions, 340 deletions
diff --git a/ocamldoc/odoc_latex.ml b/ocamldoc/odoc_latex.ml index 09f73dac2e..26dfb667fd 100644 --- a/ocamldoc/odoc_latex.ml +++ b/ocamldoc/odoc_latex.ml @@ -15,12 +15,12 @@ let print_DEBUG s = print_string s ; print_newline () -open Odoc_info +open Odoc_info open Parameter open Value open Type open Exception -open Class +open Class open Module let new_buf () = Buffer.create 1024 @@ -28,7 +28,7 @@ let new_fmt () = let b = new_buf () in let fmt = Format.formatter_of_buffer b in (fmt, - fun () -> + fun () -> Format.pp_print_flush fmt (); let s = Buffer.contents b in Buffer.reset b; @@ -47,9 +47,9 @@ let print_concat fmt sep f = [] -> () | [c] -> f c | c :: q -> - f c; - ps fmt sep; - iter q + f c; + ps fmt sep; + iter q in iter @@ -59,7 +59,7 @@ class text = (** Return latex code to make a sectionning according to the given level, and with the given latex code. *) method section_style level s = - try + try let sec = List.assoc level !Args.latex_titles in "\\"^sec^"{"^s^"}\n" with Not_found -> s @@ -103,15 +103,15 @@ class text = ("\\\\", "MAXENCE"^"XXX") ; ("&", "MAXENCE"^"YYY") ; ("\\$", "MAXENCE"^"ZZZ") - ] + ] - val mutable subst_strings_simple = - [ + val mutable subst_strings_simple = + [ ("MAXENCE"^"XXX", "{\\textbackslash}") ; "}", "\\}" ; "{", "\\{" ; ("\\\\", "MAXENCE"^"XXX") ; - ] + ] val mutable subst_strings_code = [ ("MAXENCE"^"ZZZ", "\\$"); @@ -128,7 +128,7 @@ class text = ("&", "MAXENCE"^"YYY") ; ("\\$", "MAXENCE"^"ZZZ") ; ("\\\\", "MAXENCE"^"XXX") ; - ] + ] method subst l s = List.fold_right @@ -144,7 +144,7 @@ class text = (** Escape some characters for the code style. *) method escape_code s = self#subst subst_strings_code s - + (** Make a correct latex label from a name. *) (* The following characters are forbidden in LaTeX \index: \ { } $ & # ^ _ % ~ ! " @ | (" to close the double quote) @@ -157,14 +157,14 @@ class text = let buf = Buffer.create len in for i = 0 to len - 1 do let (s_no_, s) = - match name.[i] with + match name.[i] with '_' -> ("-underscore", "_") | '~' -> ("-tilde", "~") - | '%' -> ("-percent", "%") + | '%' -> ("-percent", "%") | '@' -> ("-at", "\"@") | '!' -> ("-bang", "\"!") | '|' -> ("-pipe", "\"|") - | '<' -> ("-lt", "<") + | '<' -> ("-lt", "<") | '>' -> ("-gt", ">") | '^' -> ("-exp", "^") | '&' -> ("-ampersand", "&") @@ -176,8 +176,8 @@ class text = | '=' -> ("-equal", "=") | ':' -> ("-colon", ":") | c -> (String.make 1 c, String.make 1 c) - in - Buffer.add_string buf (if no_ then s_no_ else s) + in + Buffer.add_string buf (if no_ then s_no_ else s) done; Buffer.contents buf @@ -215,9 +215,9 @@ class text = method make_ref label = "\\ref{"^label^"}" (** Print the LaTeX code corresponding to the [text] parameter.*) - method latex_of_text fmt t = + method latex_of_text fmt t = List.iter (self#latex_of_text_element fmt) t - + (** Print the LaTeX code for the [text_element] in parameter. *) method latex_of_text_element fmt te = match te with @@ -226,7 +226,7 @@ class text = | Odoc_info.CodePre s -> self#latex_of_CodePre fmt s | Odoc_info.Verbatim s -> self#latex_of_Verbatim fmt s | Odoc_info.Bold t -> self#latex_of_Bold fmt t - | Odoc_info.Italic t -> self#latex_of_Italic fmt t + | Odoc_info.Italic t -> self#latex_of_Italic fmt t | Odoc_info.Emphasize t -> self#latex_of_Emphasize fmt t | Odoc_info.Center t -> self#latex_of_Center fmt t | Odoc_info.Left t -> self#latex_of_Left fmt t @@ -241,13 +241,16 @@ class text = | Odoc_info.Ref (name, ref_opt) -> self#latex_of_Ref fmt name ref_opt | Odoc_info.Superscript t -> self#latex_of_Superscript fmt t | Odoc_info.Subscript t -> self#latex_of_Subscript fmt t - | Odoc_info.Module_list _ -> () - | Odoc_info.Index_list -> () + | Odoc_info.Module_list _ -> () + | Odoc_info.Index_list -> () + | Odoc_info.Custom (s,t) -> self#latex_of_custom_text fmt s t + + method latex_of_custom_text fmt s t = () - method latex_of_Raw fmt s = + method latex_of_Raw fmt s = ps fmt (self#escape s) - method latex_of_Code fmt s = + method latex_of_Code fmt s = let s2 = self#escape_code s in let s3 = Str.global_replace (Str.regexp "\n") ("\\\\\n") s2 in p fmt "{\\tt{%s}}" s3 @@ -257,7 +260,7 @@ class text = ps fmt (self#escape_simple s); ps fmt "\n\\end{ocamldoccode}\n" - method latex_of_Verbatim fmt s = + method latex_of_Verbatim fmt s = ps fmt "\\begin{verbatim}"; ps fmt s; ps fmt "\\end{verbatim}" @@ -267,7 +270,7 @@ class text = self#latex_of_text fmt t; ps fmt "}" - method latex_of_Italic fmt t = + method latex_of_Italic fmt t = ps fmt "{\\it "; self#latex_of_text fmt t; ps fmt "}" @@ -294,24 +297,24 @@ class text = method latex_of_List fmt tl = ps fmt "\\begin{itemize}\n"; - List.iter - (fun t -> - ps fmt "\\item "; - self#latex_of_text fmt t; - ps fmt "\n" - ) - tl; + List.iter + (fun t -> + ps fmt "\\item "; + self#latex_of_text fmt t; + ps fmt "\n" + ) + tl; ps fmt "\\end{itemize}\n" method latex_of_Enum fmt tl = ps fmt "\\begin{enumerate}\n"; - List.iter - (fun t -> - ps fmt "\\item "; - self#latex_of_text fmt t; - ps fmt "\n" - ) - tl; + List.iter + (fun t -> + ps fmt "\\item "; + self#latex_of_text fmt t; + ps fmt "\n" + ) + tl; ps fmt "\\end{enumerate}\n" method latex_of_Newline fmt = ps fmt "\n\n" @@ -330,7 +333,7 @@ class text = match label_opt with None -> () | Some l -> - ps fmt (self#make_label (self#label ~no_: false l)) + ps fmt (self#make_label (self#label ~no_: false l)) ) method latex_of_Latex fmt s = ps fmt s @@ -343,14 +346,14 @@ class text = method latex_of_Ref fmt name ref_opt = match ref_opt with - None -> + None -> self#latex_of_text_element fmt (Odoc_info.Code (Odoc_info.use_hidden_modules name)) - | Some (RK_section _) -> + | Some (RK_section _) -> self#latex_of_text_element fmt (Latex ("["^(self#make_ref (self#label ~no_:false (Name.simple name)))^"]")) | Some kind -> - let f_label = + let f_label = match kind with Odoc_info.RK_module -> self#module_label | Odoc_info.RK_module_type -> self#module_type_label @@ -367,14 +370,14 @@ class text = [ Odoc_info.Code (Odoc_info.use_hidden_modules name) ; Latex ("["^(self#make_ref (f_label name))^"]") - ] + ] - method latex_of_Superscript fmt t = + method latex_of_Superscript fmt t = ps fmt "$^{"; self#latex_of_text fmt t; ps fmt "}$" - method latex_of_Subscript fmt t = + method latex_of_Subscript fmt t = ps fmt "$_{"; self#latex_of_text fmt t; ps fmt "}$" @@ -388,11 +391,11 @@ class virtual info = method virtual latex_of_text : Format.formatter -> Odoc_info.text -> unit (** The method used to get a [text] from an optionel info structure. *) - method virtual text_of_info : ?block: bool -> Odoc_info.info option -> Odoc_info.text + method virtual text_of_info : ?block: bool -> Odoc_info.info option -> Odoc_info.text (** Print LaTeX code for a description, except for the [i_params] field. *) - method latex_of_info fmt ?(block=false) info_opt = - self#latex_of_text fmt + method latex_of_info fmt ?(block=false) info_opt = + self#latex_of_text fmt (self#text_of_info ~block info_opt) end @@ -413,111 +416,111 @@ class latex = method first_and_rest_of_info i_opt = match i_opt with None -> ([], []) - | Some i -> + | Some i -> match i.Odoc_info.i_desc with None -> ([], self#text_of_info ~block: true i_opt) - | Some t -> + | Some t -> let (first,_) = Odoc_info.first_sentence_and_rest_of_text t in let (_, rest) = Odoc_info.first_sentence_and_rest_of_text (self#text_of_info ~block: false i_opt) in (Odoc_info.text_no_title_no_list first, rest) (** Print LaTeX code for a value. *) - method latex_of_value fmt v = + method latex_of_value fmt v = Odoc_info.reset_type_names () ; let label = self#value_label v.val_name in let latex = self#make_label label in self#latex_of_text fmt - ((Latex latex) :: + ((Latex latex) :: (to_text#text_of_value v)) (** Print LaTeX code for a class attribute. *) method latex_of_attribute fmt a = self#latex_of_text fmt - ((Latex (self#make_label (self#attribute_label a.att_value.val_name))) :: + ((Latex (self#make_label (self#attribute_label a.att_value.val_name))) :: (to_text#text_of_attribute a)) (** Print LaTeX code for a class method. *) - method latex_of_method fmt m = + method latex_of_method fmt m = self#latex_of_text fmt - ((Latex (self#make_label (self#method_label m.met_value.val_name))) :: + ((Latex (self#make_label (self#method_label m.met_value.val_name))) :: (to_text#text_of_method m)) (** Print LaTeX code for the parameters of a type. *) method latex_of_type_params fmt m_name t = let print_one (p, co, cn) = - ps fmt (Odoc_info.string_of_variance t (co,cn)); - ps fmt (self#normal_type m_name p) + ps fmt (Odoc_info.string_of_variance t (co,cn)); + ps fmt (self#normal_type m_name p) in match t.ty_parameters with [] -> () | [(p,co,cn)] -> print_one (p, co, cn) - | l -> - ps fmt "("; - print_concat fmt ", " print_one t.ty_parameters; - ps fmt ")" + | l -> + ps fmt "("; + print_concat fmt ", " print_one t.ty_parameters; + ps fmt ")" method latex_of_class_parameter_list fmt father c = - self#latex_of_text fmt - (self#text_of_class_params father c) + self#latex_of_text fmt + (self#text_of_class_params father c) (** Print LaTeX code for a type. *) method latex_of_type fmt t = let s_name = Name.simple t.ty_name in - let text = - let (fmt2, flush2) = new_fmt () in + let text = + let (fmt2, flush2) = new_fmt () in Odoc_info.reset_type_names () ; let mod_name = Name.father t.ty_name in Format.fprintf fmt2 "@[<h 2>type "; - self#latex_of_type_params fmt2 mod_name t; - (match t.ty_parameters with [] -> () | _ -> ps fmt2 " "); + self#latex_of_type_params fmt2 mod_name t; + (match t.ty_parameters with [] -> () | _ -> ps fmt2 " "); ps fmt2 s_name; - ( + ( match t.ty_manifest with None -> () - | Some typ -> + | Some typ -> p fmt2 " = %s" (self#normal_type mod_name typ) - ); - let s_type3 = + ); + let s_type3 = p fmt2 " %s" ( - match t.ty_kind with + match t.ty_kind with Type_abstract -> "" | Type_variant (_, priv) -> "="^(if priv then " private" else "") - | Type_record (_, priv) -> "= "^(if priv then "private " else "")^"{" - ) ; + | Type_record (_, priv) -> "= "^(if priv then "private " else "")^"{" + ) ; flush2 () in - - let defs = + + let defs = match t.ty_kind with Type_abstract -> [] | Type_variant (l, _) -> (List.flatten (List.map (fun constr -> - let s_cons = + let s_cons = p fmt2 "@[<h 6> | %s" constr.vc_name; ( - match constr.vc_args with + match constr.vc_args with [] -> () - | l -> - p fmt2 " %s@ %s" - "of" + | l -> + p fmt2 " %s@ %s" + "of" (self#normal_type_list ~par: false mod_name " * " l) - ); - flush2 () + ); + flush2 () in [ CodePre s_cons ] @ (match constr.vc_text with None -> [] - | Some t -> - let s = - ps fmt2 "\\begin{ocamldoccomment}\n"; - self#latex_of_text fmt2 t; - ps fmt2 "\n\\end{ocamldoccomment}\n"; - flush2 () - in + | Some t -> + let s = + ps fmt2 "\\begin{ocamldoccomment}\n"; + self#latex_of_text fmt2 t; + ps fmt2 "\n\\end{ocamldoccomment}\n"; + flush2 () + in [ Latex s] ) ) @@ -528,24 +531,24 @@ class latex = (List.flatten (List.map (fun r -> - let s_field = + let s_field = p fmt2 - "@[<h 6> %s%s :@ %s ;" + "@[<h 6> %s%s :@ %s ;" (if r.rf_mutable then "mutable " else "") r.rf_name (self#normal_type mod_name r.rf_type); - flush2 () + flush2 () in [ CodePre s_field ] @ (match r.rf_text with None -> [] - | Some t -> - let s = - ps fmt2 "\\begin{ocamldoccomment}\n"; - self#latex_of_text fmt2 t; - ps fmt2 "\n\\end{ocamldoccomment}\n"; - flush2 () - in + | Some t -> + let s = + ps fmt2 "\\begin{ocamldoccomment}\n"; + self#latex_of_text fmt2 t; + ps fmt2 "\n\\end{ocamldoccomment}\n"; + flush2 () + in [ Latex s] ) ) @@ -574,95 +577,95 @@ class latex = method latex_of_exception fmt e = Odoc_info.reset_type_names () ; self#latex_of_text fmt - ((Latex (self#make_label (self#exception_label e.ex_name))) :: + ((Latex (self#make_label (self#exception_label e.ex_name))) :: (to_text#text_of_exception e)) method latex_of_module_parameter fmt m_name p = - self#latex_of_text fmt - [ - Code "functor ("; - Code p.mp_name ; - Code " : "; - ] ; + self#latex_of_text fmt + [ + Code "functor ("; + Code p.mp_name ; + Code " : "; + ] ; self#latex_of_module_type_kind fmt m_name p.mp_kind; self#latex_of_text fmt [ Code ") -> "] method latex_of_module_type_kind fmt father kind = match kind with - Module_type_struct eles -> - self#latex_of_text fmt [Latex "\\begin{ocamldocsigend}\n"]; - List.iter (self#latex_of_module_element fmt father) eles; - self#latex_of_text fmt [Latex "\\end{ocamldocsigend}\n"] + Module_type_struct eles -> + self#latex_of_text fmt [Latex "\\begin{ocamldocsigend}\n"]; + List.iter (self#latex_of_module_element fmt father) eles; + self#latex_of_text fmt [Latex "\\end{ocamldocsigend}\n"] | Module_type_functor (p, k) -> - self#latex_of_module_parameter fmt father p; - self#latex_of_module_type_kind fmt father k + self#latex_of_module_parameter fmt father p; + self#latex_of_module_type_kind fmt father k | Module_type_alias a -> - self#latex_of_text fmt - [Code (self#relative_module_idents father a.mta_name)] + self#latex_of_text fmt + [Code (self#relative_module_idents father a.mta_name)] | Module_type_with (k, s) -> - self#latex_of_module_type_kind fmt father k; - self#latex_of_text fmt - [ Code " "; - Code (self#relative_idents father s); - ] - + self#latex_of_module_type_kind fmt father k; + self#latex_of_text fmt + [ Code " "; + Code (self#relative_idents father s); + ] + method latex_of_module_kind fmt father kind = match kind with - Module_struct eles -> - self#latex_of_text fmt [Latex "\\begin{ocamldocsigend}\n"]; - List.iter (self#latex_of_module_element fmt father) eles; - self#latex_of_text fmt [Latex "\\end{ocamldocsigend}\n"] + Module_struct eles -> + self#latex_of_text fmt [Latex "\\begin{ocamldocsigend}\n"]; + List.iter (self#latex_of_module_element fmt father) eles; + self#latex_of_text fmt [Latex "\\end{ocamldocsigend}\n"] | Module_alias a -> - self#latex_of_text fmt - [Code (self#relative_module_idents father a.ma_name)] + self#latex_of_text fmt + [Code (self#relative_module_idents father a.ma_name)] | Module_functor (p, k) -> - self#latex_of_module_parameter fmt father p; - self#latex_of_module_kind fmt father k + self#latex_of_module_parameter fmt father p; + self#latex_of_module_kind fmt father k | Module_apply (k1, k2) -> - (* TODO: l'application n'est pas correcte dans un .mli. - Que faire ? -> afficher le module_type du typedtree *) - self#latex_of_module_kind fmt father k1; - self#latex_of_text fmt [Code "("]; - self#latex_of_module_kind fmt father k2; - self#latex_of_text fmt [Code ")"] + (* TODO: l'application n'est pas correcte dans un .mli. + Que faire ? -> afficher le module_type du typedtree *) + self#latex_of_module_kind fmt father k1; + self#latex_of_text fmt [Code "("]; + self#latex_of_module_kind fmt father k2; + self#latex_of_text fmt [Code ")"] | Module_with (k, s) -> - (* TODO: à modifier quand Module_with sera plus détaillé *) - self#latex_of_module_type_kind fmt father k; - self#latex_of_text fmt - [ Code " "; - Code (self#relative_idents father s) ; - ] + (* TODO: à modifier quand Module_with sera plus détaillé *) + self#latex_of_module_type_kind fmt father k; + self#latex_of_text fmt + [ Code " "; + Code (self#relative_idents father s) ; + ] | Module_constraint (k, tk) -> - (* TODO: on affiche quoi ? *) - self#latex_of_module_kind fmt father k + (* TODO: on affiche quoi ? *) + self#latex_of_module_kind fmt father k method latex_of_class_kind fmt father kind = match kind with - Class_structure (inh, eles) -> - self#latex_of_text fmt [Latex "\\begin{ocamldocobjectend}\n"]; - self#generate_inheritance_info fmt inh; - List.iter (self#latex_of_class_element fmt father) eles; - self#latex_of_text fmt [Latex "\\end{ocamldocobjectend}\n"] + Class_structure (inh, eles) -> + self#latex_of_text fmt [Latex "\\begin{ocamldocobjectend}\n"]; + self#generate_inheritance_info fmt inh; + List.iter (self#latex_of_class_element fmt father) eles; + self#latex_of_text fmt [Latex "\\end{ocamldocobjectend}\n"] | Class_apply capp -> - (* TODO: afficher le type final à partir du typedtree *) - self#latex_of_text fmt [Raw "class application not handled yet"] - + (* TODO: afficher le type final à partir du typedtree *) + self#latex_of_text fmt [Raw "class application not handled yet"] + | Class_constr cco -> - ( + ( match cco.cco_type_parameters with [] -> () - | l -> + | l -> self#latex_of_text fmt - ( - Code "[" :: - (self#text_of_class_type_param_expr_list father l) @ - [Code "] "] - ) - ); - self#latex_of_text fmt - [Code (self#relative_idents father cco.cco_name)] + ( + Code "[" :: + (self#text_of_class_type_param_expr_list father l) @ + [Code "] "] + ) + ); + self#latex_of_text fmt + [Code (self#relative_idents father cco.cco_name)] | Class_constraint (ck, ctk) -> self#latex_of_text fmt [Code "( "] ; @@ -673,41 +676,41 @@ class latex = method latex_of_class_type_kind fmt father kind = match kind with - Class_type cta -> + Class_type cta -> ( match cta.cta_type_parameters with [] -> () - | l -> - self#latex_of_text fmt - (Code "[" :: - (self#text_of_class_type_param_expr_list father l) @ - [Code "] "] - ) + | l -> + self#latex_of_text fmt + (Code "[" :: + (self#text_of_class_type_param_expr_list father l) @ + [Code "] "] + ) ); self#latex_of_text fmt - [Code (self#relative_idents father cta.cta_name)] + [Code (self#relative_idents father cta.cta_name)] - | Class_signature (inh, eles) -> - self#latex_of_text fmt [Latex "\\begin{ocamldocobjectend}\n"]; - self#generate_inheritance_info fmt inh; - List.iter (self#latex_of_class_element fmt father) eles; - self#latex_of_text fmt [Latex "\\end{ocamldocobjectend}\n"] + | Class_signature (inh, eles) -> + self#latex_of_text fmt [Latex "\\begin{ocamldocobjectend}\n"]; + self#generate_inheritance_info fmt inh; + List.iter (self#latex_of_class_element fmt father) eles; + self#latex_of_text fmt [Latex "\\end{ocamldocobjectend}\n"] method latex_for_module_index fmt m = let s_name = Name.simple m.m_name in - self#latex_of_text fmt - [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ - (self#label ~no_:false s_name)^"`}\n" - ) - ] + self#latex_of_text fmt + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ] method latex_for_module_type_index fmt mt = let s_name = Name.simple mt.mt_name in - self#latex_of_text fmt - [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ - (self#label ~no_:false (Name.simple s_name))^"`}\n" - ) - ] + self#latex_of_text fmt + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ + (self#label ~no_:false (Name.simple s_name))^"`}\n" + ) + ] method latex_for_module_label fmt m = ps fmt (self#make_label (self#module_label m.m_name)) @@ -718,19 +721,19 @@ class latex = method latex_for_class_index fmt c = let s_name = Name.simple c.cl_name in - self#latex_of_text fmt - [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ - (self#label ~no_:false s_name)^"`}\n" - ) - ] + self#latex_of_text fmt + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ] method latex_for_class_type_index fmt ct = let s_name = Name.simple ct.clt_name in - self#latex_of_text fmt - [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ - (self#label ~no_:false s_name)^"`}\n" - ) - ] + self#latex_of_text fmt + [Latex ("\\index{"^(self#label s_name)^"@\\verb`"^ + (self#label ~no_:false s_name)^"`}\n" + ) + ] method latex_for_class_label fmt c = ps fmt (self#make_label (self#class_label c.cl_name)) @@ -741,13 +744,13 @@ class latex = (** Print the LaTeX code for the given module. *) method latex_of_module fmt m = let father = Name.father m.m_name in - let t = + let t = [ - Latex "\\begin{ocamldoccode}\n" ; - Code "module "; - Code (Name.simple m.m_name); + Latex "\\begin{ocamldoccode}\n" ; + Code "module "; + Code (Name.simple m.m_name); Code " : "; - ] + ] in self#latex_of_text fmt t; self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; @@ -757,29 +760,29 @@ class latex = self#latex_of_module_kind fmt father m.m_kind; ( match Module.module_is_functor m with - false -> () + false -> () | true -> - self#latex_of_text fmt [Newline]; - ( - match List.filter (fun (_,d) -> d <> None) - (module_parameters ~trans: false m) - with - [] -> () - | l -> - let t = - [ Bold [Raw "Parameters: "]; - List - (List.map - (fun (p,text_opt) -> - let t = match text_opt with None -> [] | Some t -> t in - ( Raw p.mp_name :: Raw ": " :: t) - ) - l - ) - ] - in - self#latex_of_text fmt t - ); + self#latex_of_text fmt [Newline]; + ( + match List.filter (fun (_,d) -> d <> None) + (module_parameters ~trans: false m) + with + [] -> () + | l -> + let t = + [ Bold [Raw "Parameters: "]; + List + (List.map + (fun (p,text_opt) -> + let t = match text_opt with None -> [] | Some t -> t in + ( Raw p.mp_name :: Raw ": " :: t) + ) + l + ) + ] + in + self#latex_of_text fmt t + ); ); self#latex_of_text fmt [Newline]; self#latex_of_info fmt ~block: true m.m_info; @@ -789,53 +792,53 @@ class latex = (** Print the LaTeX code for the given module type. *) method latex_of_module_type fmt mt = let father = Name.father mt.mt_name in - let t = + let t = [ - Latex "\\begin{ocamldoccode}\n" ; - Code "module type " ; - Code (Name.simple mt.mt_name); - ] + Latex "\\begin{ocamldoccode}\n" ; + Code "module type " ; + Code (Name.simple mt.mt_name); + ] in self#latex_of_text fmt t; ( match mt.mt_type, mt.mt_kind with - | Some mtyp, Some kind -> + | Some mtyp, Some kind -> self#latex_of_text fmt [ Code " = " ]; - self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; - self#latex_for_module_type_label fmt mt; - self#latex_for_module_type_index fmt mt; - p fmt "@[<h 4>"; - self#latex_of_module_type_kind fmt father kind + self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; + self#latex_for_module_type_label fmt mt; + self#latex_for_module_type_index fmt mt; + p fmt "@[<h 4>"; + self#latex_of_module_type_kind fmt father kind | _ -> - self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; - self#latex_for_module_type_index fmt mt; - p fmt "@[<h 4>"; + self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; + self#latex_for_module_type_index fmt mt; + p fmt "@[<h 4>"; ); ( match Module.module_type_is_functor mt with - false -> () + false -> () | true -> - self#latex_of_text fmt [Newline]; - ( - match List.filter (fun (_,d) -> d <> None) - (module_type_parameters ~trans: false mt) - with - [] -> () - | l -> - let t = - [ Bold [Raw "Parameters: "]; - List - (List.map - (fun (p,text_opt) -> - let t = match text_opt with None -> [] | Some t -> t in - ( Raw p.mp_name :: Raw ": " :: t) - ) - l - ) - ] - in - self#latex_of_text fmt t - ); + self#latex_of_text fmt [Newline]; + ( + match List.filter (fun (_,d) -> d <> None) + (module_type_parameters ~trans: false mt) + with + [] -> () + | l -> + let t = + [ Bold [Raw "Parameters: "]; + List + (List.map + (fun (p,text_opt) -> + let t = match text_opt with None -> [] | Some t -> t in + ( Raw p.mp_name :: Raw ": " :: t) + ) + l + ) + ] + in + self#latex_of_text fmt t + ); ); self#latex_of_text fmt [Newline]; self#latex_of_info fmt ~block: true mt.mt_info; @@ -844,14 +847,14 @@ class latex = (** Print the LaTeX code for the given included module. *) method latex_of_included_module fmt im = self#latex_of_text fmt - ((Code "include ") :: - (Code + ((Code "include ") :: + (Code (match im.im_module with None -> im.im_name | Some (Mod m) -> m.m_name | Some (Modtype mt) -> mt.mt_name) - ) :: - (self#text_of_info im.im_info) + ) :: + (self#text_of_info im.im_info) ) (** Print the LaTeX code for the given class. *) @@ -863,34 +866,34 @@ class latex = [] -> "" | l -> (self#normal_class_type_param_list father l)^" " in - let t = - [ - Latex "\\begin{ocamldoccode}\n" ; - Code (Printf.sprintf - "class %s%s%s : " - (if c.cl_virtual then "virtual " else "") - type_params - (Name.simple c.cl_name) - ) - ] + let t = + [ + Latex "\\begin{ocamldoccode}\n" ; + Code (Printf.sprintf + "class %s%s%s : " + (if c.cl_virtual then "virtual " else "") + type_params + (Name.simple c.cl_name) + ) + ] in self#latex_of_text fmt t; self#latex_of_class_parameter_list fmt father c; (* avoid a big gap if the kind is a consrt *) ( match c.cl_kind with - Class.Class_constr _ -> - self#latex_of_class_kind fmt father c.cl_kind + Class.Class_constr _ -> + self#latex_of_class_kind fmt father c.cl_kind | _ -> - () + () ); self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ]; self#latex_for_class_label fmt c; self#latex_for_class_index fmt c; p fmt "@[<h 4>"; (match c.cl_kind with - Class.Class_constr _ -> () - | _ -> self#latex_of_class_kind fmt father c.cl_kind + Class.Class_constr _ -> () + | _ -> self#latex_of_class_kind fmt father c.cl_kind ); self#latex_of_text fmt [Newline]; self#latex_of_info fmt ~block: true c.cl_info; @@ -905,16 +908,16 @@ class latex = [] -> "" | l -> (self#normal_class_type_param_list father l)^" " in - let t = - [ - Latex "\\begin{ocamldoccode}\n" ; - Code (Printf.sprintf - "class type %s%s%s = " - (if ct.clt_virtual then "virtual " else "") - type_params - (Name.simple ct.clt_name) - ) - ] + let t = + [ + Latex "\\begin{ocamldoccode}\n" ; + Code (Printf.sprintf + "class type %s%s%s = " + (if ct.clt_virtual then "virtual " else "") + type_params + (Name.simple ct.clt_name) + ) + ] in self#latex_of_text fmt t; @@ -958,22 +961,22 @@ class latex = let f inh = match inh.ic_class with None -> (* we can't make the reference *) - Newline :: + Newline :: Code ("inherit "^inh.ic_name) :: (match inh.ic_text with None -> [] | Some t -> Newline :: t ) | Some cct -> - let label = + let label = match cct with Cl _ -> self#class_label inh.ic_name | Cltype _ -> self#class_type_label inh.ic_name in (* we can create the reference *) - Newline :: + Newline :: Odoc_info.Code ("inherit "^inh.ic_name) :: - (Odoc_info.Latex (" ["^(self#make_ref label)^"]")) :: + (Odoc_info.Latex (" ["^(self#make_ref label)^"]")) :: (match inh.ic_text with None -> [] | Some t -> Newline :: t @@ -983,7 +986,7 @@ class latex = (** Generate the LaTeX code for the inherited classes of the given class. *) method generate_class_inheritance_info fmt cl = - let rec iter_kind k = + let rec iter_kind k = match k with Class_structure ([], _) -> () @@ -1010,12 +1013,21 @@ class latex = (** Generate the LaTeX code for the given top module, in the given buffer. *) method generate_for_top_module fmt m = let (first_t, rest_t) = self#first_and_rest_of_info m.m_info in - let text = [ Title (1, None, - [ Raw (Odoc_messages.modul^" ") ; Code m.m_name ] @ - (match first_t with - [] -> [] - | t -> (Raw " : ") :: t)) ; - ] + let text = + if m.m_text_only then + [ Title (1, None, [Raw m.m_name] @ + (match first_t with + [] -> [] + | t -> (Raw " : ") :: t) + ) ; + ] + else + [ Title (1, None, + [ Raw (Odoc_messages.modul^" ") ; Code m.m_name ] @ + (match first_t with + [] -> [] + | t -> (Raw " : ") :: t)) ; + ] in self#latex_of_text fmt text; self#latex_for_module_label fmt m; @@ -1023,12 +1035,12 @@ class latex = self#latex_of_text fmt rest_t ; self#latex_of_text fmt [ Newline ] ; - ps fmt "\\ocamldocvspace{0.5cm}\n\n"; - List.iter - (fun ele -> - self#latex_of_module_element fmt m.m_name ele; - ps fmt "\n\n" - ) + if not m.m_text_only then ps fmt "\\ocamldocvspace{0.5cm}\n\n"; + List.iter + (fun ele -> + self#latex_of_module_element fmt m.m_name ele; + ps fmt "\n\n" + ) (Module.module_elements ~trans: false m) (** Print the header of the TeX document. *) @@ -1040,44 +1052,44 @@ class latex = ps fmt "\\usepackage{url} \n"; ps fmt "\\usepackage{ocamldoc}\n"; ( - match !Args.title with + match !Args.title with None -> () - | Some s -> - ps fmt "\\title{"; - ps fmt (self#escape s); - ps fmt "}\n" + | Some s -> + ps fmt "\\title{"; + ps fmt (self#escape s); + ps fmt "}\n" ); ps fmt "\\begin{document}\n"; - (match !Args.title with - None -> () | - Some _ -> ps fmt "\\maketitle\n" + (match !Args.title with + None -> () | + Some _ -> ps fmt "\\maketitle\n" ); if !Args.with_toc then ps fmt "\\tableofcontents\n"; ( let info = Odoc_info.apply_opt - Odoc_info.info_of_comment_file !Odoc_info.Args.intro_file + Odoc_info.info_of_comment_file !Odoc_info.Args.intro_file in (match info with None -> () | Some _ -> ps fmt "\\vspace{0.2cm}"); self#latex_of_info fmt info; (match info with None -> () | Some _ -> ps fmt "\n\n") ) - + (** Generate the LaTeX style file, if it does not exists. *) method generate_style_file = try - let dir = Filename.dirname !Args.out_file in - let file = Filename.concat dir "ocamldoc.sty" in - if Sys.file_exists file then - Odoc_info.verbose (Odoc_messages.file_exists_dont_generate file) - else - ( - let chanout = open_out file in - output_string chanout Odoc_latex_style.content ; - flush chanout ; - close_out chanout; - Odoc_info.verbose (Odoc_messages.file_generated file) - ) + let dir = Filename.dirname !Args.out_file in + let file = Filename.concat dir "ocamldoc.sty" in + if Sys.file_exists file then + Odoc_info.verbose (Odoc_messages.file_exists_dont_generate file) + else + ( + let chanout = open_out file in + output_string chanout Odoc_latex_style.content ; + flush chanout ; + close_out chanout; + Odoc_info.verbose (Odoc_messages.file_generated file) + ) with Sys_error s -> prerr_endline s ; @@ -1092,40 +1104,40 @@ class latex = ( let f m = try - let chanout = + let chanout = open_out ((Filename.concat dir (Name.simple m.m_name))^".tex") in - let fmt = Format.formatter_of_out_channel chanout in + let fmt = Format.formatter_of_out_channel chanout in self#generate_for_top_module fmt m ; - Format.pp_print_flush fmt (); + Format.pp_print_flush fmt (); close_out chanout with Failure s | Sys_error s -> prerr_endline s ; - incr Odoc_info.errors + incr Odoc_info.errors in List.iter f module_list ); - + try let chanout = open_out main_file in - let fmt = Format.formatter_of_out_channel chanout in + let fmt = Format.formatter_of_out_channel chanout in if !Args.with_header then self#latex_header fmt; - List.iter - (fun m -> - if !Args.separate_files then + List.iter + (fun m -> + if !Args.separate_files then ps fmt ("\\input{"^((Name.simple m.m_name))^".tex}\n") else self#generate_for_top_module fmt m - ) + ) module_list ; if !Args.with_trailer then ps fmt "\\end{document}"; - Format.pp_print_flush fmt (); + Format.pp_print_flush fmt (); close_out chanout with Failure s | Sys_error s -> prerr_endline s ; - incr Odoc_info.errors + incr Odoc_info.errors end |