Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow generation of one latex file from multiple sources, and fixes #583

Merged
merged 3 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/catala_utils/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ module Flags = struct
| _ -> assert false )
in
required
& pos ~rev:true 0 (some converter) None
& pos 0 (some converter) None
& Arg.info [] ~docv:"FILE" ~docs:Manpage.s_arguments
~doc:"Catala master file to be compiled ($(b,-) for stdin)."

Expand Down Expand Up @@ -448,6 +448,12 @@ 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."
AltGr marked this conversation as resolved.
Show resolved Hide resolved
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
30 changes: 25 additions & 5 deletions compiler/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,15 @@ 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 +473,22 @@ 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 +500,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
12 changes: 7 additions & 5 deletions compiler/literate/latex.ml
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,19 @@ let rec law_structure_to_latex
file label
| A.LawInclude (A.CatalaFile _ | A.LegislativeText _) -> ()
| A.ModuleDef (id, extern) ->
Format.fprintf fmt "\n\\textbf{This defines the %s module \\textsc{%s}}"
Format.fprintf fmt
"\n\\textbf{This defines the \\texttt{%s} module \\texttt{%s}}"
(if extern then "external" else "catala")
(Mark.remove id)
(pre_latexify (Mark.remove id))
| A.ModuleUse (id, alias) -> (
Format.fprintf fmt
"\n\\textbf{The following makes use of the module \\textsc{%s}"
(Mark.remove id);
"\n\\textbf{The following makes use of the module \\texttt{%s}"
(pre_latexify (Mark.remove id));
match alias with
| None -> Format.fprintf fmt "}"
| Some al ->
Format.fprintf fmt " under the name \\textsc{%s}" (Mark.remove al))
Format.fprintf fmt " under the name \texttt{%s}"
(pre_latexify (Mark.remove al)))
| A.LawText t -> Format.fprintf fmt "%s" (pre_latexify t)
| A.CodeBlock (_, c, false) when not print_only_law ->
let start_line = Pos.get_start_line (Mark.get c) - 1 in
Expand Down
2 changes: 1 addition & 1 deletion tests/literate/good/test_grave_char_en.catala_en
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $ catala Interpret -s A
```catala-test-inline
$ catala latex

\textbf{This defines the catala module \textsc{Test_grave_char_en}}
\textbf{This defines the \texttt{catala} module \texttt{Test\_grave\_char\_en}}

\subsection{Law text should be able to contain grave accent ``'.}

Expand Down
Loading