Skip to content

Commit

Permalink
Allow generation of one latex file from multiple sources
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Feb 15, 2024
1 parent c13cb21 commit 4fb424d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
7 changes: 7 additions & 0 deletions compiler/catala_utils/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,13 @@ module Flags = struct
"Disables the search for counterexamples. Useful when you want a \
deterministic output from the Catala compiler, since provers can \
have some randomness in them."

let extra_files =
value
& pos_right 0 file []
& Arg.info [] ~docv:"FILE" ~docs:Manpage.s_arguments
~doc:"Additional input files."

end

(* Retrieve current version from dune *)
Expand Down
1 change: 1 addition & 0 deletions compiler/catala_utils/cli.mli
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module Flags : sig
val no_struct_literals : bool Term.t
val include_dirs : raw_file list Term.t
val disable_counterexamples : bool Term.t
val extra_files : file list Term.t
end

(** {2 Command-line application} *)
Expand Down
22 changes: 17 additions & 5 deletions compiler/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,14 @@ module Commands = struct
$ Cli.Flags.print_only_law
$ Cli.Flags.wrap_weaved_output)

let latex options output print_only_law wrap_weaved_output =
let latex options output print_only_law wrap_weaved_output extra_files =
let prg = Passes.surface options in
let prg_annex =
List.map (fun f ->
Surface.Parser_driver.parse_top_level_file (FileName f)
|> Surface.Fill_positions.fill_pos_with_legislative_info)
extra_files
in
Message.emit_debug "Weaving literate program into LaTeX";
let output_file, with_output =
get_output_format options ~ext:".tex" output
Expand All @@ -466,10 +472,15 @@ module Commands = struct
let weave_output = Literate.Latex.ast_to_latex language ~print_only_law in
Message.emit_debug "Writing to %s"
(Option.value ~default:"stdout" output_file);
let weave fmt =
weave_output fmt prg;
List.iter (fun p -> Format.fprintf fmt "@,\\newpage@,"; weave_output fmt p) prg_annex
in
if wrap_weaved_output then
Literate.Latex.wrap_latex prg.Surface.Ast.program_source_files language
fmt (fun fmt -> weave_output fmt prg)
else weave_output fmt prg
Literate.Latex.wrap_latex
(List.flatten (List.map (fun p -> p.Surface.Ast.program_source_files) (prg::prg_annex)))
language fmt weave
else weave fmt

let latex_cmd =
Cmd.v
Expand All @@ -481,7 +492,8 @@ module Commands = struct
$ Cli.Flags.Global.options
$ Cli.Flags.output
$ Cli.Flags.print_only_law
$ Cli.Flags.wrap_weaved_output)
$ Cli.Flags.wrap_weaved_output
$ Cli.Flags.extra_files)

let exceptions options includes ex_scope ex_variable =
let prg, ctxt = Passes.desugared options ~includes in
Expand Down

0 comments on commit 4fb424d

Please sign in to comment.