refactor(latex): print warning for too long lines + add instruction to compilation

This commit is contained in:
Emile Rolley 2022-05-01 16:53:04 +02:00
parent ad7fe6a21a
commit ce2c7081b0
2 changed files with 35 additions and 7 deletions

View File

@ -173,6 +173,26 @@ let wrap_latex
(** {1 Weaving} *)
(** [check_exceeding_lines max_len start_line filename content] prints a warning
message for each lines of [content] exceeding [max_len] characters. *)
let check_exceeding_lines
?(max_len = 80) (start_line : int) (filename : string) (content : string) =
content |> String.split_on_char '\n'
|> List.iteri (fun i s ->
if String.length s > max_len then (
Cli.warning_print "The line %s in %s is exceeding %s characters:"
(Cli.with_style
ANSITerminal.[ Bold; yellow ]
"%d"
(start_line + i + 1))
(Cli.with_style ANSITerminal.[ Bold; magenta ] "%s" filename)
(Cli.with_style ANSITerminal.[ Bold; red ] "%d" max_len);
Cli.warning_print "%s%s" (String.sub s 0 max_len)
(Cli.with_style
ANSITerminal.[ red ]
"%s"
String.(sub s max_len (length s - max_len)))))
let rec law_structure_to_latex
(language : C.backend_lang) (fmt : Format.formatter) (i : A.law_structure) :
unit =
@ -225,22 +245,24 @@ let rec law_structure_to_latex
| En -> "Metadata"
| Pl -> "Metadane"
in
let start_line = Pos.get_start_line (Pos.get_position c) - 1 in
let filename = Filename.basename (Pos.get_file (Pos.get_position c)) in
let block_content = Pos.unmark c in
check_exceeding_lines start_line filename block_content;
Format.fprintf fmt
"\\begin{tcolorbox}[colframe=OliveGreen, breakable, \
title=\\textcolor{black}{\\texttt{%s}},title after \
break=\\textcolor{black}{\\texttt{%s}},before skip=1em, after \
skip=1em]\n\
\\begin{minted}[numbersep=9mm, firstnumber=%d, \
\\begin{minted}[breaklines, numbersep=9mm, firstnumber=%d, \
label={\\hspace*{\\fill}\\texttt{%s}}]{%s}\n\
```catala\n\
%s```\n\
\\end{minted}\n\
\\end{tcolorbox}"
metadata_title metadata_title
(Pos.get_start_line (Pos.get_position c) - 1)
(pre_latexify (Filename.basename (Pos.get_file (Pos.get_position c))))
metadata_title metadata_title start_line (pre_latexify filename)
(get_language_extension language)
(Pos.unmark c)
block_content
(** {1 API} *)

View File

@ -25,7 +25,7 @@ of the Catala programming language development.
Building and running examples is done via Makefiles. Each example directory
contains its own Makefile, which includes `Makefile.common.mk`. This common
Makefiles defines a list of targets that call the Catala compiler with the
right options. Each of these targers can be called from the root of the
right options. Each of these targets can be called from the root of the
repository with:
make -C examples/<directory of example> <name of target>
@ -44,7 +44,13 @@ file `examples/foo/foo.catala_en`) list.
When invoking any of these targets, additional options to the Catala compiler
can be passed using the `CATALA_OPTS` Makefile variable.
> **Remark**: don't forget to run `make pygments` before generating LaTex or PDF files.
Important
: Before trying to generates LaTex or PDF files:
1. don't forget to run `make pygments`,
2. and you need to have the font
[Marianne](https://gouvfr.atlassian.net/wiki/spaces/DB/pages/223019527/Typographie+-+Typography)
installed in your machine.
## Testing examples