Commit a741e2f474c8ef95f093e7f7351fcee7dc4b83ee

Authored by Olivier Duvernois
1 parent cb876d87

*** empty log message ***

anubis_dev/library/tools/latex.anubis
... ... @@ -145,20 +145,27 @@ define String
145 145 (
146 146 String more_ahead
147 147 ) =
148   - "\\documentclass[a4paper, 11pt]{article}\n\n"
  148 + "\\documentclass[a4paper,twoside,10pt]{article}\n\n"
  149 + + "\\setlength{\\headheight}{15pt}\n"
  150 + + "\\setlength{\\headsep}{0.5cm}\n"
149 151 + "\\setlength{\\headheight}{15pt}\n"
150 152 + "\\setlength{\\marginparwidth}{0pt}\n"
151 153 + "\\setlength{\\oddsidemargin}{0pt}\n"
152 154 + "\\setlength{\\evensidemargin}{0pt}\n"
153 155 + "\\setlength{\\textwidth}{17cm}\n"
  156 + + "\\setlength{\\textheight}{23.7cm}\n"
154 157 + "\\setlength{\\parindent}{0pt}\n"
155 158 + "\\usepackage[francais]{babel}\n"
156 159 + "\\usepackage[utf8]{inputenc}\n"
157 160 + "\\usepackage{color}\n"
158 161 + "\\usepackage{graphics}\n"
  162 + + "\\usepackage{longtable}\n"
159 163 + "\\usepackage{fancyhdr}\n"
  164 + + "\\fancyhead{}\n"
  165 + + "\\fancyhead[LE]{\\thepage \\ \\ \\ \\textsl{\\leftmark} \\hfill}\n"
  166 + + "\\fancyhead[RO]{\\hfill \\textsl{\\rightmark} \\ \\ \\ \\thepage}\n"
  167 + + "\\fancyfoot{}\n"
160 168 + "\\pagestyle{fancy}\n"
161   - + "\\lhead{\\itshape Tutoriel Anubis}\n"
162 169 + "\\renewcommand{\\headrulewidth}{0.4pt}\n\n"
163 170 + more_ahead
164 171 + "\n\n".
... ... @@ -171,16 +178,20 @@ public define String
171 178 latex_page
172 179 (
173 180 String more_ahead,
  181 + Bool exist_title,
174 182 String text_from_maml,
175   - Bool table_of_contents
  183 + Bool table_of_contents,
  184 + String colors,
176 185 ) =
177 186 latex_head(more_ahead)
178 187 + "\\begin{document}\n\n"
  188 + + colors
179 189 + "\\begin{sloppypar}\n\n"
  190 + + (if exist_title then "\\maketitle \n \\thispagestyle{empty} \n \\newpage \n " else "")
  191 + + (if table_of_contents then "\\tableofcontents \n \\newpage \n" else "")
180 192 + text_from_maml
181 193 + "\n\n"
182 194 + "\\end{sloppypar}\n\n"
183   - + (if table_of_contents then "\\newpage \n \\tableofcontents \n" else "")
184 195 + "\\end{document}\n\n".
185 196  
186 197  
... ...
anubis_dev/library/tools/maml.anubis
... ... @@ -101,8 +101,9 @@ public define Result(Int32,MAML) parse_MAML(Stream s).
101 101 MAML parse trees may be translated into various formats.
102 102  
103 103 public define Text to_HTML (MAML m).
104   -public define Text to_LaTeX (MAML m).
  104 +public define Text to_LaTeX (MAML m,String public_dir).
105 105  
  106 + 'public_dir' is the directory where images are stored.
106 107  
107 108  
108 109 For compatibility with maml.anubis version 1 we provide the following functions:
... ... @@ -116,7 +117,8 @@ public define Result(Int32,String)
116 117 public define Result(Int32,String)
117 118 convert_MAML_to_LaTeX
118 119 (
119   - String maml
  120 + String maml,
  121 + String public_dir
120 122 ).
121 123  
122 124  
... ... @@ -539,13 +541,25 @@ define Text
539 541 (
540 542 String name
541 543 ) =
542   - if name = "dollar" then t-"\\$" else
543   - if name = "lpar" then t-"(" else
544   - if name = "rpar" then t-")" else
545   - if name = "par" then t-"\n\n" else
546   - if name = "item" then t-"\\item " else
  544 + if name = "dollar" then t-"\\$" else
  545 + if name = "lpar" then t-"(" else
  546 + if name = "rpar" then t-")" else
  547 + if name = "par" then t-"\n\n \\smallskip \n" else
  548 + if name = "item" then t-"\\item " else
547 549 alert.
  550 +
  551 +
  552 + Définition de couleurs
  553 + ----------------------
