From 31e2e5e10720e058292008c658dbf17bcbacac43 Mon Sep 17 00:00:00 2001
From: Charlotte Thomas
Date: Wed, 23 Mar 2022 20:23:46 +0100
Subject: [PATCH] idented with ocp-ident
---
lib/glossary.ml | 18 ++--
lib/htmlgen.ml | 242 ++++++++++++++++++++++++------------------------
lib/mathgen.ml | 106 ++++++++++-----------
lib/parser.ml | 224 ++++++++++++++++++++++----------------------
lib/utils.ml | 10 +-
5 files changed, 300 insertions(+), 300 deletions(-)
diff --git a/lib/glossary.ml b/lib/glossary.ml
index 9f8ee60..b33c4ea 100644
--- a/lib/glossary.ml
+++ b/lib/glossary.ml
@@ -71,15 +71,15 @@ let total_glossaries file =
(** Transform the glossary to an HTML file *)
let prints_glossary () =
if not @@ glossary_provided () then "" else
- let line = "\n>" in
- let line = line^"
Glossary
" in
- let rec aux result (entries) =
- match entries with
- | [] -> result
- | (desc,(name,def))::q -> let l = "\t
\n\t\t
" ^ name ^ "
\n\t\t
" ^ def ^ "
\n\t
\n"
- in aux (result^l) q
- in let line = aux line (List.of_seq (Hashtbl.to_seq glossaries))
- in line^"
\n";;
+ let line = "\n>" in
+ let line = line^"
Glossary
" in
+ let rec aux result (entries) =
+ match entries with
+ | [] -> result
+ | (desc,(name,def))::q -> let l = "\t
\n\t\t
" ^ name ^ "
\n\t\t
" ^ def ^ "
\n\t
\n"
+ in aux (result^l) q
+ in let line = aux line (List.of_seq (Hashtbl.to_seq glossaries))
+ in line^"
\n";;
let recognize_gls name =
try
diff --git a/lib/htmlgen.ml b/lib/htmlgen.ml
index 560a065..4ab8fd4 100644
--- a/lib/htmlgen.ml
+++ b/lib/htmlgen.ml
@@ -8,60 +8,60 @@ let print_table_of_content ast min_chap =
let count = [|1;1;1;1|] in
let rec aux acc ast =
match ast with
- | [] -> acc
- | Chapter (s,l)::q ->
- let chapnum = count.(0) in
- begin
- count.(0) <- count.(0) + 1;
- count.(1) <- 1;
- count.(2) <- 1;
- count.(3) <- 1;
- end;
- let str = aux "" l in
- let new_line = if chapnum>=min_chap then Printf.sprintf "Chapter %i : %s\n"
- chapnum (chapnum-min_chap+1) s else "" in
- aux (acc^new_line^str) q
-
- | Section (s,l)::q ->
- let chapnum,secnum = count.(0),count.(1) in
- begin
- count.(1) <- count.(1) + 1;
- count.(2) <- 1;
- count.(3) <- 1;
- end;
- let str = aux "" l in
- let new_line = Printf.sprintf "Section %i.%i : %s\n"
+ | [] -> acc
+ | Chapter (s,l)::q ->
+ let chapnum = count.(0) in
+ begin
+ count.(0) <- count.(0) + 1;
+ count.(1) <- 1;
+ count.(2) <- 1;
+ count.(3) <- 1;
+ end;
+ let str = aux "" l in
+ let new_line = if chapnum>=min_chap then Printf.sprintf "Chapter %i : %s\n"
+ chapnum (chapnum-min_chap+1) s else "" in
+ aux (acc^new_line^str) q
+
+ | Section (s,l)::q ->
+ let chapnum,secnum = count.(0),count.(1) in
+ begin
+ count.(1) <- count.(1) + 1;
+ count.(2) <- 1;
+ count.(3) <- 1;
+ end;
+ let str = aux "" l in
+ let new_line = Printf.sprintf "Section %i.%i : %s\n"
(2.**(float chapnum)*.3.**(float secnum)) (chapnum-min_chap+1) secnum s in
- aux (acc^new_line^str) q
-
- | Subsection (s,l)::q ->
- let chapnum,secnum,ssecnum = count.(0),count.(1),count.(2) in
- begin
- count.(2) <- count.(2) + 1;
- count.(3) <- 1;
- end;
- let str = aux "" l in
- let new_line = Printf.sprintf "Subsection %i.%i.%i : %s\n"
- (2.**(float chapnum)*.3.**(float secnum)*.5.**(float ssecnum)) (chapnum-min_chap+1) secnum ssecnum s in
- aux (acc^new_line^str) q
-
- | Subsubsection (s,l)::q ->
- let chapnum,secnum,ssecnum,sssecnum = count.(0),count.(1),count.(2),count.(3) in
- begin
- count.(3) <- count.(3) + 1;
- end;
- let str = aux "" l in
- let new_line = Printf.sprintf "Subsubsection %i.%i.%i.%i : %s\n"
- (2.**(float chapnum)*.3.**(float secnum)*.5.**(float ssecnum)*.7.**(float sssecnum)) (chapnum-min_chap+1) secnum ssecnum sssecnum s in
- aux (acc^new_line^str) q
- | Env (_,l)::q -> let a = aux acc l in aux (acc^a) q
- | _::q -> aux acc q
+ aux (acc^new_line^str) q
+
+ | Subsection (s,l)::q ->
+ let chapnum,secnum,ssecnum = count.(0),count.(1),count.(2) in
+ begin
+ count.(2) <- count.(2) + 1;
+ count.(3) <- 1;
+ end;
+ let str = aux "" l in
+ let new_line = Printf.sprintf "Subsection %i.%i.%i : %s\n"
+ (2.**(float chapnum)*.3.**(float secnum)*.5.**(float ssecnum)) (chapnum-min_chap+1) secnum ssecnum s in
+ aux (acc^new_line^str) q
+
+ | Subsubsection (s,l)::q ->
+ let chapnum,secnum,ssecnum,sssecnum = count.(0),count.(1),count.(2),count.(3) in
+ begin
+ count.(3) <- count.(3) + 1;
+ end;
+ let str = aux "" l in
+ let new_line = Printf.sprintf "Subsubsection %i.%i.%i.%i : %s\n"
+ (2.**(float chapnum)*.3.**(float secnum)*.5.**(float ssecnum)*.7.**(float sssecnum)) (chapnum-min_chap+1) secnum ssecnum sssecnum s in
+ aux (acc^new_line^str) q
+ | Env (_,l)::q -> let a = aux acc l in aux (acc^a) q
+ | _::q -> aux acc q
in (aux "" ast);;
- let parse_to_html ?(min_chap=1) write_before ast=
+let parse_to_html ?(min_chap=1) write_before ast=
let count = [|1;1;1;1|] in
let rec aux ?(write=write_before) acc ast =
- match ast with
+ match ast with
| [] -> acc
| Nul::q -> aux acc q
| Line s::q ->
@@ -74,65 +74,65 @@ let print_table_of_content ast min_chap =
in aux ~write:write (acc^line) q
| AtomicCmd (s,_)::q ->
let new_line = (match s with
- | "par" -> "
\n"
- | "bigskip" -> "
\n\n\n"
- | "\\" -> "
\n"
- | "printglossaries" -> ""
- | "sep" -> "
***
"
- | "item" -> "·"
- | "newline" -> "
\n"
- | "ast" -> "*"
- | e ->
- (try
- let structure = Hashtbl.find commands e in
- let str = aux ~write:write acc structure
- in str
- with _ -> ""))
+ | "par" -> "
\n"
+ | "bigskip" -> "\n\n\n"
+ | "\\" -> "
\n"
+ | "printglossaries" -> ""
+ | "sep" -> "
***
"
+ | "item" -> "·"
+ | "newline" -> "
\n"
+ | "ast" -> "*"
+ | e ->
+ (try
+ let structure = Hashtbl.find commands e in
+ let str = aux ~write:write acc structure
+ in str
+ with _ -> ""))
in let new_acc = if write then acc^new_line^"\n" else ""
in aux ~write:write new_acc q
-
+
| OneArgCmd (s,_,l)::q ->
let str = aux "" l in
let new_line = (match s with
- | "par" -> "
\n"
- | "bigskip" -> "\n\n\n"
- | "\\" -> "
\n"
- | "printglossaries" -> ""
- | "item" -> "·"
- | "sep" -> "
***
"
- | "newline" -> "
\n"
- | "ast" -> "*"
- | "gls" ->
+ | "par" -> "
\n"
+ | "bigskip" -> "\n\n\n"
+ | "\\" -> "
\n"
+ | "printglossaries" -> ""
+ | "item" -> "·"
+ | "sep" -> "
***
"
+ | "newline" -> "
\n"
+ | "ast" -> "*"
+ | "gls" ->
(match l with
- | [] -> ""
- | Line s::_ ->
- let name,_ = recognize_gls s in Printf.sprintf "%s " s name
- | _::_ -> "")
- | "textit" -> (Printf.sprintf "%s" str)
- | "textbf" -> (Printf.sprintf "%s" str)
- | "url" -> (Printf.sprintf "%s" (Str.global_replace (Str.regexp "\n") "" str) str)
- | e ->
- (try
- let structure = Hashtbl.find commands e in
- let str = aux ~write:write acc structure
- in str
- with _ -> ""))
+ | [] -> ""
+ | Line s::_ ->
+ let name,_ = recognize_gls s in Printf.sprintf "%s " s name
+ | _::_ -> "")
+ | "textit" -> (Printf.sprintf "%s" str)
+ | "textbf" -> (Printf.sprintf "%s" str)
+ | "url" -> (Printf.sprintf "%s" (Str.global_replace (Str.regexp "\n") "" str) str)
+ | e ->
+ (try
+ let structure = Hashtbl.find commands e in
+ let str = aux ~write:write acc structure
+ in str
+ with _ -> ""))
in let new_acc = if write then acc^(new_line) else ""
in aux ~write:write new_acc q
-
+
| Chapter (s,l)::q ->
let chapnum = count.(0) in
- begin
- count.(0) <- count.(0) + 1;
- count.(1) <- 1;
- count.(2) <- 1;
- count.(3) <- 1;
- end;
- let str = aux ~write:(chapnum>=min_chap) "" l in
- let new_line = if chapnum>=min_chap then Printf.sprintf "Chapter %i : %s
\n"
+ begin
+ count.(0) <- count.(0) + 1;
+ count.(1) <- 1;
+ count.(2) <- 1;
+ count.(3) <- 1;
+ end;
+ let str = aux ~write:(chapnum>=min_chap) "" l in
+ let new_line = if chapnum>=min_chap then Printf.sprintf "Chapter %i : %s
\n"
chapnum (chapnum-min_chap+1) s else "" in
- aux ~write:write (acc^new_line^str) q
-
+ aux ~write:write (acc^new_line^str) q
+
| Section (s,l)::q ->
let chapnum,secnum = count.(0),count.(1) in
begin
@@ -142,9 +142,9 @@ let print_table_of_content ast min_chap =
end;
let str = aux ~write:write "" l in
let new_line = Printf.sprintf "Section %i.%i : %s
\n"
- (2.**(float chapnum)*.3.**(float secnum)) (chapnum-min_chap+1) secnum s in
+ (2.**(float chapnum)*.3.**(float secnum)) (chapnum-min_chap+1) secnum s in
aux ~write:write (acc^new_line^str) q
-
+
| Subsection (s,l)::q ->
let chapnum,secnum,ssecnum = count.(0),count.(1),count.(2) in
begin
@@ -153,9 +153,9 @@ let print_table_of_content ast min_chap =
end;
let str = aux ~write:write "" l in
let new_line = Printf.sprintf "Subsection %i.%i.%i : %s
\n"
- (2.**(float chapnum)*.3.**(float secnum)*.5.**(float ssecnum)) (chapnum-min_chap+1) secnum ssecnum s in
+ (2.**(float chapnum)*.3.**(float secnum)*.5.**(float ssecnum)) (chapnum-min_chap+1) secnum ssecnum s in
aux ~write:write (acc^new_line^str) q
-
+
| Subsubsection (s,l)::q ->
let chapnum,secnum,ssecnum,sssecnum = count.(0),count.(1),count.(2),count.(3) in
begin
@@ -163,15 +163,15 @@ let print_table_of_content ast min_chap =
end;
let str = aux ~write:write "" l in
let new_line = Printf.sprintf "Subsubsection %i.%i.%i.%i : %s
\n"
- (2.**(float chapnum)*.3.**(float secnum)*.5.**(float ssecnum)*.7.**(float sssecnum)) (chapnum-min_chap+1) secnum ssecnum sssecnum s in
+ (2.**(float chapnum)*.3.**(float secnum)*.5.**(float ssecnum)*.7.**(float sssecnum)) (chapnum-min_chap+1) secnum ssecnum sssecnum s in
aux ~write:write (acc^new_line^str) q
-
+
| Env (s,l)::q ->
let str = aux ~write:write "" l in
let new_line = (match s with
- | "document" -> str
- | "center" -> Printf.sprintf "\n%s\n
" str
- | _ -> str)
+ | "document" -> str
+ | "center" -> Printf.sprintf "\n%s\n
" str
+ | _ -> str)
in aux ~write:write (acc^new_line^"\n") q
| _::q -> aux acc q
in aux "" ast;;
@@ -193,21 +193,21 @@ let prepare_body name str toc =
in let line = line ^ "