1. with Ada.Characters.Latin_1;  use Ada.Characters.Latin_1; 
  2. with Ada.Characters.Handling; use Ada.Characters.Handling; 
  3. with Ada.Exceptions;          use Ada.Exceptions; 
  4. with Basic_Io;                use Basic_Io; 
  5. package body LaTex is 
  6.  
  7. -------------------------------------------------------------------------------- 
  8.    function Table 
  9.      (Parameter : Unbounded_String := To_Unbounded_String ("{c|c|c}"); 
  10.       Lines     : Unbounded_String := Null_Unbounded_String) return Unbounded_String is 
  11.       Table_Contents : Unbounded_String := Null_Unbounded_String; 
  12.    begin 
  13.       Table_Contents := "\begin{tabular}" & Parameter & LF & "\hline" & LF & Lines & "\end{tabular}"; 
  14.       return Table_Contents; 
  15.    exception 
  16.       when Error : others => 
  17.          Put_Line ("Error in function Table!"); 
  18.          Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error)); 
  19.          return Null_Unbounded_String; 
  20.    end Table; 
  21. -------------------------------------------------------------------------------- 
  22.  
  23. -------------------------------------------------------------------------------- 
  24.    function Line (Item_List : Line_Type; First_Line : Boolean := False) return Unbounded_String is 
  25.       Line_Contents : Unbounded_String := Null_Unbounded_String; 
  26.    begin 
  27. --        if First_Line then 
  28. --           Append (Line_Contents, "\rowcolor{cyan}"); 
  29. --        end if; 
  30.  
  31.       for i in Item_List'range loop 
  32.          if i = Item_List'last then 
  33.             Append (Line_Contents, Item_List (i)); 
  34.          else 
  35.             Append (Line_Contents, Item_List (i) & " &"); 
  36.          end if; 
  37.       end loop; 
  38.       Append (Line_Contents, " \\ \hline" & LF); 
  39.       return Line_Contents; 
  40.    exception 
  41.       when Error : others => 
  42.          Put_Line ("Error in function Line!"); 
  43.          Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error)); 
  44.          return Null_Unbounded_String; 
  45.    end Line; 
  46. -------------------------------------------------------------------------------- 
  47.  
  48. -------------------------------------------------------------------------------- 
  49.    function Convert_Character (Input : Unbounded_String) return Unbounded_String is 
  50.       Output       : Unbounded_String := Null_Unbounded_String; 
  51.       Value        : Character        := ' '; 
  52.       Bracket_Open : Boolean          := False; 
  53.    begin 
  54.       for I in 1 .. Length (Input) loop 
  55.          declare 
  56.             One_Element : String := To_String (Unbounded_Slice (Input, I, I)); 
  57.          begin 
  58.             Value := One_Element (1); 
  59.             if (Bracket_Open = True) and (not Is_Digit (Value)) then 
  60.                Append (Output, "}"); 
  61.                Bracket_Open := False; 
  62.             end if; 
  63.  
  64.             case Value is 
  65.                when 'e' => 
  66.                   Append (Output, "e_{"); 
  67.                   Bracket_Open := True; 
  68.                when Circumflex => 
  69.                   Append (Output, "\wedge "); 
  70.                when others => 
  71.                   Append (Output, Unbounded_Slice (Input, I, I)); 
  72.             end case; 
  73.          end; 
  74.  
  75.          if (Bracket_Open = True and I = Length (Input)) then 
  76.             Append (Output, "}"); 
  77.             Bracket_Open := False; 
  78.          end if; 
  79.       end loop; 
  80.       return Output; 
  81.    exception 
  82.       when Error : others => 
  83.          Put_Line ("Error in function Convert_Character"); 
  84.          Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error)); 
  85.          return Null_Unbounded_String; 
  86.    end Convert_Character; 
  87. -------------------------------------------------------------------------------- 
  88.  
  89. -------------------------------------------------------------------------------- 
  90.    function Table (Matrix : String_Matrix_Type; Head_Line : Boolean := False; Formular_Elements : Boolean := true) return Unbounded_String is 
  91.       Table_Contents : Unbounded_String := Null_Unbounded_String; 
  92.       Lines          : Unbounded_String := Null_Unbounded_String; 
  93.       Parameter      : Unbounded_String := Null_Unbounded_String; 
  94.       Item_List      : Line_Type (Matrix'range (2)); 
  95.       First_Line     : Boolean          := True; 
  96.    begin 
  97.       Put_Line ("begin Table"); 
  98.       Append (Parameter, "{|"); 
  99.       for i in Matrix'range (2) loop 
  100.          Append (Parameter, "c|"); 
  101.       end loop; 
  102.       Append (Parameter, "}"); 
  103.  
  104.       for i in Matrix'range (1) loop 
  105.          for j in Matrix'range (2) loop 
  106.             if j = Matrix'first (2) then 
  107.                if Head_Line then 
  108.                   if Formular_Elements then 
  109.                      Item_List (j) := " \cellcolor{cyan}" & "$" & Matrix (i, j) & "$"; 
  110.                   else 
  111.                      Item_List (j) := trim ( Source => Matrix (i, j), Side => Ada.Strings.Left ); 
  112.                   end if; 
  113.                else 
  114.                   if Formular_Elements then 
  115.                      Item_List (j) := "$" & Matrix (i, j) & "$"; 
  116.                   else 
  117.                      Item_List (j) := trim ( Source => Matrix (i, j), Side => Ada.Strings.Left ); 
  118.                   end if; 
  119.                end if; 
  120.             else 
  121.                if Formular_Elements then 
  122.                   Item_List (j) := "$" & Matrix (i, j) & "$"; 
  123.                else 
  124.                   Item_List (j) := trim ( Source => Matrix (i, j), Side => Ada.Strings.Left ); 
  125.                end if; 
  126.             end if; 
  127.  
  128.          end loop; 
  129.          if First_Line then 
  130.             Append (Lines, Line (Item_List, First_Line => True)); 
  131.             First_Line := False; 
  132.          else 
  133.             Append (Lines, Line (Item_List)); 
  134.          end if; 
  135.       end loop; 
  136.       Table_Contents := Table (Parameter => Parameter, Lines => Lines); 
  137.       Put_Line ("end   Table"); 
  138.       return Table_Contents; 
  139.    exception 
  140.       when Error : others => 
  141.          Put_Line ("Error in function Table"); 
  142.          Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error)); 
  143.          return Null_Unbounded_String; 
  144.    end Table; 
  145. -------------------------------------------------------------------------------- 
  146.  
  147. -------------------------------------------------------------------------------- 
  148.    function Table_Short_Form (Matrix : String_Matrix_Type) return Unbounded_String is 
  149.       Table_Contents : Unbounded_String := Null_Unbounded_String; 
  150.       Lines          : Unbounded_String := Null_Unbounded_String; 
  151.       Parameter      : Unbounded_String := Null_Unbounded_String; 
  152.       Item_List      : Line_Type (Matrix'range (2)); 
  153.       First_Line     : Boolean          := True; 
  154.    begin 
  155.       Put_Line ("begin Table_Short_Form"); 
  156.       Append (Parameter, "{|"); 
  157.       for i in Matrix'range (2) loop 
  158.          Append (Parameter, "c|"); 
  159.       end loop; 
  160.       Append (Parameter, "}"); 
  161.  
  162.       for i in Matrix'range (1) loop 
  163.          for j in Matrix'range (2) loop 
  164.             if j = Matrix'first (2) then 
  165.                -- Item_List (j) := " \cellcolor{cyan}" & "$" & Convert_Character (Matrix (i, j)) & "$"; Item_List (j) := 
  166.                -- " \cellcolor{cyan}" & Convert_Character (Matrix (i, j)); 
  167.                Item_List (j) := Convert_Character (Matrix (i, j)); 
  168.             else 
  169.                -- Item_List (j) := "$" & Convert_Character (Matrix (i, j)) & "$"; 
  170.                Item_List (j) := Convert_Character (Matrix (i, j)); 
  171.             end if; 
  172.  
  173.          end loop; 
  174.          if First_Line then 
  175.             Append (Lines, Line (Item_List, First_Line => True)); 
  176.             First_Line := False; 
  177.          else 
  178.             Append (Lines, Line (Item_List)); 
  179.          end if; 
  180.       end loop; 
  181.       Table_Contents := Table (Parameter => Parameter, Lines => Lines); 
  182.       Put_Line ("end   Table_Short_Form"); 
  183.       return Table_Contents; 
  184.    exception 
  185.       when Error : others => 
  186.          Put_Line ("Error in function Table_Short_Form"); 
  187.          Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error)); 
  188.          return Null_Unbounded_String; 
  189.    end Table_Short_Form; 
  190. -------------------------------------------------------------------------------- 
  191.  
  192. -------------------------------------------------------------------------------- 
  193. end LaTex; --------------------------------------------------------------------- 
  194. --------------------------------------------------------------------------------