548 554  
  555 + Pour définir une couleur RGG, donner un nombre en 0 et 1 pour chacune des couleurs de base
  556 + Pour définir un gris, donner un nombre entre 0 (noir) et 1 (blanc)
  557 +
  558 +public define String
  559 + maml_LaTeX_colors
  560 + =
  561 + "\\definecolor{my_green}{rgb}{0.27,0.51,0.27}\n"
  562 + + "\\definecolor{my_grey}{gray}{0.25}\n".
549 563  
550 564  
551 565 Prise en compte de la balise 'big' de MAML
... ... @@ -582,6 +596,43 @@ define (String,MAML)
582 596 else (big_to_LaTeX(bigger),next).
583 597  
584 598  
  599 +
  600 +
  601 + Balise 'image'
  602 + -------------
  603 +
  604 + Le nom de l'image est sous la forme :
  605 + http://www.anubis-language.com/image.gif
  606 +
  607 + length("http://www.anubis-language.com/" = 31
  608 +
  609 +define String
  610 + get_eps_name
  611 + (
  612 + String image_path
  613 + ) =
  614 + with l = length(image_path),
  615 + img_name = substr(image_path,31,l-31),
  616 + li = length(img_name),
  617 + ext = substr(img_name,li-3,3),
  618 + if member(["gif","GIF","jpg","JPG"],ext)
  619 + then (substr(img_name,0,li-3)+"ps")
  620 + else img_name.
  621 +
  622 +define Text
  623 + image_to_LaTeX
  624 + (
  625 + MAML m,
  626 + MAML -> Text to_LaTeX,
  627 + String public_dir
  628 + ) =
  629 + if m is text(te)
  630 + then if te is Text _ - String s
  631 + then (t-("\\includegraphics{"+public_dir+"/"+get_eps_name(s)+"}"))
  632 + else to_LaTeX(m)
  633 + else to_LaTeX(m).
  634 +
  635 +
585 636  
586 637 Prise en compte de la balise 'code' de MAML
587 638 -------------------------------------------
... ... @@ -594,7 +645,7 @@ define (String,MAML)
594 645  
595 646  
596 647  
597   - Le code est écrit dans un environnement tabular.
  648 + Le code est écrit dans un environnement longtable
598 649  
599 650 Chaque ' ' contenu dans la balise est signifiant et doit donc être explicitement écrit
600 651 par LaTeX ( -> "\ ").
... ... @@ -658,47 +709,54 @@ define Text
658 709 code_to_LaTeX
659 710 (
660 711 MAML m,
661   - Maybe(String) do_paragraph
  712 + Maybe(String) do_paragraph,
  713 + String public_dir
662 714 ) =
663 715 if m is
664 716 {
665 717 text(Text t) then code_to_LaTeX(t,do_paragraph),
666 718 mark(String name) then to_text(name),
667 719 mark(String name,MAML m1) then
668   - if name = "bold" then t-"{\\bf "-code_to_LaTeX(m1,success("\\bf"))-"} " else
669   - if name = "italic" then t-"{\\it "-code_to_LaTeX(m1,success("\\it"))-"} " else
670   - if name = "yellow" then t-"\\textcolor{yellow}{"
671   - -code_to_LaTeX(m1,success("\\textcolor{yellow}{"))-"} " else
672   - if name = "red" then t-"\\textcolor{red}{"
673   - -code_to_LaTeX(m1,success("\\textcolor{red}{"))-"} " else
674   - if name = "grey" then t-"\\textcolor{yellow}{"
675   - -code_to_LaTeX(m1,success("\\textcolor{yellow}{"))-"} " else
676   - if name = "green" then t-"\\textcolor{green}{"
677   - -code_to_LaTeX(m1,success("\\textcolor{green}{"))-"} " else
678   - if name = "blue" then t-"\\textcolor{blue}{"
679   - -code_to_LaTeX(m1,success("\\textcolor{blue}{"))-"} " else
  720 + if name = "bold" then t-"{\\bf "-code_to_LaTeX(m1,success("\\bf"),public_dir)-"}" else
  721 + if name = "italic" then t-"{\\it "-code_to_LaTeX(m1,success("\\it"),public_dir)-"}" else
  722 + if name = "yellow" then
  723 + t-"\\textcolor{yellow}{"-code_to_LaTeX(m1,success("\\textcolor{yellow}{"),public_dir)-"}" else
  724 + if name = "red" then
  725 + t-"\\textcolor{red}{"-code_to_LaTeX(m1,success("\\textcolor{red}{"),public_dir)-"}" else
  726 + if name = "grey" then
  727 + t-"\\textcolor{my_grey}{"-code_to_LaTeX(m1,success("\\textcolor{my_grey}{"),public_dir)-"}" else
  728 + if name = "green" then
  729 + t-"\\textcolor{my_green}{"
  730 + -code_to_LaTeX(m1,success("\\textcolor{my_green}{"),public_dir)-"}" else
  731 + if name = "blue" then
  732 + t-"\\textcolor{blue}{"-code_to_LaTeX(m1,success("\\textcolor{blue}{"),public_dir)-"}" else
680 733 if name = "big" then (if big_to_LaTeX(1,m1) is (string_latex,next_maml) then
681   - t-("{"+string_latex)-code_to_LaTeX(next_maml,success(string_latex))-"}") else
682   - if name = "image" then t-"{\\tt ["-code_to_LaTeX(m1,success("\\tt"))-"]} " else
683   - if name = "code" then t-"\n\n {\\tt \\begin{tabular}{l}\n"
684   - -code_to_LaTeX(m1,do_paragraph)
685   - -" \\end{tabular}}\n\n \\vspace{0.5cm}" else
686   - if name = "center" then t-"\\begin{center} "-code_to_LaTeX(m1,do_paragraph)
687   - -"\\end{center} " else
688   - if name = "link" then t-"{\\tt "-code_to_LaTeX(m1,do_paragraph)-"} " else
689   - if name = "list" then t-"\\begin{itemize} "-code_to_LaTeX(m1,do_paragraph)
690   - -"\\end{itemize} " else
691   - if name = "sub" then t-"\\mbox{$_{"-code_to_LaTeX(m1,do_paragraph)-"}$} " else
692   - if name = "sup" then t-"\\mbox{\\textsuperscript{"-code_to_LaTeX(m1,do_paragraph)-"}} " else
693   - if name = "tt" then t-"{\\tt "-code_to_LaTeX(m1,success("\\tt"))-"} " else
  734 + t-("{"+string_latex)-code_to_LaTeX(next_maml,success(string_latex),public_dir)-"}") else
  735 + if name = "image" then
  736 + image_to_LaTeX(m1,(MAML ma) |-> code_to_LaTeX(ma,failure,public_dir),public_dir) else
  737 + if name = "code" then
  738 + t-"\n\n {\\tt \\setlongtables \\begin{longtable}[l]{l}\n"
  739 + -code_to_LaTeX(m1,do_paragraph,public_dir)
  740 + -" \\end{longtable}}\n\n \\vspace{0.5cm}" else
  741 + if name = "center" then t-"\\begin{center} "-code_to_LaTeX(m1,do_paragraph,public_dir)
  742 + -"\\end{center}" else
  743 + if name = "link" then t-"{\\tt "-code_to_LaTeX(m1,do_paragraph,public_dir)-"}" else
  744 + if name = "list" then t-"\\begin{itemize} "-code_to_LaTeX(m1,do_paragraph,public_dir)
  745 + -"\\end{itemize}" else
  746 + if name = "sub" then t-"\\mbox{$_{"-code_to_LaTeX(m1,do_paragraph,public_dir)-"}$}" else
  747 + if name = "sup" then
  748 + t-"\\mbox{\\textsuperscript{"-code_to_LaTeX(m1,do_paragraph,public_dir)-"}}" else
  749 + if name = "tt" then t-"{\\tt "-code_to_LaTeX(m1,success("\\tt"),public_dir)-"}" else
694 750 alert,
695 751 mark(String n,MAML m1,MAML m2) then alert,
696 752 mark(String n,MAML m1,MAML m2,MAML m3) then alert,
697 753 m1 + m2 then
698   - code_to_LaTeX(m1,do_paragraph) - code_to_LaTeX(m2,do_paragraph)
  754 + code_to_LaTeX(m1,do_paragraph,public_dir) - code_to_LaTeX(m2,do_paragraph,public_dir)
699 755 }.
700 756  
701   -
  757 +
  758 +
  759 +
