2002-03-27 08:20:32 -08:00
|
|
|
(***********************************************************************)
|
2012-08-01 05:09:31 -07:00
|
|
|
(* *)
|
2002-03-27 08:20:32 -08:00
|
|
|
(* OCamldoc *)
|
|
|
|
(* *)
|
|
|
|
(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2001 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(** Generation of LaTeX documentation. *)
|
|
|
|
|
|
|
|
let print_DEBUG s = print_string s ; print_newline ()
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
open Odoc_info
|
2002-03-27 08:20:32 -08:00
|
|
|
open Parameter
|
|
|
|
open Value
|
|
|
|
open Type
|
|
|
|
open Exception
|
2006-01-04 08:55:50 -08:00
|
|
|
open Class
|
2002-03-27 08:20:32 -08:00
|
|
|
open Module
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
|
|
|
|
|
|
|
|
let separate_files = ref false
|
|
|
|
|
|
|
|
let latex_titles = ref [
|
|
|
|
1, "section" ;
|
|
|
|
2, "subsection" ;
|
|
|
|
3, "subsubsection" ;
|
|
|
|
4, "paragraph" ;
|
|
|
|
5, "subparagraph" ;
|
|
|
|
]
|
|
|
|
|
|
|
|
let latex_value_prefix = ref Odoc_messages.default_latex_value_prefix
|
|
|
|
let latex_type_prefix = ref Odoc_messages.default_latex_type_prefix
|
2012-07-26 12:21:54 -07:00
|
|
|
let latex_type_elt_prefix = ref Odoc_messages.default_latex_type_elt_prefix
|
2010-08-24 02:45:45 -07:00
|
|
|
let latex_exception_prefix = ref Odoc_messages.default_latex_exception_prefix
|
|
|
|
let latex_module_prefix = ref Odoc_messages.default_latex_module_prefix
|
|
|
|
let latex_module_type_prefix = ref Odoc_messages.default_latex_module_type_prefix
|
|
|
|
let latex_class_prefix = ref Odoc_messages.default_latex_class_prefix
|
|
|
|
let latex_class_type_prefix = ref Odoc_messages.default_latex_class_type_prefix
|
|
|
|
let latex_attribute_prefix = ref Odoc_messages.default_latex_attribute_prefix
|
|
|
|
let latex_method_prefix = ref Odoc_messages.default_latex_method_prefix
|
|
|
|
|
2004-03-24 02:37:10 -08:00
|
|
|
let new_buf () = Buffer.create 1024
|
|
|
|
let new_fmt () =
|
|
|
|
let b = new_buf () in
|
|
|
|
let fmt = Format.formatter_of_buffer b in
|
|
|
|
(fmt,
|
2006-01-04 08:55:50 -08:00
|
|
|
fun () ->
|
2004-03-24 02:37:10 -08:00
|
|
|
Format.pp_print_flush fmt ();
|
|
|
|
let s = Buffer.contents b in
|
|
|
|
Buffer.reset b;
|
|
|
|
s
|
|
|
|
)
|
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
let p = Format.fprintf
|
|
|
|
let ps f s = Format.fprintf f "%s" s
|
|
|
|
|
|
|
|
|
2004-03-24 02:37:10 -08:00
|
|
|
let bp = Printf.bprintf
|
|
|
|
let bs = Buffer.add_string
|
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
let print_concat fmt sep f =
|
2004-03-24 02:37:10 -08:00
|
|
|
let rec iter = function
|
|
|
|
[] -> ()
|
|
|
|
| [c] -> f c
|
|
|
|
| c :: q ->
|
2006-01-04 08:55:50 -08:00
|
|
|
f c;
|
|
|
|
ps fmt sep;
|
|
|
|
iter q
|
2004-03-24 02:37:10 -08:00
|
|
|
in
|
|
|
|
iter
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Generation of LaTeX code from text structures. *)
|
|
|
|
class text =
|
|
|
|
object (self)
|
|
|
|
(** Return latex code to make a sectionning according to the given level,
|
|
|
|
and with the given latex code. *)
|
|
|
|
method section_style level s =
|
2006-01-04 08:55:50 -08:00
|
|
|
try
|
2010-08-24 02:45:45 -07:00
|
|
|
let sec = List.assoc level !latex_titles in
|
2002-07-23 07:12:03 -07:00
|
|
|
"\\"^sec^"{"^s^"}\n"
|
2002-03-27 08:20:32 -08:00
|
|
|
with Not_found -> s
|
|
|
|
|
2012-02-21 04:47:14 -08:00
|
|
|
(** Associations of strings to substitute in latex code. *)
|
|
|
|
val subst_strings = List.map (fun (x, y) -> (Str.regexp x, y))
|
2006-01-04 08:55:50 -08:00
|
|
|
[
|
2012-02-21 04:47:14 -08:00
|
|
|
"\001", "\001\002";
|
|
|
|
"\\\\", "\001b";
|
|
|
|
|
|
|
|
"{", "\\\\{";
|
|
|
|
"}", "\\\\}";
|
|
|
|
"\\$", "\\\\$";
|
|
|
|
"\\^", "{\\\\textasciicircum}";
|
2012-07-30 02:48:32 -07:00
|
|
|
"\xE0", "\\\\`a";
|
|
|
|
"\xE2", "\\\\^a";
|
|
|
|
"\xE9", "\\\\'e";
|
|
|
|
"\xE8", "\\\\`e";
|
|
|
|
"\xEA", "\\\\^e";
|
|
|
|
"\xEB", "\\\\\"e";
|
|
|
|
"\xE7", "\\\\c{c}";
|
|
|
|
"\xF4", "\\\\^o";
|
|
|
|
"\xF6", "\\\\\"o";
|
|
|
|
"\xEE", "\\\\^i";
|
|
|
|
"\xEF", "\\\\\"i";
|
|
|
|
"\xF9", "\\\\`u";
|
|
|
|
"\xFB", "\\\\^u";
|
2012-02-21 04:47:14 -08:00
|
|
|
"%", "\\\\%";
|
|
|
|
"_", "\\\\_";
|
|
|
|
"~", "\\\\~{}";
|
|
|
|
"#", "{\\char35}";
|
|
|
|
"->", "$\\\\rightarrow$";
|
|
|
|
"<-", "$\\\\leftarrow$";
|
|
|
|
">=", "$\\\\geq$";
|
|
|
|
"<=", "$\\\\leq$";
|
|
|
|
">", "$>$";
|
|
|
|
"<", "$<$";
|
|
|
|
"=", "$=$";
|
|
|
|
"|", "{\\\\textbar}";
|
|
|
|
"\\.\\.\\.", "$\\\\ldots$";
|
|
|
|
"&", "\\\\&";
|
|
|
|
|
|
|
|
"\001b", "{\\\\char92}";
|
|
|
|
"\001\002", "\001";
|
2006-01-04 08:55:50 -08:00
|
|
|
]
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2012-02-21 04:47:14 -08:00
|
|
|
val subst_strings_simple = List.map (fun (x, y) -> (Str.regexp x, y))
|
|
|
|
[
|
|
|
|
"\001", "\001\002";
|
|
|
|
"\\\\", "\001b";
|
|
|
|
"{", "\001l";
|
|
|
|
|
|
|
|
"}", "{\\\\char125}";
|
|
|
|
"'", "{\\\\textquotesingle}";
|
|
|
|
"`", "{\\\\textasciigrave}";
|
|
|
|
|
|
|
|
"\001b", "{\\\\char92}";
|
|
|
|
"\001l", "{\\\\char123}";
|
|
|
|
"\001\002", "\001";
|
|
|
|
]
|
|
|
|
|
|
|
|
val subst_strings_code = List.map (fun (x, y) -> (Str.regexp x, y))
|
|
|
|
[
|
|
|
|
"\001", "\001\002";
|
|
|
|
"\\\\", "\001b";
|
|
|
|
"{", "\001l";
|
|
|
|
|
|
|
|
"}", "{\\\\char125}";
|
|
|
|
"'", "{\\\\textquotesingle}";
|
|
|
|
"`", "{\\\\textasciigrave}";
|
|
|
|
"%", "\\\\%";
|
|
|
|
"_", "\\\\_";
|
|
|
|
"~", "{\\\\char126}";
|
|
|
|
"#", "{\\\\char35}";
|
|
|
|
"&", "\\\\&";
|
|
|
|
"\\$", "\\\\$";
|
|
|
|
"\\^", "{\\\\char94}";
|
|
|
|
|
|
|
|
"\001b", "{\\\\char92}";
|
|
|
|
"\001l", "{\\\\char123}";
|
|
|
|
"\001\002", "\001";
|
|
|
|
]
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
method subst l s =
|
2012-02-21 04:47:14 -08:00
|
|
|
List.fold_left (fun acc (re, st) -> Str.global_replace re st acc) s l
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Escape the strings which would clash with LaTeX syntax. *)
|
|
|
|
method escape s = self#subst subst_strings s
|
|
|
|
|
|
|
|
(** Escape the ['\'], ['{'] and ['}'] characters. *)
|
|
|
|
method escape_simple s = self#subst subst_strings_simple s
|
|
|
|
|
|
|
|
(** Escape some characters for the code style. *)
|
|
|
|
method escape_code s = self#subst subst_strings_code s
|
2006-01-04 08:55:50 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
(** Make a correct latex label from a name. *)
|
2002-11-22 06:57:49 -08:00
|
|
|
(* The following characters are forbidden in LaTeX \index:
|
|
|
|
\ { } $ & # ^ _ % ~ ! " @ | (" to close the double quote)
|
|
|
|
The following characters are forbidden in LaTeX \label:
|
|
|
|
\ { } $ & # ^ _ % ~
|
|
|
|
So we will use characters not forbidden in \index if no_ = true.
|
|
|
|
*)
|
2002-03-27 08:20:32 -08:00
|
|
|
method label ?(no_=true) name =
|
2002-07-09 02:38:36 -07:00
|
|
|
let len = String.length name in
|
|
|
|
let buf = Buffer.create len in
|
|
|
|
for i = 0 to len - 1 do
|
2002-11-22 06:57:49 -08:00
|
|
|
let (s_no_, s) =
|
2006-01-04 08:55:50 -08:00
|
|
|
match name.[i] with
|
2002-11-22 06:57:49 -08:00
|
|
|
'_' -> ("-underscore", "_")
|
|
|
|
| '~' -> ("-tilde", "~")
|
2006-01-04 08:55:50 -08:00
|
|
|
| '%' -> ("-percent", "%")
|
2002-11-22 06:57:49 -08:00
|
|
|
| '@' -> ("-at", "\"@")
|
|
|
|
| '!' -> ("-bang", "\"!")
|
2012-02-15 08:31:59 -08:00
|
|
|
| '|' -> ("-pipe", "\"|")
|
2006-01-04 08:55:50 -08:00
|
|
|
| '<' -> ("-lt", "<")
|
2002-11-22 06:57:49 -08:00
|
|
|
| '>' -> ("-gt", ">")
|
|
|
|
| '^' -> ("-exp", "^")
|
|
|
|
| '&' -> ("-ampersand", "&")
|
|
|
|
| '+' -> ("-plus", "+")
|
|
|
|
| '-' -> ("-minus", "-")
|
|
|
|
| '*' -> ("-star", "*")
|
|
|
|
| '/' -> ("-slash", "/")
|
|
|
|
| '$' -> ("-dollar", "$")
|
|
|
|
| '=' -> ("-equal", "=")
|
|
|
|
| ':' -> ("-colon", ":")
|
|
|
|
| c -> (String.make 1 c, String.make 1 c)
|
2006-01-04 08:55:50 -08:00
|
|
|
in
|
|
|
|
Buffer.add_string buf (if no_ then s_no_ else s)
|
2002-07-09 02:38:36 -07:00
|
|
|
done;
|
|
|
|
Buffer.contents buf
|
|
|
|
|
|
|
|
(** Make a correct label from a value name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method value_label ?no_ name = !latex_value_prefix^(self#label ?no_ name)
|
2002-07-09 02:38:36 -07:00
|
|
|
|
|
|
|
(** Make a correct label from an attribute name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method attribute_label ?no_ name = !latex_attribute_prefix^(self#label ?no_ name)
|
2002-07-09 02:38:36 -07:00
|
|
|
|
|
|
|
(** Make a correct label from a method name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method method_label ?no_ name = !latex_method_prefix^(self#label ?no_ name)
|
2002-07-09 02:38:36 -07:00
|
|
|
|
|
|
|
(** Make a correct label from a class name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method class_label ?no_ name = !latex_class_prefix^(self#label ?no_ name)
|
2002-07-09 02:38:36 -07:00
|
|
|
|
|
|
|
(** Make a correct label from a class type name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method class_type_label ?no_ name = !latex_class_type_prefix^(self#label ?no_ name)
|
2002-07-09 02:38:36 -07:00
|
|
|
|
|
|
|
(** Make a correct label from a module name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method module_label ?no_ name = !latex_module_prefix^(self#label ?no_ name)
|
2002-07-09 02:38:36 -07:00
|
|
|
|
|
|
|
(** Make a correct label from a module type name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method module_type_label ?no_ name = !latex_module_type_prefix^(self#label ?no_ name)
|
2002-07-09 02:38:36 -07:00
|
|
|
|
|
|
|
(** Make a correct label from an exception name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method exception_label ?no_ name = !latex_exception_prefix^(self#label ?no_ name)
|
2002-07-09 02:38:36 -07:00
|
|
|
|
|
|
|
(** Make a correct label from a type name. *)
|
2010-08-24 02:45:45 -07:00
|
|
|
method type_label ?no_ name = !latex_type_prefix^(self#label ?no_ name)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2012-07-26 12:21:54 -07:00
|
|
|
(** Make a correct label from a record field. *)
|
|
|
|
method recfield_label ?no_ name = !latex_type_elt_prefix^(self#label ?no_ name)
|
|
|
|
|
|
|
|
(** Make a correct label from a variant constructor. *)
|
|
|
|
method const_label ?no_ name = !latex_type_elt_prefix^(self#label ?no_ name)
|
|
|
|
|
2002-07-09 02:38:36 -07:00
|
|
|
(** Return latex code for the label of a given label. *)
|
|
|
|
method make_label label = "\\label{"^label^"}"
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2002-07-09 02:38:36 -07:00
|
|
|
(** Return latex code for the ref to a given label. *)
|
|
|
|
method make_ref label = "\\ref{"^label^"}"
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code corresponding to the [text] parameter.*)
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_text fmt t =
|
2004-03-26 07:57:03 -08:00
|
|
|
List.iter (self#latex_of_text_element fmt) t
|
2006-01-04 08:55:50 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code for the [text_element] in parameter. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_text_element fmt te =
|
2002-03-27 08:20:32 -08:00
|
|
|
match te with
|
2004-03-26 07:57:03 -08:00
|
|
|
| Odoc_info.Raw s -> self#latex_of_Raw fmt s
|
|
|
|
| Odoc_info.Code s -> self#latex_of_Code fmt s
|
|
|
|
| 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
|
2006-01-04 08:55:50 -08:00
|
|
|
| Odoc_info.Italic t -> self#latex_of_Italic fmt t
|
2004-03-26 07:57:03 -08:00
|
|
|
| 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
|
|
|
|
| Odoc_info.Right t -> self#latex_of_Right fmt t
|
|
|
|
| Odoc_info.List tl -> self#latex_of_List fmt tl
|
|
|
|
| Odoc_info.Enum tl -> self#latex_of_Enum fmt tl
|
|
|
|
| Odoc_info.Newline -> self#latex_of_Newline fmt
|
|
|
|
| Odoc_info.Block t -> self#latex_of_Block fmt t
|
|
|
|
| Odoc_info.Title (n, l_opt, t) -> self#latex_of_Title fmt n l_opt t
|
|
|
|
| Odoc_info.Latex s -> self#latex_of_Latex fmt s
|
|
|
|
| Odoc_info.Link (s, t) -> self#latex_of_Link fmt s t
|
2009-12-18 03:52:23 -08:00
|
|
|
| Odoc_info.Ref (name, ref_opt, text_opt) ->
|
|
|
|
self#latex_of_Ref fmt name ref_opt text_opt
|
2004-03-26 07:57:03 -08:00
|
|
|
| Odoc_info.Superscript t -> self#latex_of_Superscript fmt t
|
|
|
|
| Odoc_info.Subscript t -> self#latex_of_Subscript fmt t
|
2006-01-04 08:55:50 -08:00
|
|
|
| Odoc_info.Module_list _ -> ()
|
|
|
|
| Odoc_info.Index_list -> ()
|
|
|
|
| Odoc_info.Custom (s,t) -> self#latex_of_custom_text fmt s t
|
2010-03-08 08:54:13 -08:00
|
|
|
| Odoc_info.Target (target, code) -> self#latex_of_Target fmt ~target ~code
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
|
|
method latex_of_custom_text fmt s t = ()
|
2004-03-26 07:57:03 -08:00
|
|
|
|
2010-03-08 08:54:13 -08:00
|
|
|
method latex_of_Target fmt ~target ~code =
|
|
|
|
if String.lowercase target = "latex" then
|
|
|
|
self#latex_of_Latex fmt code
|
|
|
|
else
|
|
|
|
()
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_Raw fmt s =
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt (self#escape s)
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_Code fmt s =
|
2002-03-27 08:20:32 -08:00
|
|
|
let s2 = self#escape_code s in
|
|
|
|
let s3 = Str.global_replace (Str.regexp "\n") ("\\\\\n") s2 in
|
2004-03-26 07:57:03 -08:00
|
|
|
p fmt "{\\tt{%s}}" s3
|
|
|
|
|
|
|
|
method latex_of_CodePre fmt s =
|
|
|
|
ps fmt "\\begin{ocamldoccode}\n";
|
|
|
|
ps fmt (self#escape_simple s);
|
|
|
|
ps fmt "\n\\end{ocamldoccode}\n"
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_Verbatim fmt s =
|
2012-02-23 11:15:09 -08:00
|
|
|
ps fmt "\n\\begin{verbatim}\n";
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt s;
|
2012-02-23 11:15:09 -08:00
|
|
|
ps fmt "\n\\end{verbatim}\n"
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
method latex_of_Bold fmt t =
|
|
|
|
ps fmt "{\\bf ";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "}"
|
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_Italic fmt t =
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt "{\\it ";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "}"
|
|
|
|
|
|
|
|
method latex_of_Emphasize fmt t =
|
|
|
|
ps fmt "{\\em ";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "}"
|
|
|
|
|
|
|
|
method latex_of_Center fmt t =
|
|
|
|
ps fmt "\\begin{center}\n";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "\\end{center}\n"
|
|
|
|
|
|
|
|
method latex_of_Left fmt t =
|
|
|
|
ps fmt "\\begin{flushleft}\n";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "\\end{flushleft}\n"
|
|
|
|
|
|
|
|
method latex_of_Right fmt t =
|
|
|
|
ps fmt "\\begin{flushright}\n";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "\\end{flushright}\n"
|
|
|
|
|
|
|
|
method latex_of_List fmt tl =
|
|
|
|
ps fmt "\\begin{itemize}\n";
|
2006-01-04 08:55:50 -08:00
|
|
|
List.iter
|
|
|
|
(fun t ->
|
|
|
|
ps fmt "\\item ";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "\n"
|
|
|
|
)
|
|
|
|
tl;
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt "\\end{itemize}\n"
|
2004-03-24 02:37:10 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_Enum fmt tl =
|
|
|
|
ps fmt "\\begin{enumerate}\n";
|
2006-01-04 08:55:50 -08:00
|
|
|
List.iter
|
|
|
|
(fun t ->
|
|
|
|
ps fmt "\\item ";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "\n"
|
|
|
|
)
|
|
|
|
tl;
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt "\\end{enumerate}\n"
|
2004-03-24 02:37:10 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_Newline fmt = ps fmt "\n\n"
|
2004-03-24 02:37:10 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_Block fmt t =
|
|
|
|
ps fmt "\\begin{ocamldocdescription}\n";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "\n\\end{ocamldocdescription}\n"
|
2004-03-24 02:37:10 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_Title fmt n label_opt t =
|
|
|
|
let (fmt2, flush) = new_fmt () in
|
|
|
|
self#latex_of_text fmt2 t;
|
|
|
|
let s_title2 = self#section_style n (flush ()) in
|
|
|
|
ps fmt s_title2;
|
2004-03-24 02:37:10 -08:00
|
|
|
(
|
|
|
|
match label_opt with
|
|
|
|
None -> ()
|
|
|
|
| Some l ->
|
2006-01-04 08:55:50 -08:00
|
|
|
ps fmt (self#make_label (self#label ~no_: false l))
|
2004-03-24 02:37:10 -08:00
|
|
|
)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_Latex fmt s = ps fmt s
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_Link fmt s t =
|
|
|
|
self#latex_of_text fmt t ;
|
|
|
|
ps fmt "[\\url{";
|
|
|
|
ps fmt s ;
|
|
|
|
ps fmt "}]"
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2009-12-18 03:52:23 -08:00
|
|
|
method latex_of_Ref fmt name ref_opt text_opt =
|
2002-03-27 08:20:32 -08:00
|
|
|
match ref_opt with
|
2006-01-04 08:55:50 -08:00
|
|
|
None ->
|
2009-12-18 03:52:23 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
(match text_opt with
|
|
|
|
None ->
|
|
|
|
[Odoc_info.Code (Odoc_info.use_hidden_modules name)]
|
|
|
|
| Some t -> t
|
|
|
|
)
|
2006-01-04 08:55:50 -08:00
|
|
|
| Some (RK_section _) ->
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text_element fmt
|
2002-07-23 07:12:03 -07:00
|
|
|
(Latex ("["^(self#make_ref (self#label ~no_:false (Name.simple name)))^"]"))
|
|
|
|
| Some kind ->
|
2006-01-04 08:55:50 -08:00
|
|
|
let f_label =
|
2002-07-23 07:12:03 -07:00
|
|
|
match kind with
|
|
|
|
Odoc_info.RK_module -> self#module_label
|
|
|
|
| Odoc_info.RK_module_type -> self#module_type_label
|
|
|
|
| Odoc_info.RK_class -> self#class_label
|
|
|
|
| Odoc_info.RK_class_type -> self#class_type_label
|
|
|
|
| Odoc_info.RK_value -> self#value_label
|
|
|
|
| Odoc_info.RK_type -> self#type_label
|
|
|
|
| Odoc_info.RK_exception -> self#exception_label
|
|
|
|
| Odoc_info.RK_attribute -> self#attribute_label
|
|
|
|
| Odoc_info.RK_method -> self#method_label
|
2002-08-08 06:24:05 -07:00
|
|
|
| Odoc_info.RK_section _ -> assert false
|
2012-07-26 12:21:54 -07:00
|
|
|
| Odoc_info.RK_recfield -> self#recfield_label
|
|
|
|
| Odoc_info.RK_const -> self#const_label
|
2002-07-23 07:12:03 -07:00
|
|
|
in
|
2009-12-18 03:52:23 -08:00
|
|
|
let text =
|
|
|
|
match text_opt with
|
|
|
|
None -> [Odoc_info.Code (Odoc_info.use_hidden_modules name)]
|
|
|
|
| Some t -> t
|
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt
|
2009-12-18 03:52:23 -08:00
|
|
|
(text @ [Latex ("["^(self#make_ref (f_label name))^"]")])
|
2004-03-24 02:37:10 -08:00
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_Superscript fmt t =
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt "$^{";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "}$"
|
2004-03-24 02:37:10 -08:00
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_Subscript fmt t =
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt "$_{";
|
|
|
|
self#latex_of_text fmt t;
|
|
|
|
ps fmt "}$"
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
(** A class used to generate LaTeX code for info structures. *)
|
|
|
|
class virtual info =
|
|
|
|
object (self)
|
|
|
|
(** The method used to get LaTeX code from a [text]. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method virtual latex_of_text : Format.formatter -> Odoc_info.text -> unit
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** The method used to get a [text] from an optionel info structure. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
method virtual text_of_info : ?block: bool -> Odoc_info.info option -> Odoc_info.text
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print LaTeX code for a description, except for the [i_params] field. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_info fmt ?(block=false) info_opt =
|
|
|
|
self#latex_of_text fmt
|
2004-06-11 07:25:50 -07:00
|
|
|
(self#text_of_info ~block info_opt)
|
2002-03-27 08:20:32 -08:00
|
|
|
end
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
module Generator =
|
|
|
|
struct
|
2002-03-27 08:20:32 -08:00
|
|
|
(** This class is used to create objects which can generate a simple LaTeX documentation. *)
|
|
|
|
class latex =
|
|
|
|
object (self)
|
|
|
|
inherit text
|
|
|
|
inherit Odoc_to_text.to_text as to_text
|
|
|
|
inherit info
|
|
|
|
|
|
|
|
(** Get the first sentence and the rest of a description,
|
|
|
|
from an optional [info] structure. The first sentence
|
|
|
|
can be empty if it would not appear right in a title.
|
2002-06-04 02:21:38 -07:00
|
|
|
In the first sentence, the titles and lists has been removed,
|
|
|
|
since it is used in LaTeX titles and would make LaTeX complain
|
|
|
|
if we has two nested \section commands.
|
2002-03-27 08:20:32 -08:00
|
|
|
*)
|
|
|
|
method first_and_rest_of_info i_opt =
|
|
|
|
match i_opt with
|
2002-07-23 07:12:03 -07:00
|
|
|
None -> ([], [])
|
2006-01-04 08:55:50 -08:00
|
|
|
| Some i ->
|
2002-07-23 07:12:03 -07:00
|
|
|
match i.Odoc_info.i_desc with
|
|
|
|
None -> ([], self#text_of_info ~block: true i_opt)
|
2006-01-04 08:55:50 -08:00
|
|
|
| Some t ->
|
2002-07-23 07:12:03 -07:00
|
|
|
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)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print LaTeX code for a value. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_value fmt v =
|
2002-03-27 08:20:32 -08:00
|
|
|
Odoc_info.reset_type_names () ;
|
2004-03-26 07:57:03 -08:00
|
|
|
let label = self#value_label v.val_name in
|
|
|
|
let latex = self#make_label label in
|
|
|
|
self#latex_of_text fmt
|
2006-01-04 08:55:50 -08:00
|
|
|
((Latex latex) ::
|
2002-07-23 07:12:03 -07:00
|
|
|
(to_text#text_of_value v))
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print LaTeX code for a class attribute. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_attribute fmt a =
|
|
|
|
self#latex_of_text fmt
|
2006-01-04 08:55:50 -08:00
|
|
|
((Latex (self#make_label (self#attribute_label a.att_value.val_name))) ::
|
2002-07-23 07:12:03 -07:00
|
|
|
(to_text#text_of_attribute a))
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print LaTeX code for a class method. *)
|
2006-01-04 08:55:50 -08:00
|
|
|
method latex_of_method fmt m =
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt
|
2006-01-04 08:55:50 -08:00
|
|
|
((Latex (self#make_label (self#method_label m.met_value.val_name))) ::
|
2002-07-23 07:12:03 -07:00
|
|
|
(to_text#text_of_method m))
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print LaTeX code for the parameters of a type. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_type_params fmt m_name t =
|
2004-03-24 02:37:10 -08:00
|
|
|
let print_one (p, co, cn) =
|
2006-01-04 08:55:50 -08:00
|
|
|
ps fmt (Odoc_info.string_of_variance t (co,cn));
|
|
|
|
ps fmt (self#normal_type m_name p)
|
2003-09-05 08:40:12 -07:00
|
|
|
in
|
|
|
|
match t.ty_parameters with
|
2004-03-24 02:37:10 -08:00
|
|
|
[] -> ()
|
|
|
|
| [(p,co,cn)] -> print_one (p, co, cn)
|
2006-01-04 08:55:50 -08:00
|
|
|
| l ->
|
|
|
|
ps fmt "(";
|
|
|
|
print_concat fmt ", " print_one t.ty_parameters;
|
|
|
|
ps fmt ")"
|
2003-09-05 08:40:12 -07:00
|
|
|
|
2004-08-20 10:04:35 -07:00
|
|
|
method latex_of_class_parameter_list fmt father c =
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
(self#text_of_class_params father c)
|
2004-08-20 10:04:35 -07:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print LaTeX code for a type. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_type fmt t =
|
2002-03-27 08:20:32 -08:00
|
|
|
let s_name = Name.simple t.ty_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
let text =
|
|
|
|
let (fmt2, flush2) = new_fmt () in
|
2002-07-23 07:12:03 -07:00
|
|
|
Odoc_info.reset_type_names () ;
|
|
|
|
let mod_name = Name.father t.ty_name in
|
2004-03-26 07:57:03 -08:00
|
|
|
Format.fprintf fmt2 "@[<h 2>type ";
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_type_params fmt2 mod_name t;
|
|
|
|
(match t.ty_parameters with [] -> () | _ -> ps fmt2 " ");
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt2 s_name;
|
2007-10-09 03:29:37 -07:00
|
|
|
let priv = t.ty_private = Asttypes.Private in
|
2006-01-04 08:55:50 -08:00
|
|
|
(
|
2004-03-24 02:37:10 -08:00
|
|
|
match t.ty_manifest with
|
|
|
|
None -> ()
|
2006-01-04 08:55:50 -08:00
|
|
|
| Some typ ->
|
2007-10-09 03:29:37 -07:00
|
|
|
p fmt2 " = %s%s" (if priv then "private " else "") (self#normal_type mod_name typ)
|
2006-01-04 08:55:50 -08:00
|
|
|
);
|
|
|
|
let s_type3 =
|
2004-03-26 07:57:03 -08:00
|
|
|
p fmt2
|
2004-03-24 02:37:10 -08:00
|
|
|
" %s"
|
2003-07-04 02:31:03 -07:00
|
|
|
(
|
2006-01-04 08:55:50 -08:00
|
|
|
match t.ty_kind with
|
2003-07-04 02:31:03 -07:00
|
|
|
Type_abstract -> ""
|
2007-10-09 03:29:37 -07:00
|
|
|
| Type_variant _ -> "="^(if priv then " private" else "")
|
|
|
|
| Type_record _ -> "= "^(if priv then "private " else "")^"{"
|
2006-01-04 08:55:50 -08:00
|
|
|
) ;
|
2004-03-26 07:57:03 -08:00
|
|
|
flush2 ()
|
2002-07-23 07:12:03 -07:00
|
|
|
in
|
2006-01-04 08:55:50 -08:00
|
|
|
|
|
|
|
let defs =
|
2002-07-23 07:12:03 -07:00
|
|
|
match t.ty_kind with
|
|
|
|
Type_abstract -> []
|
2007-10-09 03:29:37 -07:00
|
|
|
| Type_variant l ->
|
2002-07-23 07:12:03 -07:00
|
|
|
(List.flatten
|
|
|
|
(List.map
|
|
|
|
(fun constr ->
|
2006-01-04 08:55:50 -08:00
|
|
|
let s_cons =
|
2004-03-26 07:57:03 -08:00
|
|
|
p fmt2 "@[<h 6> | %s" constr.vc_name;
|
2003-09-12 17:40:31 -07:00
|
|
|
(
|
2010-09-30 20:44:47 -07:00
|
|
|
match constr.vc_args, constr.vc_ret with
|
|
|
|
[], None -> ()
|
|
|
|
| l, None ->
|
2006-01-04 08:55:50 -08:00
|
|
|
p fmt2 " %s@ %s"
|
|
|
|
"of"
|
2004-03-22 07:06:31 -08:00
|
|
|
(self#normal_type_list ~par: false mod_name " * " l)
|
2010-09-30 20:44:47 -07:00
|
|
|
| [], Some r ->
|
|
|
|
p fmt2 " %s@ %s"
|
|
|
|
":"
|
|
|
|
(self#normal_type mod_name r)
|
|
|
|
| l, Some r ->
|
|
|
|
p fmt2 " %s@ %s@ %s@ %s"
|
|
|
|
":"
|
|
|
|
(self#normal_type_list ~par: false mod_name " * " l)
|
2012-07-30 04:52:38 -07:00
|
|
|
"->"
|
2012-07-26 12:21:54 -07:00
|
|
|
(self#normal_type mod_name r)
|
2006-01-04 08:55:50 -08:00
|
|
|
);
|
|
|
|
flush2 ()
|
2002-07-23 07:12:03 -07:00
|
|
|
in
|
|
|
|
[ CodePre s_cons ] @
|
|
|
|
(match constr.vc_text with
|
|
|
|
None -> []
|
2006-01-04 08:55:50 -08:00
|
|
|
| Some t ->
|
|
|
|
let s =
|
|
|
|
ps fmt2 "\\begin{ocamldoccomment}\n";
|
|
|
|
self#latex_of_text fmt2 t;
|
|
|
|
ps fmt2 "\n\\end{ocamldoccomment}\n";
|
|
|
|
flush2 ()
|
|
|
|
in
|
2004-03-24 02:37:10 -08:00
|
|
|
[ Latex s]
|
2002-07-23 07:12:03 -07:00
|
|
|
)
|
|
|
|
)
|
|
|
|
l
|
|
|
|
)
|
|
|
|
)
|
2007-10-09 03:29:37 -07:00
|
|
|
| Type_record l ->
|
2002-07-23 07:12:03 -07:00
|
|
|
(List.flatten
|
|
|
|
(List.map
|
|
|
|
(fun r ->
|
2006-01-04 08:55:50 -08:00
|
|
|
let s_field =
|
2004-03-26 07:57:03 -08:00
|
|
|
p fmt2
|
2006-01-04 08:55:50 -08:00
|
|
|
"@[<h 6> %s%s :@ %s ;"
|
2002-07-23 07:12:03 -07:00
|
|
|
(if r.rf_mutable then "mutable " else "")
|
2003-09-12 17:40:31 -07:00
|
|
|
r.rf_name
|
|
|
|
(self#normal_type mod_name r.rf_type);
|
2006-01-04 08:55:50 -08:00
|
|
|
flush2 ()
|
2002-07-23 07:12:03 -07:00
|
|
|
in
|
|
|
|
[ CodePre s_field ] @
|
|
|
|
(match r.rf_text with
|
|
|
|
None -> []
|
2006-01-04 08:55:50 -08:00
|
|
|
| Some t ->
|
|
|
|
let s =
|
|
|
|
ps fmt2 "\\begin{ocamldoccomment}\n";
|
|
|
|
self#latex_of_text fmt2 t;
|
|
|
|
ps fmt2 "\n\\end{ocamldoccomment}\n";
|
|
|
|
flush2 ()
|
|
|
|
in
|
2004-03-24 02:37:10 -08:00
|
|
|
[ Latex s]
|
2002-07-23 07:12:03 -07:00
|
|
|
)
|
|
|
|
)
|
|
|
|
l
|
|
|
|
)
|
|
|
|
) @
|
|
|
|
[ CodePre "}" ]
|
|
|
|
in
|
|
|
|
let defs2 = (CodePre s_type3) :: defs in
|
|
|
|
let rec iter = function
|
|
|
|
[] -> []
|
|
|
|
| [e] -> [e]
|
|
|
|
| (CodePre s1) :: (CodePre s2) :: q ->
|
|
|
|
iter ((CodePre (s1^"\n"^s2)) :: q)
|
|
|
|
| e :: q ->
|
|
|
|
e :: (iter q)
|
|
|
|
in
|
|
|
|
(iter defs2) @
|
2004-07-13 05:25:21 -07:00
|
|
|
[Latex ("\\index{"^(self#label s_name)^"@\\verb`"^(self#label ~no_:false s_name)^"`}\n")] @
|
2002-07-23 07:12:03 -07:00
|
|
|
(self#text_of_info t.ty_info)
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt
|
2002-07-23 07:12:03 -07:00
|
|
|
((Latex (self#make_label (self#type_label t.ty_name))) :: text)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print LaTeX code for an exception. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_exception fmt e =
|
2002-03-27 08:20:32 -08:00
|
|
|
Odoc_info.reset_type_names () ;
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt
|
2006-01-04 08:55:50 -08:00
|
|
|
((Latex (self#make_label (self#exception_label e.ex_name))) ::
|
2002-07-23 07:12:03 -07:00
|
|
|
(to_text#text_of_exception e))
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
method latex_of_module_parameter fmt m_name p =
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
[
|
|
|
|
Code "functor (";
|
|
|
|
Code p.mp_name ;
|
|
|
|
Code " : ";
|
|
|
|
] ;
|
2004-04-02 07:10:58 -08:00
|
|
|
self#latex_of_module_type_kind fmt m_name p.mp_kind;
|
|
|
|
self#latex_of_text fmt [ Code ") -> "]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
|
|
|
|
method latex_of_module_type_kind fmt father kind =
|
|
|
|
match kind with
|
2006-01-04 08:55:50 -08:00
|
|
|
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"]
|
2004-04-02 07:10:58 -08:00
|
|
|
| Module_type_functor (p, k) ->
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_module_parameter fmt father p;
|
|
|
|
self#latex_of_module_type_kind fmt father k
|
2004-03-26 07:57:03 -08:00
|
|
|
| Module_type_alias a ->
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
[Code (self#relative_module_idents father a.mta_name)]
|
2004-03-26 07:57:03 -08:00
|
|
|
| Module_type_with (k, s) ->
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_module_type_kind fmt father k;
|
|
|
|
self#latex_of_text fmt
|
|
|
|
[ Code " ";
|
|
|
|
Code (self#relative_idents father s);
|
|
|
|
]
|
2010-04-19 09:34:13 -07:00
|
|
|
| Module_type_typeof s ->
|
|
|
|
self#latex_of_text fmt
|
|
|
|
[ Code "module type of ";
|
|
|
|
Code (self#relative_idents father s);
|
|
|
|
]
|
2006-01-04 08:55:50 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_module_kind fmt father kind =
|
|
|
|
match kind with
|
2006-01-04 08:55:50 -08:00
|
|
|
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"]
|
2004-03-26 07:57:03 -08:00
|
|
|
| Module_alias a ->
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
[Code (self#relative_module_idents father a.ma_name)]
|
2004-04-02 07:10:58 -08:00
|
|
|
| Module_functor (p, k) ->
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_module_parameter fmt father p;
|
|
|
|
self#latex_of_module_kind fmt father k
|
2004-03-26 07:57:03 -08:00
|
|
|
| Module_apply (k1, k2) ->
|
2006-01-04 08:55:50 -08:00
|
|
|
(* 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 ")"]
|
2004-03-26 07:57:03 -08:00
|
|
|
| Module_with (k, s) ->
|
2012-07-30 02:48:32 -07:00
|
|
|
(* TODO: a modifier quand Module_with sera plus detaille *)
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_module_type_kind fmt father k;
|
|
|
|
self#latex_of_text fmt
|
|
|
|
[ Code " ";
|
|
|
|
Code (self#relative_idents father s) ;
|
|
|
|
]
|
2004-03-26 07:57:03 -08:00
|
|
|
| Module_constraint (k, tk) ->
|
2006-01-04 08:55:50 -08:00
|
|
|
(* TODO: on affiche quoi ? *)
|
|
|
|
self#latex_of_module_kind fmt father k
|
2010-04-19 09:48:42 -07:00
|
|
|
| Module_typeof s ->
|
|
|
|
self#latex_of_text fmt
|
|
|
|
[ Code "module type of ";
|
|
|
|
Code (self#relative_idents father s);
|
|
|
|
]
|
2010-05-03 08:06:17 -07:00
|
|
|
| Module_unpack (s, _) ->
|
|
|
|
self#latex_of_text fmt
|
|
|
|
[
|
|
|
|
Code (self#relative_idents father s);
|
|
|
|
]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
method latex_of_class_kind fmt father kind =
|
|
|
|
match kind with
|
2006-01-04 08:55:50 -08:00
|
|
|
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"]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
| Class_apply capp ->
|
2012-07-30 02:48:32 -07:00
|
|
|
(* TODO: afficher le type final a partir du typedtree *)
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt [Raw "class application not handled yet"]
|
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
| Class_constr cco ->
|
2006-01-04 08:55:50 -08:00
|
|
|
(
|
2004-03-26 07:57:03 -08:00
|
|
|
match cco.cco_type_parameters with
|
|
|
|
[] -> ()
|
2006-01-04 08:55:50 -08:00
|
|
|
| l ->
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt
|
2006-01-04 08:55:50 -08:00
|
|
|
(
|
|
|
|
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)]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
| Class_constraint (ck, ctk) ->
|
|
|
|
self#latex_of_text fmt [Code "( "] ;
|
|
|
|
self#latex_of_class_kind fmt father ck;
|
|
|
|
self#latex_of_text fmt [Code " : "] ;
|
|
|
|
self#latex_of_class_type_kind fmt father ctk;
|
|
|
|
self#latex_of_text fmt [Code " )"]
|
|
|
|
|
|
|
|
method latex_of_class_type_kind fmt father kind =
|
|
|
|
match kind with
|
2006-01-04 08:55:50 -08:00
|
|
|
Class_type cta ->
|
2004-03-26 07:57:03 -08:00
|
|
|
(
|
|
|
|
match cta.cta_type_parameters with
|
|
|
|
[] -> ()
|
2006-01-04 08:55:50 -08:00
|
|
|
| l ->
|
|
|
|
self#latex_of_text fmt
|
|
|
|
(Code "[" ::
|
|
|
|
(self#text_of_class_type_param_expr_list father l) @
|
|
|
|
[Code "] "]
|
|
|
|
)
|
2004-03-26 07:57:03 -08:00
|
|
|
);
|
|
|
|
self#latex_of_text fmt
|
2006-01-04 08:55:50 -08:00
|
|
|
[Code (self#relative_idents father cta.cta_name)]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
2006-01-04 08:55:50 -08:00
|
|
|
| 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"]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
method latex_for_module_index fmt m =
|
2004-07-13 05:25:21 -07:00
|
|
|
let s_name = Name.simple m.m_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
[Latex ("\\index{"^(self#label s_name)^"@\\verb`"^
|
|
|
|
(self#label ~no_:false s_name)^"`}\n"
|
|
|
|
)
|
|
|
|
]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
method latex_for_module_type_index fmt mt =
|
2004-07-13 05:25:21 -07:00
|
|
|
let s_name = Name.simple mt.mt_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
[Latex ("\\index{"^(self#label s_name)^"@\\verb`"^
|
|
|
|
(self#label ~no_:false (Name.simple s_name))^"`}\n"
|
|
|
|
)
|
|
|
|
]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
method latex_for_module_label fmt m =
|
|
|
|
ps fmt (self#make_label (self#module_label m.m_name))
|
|
|
|
|
|
|
|
method latex_for_module_type_label fmt mt =
|
|
|
|
ps fmt (self#make_label (self#module_type_label mt.mt_name))
|
|
|
|
|
|
|
|
|
|
|
|
method latex_for_class_index fmt c =
|
2004-07-13 05:25:21 -07:00
|
|
|
let s_name = Name.simple c.cl_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
[Latex ("\\index{"^(self#label s_name)^"@\\verb`"^
|
|
|
|
(self#label ~no_:false s_name)^"`}\n"
|
|
|
|
)
|
|
|
|
]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
method latex_for_class_type_index fmt ct =
|
2004-07-13 05:25:21 -07:00
|
|
|
let s_name = Name.simple ct.clt_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt
|
|
|
|
[Latex ("\\index{"^(self#label s_name)^"@\\verb`"^
|
|
|
|
(self#label ~no_:false s_name)^"`}\n"
|
|
|
|
)
|
|
|
|
]
|
2004-03-26 07:57:03 -08:00
|
|
|
|
|
|
|
method latex_for_class_label fmt c =
|
|
|
|
ps fmt (self#make_label (self#class_label c.cl_name))
|
|
|
|
|
|
|
|
method latex_for_class_type_label fmt ct =
|
|
|
|
ps fmt (self#make_label (self#class_type_label ct.clt_name))
|
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code for the given module. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_module fmt m =
|
|
|
|
let father = Name.father m.m_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
let t =
|
2004-03-26 07:57:03 -08:00
|
|
|
[
|
2006-01-04 08:55:50 -08:00
|
|
|
Latex "\\begin{ocamldoccode}\n" ;
|
|
|
|
Code "module ";
|
|
|
|
Code (Name.simple m.m_name);
|
2004-03-26 07:57:03 -08:00
|
|
|
Code " : ";
|
2006-01-04 08:55:50 -08:00
|
|
|
]
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt t;
|
|
|
|
self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ];
|
|
|
|
self#latex_for_module_label fmt m;
|
|
|
|
self#latex_for_module_index fmt m;
|
|
|
|
p fmt "@[<h 4>";
|
|
|
|
self#latex_of_module_kind fmt father m.m_kind;
|
|
|
|
(
|
|
|
|
match Module.module_is_functor m with
|
2006-01-04 08:55:50 -08:00
|
|
|
false -> ()
|
2004-03-26 07:57:03 -08:00
|
|
|
| true ->
|
2006-01-04 08:55:50 -08:00
|
|
|
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
|
|
|
|
);
|
2004-03-26 07:57:03 -08:00
|
|
|
);
|
|
|
|
self#latex_of_text fmt [Newline];
|
2004-06-11 07:25:50 -07:00
|
|
|
self#latex_of_info fmt ~block: true m.m_info;
|
2004-03-26 07:57:03 -08:00
|
|
|
p fmt "@]";
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code for the given module type. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_module_type fmt mt =
|
2002-04-05 01:20:29 -08:00
|
|
|
let father = Name.father mt.mt_name in
|
2006-01-04 08:55:50 -08:00
|
|
|
let t =
|
2004-03-26 07:57:03 -08:00
|
|
|
[
|
2006-01-04 08:55:50 -08:00
|
|
|
Latex "\\begin{ocamldoccode}\n" ;
|
|
|
|
Code "module type " ;
|
|
|
|
Code (Name.simple mt.mt_name);
|
|
|
|
]
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt t;
|
|
|
|
(
|
|
|
|
match mt.mt_type, mt.mt_kind with
|
2006-01-04 08:55:50 -08:00
|
|
|
| Some mtyp, Some kind ->
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt [ Code " = " ];
|
2006-01-04 08:55:50 -08:00
|
|
|
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
|
2004-03-26 07:57:03 -08:00
|
|
|
| _ ->
|
2006-01-04 08:55:50 -08:00
|
|
|
self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ];
|
|
|
|
self#latex_for_module_type_index fmt mt;
|
|
|
|
p fmt "@[<h 4>";
|
2004-03-26 07:57:03 -08:00
|
|
|
);
|
|
|
|
(
|
|
|
|
match Module.module_type_is_functor mt with
|
2006-01-04 08:55:50 -08:00
|
|
|
false -> ()
|
2004-03-26 07:57:03 -08:00
|
|
|
| true ->
|
2006-01-04 08:55:50 -08:00
|
|
|
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
|
|
|
|
);
|
2004-03-26 07:57:03 -08:00
|
|
|
);
|
|
|
|
self#latex_of_text fmt [Newline];
|
2004-06-11 07:25:50 -07:00
|
|
|
self#latex_of_info fmt ~block: true mt.mt_info;
|
2004-03-26 07:57:03 -08:00
|
|
|
p fmt "@]";
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code for the given included module. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_included_module fmt im =
|
|
|
|
self#latex_of_text fmt
|
2006-01-04 08:55:50 -08:00
|
|
|
((Code "include ") ::
|
|
|
|
(Code
|
2004-03-24 02:37:10 -08:00
|
|
|
(match im.im_module with
|
|
|
|
None -> im.im_name
|
|
|
|
| Some (Mod m) -> m.m_name
|
|
|
|
| Some (Modtype mt) -> mt.mt_name)
|
2006-01-04 08:55:50 -08:00
|
|
|
) ::
|
|
|
|
(self#text_of_info im.im_info)
|
2004-03-24 02:37:10 -08:00
|
|
|
)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code for the given class. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_class fmt c =
|
2002-03-27 08:20:32 -08:00
|
|
|
Odoc_info.reset_type_names () ;
|
|
|
|
let father = Name.father c.cl_name in
|
2004-03-26 07:57:03 -08:00
|
|
|
let type_params =
|
|
|
|
match c.cl_type_parameters with
|
|
|
|
[] -> ""
|
|
|
|
| l -> (self#normal_class_type_param_list father l)^" "
|
|
|
|
in
|
2006-01-04 08:55:50 -08:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
]
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt t;
|
2004-08-20 10:04:35 -07:00
|
|
|
self#latex_of_class_parameter_list fmt father c;
|
|
|
|
(* avoid a big gap if the kind is a consrt *)
|
|
|
|
(
|
|
|
|
match c.cl_kind with
|
2006-01-04 08:55:50 -08:00
|
|
|
Class.Class_constr _ ->
|
|
|
|
self#latex_of_class_kind fmt father c.cl_kind
|
2004-08-20 10:04:35 -07:00
|
|
|
| _ ->
|
2006-01-04 08:55:50 -08:00
|
|
|
()
|
2004-08-20 10:04:35 -07:00
|
|
|
);
|
2004-03-26 07:57:03 -08:00
|
|
|
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>";
|
2004-08-20 10:04:35 -07:00
|
|
|
(match c.cl_kind with
|
2006-01-04 08:55:50 -08:00
|
|
|
Class.Class_constr _ -> ()
|
|
|
|
| _ -> self#latex_of_class_kind fmt father c.cl_kind
|
2004-08-20 10:04:35 -07:00
|
|
|
);
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt [Newline];
|
2004-06-11 07:25:50 -07:00
|
|
|
self#latex_of_info fmt ~block: true c.cl_info;
|
2004-03-26 07:57:03 -08:00
|
|
|
p fmt "@]"
|
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code for the given class type. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_class_type fmt ct =
|
2002-03-27 08:20:32 -08:00
|
|
|
Odoc_info.reset_type_names () ;
|
|
|
|
let father = Name.father ct.clt_name in
|
2004-03-26 07:57:03 -08:00
|
|
|
let type_params =
|
|
|
|
match ct.clt_type_parameters with
|
|
|
|
[] -> ""
|
|
|
|
| l -> (self#normal_class_type_param_list father l)^" "
|
|
|
|
in
|
2006-01-04 08:55:50 -08:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
]
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt t;
|
|
|
|
|
|
|
|
self#latex_of_text fmt [ Latex "\\end{ocamldoccode}\n" ];
|
|
|
|
self#latex_for_class_type_label fmt ct;
|
|
|
|
self#latex_for_class_type_index fmt ct;
|
|
|
|
p fmt "@[<h 4>";
|
|
|
|
self#latex_of_class_type_kind fmt father ct.clt_kind;
|
|
|
|
self#latex_of_text fmt [Newline];
|
2004-06-11 07:25:50 -07:00
|
|
|
self#latex_of_info fmt ~block: true ct.clt_info;
|
2004-03-26 07:57:03 -08:00
|
|
|
p fmt "@]"
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code for the given class element. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_class_element fmt class_name class_ele =
|
|
|
|
self#latex_of_text fmt [Newline];
|
2004-03-24 02:37:10 -08:00
|
|
|
match class_ele with
|
2004-03-26 07:57:03 -08:00
|
|
|
Class_attribute att -> self#latex_of_attribute fmt att
|
|
|
|
| Class_method met -> self#latex_of_method fmt met
|
2004-03-24 02:37:10 -08:00
|
|
|
| Class_comment t ->
|
|
|
|
match t with
|
|
|
|
| [] -> ()
|
2004-03-26 07:57:03 -08:00
|
|
|
| (Title (_,_,_)) :: _ -> self#latex_of_text fmt t
|
|
|
|
| _ -> self#latex_of_text fmt [ Title ((Name.depth class_name) + 2, None, t) ]
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the LaTeX code for the given module element. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method latex_of_module_element fmt module_name module_ele =
|
|
|
|
self#latex_of_text fmt [Newline];
|
2004-03-24 02:37:10 -08:00
|
|
|
match module_ele with
|
2004-03-26 07:57:03 -08:00
|
|
|
Element_module m -> self#latex_of_module fmt m
|
|
|
|
| Element_module_type mt -> self#latex_of_module_type fmt mt
|
|
|
|
| Element_included_module im -> self#latex_of_included_module fmt im
|
|
|
|
| Element_class c -> self#latex_of_class fmt c
|
|
|
|
| Element_class_type ct -> self#latex_of_class_type fmt ct
|
|
|
|
| Element_value v -> self#latex_of_value fmt v
|
|
|
|
| Element_exception e -> self#latex_of_exception fmt e
|
|
|
|
| Element_type t -> self#latex_of_type fmt t
|
|
|
|
| Element_module_comment t -> self#latex_of_text fmt t
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Generate the LaTeX code for the given list of inherited classes.*)
|
2004-03-26 07:57:03 -08:00
|
|
|
method generate_inheritance_info fmt inher_l =
|
2002-03-27 08:20:32 -08:00
|
|
|
let f inh =
|
2002-07-23 07:12:03 -07:00
|
|
|
match inh.ic_class with
|
|
|
|
None -> (* we can't make the reference *)
|
2006-01-04 08:55:50 -08:00
|
|
|
Newline ::
|
2004-03-26 07:57:03 -08:00
|
|
|
Code ("inherit "^inh.ic_name) ::
|
2002-07-23 07:12:03 -07:00
|
|
|
(match inh.ic_text with
|
|
|
|
None -> []
|
|
|
|
| Some t -> Newline :: t
|
|
|
|
)
|
|
|
|
| Some cct ->
|
2006-01-04 08:55:50 -08:00
|
|
|
let label =
|
2002-07-23 07:12:03 -07:00
|
|
|
match cct with
|
|
|
|
Cl _ -> self#class_label inh.ic_name
|
|
|
|
| Cltype _ -> self#class_type_label inh.ic_name
|
|
|
|
in
|
|
|
|
(* we can create the reference *)
|
2006-01-04 08:55:50 -08:00
|
|
|
Newline ::
|
2004-03-26 07:57:03 -08:00
|
|
|
Odoc_info.Code ("inherit "^inh.ic_name) ::
|
2006-01-04 08:55:50 -08:00
|
|
|
(Odoc_info.Latex (" ["^(self#make_ref label)^"]")) ::
|
2002-07-23 07:12:03 -07:00
|
|
|
(match inh.ic_text with
|
|
|
|
None -> []
|
|
|
|
| Some t -> Newline :: t
|
|
|
|
)
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
List.iter (self#latex_of_text fmt) (List.map f inher_l)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
|
|
|
(** Generate the LaTeX code for the inherited classes of the given class. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method generate_class_inheritance_info fmt cl =
|
2006-01-04 08:55:50 -08:00
|
|
|
let rec iter_kind k =
|
2002-07-23 07:12:03 -07:00
|
|
|
match k with
|
|
|
|
Class_structure ([], _) ->
|
|
|
|
()
|
|
|
|
| Class_structure (l, _) ->
|
2004-03-26 07:57:03 -08:00
|
|
|
self#generate_inheritance_info fmt l
|
2002-07-23 07:12:03 -07:00
|
|
|
| Class_constraint (k, _) ->
|
|
|
|
iter_kind k
|
|
|
|
| Class_apply _
|
|
|
|
| Class_constr _ ->
|
|
|
|
()
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
|
|
|
iter_kind cl.cl_kind
|
|
|
|
|
|
|
|
(** Generate the LaTeX code for the inherited classes of the given class type. *)
|
2004-03-26 07:57:03 -08:00
|
|
|
method generate_class_type_inheritance_info fmt clt =
|
2002-03-27 08:20:32 -08:00
|
|
|
match clt.clt_kind with
|
2002-07-23 07:12:03 -07:00
|
|
|
Class_signature ([], _) ->
|
|
|
|
()
|
|
|
|
| Class_signature (l, _) ->
|
2004-03-26 07:57:03 -08:00
|
|
|
self#generate_inheritance_info fmt l
|
2002-07-23 07:12:03 -07:00
|
|
|
| Class_type _ ->
|
|
|
|
()
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-03-26 07:57:03 -08:00
|
|
|
(** Generate the LaTeX code for the given top module, in the given buffer. *)
|
|
|
|
method generate_for_top_module fmt m =
|
2002-03-27 08:20:32 -08:00
|
|
|
let (first_t, rest_t) = self#first_and_rest_of_info m.m_info in
|
2006-01-04 08:55:50 -08:00
|
|
|
let text =
|
2006-09-20 04:14:37 -07:00
|
|
|
if m.m_text_only then
|
|
|
|
[ Title (1, None, [Raw m.m_name] @
|
2006-01-04 08:55:50 -08:00
|
|
|
(match first_t with
|
|
|
|
[] -> []
|
|
|
|
| t -> (Raw " : ") :: t)
|
2006-09-20 04:14:37 -07:00
|
|
|
) ;
|
|
|
|
]
|
|
|
|
else
|
|
|
|
[ Title (1, None,
|
2006-01-04 08:55:50 -08:00
|
|
|
[ Raw (Odoc_messages.modul^" ") ; Code m.m_name ] @
|
|
|
|
(match first_t with
|
|
|
|
[] -> []
|
|
|
|
| t -> (Raw " : ") :: t)) ;
|
|
|
|
]
|
2002-03-27 08:20:32 -08:00
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
self#latex_of_text fmt text;
|
|
|
|
self#latex_for_module_label fmt m;
|
|
|
|
self#latex_for_module_index fmt m;
|
|
|
|
self#latex_of_text fmt rest_t ;
|
|
|
|
|
|
|
|
self#latex_of_text fmt [ Newline ] ;
|
2006-01-04 08:55:50 -08:00
|
|
|
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"
|
|
|
|
)
|
2004-03-26 07:57:03 -08:00
|
|
|
(Module.module_elements ~trans: false m)
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2004-04-02 07:10:58 -08:00
|
|
|
(** Print the header of the TeX document. *)
|
2006-09-20 04:14:37 -07:00
|
|
|
method latex_header fmt module_list =
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt "\\documentclass[11pt]{article} \n";
|
|
|
|
ps fmt "\\usepackage[latin1]{inputenc} \n";
|
|
|
|
ps fmt "\\usepackage[T1]{fontenc} \n";
|
2012-02-21 04:47:14 -08:00
|
|
|
ps fmt "\\usepackage{textcomp}\n";
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt "\\usepackage{fullpage} \n";
|
|
|
|
ps fmt "\\usepackage{url} \n";
|
|
|
|
ps fmt "\\usepackage{ocamldoc}\n";
|
2002-03-27 08:20:32 -08:00
|
|
|
(
|
2010-08-24 02:45:45 -07:00
|
|
|
match !Global.title with
|
2004-03-24 02:37:10 -08:00
|
|
|
None -> ()
|
2006-01-04 08:55:50 -08:00
|
|
|
| Some s ->
|
|
|
|
ps fmt "\\title{";
|
|
|
|
ps fmt (self#escape s);
|
|
|
|
ps fmt "}\n"
|
2004-03-24 02:37:10 -08:00
|
|
|
);
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt "\\begin{document}\n";
|
2010-08-24 02:45:45 -07:00
|
|
|
(match !Global.title with
|
2006-01-04 08:55:50 -08:00
|
|
|
None -> () |
|
|
|
|
Some _ -> ps fmt "\\maketitle\n"
|
2004-03-24 02:37:10 -08:00
|
|
|
);
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Global.with_toc then ps fmt "\\tableofcontents\n";
|
2003-11-21 06:32:58 -08:00
|
|
|
(
|
|
|
|
let info = Odoc_info.apply_opt
|
2006-09-20 04:14:37 -07:00
|
|
|
(Odoc_info.info_of_comment_file module_list)
|
2010-08-24 02:45:45 -07:00
|
|
|
!Odoc_info.Global.intro_file
|
2003-11-21 06:32:58 -08:00
|
|
|
in
|
2004-03-26 07:57:03 -08:00
|
|
|
(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")
|
2003-11-21 06:32:58 -08:00
|
|
|
)
|
2006-01-04 08:55:50 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
|
2003-07-04 03:02:13 -07:00
|
|
|
(** Generate the LaTeX style file, if it does not exists. *)
|
|
|
|
method generate_style_file =
|
|
|
|
try
|
2010-08-24 02:45:45 -07:00
|
|
|
let dir = Filename.dirname !Global.out_file in
|
2006-01-04 08:55:50 -08:00
|
|
|
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)
|
|
|
|
)
|
2003-07-04 03:02:13 -07:00
|
|
|
with
|
|
|
|
Sys_error s ->
|
|
|
|
prerr_endline s ;
|
|
|
|
incr Odoc_info.errors ;
|
|
|
|
|
2010-08-24 02:45:45 -07:00
|
|
|
(** Generate the LaTeX file from a module list, in the {!Odoc_info.Global.out_file} file. *)
|
2002-03-27 08:20:32 -08:00
|
|
|
method generate module_list =
|
2003-07-04 03:02:13 -07:00
|
|
|
self#generate_style_file ;
|
2010-08-24 02:45:45 -07:00
|
|
|
let main_file = !Global.out_file in
|
2004-04-02 07:20:39 -08:00
|
|
|
let dir = Filename.dirname main_file in
|
2010-08-24 02:45:45 -07:00
|
|
|
if !separate_files then
|
2002-07-23 07:12:03 -07:00
|
|
|
(
|
|
|
|
let f m =
|
|
|
|
try
|
2006-01-04 08:55:50 -08:00
|
|
|
let chanout =
|
2004-04-02 07:20:39 -08:00
|
|
|
open_out ((Filename.concat dir (Name.simple m.m_name))^".tex")
|
2002-07-23 07:12:03 -07:00
|
|
|
in
|
2006-01-04 08:55:50 -08:00
|
|
|
let fmt = Format.formatter_of_out_channel chanout in
|
2004-03-26 07:57:03 -08:00
|
|
|
self#generate_for_top_module fmt m ;
|
2006-01-04 08:55:50 -08:00
|
|
|
Format.pp_print_flush fmt ();
|
2002-07-23 07:12:03 -07:00
|
|
|
close_out chanout
|
|
|
|
with
|
|
|
|
Failure s
|
|
|
|
| Sys_error s ->
|
|
|
|
prerr_endline s ;
|
2006-01-04 08:55:50 -08:00
|
|
|
incr Odoc_info.errors
|
2002-07-23 07:12:03 -07:00
|
|
|
in
|
|
|
|
List.iter f module_list
|
|
|
|
);
|
2006-01-04 08:55:50 -08:00
|
|
|
|
2002-03-27 08:20:32 -08:00
|
|
|
try
|
2004-04-02 07:20:39 -08:00
|
|
|
let chanout = open_out main_file in
|
2006-01-04 08:55:50 -08:00
|
|
|
let fmt = Format.formatter_of_out_channel chanout in
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Global.with_header then self#latex_header fmt module_list;
|
2006-01-04 08:55:50 -08:00
|
|
|
List.iter
|
|
|
|
(fun m ->
|
2010-08-24 02:45:45 -07:00
|
|
|
if !separate_files then
|
2004-03-26 07:57:03 -08:00
|
|
|
ps fmt ("\\input{"^((Name.simple m.m_name))^".tex}\n")
|
2004-03-24 02:37:10 -08:00
|
|
|
else
|
2004-03-26 07:57:03 -08:00
|
|
|
self#generate_for_top_module fmt m
|
2006-01-04 08:55:50 -08:00
|
|
|
)
|
2002-07-23 07:12:03 -07:00
|
|
|
module_list ;
|
2010-08-24 02:45:45 -07:00
|
|
|
if !Global.with_trailer then ps fmt "\\end{document}";
|
2006-01-04 08:55:50 -08:00
|
|
|
Format.pp_print_flush fmt ();
|
2002-07-23 07:12:03 -07:00
|
|
|
close_out chanout
|
2002-03-27 08:20:32 -08:00
|
|
|
with
|
2002-07-23 07:12:03 -07:00
|
|
|
Failure s
|
2002-03-27 08:20:32 -08:00
|
|
|
| Sys_error s ->
|
2002-07-23 07:12:03 -07:00
|
|
|
prerr_endline s ;
|
2006-01-04 08:55:50 -08:00
|
|
|
incr Odoc_info.errors
|
2002-03-27 08:20:32 -08:00
|
|
|
end
|
2010-08-24 02:45:45 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
module type Latex_generator = module type of Generator
|