mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-09 22:16:10 +03:00
Pretty print math symbols in html and latex outputs
This commit is contained in:
parent
1122ca42ae
commit
4464417ec9
@ -153,11 +153,21 @@ let program_item_to_html (i : A.program_item) (custom_pygments : string option)
|
||||
| _ -> "#" )
|
||||
(pre_html (Pos.unmark a.law_article_name))
|
||||
| A.CodeBlock (_, c) | A.MetadataBlock (_, c) ->
|
||||
let syms = R.regexp "!=|<=|>=|--|->" in
|
||||
let syms_subst = function
|
||||
| "!=" -> "≠"
|
||||
| "<=" -> "≤"
|
||||
| ">=" -> "≥"
|
||||
| "--" -> "—"
|
||||
| "->" -> "→"
|
||||
| s -> s
|
||||
in
|
||||
let pprinted_c = R.substitute ~rex:syms ~subst:syms_subst (Pos.unmark c) in
|
||||
let formatted_original_code =
|
||||
P.sprintf "<div class='code-wrapper'>\n<div class='filename'>%s</div>\n%s\n</div>"
|
||||
(Pos.get_file (Pos.get_position c))
|
||||
(pygmentize_code
|
||||
(Pos.same_pos_as ("/*" ^ Pos.unmark c ^ "*/") c)
|
||||
(Pos.same_pos_as ("/*" ^ pprinted_c ^ "*/") c)
|
||||
language custom_pygments)
|
||||
in
|
||||
formatted_original_code
|
||||
|
@ -98,6 +98,18 @@ let wrap_latex (code : string) (source_files : string list) (custom_pygments : s
|
||||
source_files))
|
||||
code
|
||||
|
||||
let math_syms_replace (c : string) : string =
|
||||
let syms = R.regexp "!=|<=|>=|--|->" in
|
||||
let syms2cmd = function
|
||||
| "!=" -> "$\\neq$"
|
||||
| "<=" -> "$\\leq$"
|
||||
| ">=" -> "$\\geq$"
|
||||
| "--" -> "\\textemdash"
|
||||
| "->" -> "$\\rightarrow$"
|
||||
| s -> s
|
||||
in
|
||||
R.substitute ~rex:syms ~subst:(fun s -> "|" ^ syms2cmd s ^ "|") c
|
||||
|
||||
let program_item_to_latex (i : A.program_item) (language : C.language_option) : string =
|
||||
match i with
|
||||
| A.LawHeading (title, precedence) ->
|
||||
@ -108,26 +120,27 @@ let program_item_to_latex (i : A.program_item) (language : C.language_option) :
|
||||
| A.LawArticle a -> P.sprintf "\\paragraph{%s}" (pre_latexify (Pos.unmark a.law_article_name))
|
||||
| A.CodeBlock (_, c) ->
|
||||
P.sprintf
|
||||
"\\begin{minted}[label={\\hspace*{\\fill}\\texttt{%s}},firstnumber=%d]{%s}\n\
|
||||
"\\begin{minted}[escapeinside=||,mathescape=true,label={\\hspace*{\\fill}\\texttt{%s}},firstnumber=%d]{%s}\n\
|
||||
/*%s*/\n\
|
||||
\\end{minted}"
|
||||
(pre_latexify (Filename.basename (Pos.get_file (Pos.get_position c))))
|
||||
(Pos.get_start_line (Pos.get_position c) + 1)
|
||||
(match language with C.Fr -> "catala_fr" | C.En -> "catala_en")
|
||||
(Pos.unmark c)
|
||||
(math_syms_replace (Pos.unmark c))
|
||||
| A.MetadataBlock (_, c) ->
|
||||
P.sprintf
|
||||
"\\begin{tcolorbox}[colframe=OliveGreen, breakable, \
|
||||
title=\\textcolor{black}{\\texttt{Métadonnées}},title after \
|
||||
break=\\textcolor{black}{\\texttt{Métadonnées}},before skip=1em, after skip=1em]\n\
|
||||
\\begin{minted}[numbersep=9mm, firstnumber=%d, label={\\hspace*{\\fill}\\texttt{%s}}]{%s}\n\
|
||||
\\begin{minted}[escapeinside=||,mathescape=true,numbersep=9mm, firstnumber=%d, \
|
||||
label={\\hspace*{\\fill}\\texttt{%s}}]{%s}\n\
|
||||
/*%s*/\n\
|
||||
\\end{minted}\n\
|
||||
\\end{tcolorbox}"
|
||||
(Pos.get_start_line (Pos.get_position c) + 1)
|
||||
(pre_latexify (Filename.basename (Pos.get_file (Pos.get_position c))))
|
||||
(match language with C.Fr -> "catala_fr" | C.En -> "catala_en")
|
||||
(Pos.unmark c)
|
||||
(math_syms_replace (Pos.unmark c))
|
||||
| A.LawInclude (A.PdfFile ((file, _), page)) ->
|
||||
let label = file ^ match page with None -> "" | Some p -> P.sprintf "_page_%d," p in
|
||||
P.sprintf
|
||||
|
Loading…
Reference in New Issue
Block a user