mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-08 07:51:43 +03:00
Weaving to LaTeX
This commit is contained in:
parent
56bc45db9d
commit
c6a9b0b8f9
5
.ocamlformat
Normal file
5
.ocamlformat
Normal file
@ -0,0 +1,5 @@
|
||||
profile = default
|
||||
margin = 100
|
||||
exp-grouping = preserve
|
||||
wrap-comments
|
||||
parse-docstrings
|
@ -22,10 +22,10 @@ open Cli
|
||||
let driver
|
||||
(source_files : string list)
|
||||
(debug: bool)
|
||||
(_backend: string)
|
||||
(_output_file : string)
|
||||
(backend: string)
|
||||
(output_file : string)
|
||||
: int =
|
||||
Cli.debug_flag := debug;
|
||||
Cli.debug_flag := debug;
|
||||
Cli.debug_print "Reading files...";
|
||||
let program = ref [] in
|
||||
List.iter (fun source_file ->
|
||||
@ -47,7 +47,19 @@ Cli.debug_flag := debug;
|
||||
exit (-1)
|
||||
end
|
||||
) source_files;
|
||||
exit 0
|
||||
if backend = "LaTeX" then
|
||||
let weaved_output =
|
||||
String.concat "\n\n" (List.map (fun file -> Weave.ast_to_latex file) !program)
|
||||
in
|
||||
Cli.debug_print (Printf.sprintf "Writing to %s" output_file);
|
||||
let oc = open_out output_file in
|
||||
Printf.fprintf oc "%s" weaved_output;
|
||||
close_out oc;
|
||||
0
|
||||
else begin
|
||||
Cli.error_print (Printf.sprintf "Unkown backend: %s" backend);
|
||||
1
|
||||
end
|
||||
|
||||
let main () =
|
||||
Cmdliner.Term.exit @@ Cmdliner.Term.eval (Cli.lawspec_t driver, Cli.info)
|
||||
|
@ -5,3 +5,6 @@
|
||||
(libraries ANSITerminal sedlex menhirLib re cmdliner dune-build-info)
|
||||
(preprocess (pps sedlex.ppx))
|
||||
)
|
||||
|
||||
(documentation
|
||||
(package lawspec))
|
||||
|
@ -29,7 +29,7 @@ let source_file_item_to_latex (i: A.source_file_item) : string =
|
||||
| A.LawCode c -> P.sprintf "\\subsection{%s}" c
|
||||
| A.LawText t -> t
|
||||
| A.LawArticle a -> P.sprintf "\\paragraph{%s}" a
|
||||
| A.CodeBlock -> "code"
|
||||
| A.CodeBlock -> P.sprintf "\\begin{lstlisting}\n%s\n\\end{lstlisting}" "code"
|
||||
|
||||
let ast_to_latex (file : A.source_file) : string =
|
||||
String.concat "\n\n" (List.map (fun i ->
|
1
test/.gitignore
vendored
Normal file
1
test/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.tex
|
@ -1,6 +1,6 @@
|
||||
@@ Code de la sécurité sociale @@
|
||||
@@Code de la sécurité sociale@@
|
||||
|
||||
@ Article L521-3 @
|
||||
@Article L521-3@
|
||||
|
||||
Blablabla, etc
|
||||
|
||||
@ -14,4 +14,4 @@ code
|
||||
|
||||
*/
|
||||
|
||||
@ Article L522-3 @
|
||||
@Article L522-3@
|
||||
|
Loading…
Reference in New Issue
Block a user