Subversion Repositories wimsdev

Rev

Rev 11931 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #!/usr/local/bin/perl
  2. # -*- coding: utf-8 -*-
  3.  
  4. open ('TEX', '>/tmp/chemtest.tex');
  5. print TEX "\\documentclass{article}\n";
  6. #print TEX "\\usepackage[frenchb]{babel}\n";
  7. print TEX "\\usepackage{a4wide}\n";
  8. print TEX "\\usepackage[utf8]{inputenc}\n";
  9. #print TEX "\\usepackage {lmodern}\n";
  10.  
  11. print TEX "\\title{Chemeq, a parser for chemical equations}\n";
  12. print TEX "\\author{\\copyright{} GPL 2000-2013, Georges Khaznadar
  13. \\emph{georgesk\@debian.org}}\n";
  14. print TEX "\\begin{document}\n\\maketitle\n\n\\sloppy\n";
  15. print TEX "\\abstract{Chemtest is a parser which analyses its standard input
  16. and outputs useful strings accounting for informations related to chemical
  17. equations. It can be embedded in educational applications.
  18. Here are listed examples of possible inputs for
  19. chemeq. Some outputs are usefully interpreted by the LaTeX language
  20. in math mode. The other outputs are typeset with \\texttt{teletype fonts}.}\n\n";
  21.  
  22.  
  23. $lignes_de_reponse = 6;
  24.  
  25. print TEX "Currently, when \\texttt{chemeq} is fed with a chemical equation or a
  26. combination of chemical equations on its standard input, it gives ",$lignes_de_reponse," lines on its standard output.\n";
  27. print TEX "\~\\\\\[3ex]\n\\hrule\n\\tableofcontents\n\~\\\\\[3ex]\n\\hrule\n";
  28.  
  29. while(chomp($essai = <STDIN>)){
  30.     if(length($essai) != 0 && substr($essai,0,1) ne "#"){
  31.         for ($i=0; $i < $lignes_de_reponse; $i++){
  32.             chomp($tmp=<STDIN>); @reponse[$i]=$tmp;
  33.         }
  34.         $essai_ = $essai;
  35.         $essai_ =~ s/\'/\\\'/g;
  36.         @args = ("echo \"$essai_\" | chemeq > /tmp/tmp.1");
  37.         system @args;
  38.         open (TMP,'/tmp/tmp.1');
  39.         $essai =~ s/\^/\\\^{}/g;
  40.         $essai =~ s/\>/\$>\$/g;
  41.         $essai =~ s/\_/\\\_{}/g;
  42.         $ok=1;
  43.         for ($i=0; $i < $lignes_de_reponse; $i++){
  44.             chomp($tmp=<TMP>); @result[$i]=$tmp;
  45.             if (@result[$i] ne @reponse[$i]){
  46.                 @idem[i]="KO";
  47.                 $ok=0;
  48.             }
  49.             else {
  50.                 @idem[i]="OK";
  51.             }
  52.         }
  53.         if ($ok==1){
  54.             print TEX "\\section{OK : \\texttt{$essai}}\n";
  55.         }
  56.         else {
  57.             print TEX "\\section{ERROR : \\texttt{$essai}}\n";
  58.         }
  59.         for ($i=0; $i < $lignes_de_reponse; $i++){
  60.             print TEX @idem[i],"  ";
  61.         }
  62.         print TEX "\\\\\n";
  63.         print TEX "Expected output :\n";
  64.         print TEX "\\begin{enumerate} \n";
  65.         for ($i=0; $i < $lignes_de_reponse; $i++){
  66.             print TEX "\\item ";
  67.             if (@reponse[$i] =~ /\\/){
  68.                 print TEX "\$\$",@reponse[$i],"\$\$\n";
  69.             }
  70.             else {
  71.                 $buffer = @reponse[$i];
  72.                 $buffer =~ s/\^/\\\^{}/g;
  73.                 $buffer =~ s/\>/\$>\$/g;
  74.                 $buffer =~ s/\_/\\\_{}/g;
  75.                 $buffer =~ s/\|/\$|\$/g;
  76.                 print TEX "\\texttt{", $buffer,"}\n";
  77.             }
  78.         }
  79.         print TEX "\\end{enumerate}\n";
  80.         if (!$ok){
  81.             print TEX "found output :\n";
  82.             print TEX "\\begin{enumerate} \n";
  83.             for ($i=0; $i < $lignes_de_reponse; $i++){
  84.                 print TEX "\\item \\verb|", @reponse[$i], "|\n";
  85.             }
  86.             print TEX "\\end{enumerate}\n";
  87.         }
  88.     }
  89. }
  90.  
  91. print TEX "\\end{document}\n";
  92.  
  93. close TEX;
  94.  
  95. system ("(cd /tmp; echo q | latex chemtest.tex)");
  96. system ("(cd /tmp; echo q | latex chemtest.tex)");
  97. system ("(cd /tmp; xdvi chemtest.dvi)");
  98. system ("(cd /tmp;rm -f chemtest* tmp.1)");
  99.