with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Exceptions; use Ada.Exceptions;
with Basic_Io; use Basic_Io;
package body LaTex is
function Table
(Parameter : Unbounded_String := To_Unbounded_String ("{c|c|c}");
Lines : Unbounded_String := Null_Unbounded_String) return Unbounded_String is
Table_Contents : Unbounded_String := Null_Unbounded_String;
begin
Table_Contents := "\begin{tabular}" & Parameter & LF & "\hline" & LF & Lines & "\end{tabular}";
return Table_Contents;
exception
when Error : others =>
Put_Line ("Error in function Table!");
Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error));
return Null_Unbounded_String;
end Table;
function Line (Item_List : Line_Type; First_Line : Boolean := False) return Unbounded_String is
Line_Contents : Unbounded_String := Null_Unbounded_String;
begin
for i in Item_List'range loop
if i = Item_List'last then
Append (Line_Contents, Item_List (i));
else
Append (Line_Contents, Item_List (i) & " &");
end if;
end loop;
Append (Line_Contents, " \\ \hline" & LF);
return Line_Contents;
exception
when Error : others =>
Put_Line ("Error in function Line!");
Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error));
return Null_Unbounded_String;
end Line;
function Convert_Character (Input : Unbounded_String) return Unbounded_String is
Output : Unbounded_String := Null_Unbounded_String;
Value : Character := ' ';
Bracket_Open : Boolean := False;
begin
for I in 1 .. Length (Input) loop
declare
One_Element : String := To_String (Unbounded_Slice (Input, I, I));
begin
Value := One_Element (1);
if (Bracket_Open = True) and (not Is_Digit (Value)) then
Append (Output, "}");
Bracket_Open := False;
end if;
case Value is
when 'e' =>
Append (Output, "e_{");
Bracket_Open := True;
when Circumflex =>
Append (Output, "\wedge ");
when others =>
Append (Output, Unbounded_Slice (Input, I, I));
end case;
end;
if (Bracket_Open = True and I = Length (Input)) then
Append (Output, "}");
Bracket_Open := False;
end if;
end loop;
return Output;
exception
when Error : others =>
Put_Line ("Error in function Convert_Character");
Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error));
return Null_Unbounded_String;
end Convert_Character;
function Table (Matrix : String_Matrix_Type; Head_Line : Boolean := False; Formular_Elements : Boolean := true) return Unbounded_String is
Table_Contents : Unbounded_String := Null_Unbounded_String;
Lines : Unbounded_String := Null_Unbounded_String;
Parameter : Unbounded_String := Null_Unbounded_String;
Item_List : Line_Type (Matrix'range (2));
First_Line : Boolean := True;
begin
Put_Line ("begin Table");
Append (Parameter, "{|");
for i in Matrix'range (2) loop
Append (Parameter, "c|");
end loop;
Append (Parameter, "}");
for i in Matrix'range (1) loop
for j in Matrix'range (2) loop
if j = Matrix'first (2) then
if Head_Line then
if Formular_Elements then
Item_List (j) := " \cellcolor{cyan}" & "$" & Matrix (i, j) & "$";
else
Item_List (j) := trim ( Source => Matrix (i, j), Side => Ada.Strings.Left );
end if;
else
if Formular_Elements then
Item_List (j) := "$" & Matrix (i, j) & "$";
else
Item_List (j) := trim ( Source => Matrix (i, j), Side => Ada.Strings.Left );
end if;
end if;
else
if Formular_Elements then
Item_List (j) := "$" & Matrix (i, j) & "$";
else
Item_List (j) := trim ( Source => Matrix (i, j), Side => Ada.Strings.Left );
end if;
end if;
end loop;
if First_Line then
Append (Lines, Line (Item_List, First_Line => True));
First_Line := False;
else
Append (Lines, Line (Item_List));
end if;
end loop;
Table_Contents := Table (Parameter => Parameter, Lines => Lines);
Put_Line ("end Table");
return Table_Contents;
exception
when Error : others =>
Put_Line ("Error in function Table");
Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error));
return Null_Unbounded_String;
end Table;
function Table_Short_Form (Matrix : String_Matrix_Type) return Unbounded_String is
Table_Contents : Unbounded_String := Null_Unbounded_String;
Lines : Unbounded_String := Null_Unbounded_String;
Parameter : Unbounded_String := Null_Unbounded_String;
Item_List : Line_Type (Matrix'range (2));
First_Line : Boolean := True;
begin
Put_Line ("begin Table_Short_Form");
Append (Parameter, "{|");
for i in Matrix'range (2) loop
Append (Parameter, "c|");
end loop;
Append (Parameter, "}");
for i in Matrix'range (1) loop
for j in Matrix'range (2) loop
if j = Matrix'first (2) then
Item_List (j) := Convert_Character (Matrix (i, j));
else
Item_List (j) := Convert_Character (Matrix (i, j));
end if;
end loop;
if First_Line then
Append (Lines, Line (Item_List, First_Line => True));
First_Line := False;
else
Append (Lines, Line (Item_List));
end if;
end loop;
Table_Contents := Table (Parameter => Parameter, Lines => Lines);
Put_Line ("end Table_Short_Form");
return Table_Contents;
exception
when Error : others =>
Put_Line ("Error in function Table_Short_Form");
Put_Line ("Exception_Information: " & Ada.Exceptions.Exception_Information (Error));
return Null_Unbounded_String;
end Table_Short_Form;
end LaTex;