Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file latex.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342(* 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. *)openCatala_utilsopenLiterate_commonmoduleA=Surface.AstmoduleC=Global(** {1 Helpers} *)letlines_of_code=ref0letupdate_lines_of_codec=lines_of_code:=!lines_of_code+Pos.get_end_line(Mark.getc)-Pos.get_start_line(Mark.getc)-1(** Escapes 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{fancyvrb,fvextra}
\usepackage{color}
\usepackage{longtable}
\usepackage{booktabs,tabularx}
\usepackage{newunicodechar}
\usepackage{textcomp}
\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$}
%s
\newcommand*\FancyVerbStartString{\PY{l+s}{```catala}}
\newcommand*\FancyVerbStopString{\PY{l+s}{```}}
%% We have to do that to enable line breaks in pygmentize outputs:
\let\oldPY\PY
\renewcommand{\PY}[2]{%%
\oldPY{#1}{\FancyVerbBreakStart{}#2\FancyVerbBreakStop{}}}
\fvset{
numbers=left,
frame=lines,
framesep=3mm,
breaklines,
breakanywhere,
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 *)(call_pygmentize["-f";"latex";"-S";"default"])(literal_titlelanguage)(literal_generated_bylanguage)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} *)letcode_block~metalangfmt(code,pos)=(* Pygments does'nt allow to specify multiple 'verboptions' (escaping bug ?)
so we call it with "nowrap" and write the FancyVrb wrapper ourselves. *)letpygmentized_code=letcontents=String.concat""["```catala\n";code;"```"]inletoutput=File.with_temp_file"catala_latex_pygments""in"~contents@@funtemp_file_in->call_pygmentize~lang["-f";"latex";"-O";"\"nowrap\"";temp_file_in]in(* somehow even with the "nowrap" option on [pygmentize] still emits a
wrapping [Verbatim] env. So we remove it with regexp finding. *)letenv_rex=Re.compile@@Re.seq[Re.char'\\';Re.alt[Re.str"begin";Re.str"end"];Re.str"{Verbatim}";Re.opt(Re.seq[Re.char'[';Re.rep(Re.diffRe.any(Re.char']'));Re.char']';]);Re.char'\n';]inRe.replace_stringenv_rex~by:""outputinFormat.fprintffmt{latex|\begin{Verbatim}[commandchars=\\\{\},numbers=left,firstnumber=%d,stepnumber=1,label={\hspace*{\fill}\texttt{%s}}%s]|latex}(Pos.get_start_linepos+1)(pre_latexify(Filename.basename(Pos.get_filepos)))(ifmetathen",numbersep=9mm"else"");Format.pp_print_newlinefmt();Format.pp_print_stringfmtpygmentized_code;Format.pp_print_stringfmt"\\end{Verbatim}\n"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(Mark.removeheading.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.ModuleDef(id,extern)->(matchlanguagewith|Fr->Format.fprintffmt"\n\\textbf{Ceci définit le module %s \\texttt{%s}}"(ifexternthen"externe"else"catala")|_->Format.fprintffmt"\n\\textbf{This defines the %s module \\texttt{%s}}"(ifexternthen"external"else"catala"))(pre_latexify(Mark.removeid))|A.ModuleUse(id,alias)->((matchlanguagewith|Fr->Format.fprintffmt"\n\\textbf{Ce qui suit utilise le module \\texttt{%s}"|_->Format.fprintffmt"\n\\textbf{The following makes use of the module \\texttt{%s}")(pre_latexify(Mark.removeid));matchaliaswith|None->Format.fprintffmt"}"|Someal->(matchlanguagewith|Fr->Format.fprintffmt" sous le nom \\texttt{%s}}"|_->Format.fprintffmt" under the name \\texttt{%s}}")(pre_latexify(Mark.removeal)))|A.LawTextt->Format.fprintffmt"%s"(pre_latexifyt)|A.CodeBlock(_,c,false)whennotprint_only_law->letstart_line=Pos.get_start_line(Mark.getc)+1inletfilename=Pos.get_file(Mark.getc)inletblock_content=Mark.removecincheck_exceeding_linesstart_linefilenameblock_content;update_lines_of_codec;code_block~meta:falselanguagefmtc|A.CodeBlock(_,c,true)whennotprint_only_law->letmetadata_title=matchlanguagewith|Fr->"Métadonnées"|En->"Metadata"|Pl->"Metadane"inletstart_line=Pos.get_start_line(Mark.getc)+1inletfilename=Pos.get_file(Mark.getc)inletblock_content=Mark.removecincheck_exceeding_linesstart_linefilenameblock_content;update_lines_of_codec;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\
%a\n\
\\end{tcolorbox}"metadata_titlemetadata_title(code_block~meta:truelanguage)c|A.CodeBlock_->()(** {1 API} *)letast_to_latex(language:C.backend_lang)~(print_only_law:bool)(fmt:Format.formatter)(program:A.program):unit=Format.pp_open_vboxfmt0;List.iter(funitem->law_structure_to_latexlanguageprint_only_lawfmtitem;Format.pp_print_cutfmt())program.program_items;Format.pp_close_boxfmt();Message.debug"Lines of Catala inside literate source code: %d"!lines_of_code