702 760  
703 761 Fonction générique MAML -> Text
704 762 -------------------------------
... ... @@ -707,6 +765,7 @@ public define Text
707 765 to_LaTeX
708 766 (
709 767 MAML m,
  768 + String public_dir
710 769 ) =
711 770 if m is
712 771 {
... ... @@ -715,30 +774,32 @@ public define Text
715 774 mark(String name) then to_text(name),
716 775  
717 776 mark(String name,MAML a1) then
718   - if name = "bold" then t-"{\\bf "-to_LaTeX(a1)-"} " else
719   - if name = "italic" then t-"{\\it "-to_LaTeX(a1)-"} " else
720   - if name = "yellow" then t-"\\textcolor{yellow}{" -to_LaTeX(a1)-"} " else
721   - if name = "red" then t-"\\textcolor{red}{" -to_LaTeX(a1)-"} " else
722   - if name = "grey" then t-"\\textcolor{yellow}{"-to_LaTeX(a1)-"} " else
723   - if name = "green" then t-"\\textcolor{green}{" -to_LaTeX(a1)-"} " else
724   - if name = "blue" then t-"\\textcolor{blue}{" -to_LaTeX(a1)-"} " else
  777 + if name = "bold" then t-"{\\bf "-to_LaTeX(a1,public_dir)-"}" else
  778 + if name = "italic" then t-"{\\it "-to_LaTeX(a1,public_dir)-"}" else
  779 + if name = "yellow" then t-"\\textcolor{yellow}{" -to_LaTeX(a1,public_dir)-"}" else
  780 + if name = "red" then t-"\\textcolor{red}{" -to_LaTeX(a1,public_dir)-"}" else
  781 + if name = "grey" then t-"\\textcolor{my_grey}{"-to_LaTeX(a1,public_dir)-"}" else
  782 + if name = "green" then t-"\\textcolor{my_green}{" -to_LaTeX(a1,public_dir)-"}" else
  783 + if name = "blue" then t-"\\textcolor{blue}{" -to_LaTeX(a1,public_dir)-"}" else
725 784 if name = "big" then (if big_to_LaTeX(1,a1) is (string_latex,next_maml) then
726   - t-("{"+string_latex)-to_LaTeX(next_maml)-"}") else
727   - if name = "image" then t-"{\\tt ["-to_LaTeX(a1)-"]} " else
728   - if name = "code" then t-"\n\n {\\tt \\begin{tabular}{l}\n"
729   - -code_to_LaTeX(a1,failure)
730   - -" \\end{tabular}}\n\n \\vspace{0.5cm}" else
731   - if name = "center" then t-"\\begin{center} "-to_LaTeX(a1)-"\\end{center} " else
732   - if name = "link" then t-"{\\tt "-to_LaTeX(a1)-"} " else
733   - if name = "list" then t-"\\begin{itemize} "-to_LaTeX(a1)-"\\end{itemize} " else
734   - if name = "sub" then t-"\\mbox{$_{"-to_LaTeX(a1)-"}$} " else
735   - if name = "sup" then t-"\\mbox{\\textsuperscript{"-to_LaTeX(a1)-"}} " else
736   - if name = "tt" then t-"{\\tt "-to_LaTeX(a1)-"} " else
  785 + t-("{"+string_latex)-to_LaTeX(next_maml,public_dir)-"}") else
  786 + if name = "image" then
  787 + image_to_LaTeX(a1,(MAML ma) |-> to_LaTeX(ma,public_dir),public_dir) else
  788 + if name = "code" then
  789 + t-"\n\n {\\tt \\setlongtables \\begin{longtable}[l]{l}\n"
  790 + -code_to_LaTeX(a1,failure,public_dir)
  791 + -" \\end{longtable}} \n\n \\vspace{0.5cm}" else
  792 + if name = "center" then t-"\\begin{center} "-to_LaTeX(a1,public_dir)-"\\end{center}" else
  793 + if name = "link" then t-"{\\tt "-to_LaTeX(a1,public_dir)-"}" else
  794 + if name = "list" then t-"\\begin{itemize} "-to_LaTeX(a1,public_dir)-"\\end{itemize}" else
  795 + if name = "sub" then t-"\\mbox{$_{"-to_LaTeX(a1,public_dir)-"}$}" else
  796 + if name = "sup" then t-"\\mbox{\\textsuperscript{"-to_LaTeX(a1,public_dir)-"}}" else
  797 + if name = "tt" then t-"{\\tt "-to_LaTeX(a1,public_dir)-"}" else
737 798 alert,
738 799  
739 800 mark(String name,MAML a1,MAML a2) then alert,
740 801 mark(String name,MAML a1,MAML a2,MAML a3) then alert,
741   - m1 + m2 then to_LaTeX(m1) - to_LaTeX(m2)
  802 + m1 + m2 then to_LaTeX(m1,public_dir) - to_LaTeX(m2,public_dir)
742 803 }.
743 804  
744 805  
... ... @@ -774,12 +835,13 @@ public define Result(Int32,String)
774 835 public define Result(Int32,String)
775 836 convert_MAML_to_LaTeX
776 837 (
777   - String s
  838 + String s,
  839 + String public_dir
778 840 ) =
779 841 if parse_MAML(make_stream(s)) is
780 842 {
781 843 error(i) then error(i),
782   - ok(m) then ok(to_string(to_LaTeX(m)))
  844 + ok(m) then ok(to_string(to_LaTeX(m,public_dir)))
783 845 }.
784 846  
785 847  
786 848 \ No newline at end of file
... ...