| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Common |
| 12 |
open Index |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
let output_char c = output_char !out_channel c |
| 17 |
|
| 18 |
let output_string s = output_string !out_channel s |
| 19 |
|
| 20 |
let printf s = Printf.fprintf !out_channel s |
| 21 |
|
| 22 |
let sprintf = Printf.sprintf |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
let build_table l = |
| 27 |
let h = Hashtbl.create 101 in |
| 28 |
List.iter (fun key ->Hashtbl.add h key ()) l; |
| 29 |
function s -> try Hashtbl.find h s; true with Not_found -> false |
| 30 |
|
| 31 |
let is_keyword = |
| 32 |
build_table |
| 33 |
[ "About"; "Axiom"; "Abort"; "Chapter"; "Check"; "Coercion"; "Compute"; "CoFixpoint"; |
| 34 |
"CoInductive"; "Corollary"; "Defined"; "Definition"; "End"; "Eval"; "Example"; |
| 35 |
"Export"; "Fact"; "Fix"; "Fixpoint"; "From"; "Function"; "Generalizable"; "Global"; "Grammar"; |
| 36 |
"Guarded"; "Goal"; "Hint"; "Debug"; "On"; |
| 37 |
"Hypothesis"; "Hypotheses"; |
| 38 |
"Resolve"; "Unfold"; "Immediate"; "Extern"; "Constructors"; "Rewrite"; |
| 39 |
"Implicit"; "Import"; "Inductive"; |
| 40 |
"Infix"; "Lemma"; "Let"; "Load"; "Local"; "Locate"; "Ltac"; |
| 41 |
"Module"; "Module Type"; "Declare Module"; "Include"; |
| 42 |
"Mutual"; "Parameter"; "Parameters"; "Print"; "Printing"; "All"; "Proof"; "Proof with"; "Qed"; |
| 43 |
"Record"; "Recursive"; "Remark"; "Require"; "Save"; "Scheme"; "Assumptions"; "Axioms"; "Universes"; |
| 44 |
"Induction"; "for"; "Sort"; "Section"; "Show"; "Structure"; "Syntactic"; "Syntax"; "Tactic"; "Theorem"; |
| 45 |
"Search"; "SearchPattern"; "SearchRewrite"; |
| 46 |
"Set"; "Types"; "Undo"; "Unset"; "Variable"; "Variables"; "Context"; |
| 47 |
"Notation"; "Reserved Notation"; "Tactic Notation"; "Number Notation"; "String Notation"; "Enable Notation"; "Disable Notation"; |
| 48 |
"Delimit"; "Bind"; "Open"; "Scope"; "Inline"; |
| 49 |
"Implicit Arguments"; "Add"; "Strict"; |
| 50 |
"Typeclasses"; "Instance"; "Global Instance"; "Class"; "Instantiation"; |
| 51 |
"goal"; "goals"; "vm_compute"; |
| 52 |
"Opaque"; "Transparent"; "Time"; |
| 53 |
"Extraction"; "Extract"; |
| 54 |
"Variant"; |
| 55 |
|
| 56 |
"Program Definition"; "Program Example"; "Program Fixpoint"; "Program Lemma"; |
| 57 |
"Obligation"; "Obligations"; "Solve"; "using"; "Next Obligation"; "Next"; |
| 58 |
"Program Instance"; "Equations"; "Equations_nocomp"; |
| 59 |
|
| 60 |
"forall"; "match"; "as"; "in"; "return"; "with"; "end"; "let"; "fun"; |
| 61 |
"if"; "then"; "else"; "Prop"; "Set"; "Type"; ":="; "where"; "struct"; "wf"; "measure"; |
| 62 |
"fix"; "cofix"; "is"; |
| 63 |
|
| 64 |
"before"; "after"; "constr"; "ltac"; "goal"; "context"; "beta"; "delta"; "iota"; "zeta"; "lazymatch"; "type"; "of"; "rec"; |
| 65 |
|
| 66 |
"level"; "associativity"; "no" |
| 67 |
] |
| 68 |
|
| 69 |
let is_tactic = |
| 70 |
build_table |
| 71 |
[ "intro"; "intros"; "apply"; "rewrite"; "refine"; "case"; "clear"; "injection"; |
| 72 |
"progress"; "setoid_rewrite"; "left"; "right"; "constructor"; |
| 73 |
"econstructor"; "decide equality"; "abstract"; "exists"; "cbv"; "simple destruct"; |
| 74 |
"info"; "field"; "specialize"; "evar"; "solve"; "instantiate"; "info_auto"; "info_eauto"; |
| 75 |
"quote"; "eexact"; "autorewrite"; |
| 76 |
"destruct"; "destruction"; "destruct_call"; "dependent"; "elim"; "extensionality"; |
| 77 |
"f_equal"; "generalize"; "generalize_eqs"; "generalize_eqs_vars"; "induction"; "rename"; "move"; |
| 78 |
"set"; "assert"; "do"; "repeat"; |
| 79 |
"cut"; "assumption"; "exact"; "split"; "subst"; "try"; "discriminate"; |
| 80 |
"simpl"; "unfold"; "red"; "compute"; "at"; "in"; "by"; |
| 81 |
"reflexivity"; "symmetry"; "transitivity"; |
| 82 |
"replace"; "setoid_replace"; "inversion"; "inversion_clear"; |
| 83 |
"pattern"; "intuition"; "congruence"; "fail"; "fresh"; |
| 84 |
"trivial"; "tauto"; "firstorder"; "ring"; |
| 85 |
"clapply"; "program_simpl"; "program_simplify"; "eapply"; "auto"; "eauto"; |
| 86 |
"change"; "fold"; "hnf"; "lazy"; "simple"; "eexists"; "debug"; "idtac"; "first"; "type of"; "pose"; |
| 87 |
"eval"; "instantiate"; "until" ] |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
let current_module : (string * string option) ref = ref ("",None) |
| 92 |
|
| 93 |
let get_module withsub = |
| 94 |
let (m,sub) = !current_module in |
| 95 |
if withsub then |
| 96 |
match sub with |
| 97 |
| None -> m |
| 98 |
| Some sub -> m ^ ": " ^ sub |
| 99 |
else |
| 100 |
m |
| 101 |
|
| 102 |
let set_module m sub = current_module := (m,sub); |
| 103 |
page_title := get_module true |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
let item_level = ref 0 |
| 108 |
let in_doc = ref false |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
let initialize_texmacs () = |
| 113 |
let ensuremath x = sprintf "<with|mode|math|\\<%s\\>>" x in |
| 114 |
List.fold_right (fun (s,t) tt -> Tokens.ttree_add tt s t) |
| 115 |
[ "*", ensuremath "times"; |
| 116 |
"->", ensuremath "rightarrow"; |
| 117 |
"<-", ensuremath "leftarrow"; |
| 118 |
"<->", ensuremath "leftrightarrow"; |
| 119 |
"=>", ensuremath "Rightarrow"; |
| 120 |
"<=", ensuremath "le"; |
| 121 |
">=", ensuremath "ge"; |
| 122 |
"<>", ensuremath "noteq"; |
| 123 |
"~", ensuremath "lnot"; |
| 124 |
"/\\", ensuremath "land"; |
| 125 |
"\\/", ensuremath "lor"; |
| 126 |
"|-", ensuremath "vdash" |
| 127 |
] Tokens.empty_ttree |
| 128 |
|
| 129 |
let token_tree_texmacs = ref (initialize_texmacs ()) |
| 130 |
|
| 131 |
let token_tree_latex = ref Tokens.empty_ttree |
| 132 |
let token_tree_html = ref Tokens.empty_ttree |
| 133 |
|
| 134 |
let initialize_tex_html () = |
| 135 |
let if_utf8 = if !prefs.encoding.utf8 then fun x -> Some x else fun _ -> None in |
| 136 |
let (tree_latex, tree_html) = List.fold_right (fun (s,l,l') (tt,tt') -> |
| 137 |
(Tokens.ttree_add tt s l, |
| 138 |
match l' with None -> tt' | Some l' -> Tokens.ttree_add tt' s l')) |
| 139 |
[ "*" , "\\ensuremath{\\times}", if_utf8 "×"; |
| 140 |
"|", "\\ensuremath{|}", None; |
| 141 |
"->", "\\ensuremath{\\rightarrow}", if_utf8 "→"; |
| 142 |
"->~", "\\ensuremath{\\rightarrow\\lnot}", None; |
| 143 |
"->~~", "\\ensuremath{\\rightarrow\\lnot\\lnot}", None; |
| 144 |
"<-", "\\ensuremath{\\leftarrow}", None; |
| 145 |
"<->", "\\ensuremath{\\leftrightarrow}", if_utf8 "↔"; |
| 146 |
"=>", "\\ensuremath{\\Rightarrow}", if_utf8 "⇒"; |
| 147 |
"<=", "\\ensuremath{\\le}", if_utf8 "≤"; |
| 148 |
">=", "\\ensuremath{\\ge}", if_utf8 "≥"; |
| 149 |
"<>", "\\ensuremath{\\not=}", if_utf8 "≠"; |
| 150 |
"~", "\\ensuremath{\\lnot}", if_utf8 "¬"; |
| 151 |
"/\\", "\\ensuremath{\\land}", if_utf8 "∧"; |
| 152 |
"\\/", "\\ensuremath{\\lor}", if_utf8 "∨"; |
| 153 |
"|-", "\\ensuremath{\\vdash}", None; |
| 154 |
"forall", "\\ensuremath{\\forall}", if_utf8 "∀"; |
| 155 |
"exists", "\\ensuremath{\\exists}", if_utf8 "∃"; |
| 156 |
"Π", "\\ensuremath{\\Pi}", if_utf8 "Π"; |
| 157 |
"λ", "\\ensuremath{\\lambda}", if_utf8 "λ"; |
| 158 |
|
| 159 |
] (Tokens.empty_ttree,Tokens.empty_ttree) in |
| 160 |
token_tree_latex := tree_latex; |
| 161 |
token_tree_html := tree_html |
| 162 |
|
| 163 |
let add_printing_token s (t1,t2) = |
| 164 |
(match t1 with None -> () | Some t1 -> |
| 165 |
token_tree_latex := Tokens.ttree_add !token_tree_latex s t1); |
| 166 |
(match t2 with None -> () | Some t2 -> |
| 167 |
token_tree_html := Tokens.ttree_add !token_tree_html s t2) |
| 168 |
|
| 169 |
let remove_printing_token s = |
| 170 |
token_tree_latex := Tokens.ttree_remove !token_tree_latex s; |
| 171 |
token_tree_html := Tokens.ttree_remove !token_tree_html s |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
type toc_entry = |
| 176 |
| Toc_library of string * string option |
| 177 |
| Toc_section of int * (unit -> unit) * string |
| 178 |
|
| 179 |
let (toc_q : toc_entry Queue.t) = Queue.create () |
| 180 |
|
| 181 |
let add_toc_entry e = Queue.add e toc_q |
| 182 |
|
| 183 |
let new_label = let r = ref 0 in fun () -> incr r; "lab" ^ string_of_int !r |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
module Latex = struct |
| 188 |
|
| 189 |
let in_title = ref false |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
let (preamble : string Queue.t) = Queue.create () |
| 194 |
|
| 195 |
let push_in_preamble s = Queue.add s preamble |
| 196 |
|
| 197 |
let utf8x_extra_support () = |
| 198 |
printf "\n"; |
| 199 |
printf "%%Warning: tipa declares many non-standard macros used by utf8x to\n"; |
| 200 |
printf "%%interpret utf8 characters but extra packages might have to be added\n"; |
| 201 |
printf "%%such as \"textgreek\" for Greek letters not already in tipa\n"; |
| 202 |
printf "%%or \"stmaryrd\" for mathematical symbols.\n"; |
| 203 |
printf "%%Utf8 codes missing a LaTeX interpretation can be defined by using\n"; |
| 204 |
printf "%%\\DeclareUnicodeCharacter{code}{interpretation}.\n"; |
| 205 |
printf "%%Use coqdoc's option -p to add new packages or declarations.\n"; |
| 206 |
printf "\\usepackage{tipa}\n"; |
| 207 |
printf "\n" |
| 208 |
|
| 209 |
let header () = |
| 210 |
if !prefs.header_trailer then begin |
| 211 |
printf "\\documentclass[12pt]{report}\n"; |
| 212 |
if !prefs.encoding.inputenc != "" then |
| 213 |
printf "\\usepackage[%s]{inputenc}\n" !prefs.encoding.inputenc; |
| 214 |
if !prefs.encoding.inputenc = "utf8x" then utf8x_extra_support (); |
| 215 |
printf "\\usepackage[T1]{fontenc}\n"; |
| 216 |
printf "\\usepackage{fullpage}\n"; |
| 217 |
printf "\\usepackage{coqdoc}\n"; |
| 218 |
printf "\\usepackage{amsmath,amssymb}\n"; |
| 219 |
printf "\\usepackage{url}\n"; |
| 220 |
(match !prefs.toc_depth with |
| 221 |
| None -> () |
| 222 |
| Some n -> printf "\\setcounter{tocdepth}{%i}\n" n); |
| 223 |
Queue.iter (fun s -> printf "%s\n" s) preamble; |
| 224 |
printf "\\begin{document}\n" |
| 225 |
end; |
| 226 |
output_string |
| 227 |
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"; |
| 228 |
output_string |
| 229 |
"%% This file has been automatically generated with the command\n"; |
| 230 |
output_string "%% "; |
| 231 |
Array.iter (fun s -> printf "%s " s) Sys.argv; |
| 232 |
printf "\n"; |
| 233 |
output_string |
| 234 |
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" |
| 235 |
|
| 236 |
let trailer () = |
| 237 |
if !prefs.header_trailer then begin |
| 238 |
printf "\\end{document}\n" |
| 239 |
end |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
let nbsp () = output_char '~' |
| 244 |
|
| 245 |
let char c = match c with |
| 246 |
| '\\' -> |
| 247 |
printf "\\symbol{92}" |
| 248 |
| '$' | '#' | '%' | '&' | '{' | '}' | '_' -> |
| 249 |
output_char '\\'; output_char c |
| 250 |
| '^' | '~' -> |
| 251 |
output_char '\\'; output_char c; printf "{}" |
| 252 |
| _ -> |
| 253 |
output_char c |
| 254 |
|
| 255 |
let label_char c = match c with |
| 256 |
| '_' -> output_char ' ' |
| 257 |
| '\\' | '$' | '#' | '%' | '&' | '{' | '}' |
| 258 |
| '^' | '~' -> printf "x%X" (Char.code c) |
| 259 |
| _ -> if c >= '\x80' then printf "x%X" (Char.code c) else output_char c |
| 260 |
|
| 261 |
let label_ident s = |
| 262 |
for i = 0 to String.length s - 1 do label_char s.[i] done |
| 263 |
|
| 264 |
let latex_char = output_char |
| 265 |
let latex_string = output_string |
| 266 |
|
| 267 |
let html_char _ = () |
| 268 |
let html_string _ = () |
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
let escaped = |
| 273 |
let buff = Buffer.create 5 in |
| 274 |
fun s -> |
| 275 |
Buffer.clear buff; |
| 276 |
for i = 0 to String.length s - 1 do |
| 277 |
match s.[i] with |
| 278 |
| '\\' -> |
| 279 |
Buffer.add_string buff "\\symbol{92}" |
| 280 |
| '$' | '#' | '%' | '&' | '{' | '}' | '_' as c -> |
| 281 |
Buffer.add_char buff '\\'; Buffer.add_char buff c |
| 282 |
| '^' | '~' as c -> |
| 283 |
Buffer.add_char buff '\\'; Buffer.add_char buff c; |
| 284 |
Buffer.add_string buff "{}" |
| 285 |
| '\'' -> |
| 286 |
if i < String.length s - 1 && s.[i+1] = '\'' then begin |
| 287 |
Buffer.add_char buff '\''; Buffer.add_char buff '{'; |
| 288 |
Buffer.add_char buff '}' |
| 289 |
end else |
| 290 |
Buffer.add_char buff '\'' |
| 291 |
| c -> |
| 292 |
Buffer.add_char buff c |
| 293 |
done; |
| 294 |
Buffer.contents buff |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
let start_module () = |
| 299 |
let ln = !prefs.lib_name in |
| 300 |
if not !prefs.short then begin |
| 301 |
printf "\\coqlibrary{"; |
| 302 |
label_ident (get_module false); |
| 303 |
printf "}{"; |
| 304 |
if ln <> "" then printf "%s " ln; |
| 305 |
printf "}{%s}\n\n" (escaped (get_module true)) |
| 306 |
end |
| 307 |
|
| 308 |
let start_latex_math () = output_char '$' |
| 309 |
|
| 310 |
let stop_latex_math () = output_char '$' |
| 311 |
|
| 312 |
let start_quote () = output_char '`'; output_char '`' |
| 313 |
let stop_quote () = output_char '\''; output_char '\'' |
| 314 |
|
| 315 |
let start_verbatim inline = |
| 316 |
if inline then printf "\\texttt{" |
| 317 |
else printf "\\begin{verbatim}\n" |
| 318 |
|
| 319 |
let stop_verbatim inline = |
| 320 |
if inline then printf "}" |
| 321 |
else printf "\\end{verbatim}\n" |
| 322 |
|
| 323 |
let url addr name = |
| 324 |
printf "%s\\footnote{\\url{%s}}" |
| 325 |
(match name with |
| 326 |
| None -> "" |
| 327 |
| Some n -> n) |
| 328 |
addr |
| 329 |
|
| 330 |
let indentation n = |
| 331 |
if n == 0 then |
| 332 |
printf "\\coqdocnoindent\n" |
| 333 |
else |
| 334 |
let space = 0.5 *. (float n) in |
| 335 |
printf "\\coqdocindent{%2.2fem}\n" space |
| 336 |
|
| 337 |
let ident_ref m fid typ s = |
| 338 |
let id = if fid <> "" then (m ^ "." ^ fid) else m in |
| 339 |
match find_module m with |
| 340 |
| Local -> |
| 341 |
printf "\\coqref{"; label_ident id; |
| 342 |
printf "}{\\coqdoc%s{%s}}" (type_name typ) s |
| 343 |
| External m when !prefs.externals -> |
| 344 |
printf "\\coqexternalref{"; label_ident fid; |
| 345 |
printf "}{%s}{\\coqdoc%s{%s}}" (escaped m) (type_name typ) s |
| 346 |
| External _ | Unknown -> |
| 347 |
printf "\\coqdoc%s{%s}" (type_name typ) s |
| 348 |
|
| 349 |
let defref m id ty s = |
| 350 |
if ty <> Notation then |
| 351 |
(printf "\\coqdef{"; label_ident (m ^ "." ^ id); |
| 352 |
printf "}{%s}{\\coqdoc%s{%s}}" s (type_name ty) s) |
| 353 |
else |
| 354 |
|
| 355 |
|
| 356 |
(printf "\\coqdef{"; label_ident (m ^ "." ^ id); |
| 357 |
printf "}{%s}{%s}" s s) |
| 358 |
|
| 359 |
let reference s = function |
| 360 |
| Def [] -> assert false |
| 361 |
| Def ((fullid,typ) :: _) -> |
| 362 |
defref (get_module false) fullid typ s |
| 363 |
| Ref (m,fullid,typ) -> |
| 364 |
ident_ref m fullid typ s |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
let output_sublexer_string doescape issymbchar tag s = |
| 372 |
let s = if doescape then escaped s else s in |
| 373 |
match tag with |
| 374 |
| Some ref -> reference s ref |
| 375 |
| None -> if issymbchar then output_string s else printf "\\coqdocvar{%s}" s |
| 376 |
|
| 377 |
let last_was_in = ref false |
| 378 |
|
| 379 |
let sublexer c loc = |
| 380 |
if c = '*' && !last_was_in then begin |
| 381 |
Tokens.flush_sublexer (); |
| 382 |
output_char '*' |
| 383 |
end else begin |
| 384 |
let tag = |
| 385 |
try Some (Index.find (get_module false) loc) with Not_found -> None |
| 386 |
in |
| 387 |
Tokens.output_tagged_symbol_char tag c |
| 388 |
end; |
| 389 |
last_was_in := false |
| 390 |
|
| 391 |
let sublexer_in_doc c = |
| 392 |
if c = '*' && !last_was_in then begin |
| 393 |
Tokens.flush_sublexer (); |
| 394 |
output_char '*' |
| 395 |
end else |
| 396 |
Tokens.output_tagged_symbol_char None c; |
| 397 |
last_was_in := false |
| 398 |
|
| 399 |
let initialize () = |
| 400 |
initialize_tex_html (); |
| 401 |
Tokens.token_tree := token_tree_latex; |
| 402 |
Tokens.outfun := output_sublexer_string |
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
let translate s = |
| 407 |
match Tokens.translate s with Some s -> s | None -> escaped s |
| 408 |
|
| 409 |
let keyword s loc = |
| 410 |
printf "\\coqdockw{%s}" (translate s) |
| 411 |
|
| 412 |
let ident s loc = |
| 413 |
last_was_in := s = "in"; |
| 414 |
try |
| 415 |
match loc with |
| 416 |
| None -> raise Not_found |
| 417 |
| Some loc -> |
| 418 |
let tag = Index.find (get_module false) loc in |
| 419 |
reference (translate s) tag |
| 420 |
with Not_found -> |
| 421 |
if is_tactic s then |
| 422 |
printf "\\coqdoctac{%s}" (translate s) |
| 423 |
else if is_keyword s then |
| 424 |
printf "\\coqdockw{%s}" (translate s) |
| 425 |
else if !prefs.interpolate && !in_doc |
| 426 |
then |
| 427 |
try |
| 428 |
let tag = Index.find_string s in |
| 429 |
reference (translate s) tag |
| 430 |
with _ -> Tokens.output_tagged_ident_string s |
| 431 |
else Tokens.output_tagged_ident_string s |
| 432 |
|
| 433 |
let ident s l = |
| 434 |
if !in_title then ( |
| 435 |
printf "\\texorpdfstring{\\protect"; |
| 436 |
ident s l; |
| 437 |
printf "}{%s}" (translate s)) |
| 438 |
else |
| 439 |
ident s l |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
let proofbox () = printf "\\ensuremath{\\Box}" |
| 444 |
|
| 445 |
let rec reach_item_level n = |
| 446 |
if !item_level < n then begin |
| 447 |
printf "\n\\begin{itemize}\n\\item "; incr item_level; |
| 448 |
reach_item_level n |
| 449 |
end else if !item_level > n then begin |
| 450 |
printf "\n\\end{itemize}\n"; decr item_level; |
| 451 |
reach_item_level n |
| 452 |
end |
| 453 |
|
| 454 |
let item n = |
| 455 |
let old_level = !item_level in |
| 456 |
reach_item_level n; |
| 457 |
if n <= old_level then printf "\n\\item " |
| 458 |
|
| 459 |
let stop_item () = reach_item_level 0 |
| 460 |
|
| 461 |
let start_doc () = in_doc := true |
| 462 |
|
| 463 |
let end_doc () = in_doc := false; stop_item () |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
let start_emph () = printf "\\textit{" |
| 468 |
|
| 469 |
let stop_emph () = printf "}" |
| 470 |
|
| 471 |
let start_details _ = () |
| 472 |
|
| 473 |
let stop_details () = () |
| 474 |
|
| 475 |
|
| 476 |
let start_comment () = printf "\\begin{coqdoccomment}\n" |
| 477 |
|
| 478 |
let end_comment () = printf "\\end{coqdoccomment}\n" |
| 479 |
|
| 480 |
let start_coq () = printf "\\begin{coqdoccode}\n" |
| 481 |
|
| 482 |
let end_coq () = printf "\\end{coqdoccode}\n" |
| 483 |
|
| 484 |
let section_kind = function |
| 485 |
| 1 -> "\\section{" |
| 486 |
| 2 -> "\\subsection{" |
| 487 |
| 3 -> "\\subsubsection{" |
| 488 |
| 4 -> "\\paragraph{" |
| 489 |
| _ -> assert false |
| 490 |
|
| 491 |
let section lev f = |
| 492 |
stop_item (); |
| 493 |
output_string (section_kind lev); |
| 494 |
in_title := true; f (); in_title := false; |
| 495 |
printf "}\n\n" |
| 496 |
|
| 497 |
let rule () = |
| 498 |
printf "\\par\n\\noindent\\hrulefill\\par\n\\noindent{}" |
| 499 |
|
| 500 |
let paragraph () = printf "\n\n" |
| 501 |
|
| 502 |
let line_break () = printf "\\coqdoceol\n" |
| 503 |
|
| 504 |
let empty_line_of_code () = printf "\\coqdocemptyline\n" |
| 505 |
|
| 506 |
let start_inline_coq_block () = line_break (); empty_line_of_code () |
| 507 |
|
| 508 |
let end_inline_coq_block () = empty_line_of_code () |
| 509 |
|
| 510 |
let start_inline_coq () = () |
| 511 |
|
| 512 |
let end_inline_coq () = () |
| 513 |
|
| 514 |
let make_multi_index () = () |
| 515 |
|
| 516 |
let make_index () = () |
| 517 |
|
| 518 |
let make_toc () = printf "\\tableofcontents\n" |
| 519 |
|
| 520 |
end |
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
module Html = struct |
| 526 |
|
| 527 |
let title_re = Str.regexp_string "@@TITLE@@" |
| 528 |
|
| 529 |
let header () = |
| 530 |
if !prefs.header_trailer then begin |
| 531 |
match !prefs.header_file with |
| 532 |
| None -> |
| 533 |
printf "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n"; |
| 534 |
printf "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"; |
| 535 |
printf "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n"; |
| 536 |
printf "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\" />\n" !prefs.encoding.charset; |
| 537 |
printf "<link href=\"coqdoc.css\" rel=\"stylesheet\" type=\"text/css\" />\n"; |
| 538 |
printf "<title>%s</title>\n</head>\n\n" !page_title; |
| 539 |
printf "<body>\n\n<div id=\"page\">\n\n<div id=\"header\">\n</div>\n\n"; |
| 540 |
printf "<div id=\"main\">\n\n" |
| 541 |
| Some f -> |
| 542 |
let cin = open_in f in |
| 543 |
try |
| 544 |
while true do |
| 545 |
let s = input_line cin in |
| 546 |
let s = Str.global_replace title_re !page_title s in |
| 547 |
printf "%s\n" s |
| 548 |
done |
| 549 |
with End_of_file -> close_in cin |
| 550 |
end |
| 551 |
|
| 552 |
let trailer () = |
| 553 |
if !prefs.header_trailer then begin |
| 554 |
match !prefs.footer_file with |
| 555 |
| None -> |
| 556 |
if !prefs.index && (get_module false) <> "Index" then |
| 557 |
printf "</div>\n\n<div id=\"footer\">\n<hr/><a href=\"%s.html\">Index</a>" !prefs.index_name; |
| 558 |
printf "<hr/>This page has been generated by "; |
| 559 |
printf "<a href=\"%s\">coqdoc</a>\n" Coq_config.wwwcoq; |
| 560 |
printf "</div>\n\n</div>\n\n</body>\n</html>" |
| 561 |
| Some f -> |
| 562 |
let cin = open_in f in |
| 563 |
try |
| 564 |
while true do |
| 565 |
let s = input_line cin in |
| 566 |
printf "%s\n" s |
| 567 |
done |
| 568 |
with End_of_file -> close_in cin |
| 569 |
end |
| 570 |
|
| 571 |
let start_module () = |
| 572 |
let ln = !prefs.lib_name in |
| 573 |
if not !prefs.short then begin |
| 574 |
let (m,sub) = !current_module in |
| 575 |
add_toc_entry (Toc_library (m,sub)); |
| 576 |
if ln = "" then |
| 577 |
printf "<h1 class=\"libtitle\">%s</h1>\n\n" (get_module true) |
| 578 |
else |
| 579 |
printf "<h1 class=\"libtitle\">%s %s</h1>\n\n" ln (get_module true) |
| 580 |
end |
| 581 |
|
| 582 |
let indentation n = for _i = 1 to n do printf " " done |
| 583 |
|
| 584 |
let line_break () = printf "<br/>\n" |
| 585 |
|
| 586 |
let empty_line_of_code () = |
| 587 |
printf "\n<br/>\n" |
| 588 |
|
| 589 |
let nbsp () = printf " " |
| 590 |
|
| 591 |
let char = function |
| 592 |
| '<' -> printf "<" |
| 593 |
| '>' -> printf ">" |
| 594 |
| '&' -> printf "&" |
| 595 |
| c -> output_char c |
| 596 |
|
| 597 |
let escaped = |
| 598 |
let buff = Buffer.create 5 in |
| 599 |
fun s -> |
| 600 |
Buffer.clear buff; |
| 601 |
for i = 0 to String.length s - 1 do |
| 602 |
match s.[i] with |
| 603 |
| '<' -> Buffer.add_string buff "<" |
| 604 |
| '>' -> Buffer.add_string buff ">" |
| 605 |
| '&' -> Buffer.add_string buff "&" |
| 606 |
| '\"' -> Buffer.add_string buff """ |
| 607 |
| c -> Buffer.add_char buff c |
| 608 |
done; |
| 609 |
Buffer.contents buff |
| 610 |
|
| 611 |
let sanitize_name s = |
| 612 |
let rec loop esc i = |
| 613 |
if i < 0 then if esc then escaped s else s |
| 614 |
else match s.[i] with |
| 615 |
| 'a'..'z' | 'A'..'Z' | '0'..'9' | '.' | '_' -> loop esc (i-1) |
| 616 |
| '<' | '>' | '&' | '\'' | '\"' -> loop true (i-1) |
| 617 |
| '-' | ':' -> loop esc (i-1) |
| 618 |
| _ -> |
| 619 |
|
| 620 |
|
| 621 |
Digest.to_hex (Digest.string s) |
| 622 |
in loop false (String.length s - 1) |
| 623 |
|
| 624 |
let latex_char _ = () |
| 625 |
let latex_string _ = () |
| 626 |
|
| 627 |
let html_char = output_char |
| 628 |
let html_string = output_string |
| 629 |
|
| 630 |
let start_latex_math () = () |
| 631 |
let stop_latex_math () = () |
| 632 |
|
| 633 |
let start_quote () = char '"' |
| 634 |
let stop_quote () = start_quote () |
| 635 |
|
| 636 |
let start_verbatim inline = |
| 637 |
if inline then printf "<code>" |
| 638 |
else printf "<pre>\n" |
| 639 |
|
| 640 |
let stop_verbatim inline = |
| 641 |
if inline then printf "</code>" |
| 642 |
else printf "</pre>\n" |
| 643 |
|
| 644 |
let url addr name = |
| 645 |
printf "<a href=\"%s\">%s</a>" addr |
| 646 |
(match name with |
| 647 |
| Some n -> n |
| 648 |
| None -> addr) |
| 649 |
|
| 650 |
let ident_ref m fid typ s = |
| 651 |
match find_module m with |
| 652 |
| Local -> |
| 653 |
printf "<a class=\"idref\" href=\"%s.html#%s\">" m (sanitize_name fid); |
| 654 |
printf "<span class=\"id\" title=\"%s\">%s</span></a>" typ s |
| 655 |
| External m when !prefs.externals -> |
| 656 |
printf "<a class=\"idref\" href=\"%s.html#%s\">" m (sanitize_name fid); |
| 657 |
printf "<span class=\"id\" title=\"%s\">%s</span></a>" typ s |
| 658 |
| External _ | Unknown -> |
| 659 |
printf "<span class=\"id\" title=\"%s\">%s</span>" typ s |
| 660 |
|
| 661 |
let reference s r = |
| 662 |
match r with |
| 663 |
| Def [] -> assert false |
| 664 |
| Def [fullid,ty] -> |
| 665 |
let s' = sanitize_name fullid in |
| 666 |
printf "<a id=\"%s\" class=\"idref\" href=\"#%s\">" s' s'; |
| 667 |
printf "<span class=\"id\" title=\"%s\">%s</span></a>" (type_name ty) s |
| 668 |
| Def ((hd_id,_) :: tail as all) -> |
| 669 |
let hd = sanitize_name hd_id in |
| 670 |
let all_tys = all |
| 671 |
|> List.map (fun (_,ty) -> type_name ty) |
| 672 |
|> CList.sort_uniquize String.compare |
| 673 |
|> String.concat ", " in |
| 674 |
printf "<a id=\"%s\" class=\"idref\" href=\"#%s\"><span class=\"id\" title=\"%s\">" hd hd all_tys; |
| 675 |
List.iter (fun (fullid,_) -> |
| 676 |
let s' = sanitize_name fullid in |
| 677 |
printf "<span id=\"%s\" class=\"id\">" s') |
| 678 |
tail; |
| 679 |
printf "%s" s; |
| 680 |
List.iter (fun _ -> printf "</span>") tail; |
| 681 |
printf "</span></a>"; |
| 682 |
| Ref (m,fullid,ty) -> |
| 683 |
ident_ref m fullid (type_name ty) s |
| 684 |
|
| 685 |
let output_sublexer_string doescape issymbchar tag s = |
| 686 |
let s = if doescape then escaped s else s in |
| 687 |
match tag with |
| 688 |
| Some ref -> reference s ref |
| 689 |
| None -> |
| 690 |
if issymbchar then output_string s |
| 691 |
else printf "<span class=\"id\" title=\"var\">%s</span>" s |
| 692 |
|
| 693 |
let sublexer c loc = |
| 694 |
let tag = |
| 695 |
try Some (Index.find (get_module false) loc) with Not_found -> None |
| 696 |
in |
| 697 |
Tokens.output_tagged_symbol_char tag c |
| 698 |
|
| 699 |
let sublexer_in_doc c = |
| 700 |
Tokens.output_tagged_symbol_char None c |
| 701 |
|
| 702 |
let initialize () = |
| 703 |
initialize_tex_html(); |
| 704 |
Tokens.token_tree := token_tree_html; |
| 705 |
Tokens.outfun := output_sublexer_string |
| 706 |
|
| 707 |
let translate s = |
| 708 |
match Tokens.translate s with Some s -> s | None -> escaped s |
| 709 |
|
| 710 |
let keyword s loc = |
| 711 |
printf "<span class=\"id\" title=\"keyword\">%s</span>" (translate s) |
| 712 |
|
| 713 |
let ident s loc = |
| 714 |
try |
| 715 |
match loc with |
| 716 |
| None -> raise Not_found |
| 717 |
| Some loc -> |
| 718 |
reference (translate s) (Index.find (get_module false) loc) |
| 719 |
with Not_found -> |
| 720 |
if is_tactic s then |
| 721 |
printf "<span class=\"id\" title=\"tactic\">%s</span>" (translate s) |
| 722 |
else if is_keyword s then |
| 723 |
printf "<span class=\"id\" title=\"keyword\">%s</span>" (translate s) |
| 724 |
else if !prefs.interpolate && !in_doc then |
| 725 |
try reference (translate s) (Index.find_string s) |
| 726 |
with Not_found -> Tokens.output_tagged_ident_string s |
| 727 |
else |
| 728 |
Tokens.output_tagged_ident_string s |
| 729 |
|
| 730 |
let proofbox () = printf "<font size=-2>☐</font>" |
| 731 |
|
| 732 |
let rec reach_item_level n = |
| 733 |
if !item_level < n then begin |
| 734 |
printf "<ul class=\"doclist\">\n<li>"; incr item_level; |
| 735 |
reach_item_level n |
| 736 |
end else if !item_level > n then begin |
| 737 |
printf "\n</li>\n</ul>\n"; decr item_level; |
| 738 |
reach_item_level n |
| 739 |
end |
| 740 |
|
| 741 |
let item n = |
| 742 |
let old_level = !item_level in |
| 743 |
reach_item_level n; |
| 744 |
if n <= old_level then printf "\n</li>\n<li>" |
| 745 |
|
| 746 |
let stop_item () = reach_item_level 0 |
| 747 |
|
| 748 |
let start_coq () = if not !prefs.raw_comments then printf "<div class=\"code\">\n" |
| 749 |
|
| 750 |
let end_coq () = if not !prefs.raw_comments then printf "</div>\n" |
| 751 |
|
| 752 |
let start_doc () = in_doc := true; |
| 753 |
if not !prefs.raw_comments then |
| 754 |
printf "\n<div class=\"doc\">\n" |
| 755 |
|
| 756 |
let end_doc () = in_doc := false; |
| 757 |
stop_item (); |
| 758 |
if not !prefs.raw_comments then printf "</div>\n" |
| 759 |
|
| 760 |
let start_emph () = printf "<i>" |
| 761 |
|
| 762 |
let stop_emph () = printf "</i>" |
| 763 |
|
| 764 |
let start_details = function |
| 765 |
| Some s -> printf "<details><summary>%s</summary>" s |
| 766 |
| _ -> printf "<details>" |
| 767 |
|
| 768 |
let stop_details () = printf "</details>" |
| 769 |
|
| 770 |
let start_comment () = printf "<span class=\"comment\">(*" |
| 771 |
|
| 772 |
let end_comment () = printf "*)</span>" |
| 773 |
|
| 774 |
let start_inline_coq () = |
| 775 |
if !prefs.inline_notmono then printf "<span class=\"inlinecodenm\">" |
| 776 |
else printf "<span class=\"inlinecode\">" |
| 777 |
|
| 778 |
let end_inline_coq () = printf "</span>" |
| 779 |
|
| 780 |
let start_inline_coq_block () = line_break (); start_inline_coq () |
| 781 |
|
| 782 |
let end_inline_coq_block () = end_inline_coq () |
| 783 |
|
| 784 |
let paragraph () = printf "\n<div class=\"paragraph\"> </div>\n\n" |
| 785 |
|
| 786 |
|
| 787 |
let inf_rule assumptions (_,_,midnm) conclusions = |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
let replace_spaces str = |
| 792 |
let rec copy a n = match n with 0 -> [] | n -> (a :: copy a (n - 1)) in |
| 793 |
let results = Str.full_split (Str.regexp "[' '][' '][' ']+") str in |
| 794 |
let strs = List.map (fun r -> match r with |
| 795 |
| Str.Text s -> [s] |
| 796 |
| Str.Delim s -> |
| 797 |
copy " " (String.length s)) |
| 798 |
results |
| 799 |
in |
| 800 |
String.concat "" (List.concat strs) |
| 801 |
in |
| 802 |
let start_assumption line = |
| 803 |
(printf "<tr class=\"infruleassumption\">\n"; |
| 804 |
printf " <td class=\"infrule\">%s</td>\n" (replace_spaces line)) in |
| 805 |
let end_assumption () = |
| 806 |
(printf " <td></td>\n"; |
| 807 |
printf "</tr>\n") in |
| 808 |
let rec print_assumptions hyps = |
| 809 |
match hyps with |
| 810 |
| [] -> start_assumption " " |
| 811 |
| [(_,hyp)] -> start_assumption hyp |
| 812 |
| ((_,hyp) :: hyps') -> (start_assumption hyp; |
| 813 |
end_assumption (); |
| 814 |
print_assumptions hyps') in |
| 815 |
printf "<center><table class=\"infrule\">\n"; |
| 816 |
print_assumptions assumptions; |
| 817 |
printf " <td class=\"infrulenamecol\" rowspan=\"3\">\n"; |
| 818 |
(match midnm with |
| 819 |
| None -> printf " \n </td>" |
| 820 |
| Some s -> printf " %s \n </td>" s); |
| 821 |
printf "</tr>\n"; |
| 822 |
printf "<tr class=\"infrulemiddle\">\n"; |
| 823 |
printf " <td class=\"infrule\"><hr /></td>\n"; |
| 824 |
printf "</tr>\n"; |
| 825 |
print_assumptions conclusions; |
| 826 |
end_assumption (); |
| 827 |
printf "</table></center>" |
| 828 |
|
| 829 |
let section lev f = |
| 830 |
let lab = new_label () in |
| 831 |
let r = sprintf "%s.html#%s" (get_module false) lab in |
| 832 |
(match !prefs.toc_depth with |
| 833 |
| None -> add_toc_entry (Toc_section (lev, f, r)) |
| 834 |
| Some n -> if lev <= n then add_toc_entry (Toc_section (lev, f, r)) |
| 835 |
else ()); |
| 836 |
stop_item (); |
| 837 |
printf "<a id=\"%s\"></a><h%d class=\"section\">" lab lev; |
| 838 |
f (); |
| 839 |
printf "</h%d>\n" lev |
| 840 |
|
| 841 |
let rule () = printf "<hr/>\n" |
| 842 |
|
| 843 |
|
| 844 |
let index_ref i c = |
| 845 |
let idxc = sprintf "%s_%c" i.idx_name c in |
| 846 |
!prefs.index_name ^ (if !prefs.multi_index then "_" ^ idxc ^ ".html" else ".html#" ^ idxc) |
| 847 |
|
| 848 |
let letter_index category idx (c,l) = |
| 849 |
if l <> [] then begin |
| 850 |
let cat = if category && idx <> "global" then "(" ^ idx ^ ")" else "" in |
| 851 |
printf "<a id=\"%s_%c\"></a><h2>%s %s</h2>\n" idx c (display_letter c) cat; |
| 852 |
List.iter |
| 853 |
(fun (id,(text,link,t)) -> |
| 854 |
let id' = escaped (prepare_entry id t) in |
| 855 |
printf "<a href=\"%s\">%s</a> %s<br/>\n" link id' text) l; |
| 856 |
printf "<br/><br/>" |
| 857 |
end |
| 858 |
|
| 859 |
let all_letters i = List.iter (letter_index false i.idx_name) i.idx_entries |
| 860 |
|
| 861 |
|
| 862 |
) |
| 863 |
let format_global_index = |
| 864 |
Index.map |
| 865 |
(fun s (m,t) -> |
| 866 |
if t = Library then |
| 867 |
let ln = !prefs.lib_name in |
| 868 |
if ln <> "" then |
| 869 |
"[" ^ String.lowercase_ascii ln ^ "]", m ^ ".html", t |
| 870 |
else |
| 871 |
"[library]", m ^ ".html", t |
| 872 |
else |
| 873 |
sprintf "[%s, in <a href=\"%s.html\">%s</a>]" (type_name t) m m , |
| 874 |
sprintf "%s.html#%s" m (sanitize_name s), t) |
| 875 |
|
| 876 |
let format_bytype_index = function |
| 877 |
| Library, idx -> |
| 878 |
Index.map (fun id m -> "", m ^ ".html", Library) idx |
| 879 |
| (t,idx) -> |
| 880 |
Index.map |
| 881 |
(fun s m -> |
| 882 |
let text = sprintf "[in <a href=\"%s.html\">%s</a>]" m m in |
| 883 |
(text, sprintf "%s.html#%s" m (sanitize_name s), t)) idx |
| 884 |
|
| 885 |
|
| 886 |
let print_index_table_item i = |
| 887 |
printf "<tr>\n<td>%s Index</td>\n" (String.capitalize_ascii i.idx_name); |
| 888 |
List.iter |
| 889 |
(fun (c,l) -> |
| 890 |
if l <> [] then |
| 891 |
printf "<td><a href=\"%s\">%s</a></td>\n" (index_ref i c) |
| 892 |
(display_letter c) |
| 893 |
else |
| 894 |
printf "<td>%s</td>\n" (display_letter c)) |
| 895 |
i.idx_entries; |
| 896 |
let n = i.idx_size in |
| 897 |
printf "<td>(%d %s)</td>\n" n (if n > 1 then "entries" else "entry"); |
| 898 |
printf "</tr>\n" |
| 899 |
|
| 900 |
let print_index_table idxl = |
| 901 |
printf "<table>\n"; |
| 902 |
List.iter print_index_table_item idxl; |
| 903 |
printf "</table>\n" |
| 904 |
|
| 905 |
let make_one_multi_index prt_tbl i = |
| 906 |
) |
| 907 |
let idx = i.idx_name in |
| 908 |
let one_letter ((c,l) as cl) = |
| 909 |
open_out_file (sprintf "%s_%s_%c.html" !prefs.index_name idx c); |
| 910 |
if (!prefs.header_trailer) then header (); |
| 911 |
prt_tbl (); printf "<hr/>"; |
| 912 |
letter_index true idx cl; |
| 913 |
if List.length l > 30 then begin printf "<hr/>"; prt_tbl () end; |
| 914 |
if (!prefs.header_trailer) then trailer (); |
| 915 |
close_out_file () |
| 916 |
in |
| 917 |
List.iter one_letter i.idx_entries |
| 918 |
|
| 919 |
let make_multi_index () = |
| 920 |
let all_index = |
| 921 |
let glob,bt = Index.all_entries () in |
| 922 |
(format_global_index glob) :: |
| 923 |
(List.map format_bytype_index bt) in |
| 924 |
let print_table () = print_index_table all_index in |
| 925 |
List.iter (make_one_multi_index print_table) all_index |
| 926 |
|
| 927 |
let make_index () = |
| 928 |
let all_index = |
| 929 |
let glob,bt = Index.all_entries () in |
| 930 |
(format_global_index glob) :: |
| 931 |
(List.map format_bytype_index bt) in |
| 932 |
let print_table () = print_index_table all_index in |
| 933 |
let print_one_index i = |
| 934 |
if i.idx_size > 0 then begin |
| 935 |
printf "<hr/>\n<h1>%s Index</h1>\n" (String.capitalize_ascii i.idx_name); |
| 936 |
all_letters i |
| 937 |
end |
| 938 |
in |
| 939 |
set_module "Index" None; |
| 940 |
if !prefs.title <> "" then printf "<h1>%s</h1>\n" !prefs.title; |
| 941 |
print_table (); |
| 942 |
if not (!prefs.multi_index) then |
| 943 |
begin |
| 944 |
List.iter print_one_index all_index; |
| 945 |
printf "<hr/>"; print_table () |
| 946 |
end |
| 947 |
|
| 948 |
let make_toc () = |
| 949 |
let ln = !prefs.lib_name in |
| 950 |
let make_toc_entry = function |
| 951 |
| Toc_library (m,sub) -> |
| 952 |
stop_item (); |
| 953 |
let ms = match sub with | None -> m | Some s -> m ^ ": " ^ s in |
| 954 |
if ln = "" then |
| 955 |
printf "<h2><a href=\"%s.html\">%s</a></h2>\n" m ms |
| 956 |
else |
| 957 |
printf "<h2><a href=\"%s.html\">%s %s</a></h2>\n" m ln ms |
| 958 |
| Toc_section (n, f, r) -> |
| 959 |
item n; |
| 960 |
printf "<a href=\"%s\">" r; f (); printf "</a>\n" |
| 961 |
in |
| 962 |
printf "<div id=\"toc\">\n"; |
| 963 |
Queue.iter make_toc_entry toc_q; |
| 964 |
stop_item (); |
| 965 |
printf "</div>\n" |
| 966 |
|
| 967 |
end |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
module TeXmacs = struct |
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
let (_ : string Queue.t) = |
| 977 |
in_doc := false; Queue.create () |
| 978 |
|
| 979 |
let header () = |
| 980 |
output_string |
| 981 |
"(*i This file has been automatically generated with the command \n"; |
| 982 |
output_string |
| 983 |
" "; Array.iter (fun s -> printf "%s " s) Sys.argv; printf " *)\n" |
| 984 |
|
| 985 |
let trailer () = () |
| 986 |
|
| 987 |
let nbsp () = output_char ' ' |
| 988 |
|
| 989 |
let char_true c = match c with |
| 990 |
| '\\' -> printf "\\\\" |
| 991 |
| '<' -> printf "\\<" |
| 992 |
| '|' -> printf "\\|" |
| 993 |
| '>' -> printf "\\>" |
| 994 |
| _ -> output_char c |
| 995 |
|
| 996 |
let char c = if !in_doc then char_true c else output_char c |
| 997 |
|
| 998 |
let latex_char = char_true |
| 999 |
let latex_string = String.iter latex_char |
| 1000 |
|
| 1001 |
let html_char _ = () |
| 1002 |
let html_string _ = () |
| 1003 |
|
| 1004 |
let raw_ident s = |
| 1005 |
for i = 0 to String.length s - 1 do char s.[i] done |
| 1006 |
|
| 1007 |
let start_module () = () |
| 1008 |
|
| 1009 |
let start_latex_math () = printf "<with|mode|math|" |
| 1010 |
|
| 1011 |
let stop_latex_math () = output_char '>' |
| 1012 |
|
| 1013 |
let start_verbatim inline = in_doc := true; printf "<\\verbatim>" |
| 1014 |
let stop_verbatim inline = in_doc := false; printf "</verbatim>" |
| 1015 |
|
| 1016 |
let url addr name = |
| 1017 |
printf "%s<\\footnote><\\url>%s</url></footnote>" addr |
| 1018 |
(match name with |
| 1019 |
| None -> "" |
| 1020 |
| Some n -> n) |
| 1021 |
|
| 1022 |
let start_quote () = output_char '`'; output_char '`' |
| 1023 |
let stop_quote () = output_char '\''; output_char '\'' |
| 1024 |
|
| 1025 |
let indentation n = () |
| 1026 |
|
| 1027 |
let keyword s = |
| 1028 |
printf "<kw|"; raw_ident s; printf ">" |
| 1029 |
|
| 1030 |
let ident_true s = |
| 1031 |
if is_keyword s then keyword s |
| 1032 |
else raw_ident s |
| 1033 |
|
| 1034 |
let keyword s loc = keyword s |
| 1035 |
let ident s _ = if !in_doc then ident_true s else raw_ident s |
| 1036 |
|
| 1037 |
let output_sublexer_string doescape issymbchar tag s = |
| 1038 |
if doescape then raw_ident s else output_string s |
| 1039 |
|
| 1040 |
let sublexer c l = |
| 1041 |
if !in_doc then Tokens.output_tagged_symbol_char None c else char c |
| 1042 |
|
| 1043 |
let sublexer_in_doc c = |
| 1044 |
char c |
| 1045 |
|
| 1046 |
let initialize () = |
| 1047 |
Tokens.token_tree := token_tree_texmacs; |
| 1048 |
Tokens.outfun := output_sublexer_string |
| 1049 |
|
| 1050 |
let proofbox () = printf "QED" |
| 1051 |
|
| 1052 |
let rec reach_item_level n = |
| 1053 |
if !item_level < n then begin |
| 1054 |
printf "\n<\\itemize>\n<item>"; incr item_level; |
| 1055 |
reach_item_level n |
| 1056 |
end else if !item_level > n then begin |
| 1057 |
printf "\n</itemize>"; decr item_level; |
| 1058 |
reach_item_level n |
| 1059 |
end |
| 1060 |
|
| 1061 |
let item n = |
| 1062 |
let old_level = !item_level in |
| 1063 |
reach_item_level n; |
| 1064 |
if n <= old_level then printf "\n\n<item>" |
| 1065 |
|
| 1066 |
let stop_item () = reach_item_level 0 |
| 1067 |
|
| 1068 |
let start_doc () = in_doc := true; printf "(** texmacs: " |
| 1069 |
|
| 1070 |
let end_doc () = stop_item (); in_doc := false; printf " *)" |
| 1071 |
|
| 1072 |
let start_coq () = () |
| 1073 |
|
| 1074 |
let end_coq () = () |
| 1075 |
|
| 1076 |
let start_emph () = printf "<with|font shape|italic|" |
| 1077 |
let stop_emph () = printf ">" |
| 1078 |
|
| 1079 |
let start_details _ = () |
| 1080 |
let stop_details () = () |
| 1081 |
|
| 1082 |
let start_comment () = () |
| 1083 |
let end_comment () = () |
| 1084 |
|
| 1085 |
let section_kind = function |
| 1086 |
| 1 -> "section" |
| 1087 |
| 2 -> "subsection" |
| 1088 |
| 3 -> "subsubsection" |
| 1089 |
| 4 -> "paragraph" |
| 1090 |
| _ -> assert false |
| 1091 |
|
| 1092 |
let section lev f = |
| 1093 |
stop_item (); |
| 1094 |
printf "<"; output_string (section_kind lev); printf "|"; |
| 1095 |
f (); printf ">\n\n" |
| 1096 |
|
| 1097 |
let rule () = |
| 1098 |
printf "\n<hrule>\n" |
| 1099 |
|
| 1100 |
let paragraph () = printf "\n\n" |
| 1101 |
|
| 1102 |
let line_break () = printf "\n" |
| 1103 |
|
| 1104 |
let empty_line_of_code () = printf "\n" |
| 1105 |
|
| 1106 |
let start_inline_coq () = printf "<verbatim|[" |
| 1107 |
|
| 1108 |
let end_inline_coq () = printf "]>" |
| 1109 |
|
| 1110 |
let start_inline_coq_block () = line_break (); start_inline_coq () |
| 1111 |
|
| 1112 |
let end_inline_coq_block () = end_inline_coq () |
| 1113 |
|
| 1114 |
let make_multi_index () = () |
| 1115 |
|
| 1116 |
let make_index () = () |
| 1117 |
|
| 1118 |
let make_toc () = () |
| 1119 |
|
| 1120 |
end |
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
module Raw = struct |
| 1126 |
|
| 1127 |
let header () = () |
| 1128 |
|
| 1129 |
let trailer () = () |
| 1130 |
|
| 1131 |
let nbsp () = output_char ' ' |
| 1132 |
|
| 1133 |
let char = output_char |
| 1134 |
|
| 1135 |
let latex_char = output_char |
| 1136 |
let latex_string = output_string |
| 1137 |
|
| 1138 |
let html_char _ = () |
| 1139 |
let html_string _ = () |
| 1140 |
|
| 1141 |
let raw_ident s = |
| 1142 |
for i = 0 to String.length s - 1 do char s.[i] done |
| 1143 |
|
| 1144 |
let start_module () = () |
| 1145 |
|
| 1146 |
let start_latex_math () = () |
| 1147 |
let stop_latex_math () = () |
| 1148 |
|
| 1149 |
let start_verbatim inline = () |
| 1150 |
let stop_verbatim inline = () |
| 1151 |
|
| 1152 |
let url addr name = |
| 1153 |
match name with |
| 1154 |
| Some n -> printf "%s (%s)" n addr |
| 1155 |
| None -> printf "%s" addr |
| 1156 |
|
| 1157 |
let start_quote () = printf "\"" |
| 1158 |
let stop_quote () = printf "\"" |
| 1159 |
|
| 1160 |
let indentation n = |
| 1161 |
for _i = 1 to n do printf " " done |
| 1162 |
|
| 1163 |
let keyword s loc = raw_ident s |
| 1164 |
let ident s loc = raw_ident s |
| 1165 |
|
| 1166 |
let sublexer c l = char c |
| 1167 |
let sublexer_in_doc c = char c |
| 1168 |
|
| 1169 |
let initialize () = |
| 1170 |
Tokens.token_tree := ref Tokens.empty_ttree; |
| 1171 |
Tokens.outfun := (fun _ _ _ _ -> failwith "Useless") |
| 1172 |
|
| 1173 |
let proofbox () = printf "[]" |
| 1174 |
|
| 1175 |
let item n = printf "- " |
| 1176 |
let stop_item () = () |
| 1177 |
let reach_item_level _ = () |
| 1178 |
|
| 1179 |
let start_doc () = printf "(** " |
| 1180 |
let end_doc () = printf " *)\n" |
| 1181 |
|
| 1182 |
let start_emph () = printf "_" |
| 1183 |
let stop_emph () = printf "_" |
| 1184 |
|
| 1185 |
let start_details _ = () |
| 1186 |
let stop_details () = () |
| 1187 |
|
| 1188 |
let start_comment () = printf "(*" |
| 1189 |
let end_comment () = printf "*)" |
| 1190 |
|
| 1191 |
let start_coq () = () |
| 1192 |
let end_coq () = () |
| 1193 |
|
| 1194 |
let section_kind = |
| 1195 |
function |
| 1196 |
| 1 -> "* " |
| 1197 |
| 2 -> "** " |
| 1198 |
| 3 -> "*** " |
| 1199 |
| 4 -> "**** " |
| 1200 |
| _ -> assert false |
| 1201 |
|
| 1202 |
let section lev f = |
| 1203 |
output_string (section_kind lev); |
| 1204 |
f () |
| 1205 |
|
| 1206 |
let rule () = () |
| 1207 |
|
| 1208 |
let paragraph () = printf "\n\n" |
| 1209 |
|
| 1210 |
let line_break () = printf "\n" |
| 1211 |
|
| 1212 |
let empty_line_of_code () = printf "\n" |
| 1213 |
|
| 1214 |
let start_inline_coq () = () |
| 1215 |
let end_inline_coq () = () |
| 1216 |
|
| 1217 |
let start_inline_coq_block () = line_break (); start_inline_coq () |
| 1218 |
let end_inline_coq_block () = end_inline_coq () |
| 1219 |
|
| 1220 |
let make_multi_index () = () |
| 1221 |
let make_index () = () |
| 1222 |
let make_toc () = () |
| 1223 |
|
| 1224 |
end |
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
let select f1 f2 f3 f4 x = |
| 1231 |
match !prefs.targetlang with LaTeX -> f1 x | HTML -> f2 x | TeXmacs -> f3 x | Raw -> f4 x |
| 1232 |
|
| 1233 |
let push_in_preamble = Latex.push_in_preamble |
| 1234 |
|
| 1235 |
let header = select Latex.header Html.header TeXmacs.header Raw.header |
| 1236 |
let trailer = select Latex.trailer Html.trailer TeXmacs.trailer Raw.trailer |
| 1237 |
|
| 1238 |
let start_module = |
| 1239 |
select Latex.start_module Html.start_module TeXmacs.start_module Raw.start_module |
| 1240 |
|
| 1241 |
let start_doc = select Latex.start_doc Html.start_doc TeXmacs.start_doc Raw.start_doc |
| 1242 |
let end_doc = select Latex.end_doc Html.end_doc TeXmacs.end_doc Raw.end_doc |
| 1243 |
|
| 1244 |
let start_comment = select Latex.start_comment Html.start_comment TeXmacs.start_comment Raw.start_comment |
| 1245 |
let end_comment = select Latex.end_comment Html.end_comment TeXmacs.end_comment Raw.end_comment |
| 1246 |
|
| 1247 |
let start_coq = select Latex.start_coq Html.start_coq TeXmacs.start_coq Raw.start_coq |
| 1248 |
let end_coq = select Latex.end_coq Html.end_coq TeXmacs.end_coq Raw.end_coq |
| 1249 |
|
| 1250 |
let start_inline_coq = |
| 1251 |
select Latex.start_inline_coq Html.start_inline_coq TeXmacs.start_inline_coq Raw.start_inline_coq |
| 1252 |
let end_inline_coq = |
| 1253 |
select Latex.end_inline_coq Html.end_inline_coq TeXmacs.end_inline_coq Raw.end_inline_coq |
| 1254 |
|
| 1255 |
let start_inline_coq_block = |
| 1256 |
select Latex.start_inline_coq_block Html.start_inline_coq_block |
| 1257 |
TeXmacs.start_inline_coq_block Raw.start_inline_coq_block |
| 1258 |
let end_inline_coq_block = |
| 1259 |
select Latex.end_inline_coq_block Html.end_inline_coq_block TeXmacs.end_inline_coq_block Raw.end_inline_coq_block |
| 1260 |
|
| 1261 |
let indentation = select Latex.indentation Html.indentation TeXmacs.indentation Raw.indentation |
| 1262 |
let paragraph = select Latex.paragraph Html.paragraph TeXmacs.paragraph Raw.paragraph |
| 1263 |
let line_break = select Latex.line_break Html.line_break TeXmacs.line_break Raw.line_break |
| 1264 |
let empty_line_of_code = select |
| 1265 |
Latex.empty_line_of_code Html.empty_line_of_code TeXmacs.empty_line_of_code Raw.empty_line_of_code |
| 1266 |
|
| 1267 |
let section = select Latex.section Html.section TeXmacs.section Raw.section |
| 1268 |
let item = select Latex.item Html.item TeXmacs.item Raw.item |
| 1269 |
let stop_item = select Latex.stop_item Html.stop_item TeXmacs.stop_item Raw.stop_item |
| 1270 |
let reach_item_level = select Latex.reach_item_level Html.reach_item_level TeXmacs.reach_item_level Raw.reach_item_level |
| 1271 |
let rule = select Latex.rule Html.rule TeXmacs.rule Raw.rule |
| 1272 |
|
| 1273 |
let nbsp = select Latex.nbsp Html.nbsp TeXmacs.nbsp Raw.nbsp |
| 1274 |
let char = select Latex.char Html.char TeXmacs.char Raw.char |
| 1275 |
let keyword = select Latex.keyword Html.keyword TeXmacs.keyword Raw.keyword |
| 1276 |
let ident = select Latex.ident Html.ident TeXmacs.ident Raw.ident |
| 1277 |
let sublexer = select Latex.sublexer Html.sublexer TeXmacs.sublexer Raw.sublexer |
| 1278 |
let sublexer_in_doc = select Latex.sublexer_in_doc Html.sublexer_in_doc TeXmacs.sublexer_in_doc Raw.sublexer_in_doc |
| 1279 |
let initialize = select Latex.initialize Html.initialize TeXmacs.initialize Raw.initialize |
| 1280 |
|
| 1281 |
let proofbox = select Latex.proofbox Html.proofbox TeXmacs.proofbox Raw.proofbox |
| 1282 |
|
| 1283 |
let latex_char = select Latex.latex_char Html.latex_char TeXmacs.latex_char Raw.latex_char |
| 1284 |
let latex_string = |
| 1285 |
select Latex.latex_string Html.latex_string TeXmacs.latex_string Raw.latex_string |
| 1286 |
let html_char = select Latex.html_char Html.html_char TeXmacs.html_char Raw.html_char |
| 1287 |
let html_string = |
| 1288 |
select Latex.html_string Html.html_string TeXmacs.html_string Raw.html_string |
| 1289 |
|
| 1290 |
let start_emph = |
| 1291 |
select Latex.start_emph Html.start_emph TeXmacs.start_emph Raw.start_emph |
| 1292 |
let stop_emph = |
| 1293 |
select Latex.stop_emph Html.stop_emph TeXmacs.stop_emph Raw.stop_emph |
| 1294 |
|
| 1295 |
let start_details = |
| 1296 |
select Latex.start_details Html.start_details TeXmacs.start_details Raw.start_details |
| 1297 |
let stop_details = |
| 1298 |
select Latex.stop_details Html.stop_details TeXmacs.stop_details Raw.stop_details |
| 1299 |
|
| 1300 |
let start_latex_math = |
| 1301 |
select Latex.start_latex_math Html.start_latex_math TeXmacs.start_latex_math Raw.start_latex_math |
| 1302 |
let stop_latex_math = |
| 1303 |
select Latex.stop_latex_math Html.stop_latex_math TeXmacs.stop_latex_math Raw.stop_latex_math |
| 1304 |
|
| 1305 |
let start_verbatim = |
| 1306 |
select Latex.start_verbatim Html.start_verbatim TeXmacs.start_verbatim Raw.start_verbatim |
| 1307 |
let stop_verbatim = |
| 1308 |
select Latex.stop_verbatim Html.stop_verbatim TeXmacs.stop_verbatim Raw.stop_verbatim |
| 1309 |
let verbatim_char inline = |
| 1310 |
select (if inline then Latex.char else output_char) Html.char TeXmacs.char Raw.char |
| 1311 |
let hard_verbatim_char = output_char |
| 1312 |
|
| 1313 |
let url = |
| 1314 |
select Latex.url Html.url TeXmacs.url Raw.url |
| 1315 |
|
| 1316 |
let start_quote = |
| 1317 |
select Latex.start_quote Html.start_quote TeXmacs.start_quote Raw.start_quote |
| 1318 |
let stop_quote = |
| 1319 |
select Latex.stop_quote Html.stop_quote TeXmacs.stop_quote Raw.stop_quote |
| 1320 |
|
| 1321 |
let inf_rule_dumb assumptions (midsp,midln,midnm) conclusions = |
| 1322 |
start_verbatim false; |
| 1323 |
let dumb_line = |
| 1324 |
function (sp,ln) -> (String.iter char ((String.make sp ' ') ^ ln); |
| 1325 |
char '\n') |
| 1326 |
in |
| 1327 |
(List.iter dumb_line assumptions; |
| 1328 |
dumb_line (midsp, midln ^ (match midnm with |
| 1329 |
| Some s -> " " ^ s |
| 1330 |
| None -> "")); |
| 1331 |
List.iter dumb_line conclusions); |
| 1332 |
stop_verbatim false |
| 1333 |
|
| 1334 |
let inf_rule = select inf_rule_dumb Html.inf_rule inf_rule_dumb inf_rule_dumb |
| 1335 |
|
| 1336 |
let make_multi_index = select Latex.make_multi_index Html.make_multi_index TeXmacs.make_multi_index Raw.make_multi_index |
| 1337 |
let make_index = select Latex.make_index Html.make_index TeXmacs.make_index Raw.make_index |
| 1338 |
let make_toc = select Latex.make_toc Html.make_toc TeXmacs.make_toc Raw.make_toc |