mirror of
https://github.com/CatalaLang/catala.git
synced 2024-11-09 22:16:10 +03:00
Merge pull request #12 from CatalaLang/mathsymbols
Pretty print maths symbols in html and latex outputs
This commit is contained in:
commit
3a7030ded7
@ -153,11 +153,24 @@ 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 date = "\\d\\d/\\d\\d/\\d\\d\\d\\d" in
|
||||
let syms = R.regexp (date ^ "|!=|<=|>=|--|->|\*|\/") 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
|
||||
|
@ -38,12 +38,20 @@ let wrap_latex (code : string) (source_files : string list) (custom_pygments : s
|
||||
\\usepackage[%s]{babel}\n\
|
||||
\\usepackage{lmodern}\n\
|
||||
\\usepackage{minted}\n\
|
||||
\\usepackage{amssymb}\n\
|
||||
\\usepackage{newunicodechar}\n\
|
||||
%s\n\
|
||||
\\usepackage{textcomp}\n\
|
||||
\\usepackage[hidelinks]{hyperref}\n\
|
||||
\\usepackage[dvipsnames]{xcolor}\n\
|
||||
\\usepackage{fullpage}\n\
|
||||
\\usepackage[many]{tcolorbox}\n\n\
|
||||
\\newunicodechar{÷}{$\\div$}\n\
|
||||
\\newunicodechar{×}{$\\times$}\n\
|
||||
\\newunicodechar{≤}{$\\leqslant$}\n\
|
||||
\\newunicodechar{≥}{$\\geqslant$}\n\
|
||||
\\newunicodechar{→}{$\\rightarrow$}\n\
|
||||
\\newunicodechar{≠}{$\\neq$}\n\n\
|
||||
\\fvset{\n\
|
||||
commandchars=\\\\\\{\\},\n\
|
||||
numbers=left,\n\
|
||||
@ -98,6 +106,21 @@ let wrap_latex (code : string) (source_files : string list) (custom_pygments : s
|
||||
source_files))
|
||||
code
|
||||
|
||||
let math_syms_replace (c : string) : string =
|
||||
let date = "\\d\\d/\\d\\d/\\d\\d\\d\\d" in
|
||||
let syms = R.regexp (date ^ "|!=|<=|>=|--|->|\*|/") in
|
||||
let syms2cmd = function
|
||||
| "!=" -> "≠"
|
||||
| "<=" -> "≤"
|
||||
| ">=" -> "≥"
|
||||
| "--" -> "—"
|
||||
| "->" -> "→"
|
||||
| "*" -> "×"
|
||||
| "/" -> "÷"
|
||||
| s -> s
|
||||
in
|
||||
R.substitute ~rex:syms ~subst:syms2cmd c
|
||||
|
||||
let program_item_to_latex (i : A.program_item) (language : C.language_option) : string =
|
||||
match i with
|
||||
| A.LawHeading (title, precedence) ->
|
||||
@ -114,7 +137,7 @@ let program_item_to_latex (i : A.program_item) (language : C.language_option) :
|
||||
(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, \
|
||||
@ -127,7 +150,7 @@ let program_item_to_latex (i : A.program_item) (language : C.language_option) :
|
||||
(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