Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file latex.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289(* This file is part of the Catala compiler, a specification language for tax
and social benefits computation rules. Copyright (C) 2020 Inria,
contributors: Denis Merigoux <denis.merigoux@inria.fr>, Emile Rolley
<emile.rolley@tuta.io>
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License. *)(** This modules weaves the source code and the legislative text together into a
document that law professionals can understand. *)openUtilsopenLiterate_commonmoduleA=Surface.AstmoduleR=Re.PcremoduleC=Cli(** {1 Helpers} *)(** Espaces various LaTeX-sensitive characters *)letpre_latexify(s:string):string=(* Then we send to pandoc, to ensure the markdown features used in the
original document are correctly printed! *)String.trim(run_pandocs`Latex)(** Usage: [wrap_latex source_files custom_pygments language fmt wrapped]
Prints an LaTeX complete documùent structure around the [wrapped] content. *)letwrap_latex(source_files:stringlist)(language:C.backend_lang)(fmt:Format.formatter)(wrapped:Format.formatter->unit)=Format.fprintffmt{latex|\documentclass[%s, 11pt, a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{babel}
\usepackage{fontspec}
\usepackage[hidelinks]{hyperref}
%s
\usepackage{minted}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{newunicodechar}
\usepackage{textcomp}
\usepackage[hidelinks]{hyperref}
\usepackage[dvipsnames]{xcolor}
\usepackage[left=2cm,right=2cm,top=3cm,bottom=3cm,headheight=2cm]{geometry}
\usepackage[many]{tcolorbox}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhead[C]{\leftmark}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0.5pt}
\renewcommand{\footrulewidth}{0.5pt}
\usepackage{titlesec}
\titleclass{\subsubsubsection}{straight}[\subsection]
\newcounter{subsubsubsection}[subsubsection]
\renewcommand\thesubsubsubsection{\thesubsubsection.\arabic{subsubsubsection}}
\titleformat{\subsubsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsubsection}{1em}{}
\titlespacing*{\subsubsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titleclass{\subsubsubsubsection}{straight}[\subsubsection]
\newcounter{subsubsubsubsection}[subsubsubsection]
\renewcommand\thesubsubsubsubsection{\thesubsubsubsection.\arabic{subsubsubsubsection}}
\titleformat{\subsubsubsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsubsubsection}{0.75em}{}
\titlespacing*{\subsubsubsubsection}{0pt}{2.75ex plus 1ex minus .2ex}{1.25ex plus .2ex}
\titleclass{\subsubsubsubsubsection}{straight}[\subsubsubsection]
\newcounter{subsubsubsubsubsection}[subsubsubsubsection]
\renewcommand\thesubsubsubsubsubsection{\thesubsubsubsubsection.\arabic{subsubsubsubsubsection}}
\titleformat{\subsubsubsubsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsubsubsubsection}{0.7em}{}
\titlespacing*{\subsubsubsubsubsection}{0pt}{2.5ex plus 1ex minus .2ex}{1.1ex plus .2ex}
\titleclass{\subsubsubsubsubsubsection}{straight}[\subsubsubsubsection]
\newcounter{subsubsubsubsubsubsection}[subsubsubsubsubsection]
\renewcommand\thesubsubsubsubsubsubsection{\thesubsubsubsubsubsection.\arabic{subsubsubsubsubsubsection}}
\titleformat{\subsubsubsubsubsubsection}{\normalfont\normalsize\bfseries}{\thesubsubsubsubsubsubsection}{0.6em}{}
\titlespacing*{\subsubsubsubsubsubsection}{0pt}{2.25ex plus 1ex minus .2ex}{1ex plus .2ex}
\makeatletter
\def\toclevel@subsubsubsection{4}
\def\toclevel@subsubsubsubsection{5}
\def\toclevel@subsubsubsubsubsection{6}
\def\toclevel@subsubsubsubsubsubsection{7}
\def\toclevel@paragraph{8}
\def\toclevel@subparagraph{9}
\def\l@subsection{\@dottedtocline{1}{1em}{0.5em}}
\def\l@subsubsection{\@dottedtocline{2}{2em}{1em}}
\def\l@subsubsubsection{\@dottedtocline{3}{3em}{1.5em}}
\def\l@subsubsubsubsection{\@dottedtocline{5}{4em}{2em}}
\def\l@subsubsubsubsubsection{\@dottedtocline{6}{5em}{2.5em}}
\def\l@subsubsubsubsubsubsection{\@dottedtocline{7}{6em}{3em}}
\def\l@paragraph{\@dottedtocline{8}{7em}{3.5em}}
\def\l@subparagraph{\@dottedtocline{9}{8em}{4em}}
\makeatother
\setcounter{secnumdepth}{0}
\setcounter{tocdepth}{9}
\newunicodechar{÷}{$\div$}
\newunicodechar{×}{$\times$}
\newunicodechar{≤}{$\leqslant$}
\newunicodechar{≥}{$\geqslant$}
\newunicodechar{→}{$\rightarrow$}
\newunicodechar{≠}{$\neq$}
\newcommand*\FancyVerbStartString{```catala}
\newcommand*\FancyVerbStopString{```}
\fvset{
numbers=left,
frame=lines,
framesep=3mm,
rulecolor=\color{gray!70},
firstnumber=last,
codes={\catcode`\$=3\catcode`\^=7}
}
\newcommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\title{
%s\\
%s Catala version %s
}
\begin{document}
\maketitle
%s
%s :
\begin{itemize}%s\end{itemize}
\clearpage
\tableofcontents
\[\star\star\star\]
\clearpage|latex}(matchlanguagewithFr->"french"|En->"english"|Pl->"polish")(matchlanguagewithFr->"\\setmainfont{Marianne}"|_->"")(* for France, we use the official font of the French state design system
https://gouvfr.atlassian.net/wiki/spaces/DB/pages/223019527/Typographie+-+Typography *)(literal_titlelanguage)(literal_generated_bylanguage)Utils.Cli.version(pre_latexify(literal_disclaimer_and_linklanguage))(literal_source_fileslanguage)(String.concat((matchlanguagewithFr->" ;"|En->";"|Pl->";")^"\n")(List.map(funfilename->letmtime=(Unix.statfilename).Unix.st_mtimeinletltime=Unix.localtimemtimeinletftime=Printf.sprintf"%d-%02d-%02d %d:%02d"(1900+ltime.Unix.tm_year)(ltime.Unix.tm_mon+1)ltime.Unix.tm_mdayltime.Unix.tm_hourltime.Unix.tm_mininPrintf.sprintf"\\item\\texttt{%s}, %s %s"(pre_latexify(Filename.basenamefilename))(literal_last_modificationlanguage)ftime)source_files)^".");wrappedfmt;Format.fprintffmt"\n\n\\end{document}"(** {1 Weaving} *)(** [check_exceeding_lines max_len start_line filename content] prints a warning
message for each lines of [content] exceeding [max_len] characters. *)letcheck_exceeding_lines?(max_len=80)(start_line:int)(filename:string)(content:string)=content|>String.split_on_char'\n'|>List.iteri(funis->ifString.length(Ubase.from_utf8s)(* we remove diacritics to avoid false positives due to UFT8 encoding
not taken into account by String *)>max_lenthen(Cli.warning_print"The line %s in %s is exceeding %s characters:"(Cli.with_styleANSITerminal.[Bold;yellow]"%d"(start_line+i+1))(Cli.with_styleANSITerminal.[Bold;magenta]"%s"filename)(Cli.with_styleANSITerminal.[Bold;red]"%d"max_len);Cli.warning_print"%s%s"(String.subs0max_len)(Cli.with_styleANSITerminal.[red]"%s"String.(subsmax_len(lengths-max_len)))))letreclaw_structure_to_latex(language:C.backend_lang)(print_only_law:bool)(fmt:Format.formatter)(i:A.law_structure):unit=matchiwith|A.LawHeading(heading,children)->Format.fprintffmt"\\%s{%s}\n\n"(matchheading.law_heading_precedencewith|0->"section"|1->"subsection"|2->"subsubsection"|3->"subsubsubsection"|4->"subsubsubsubsection"|5->"subsubsubsubsubsection"|6->"subsubsubsubsubsubsection"|7->"paragraph"|_->"subparagraph")(pre_latexify(Marked.unmarkheading.law_heading_name));Format.pp_print_list~pp_sep:(funfmt()->Format.fprintffmt"\n\n")(law_structure_to_latexlanguageprint_only_law)fmtchildren|A.LawInclude(A.PdfFile((file,_),page))->letlabel=file^matchpagewithNone->""|Somep->Format.sprintf"_page_%d,"pinFormat.fprintffmt"\\begin{center}\\textit{Annexe incluse, retranscrite page \
\\pageref{%s}}\\end{center} \
\\begin{figure}[p]\\begin{center}\\includegraphics[%swidth=\\textwidth]{%s}\\label{%s}\\end{center}\\end{figure}"label(matchpagewithNone->""|Somep->Format.sprintf"page=%d,"p)filelabel|A.LawInclude(A.CatalaFile_|A.LegislativeText_)->()|A.LawTextt->Format.fprintffmt"%s"(pre_latexifyt)|A.CodeBlock(_,c,false)whennotprint_only_law->Format.fprintffmt"\\begin{minted}[label={\\hspace*{\\fill}\\texttt{%s}},firstnumber=%d]{%s}\n\
```catala\n\
%s```\n\
\\end{minted}"(pre_latexify(Filename.basename(Pos.get_file(Marked.get_markc))))(Pos.get_start_line(Marked.get_markc)-1)(get_language_extensionlanguage)(Marked.unmarkc)|A.CodeBlock(_,c,true)whennotprint_only_law->letmetadata_title=matchlanguagewith|Fr->"Métadonnées"|En->"Metadata"|Pl->"Metadane"inletstart_line=Pos.get_start_line(Marked.get_markc)-1inletfilename=Filename.basename(Pos.get_file(Marked.get_markc))inletblock_content=Marked.unmarkcincheck_exceeding_linesstart_linefilenameblock_content;Format.fprintffmt"\\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, breaklines, \
label={\\hspace*{\\fill}\\texttt{%s}}]{%s}\n\
```catala\n\
%s```\n\
\\end{minted}\n\
\\end{tcolorbox}"metadata_titlemetadata_titlestart_line(pre_latexifyfilename)(get_language_extensionlanguage)block_content|A.CodeBlock_->()(** {1 API} *)letast_to_latex(language:C.backend_lang)~(print_only_law:bool)(fmt:Format.formatter)(program:A.program):unit=Format.pp_print_list~pp_sep:(funfmt()->Format.fprintffmt"\n\n")(law_structure_to_latexlanguageprint_only_law)fmtprogram.program_items