Commit 236e15af2feccbd128a88cae35b80a43c3615986
1 parent
4867b51d
*** empty log message ***
Showing
1 changed file
with
202 additions
and
8 deletions
Show diff stats
anubis_dev/library/tools/maml.anubis
| ... | ... | @@ -591,6 +591,54 @@ public define Text |
| 591 | 591 | |
| 592 | 592 | *** Translating to LaTeX. |
| 593 | 593 | |
| 594 | +define List(SpecialChar) | |
| 595 | + latex_schar | |
| 596 | + = | |
| 597 | + [ | |
| 598 | +// schar(' ', "\n"), | |
| 599 | + schar('<', "\\textless"), | |
| 600 | + schar('>', "\\textgreater"), | |
| 601 | + schar('&', "\\& "), | |
| 602 | + schar('#', "\\# "), | |
| 603 | + schar('{', "\\{ "), | |
| 604 | + schar('}', "\\} "), | |
| 605 | + schar('_', "\\_"), | |
| 606 | + schar('\\', "\\textbackslash "), | |
| 607 | + schar('^', "\\textasciicircum "), | |
| 608 | + schar('~', "\\textasciitilde "), | |
| 609 | + schar('[', "{[}"), // un espace devant le [ pour éviter la séquence \\[] | |
| 610 | + //schar(']', "\\verb+]+"), -> NO | |
| 611 | + //schar(']', "\\mbox{\\verb+]+}"), -> NO | |
| 612 | + //schar(']', "\\protect{\\verb+]+}"), -> NO | |
| 613 | + //schar(']', "]"), | |
| 614 | + schar('|', "\\textbar"), | |
| 615 | + schar('<', "\\textless"), | |
| 616 | + schar('>', "\\textgreater") | |
| 617 | + ]. | |
| 618 | + | |
| 619 | + | |
| 620 | +define String | |
| 621 | + latex_head | |
| 622 | + ( | |
| 623 | + String more_ahead | |
| 624 | + ) = | |
| 625 | + "\\documentclass[a4paper, 11pt]{article}\n\n" | |
| 626 | + + "\\setlength{\\headheight}{15pt}\n" | |
| 627 | + + "\\setlength{\\marginparwidth}{0pt}\n" | |
| 628 | + + "\\setlength{\\oddsidemargin}{0pt}\n" | |
| 629 | + + "\\setlength{\\evensidemargin}{0pt}\n" | |
| 630 | + + "\\setlength{\\textwidth}{17cm}\n" | |
| 631 | + + "\\setlength{\\parindent}{0pt}\n" | |
| 632 | + + "\\usepackage[francais]{babel}\n" | |
| 633 | + + "\\usepackage[utf8]{inputenc}\n" | |
| 634 | + + "\\usepackage{color}\n" | |
| 635 | + + "\\usepackage{graphics}\n" | |
| 636 | + + "\\usepackage{fancyhdr}\n" | |
| 637 | + + "\\pagestyle{fancy}\n" | |
| 638 | + + "\\lhead{\\itshape Tutoriel Anubis}\n" | |
| 639 | + + "\\renewcommand{\\headrulewidth}{0.4pt}\n\n" | |
| 640 | + + more_ahead | |
| 641 | + + "\n\n". | |
| 594 | 642 | |
| 595 | 643 | public define String |
| 596 | 644 | latex_page |
| ... | ... | @@ -598,24 +646,170 @@ public define String |
| 598 | 646 | String more_ahead, |
| 599 | 647 | String text_from_maml |
| 600 | 648 | ) = |
| 601 | - alert. | |
| 649 | + latex_head(more_ahead) | |
| 650 | + + "\\begin{document}\n\n" | |
| 651 | + + text_from_maml | |
| 652 | + + "\n\n" | |
| 653 | + + "\\end{document}\n\n". | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | +define String | |
| 658 | + code_to_LaTeX | |
| 659 | + ( | |
| 660 | + List(Int8) l, | |
| 661 | + Bool do_paragraph | |
| 662 | + ) = | |
| 663 | + if l is | |
| 664 | + { | |
| 665 | + [] then "", | |
| 666 | + [h . t] then | |
| 667 | + (if h = ' ' then "\\ " else | |
| 668 | + if do_paragraph | |
| 669 | + then if h = '\n' then "\\\\ " else transform_schar(h,latex_schar) | |
| 670 | + else transform_schar(h,latex_schar)) | |
| 671 | + + code_to_LaTeX(t,do_paragraph) | |
| 672 | + }. | |
| 673 | + | |
| 674 | + | |
| 675 | +define String | |
| 676 | + code_to_LaTeX | |
| 677 | + ( | |
| 678 | + List(Int8) l, | |
| 679 | + Maybe(String) do_paragraph | |
| 680 | + ) = | |
| 681 | + if l is | |
| 682 | + { | |
| 683 | + [] then "", | |
| 684 | + [h . t] then | |
| 685 | + (if h = ' ' then "\\ " else | |
| 686 | + if h = '\n' then | |
| 687 | + if do_paragraph is // { | |
| 688 | + { | |
| 689 | + failure then "\\\\ ", | |
| 690 | + success(s) then "} \\\\ "+s | |
| 691 | + } | |
| 692 | + else transform_schar(h,latex_schar)) | |
| 693 | + + code_to_LaTeX(t,do_paragraph) | |
| 694 | + }. | |
| 695 | + | |
| 696 | +define Text | |
| 697 | + code_to_LaTeX | |
| 698 | + ( | |
| 699 | + Text text, | |
| 700 | + Maybe(String) do_paragraph | |
| 701 | + ) = | |
| 702 | + if text is | |
| 703 | + { | |
| 704 | + t then t, | |
| 705 | + Text te - String s then code_to_LaTeX(te,do_paragraph) - code_to_LaTeX(explode(s),do_paragraph), | |
| 706 | + Text t1 - Text t2 then code_to_LaTeX(t1,do_paragraph) - code_to_LaTeX(t2,do_paragraph) | |
| 707 | + }. | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | +define Text | |
| 712 | + to_text | |
| 713 | + ( | |
| 714 | + String name | |
| 715 | + ) = | |
| 716 | + if name = "dollar" then t-"\\$" else | |
| 717 | + if name = "lpar" then t-"(" else | |
| 718 | + if name = "rpar" then t-")" else | |
| 719 | + if name = "par" then t-"\n\n" else | |
| 720 | + if name = "item" then t-"\\item " else | |
| 721 | + alert. | |
| 722 | + | |
| 723 | + | |
| 724 | +define Text | |
| 725 | + code_to_LaTeX | |
| 726 | + ( | |
| 727 | + MAML m, | |
| 728 | + Maybe(String) do_paragraph | |
| 729 | + ) = | |
| 730 | + if m is | |
| 731 | + { | |
| 732 | + text(Text t) then code_to_LaTeX(t,do_paragraph), | |
| 733 | + mark(String name) then to_text(name), | |
| 734 | + mark(String name,MAML m1) then | |
| 735 | + if name = "bold" then t-"{\\bf "-code_to_LaTeX(m1,do_paragraph)-"} " else | |
| 736 | + if name = "italic" then t-"{\\it "-code_to_LaTeX(m1,do_paragraph)-"} " else | |
| 737 | + if name = "yellow" then t-"\\textcolor{yellow}{" | |
| 738 | + -code_to_LaTeX(m1,success("\\textcolor{yellow}{"))-"} " else | |
| 739 | + if name = "red" then t-"\\textcolor{red}{" | |
| 740 | + -code_to_LaTeX(m1,success("\\textcolor{red}{"))-"} " else | |
| 741 | + if name = "grey" then t-"\\textcolor{yellow}{" | |
| 742 | + -code_to_LaTeX(m1,success("\\textcolor{yellow}{"))-"} " else | |
| 743 | + if name = "green" then t-"\\textcolor{green}{" | |
| 744 | + -code_to_LaTeX(m1,success("\\textcolor{green}{"))-"} " else | |
| 745 | + if name = "blue" then t-"\\textcolor{blue}{" | |
| 746 | + -code_to_LaTeX(m1,success("\\textcolor{blue}{"))-"} " else | |
| 747 | + if name = "big" then t-"{\\Large"-code_to_LaTeX(m1,do_paragraph)-"} " else | |
| 748 | + if name = "image" then t-"{\\tt ["-code_to_LaTeX(m1,do_paragraph)-"]} " else | |
| 749 | + if name = "code" then t-"\n\n {\\tt \\begin{tabular}{l}\n" | |
| 750 | + -code_to_LaTeX(m1,do_paragraph) | |
| 751 | + -" \\end{tabular}}\n\n \\vspace{0.5cm}" else | |
| 752 | + if name = "center" then t-"\\begin{center} "-code_to_LaTeX(m1,do_paragraph) | |
| 753 | + -"\\end{center} " else | |
| 754 | + if name = "link" then t-"{\\tt "-code_to_LaTeX(m1,do_paragraph)-"} " else | |
| 755 | + if name = "list" then t-"\\begin{itemize} "-code_to_LaTeX(m1,do_paragraph) | |
| 756 | + -"\\end{itemize} " else | |
| 757 | + if name = "sub" then t-"\\mbox{$_{"-code_to_LaTeX(m1,do_paragraph)-"}$} " else | |
| 758 | + if name = "sup" then t-"\\mbox{\\textsuperscript{"-code_to_LaTeX(m1,do_paragraph)-"}} " else | |
| 759 | + if name = "tt" then t-"{\\tt "-code_to_LaTeX(m1,do_paragraph)-"} " else | |
| 760 | + alert, | |
| 761 | + mark(String n,MAML m1,MAML m2) then alert, | |
| 762 | + mark(String n,MAML m1,MAML m2,MAML m3) then alert, | |
| 763 | + m1 + m2 then | |
| 764 | + code_to_LaTeX(m1,do_paragraph) - code_to_LaTeX(m2,do_paragraph) | |
| 765 | + }. | |
| 766 | + | |
| 767 | + | |
| 602 | 768 | |
| 603 | 769 | public define Text |
| 604 | 770 | to_LaTeX |
| 605 | 771 | ( |
| 606 | - MAML m | |
| 772 | + MAML m, | |
| 607 | 773 | ) = |
| 608 | - alert. | |
| 609 | 774 | if m is |
| 610 | 775 | { |
| 611 | - text(Text t) then t, | |
| 612 | - mark(String name) then | |
| 613 | - if name = "dollar" then t-"\verb+$+" else | |
| 614 | - if | |
| 615 | - }. | |
| 776 | + text(Text t) then to_special_characters(t,latex_schar), | |
| 777 | + | |
| 778 | + mark(String name) then to_text(name), | |
| 616 | 779 | |
| 780 | + mark(String name,MAML a1) then | |
| 781 | + if name = "bold" then t-"{\\bf "-to_LaTeX(a1)-"} " else | |
| 782 | + if name = "italic" then t-"{\\it "-to_LaTeX(a1)-"} " else | |
| 783 | + if name = "yellow" then t-"\\textcolor{yellow}{" -to_LaTeX(a1)-"} " else | |
| 784 | + if name = "red" then t-"\\textcolor{red}{" -to_LaTeX(a1)-"} " else | |
| 785 | + if name = "grey" then t-"\\textcolor{yellow}{"-to_LaTeX(a1)-"} " else | |
| 786 | + if name = "green" then t-"\\textcolor{green}{" -to_LaTeX(a1)-"} " else | |
| 787 | + if name = "blue" then t-"\\textcolor{blue}{" -to_LaTeX(a1)-"} " else | |
| 788 | + if name = "big" then t-"\\Large{"-to_LaTeX(a1)-"} " else | |
| 789 | + if name = "image" then t-"{\\tt ["-to_LaTeX(a1)-"]} " else | |
| 790 | + if name = "code" then t-"\n\n {\\tt \\begin{tabular}{l}\n" | |
| 791 | + -code_to_LaTeX(a1,failure) | |
| 792 | + -" \\end{tabular}}\n\n \\vspace{0.5cm}" else | |
| 793 | + if name = "center" then t-"\\begin{center} "-to_LaTeX(a1)-"\\end{center} " else | |
| 794 | + if name = "link" then t-"{\\tt "-to_LaTeX(a1)-"} " else | |
| 795 | + if name = "list" then t-"\\begin{itemize} "-to_LaTeX(a1)-"\\end{itemize} " else | |
| 796 | + if name = "sub" then t-"\\mbox{$_{"-to_LaTeX(a1)-"}$} " else | |
| 797 | + if name = "sup" then t-"\\mbox{\\textsuperscript{"-to_LaTeX(a1)-"}} " else | |
| 798 | + if name = "tt" then t-"{\\tt "-to_LaTeX(a1)-"} " else | |
| 799 | + alert, | |
| 800 | + | |
| 801 | + mark(String name,MAML a1,MAML a2) then alert, | |
| 802 | + mark(String name,MAML a1,MAML a2,MAML a3) then alert, | |
| 803 | + m1 + m2 then to_LaTeX(m1) - to_LaTeX(m2) | |
| 804 | + }. | |
| 617 | 805 | |
| 618 | 806 | |
| 807 | + public define Text | |
| 808 | + to_LaTeX | |
| 809 | + ( | |
| 810 | + MAML m, | |
| 811 | + ) = | |
| 812 | + to_LaTeX(m,true). | |
| 619 | 813 | |
| 620 | 814 | *** Compatibility with maml.anubis version 1. |
| 621 | 815 | ... | ... |