=========================
LaTeX Code generation
=========================


The second part is the conversion of the above information into latex
code, which can then be included in the documentation. At first,
let's test the seperate functions that are used to build the LaTeX
Code. (Testing them together would be too complex)

 >>> from sa_tools.tools import read_sa_tables, read_sa_indexes, read_sa_classes
 >>> tables = read_sa_tables('sa_tools.tests.tables')
 >>> index_dict = read_sa_indexes('sa_tools.tests.tables')
 >>> classes_dict = read_sa_classes('sa_tools.tests.tables')
 >>> from sa_tools.latex import latex_table_header, sa2latex
 
Print Header Section

 >>> for t in latex_table_header(tables[0], 'Person', classes_dict['myperson']): 
 ...     print t
 \parskip6ex
 \parbox{15cm}{
 {\bf Table  myperson} (person)\\
 Mapped to Class {\bf Person} \\

Print Header Description

 >>> from sa_tools.latex import latex_table_desc
 >>> from sa_tools.tests.tables import IMyPerson
 >>> latex_table_desc(IMyPerson, tables[0])
 u' This is a person {\\bf DB: }Important Table'

Print Table Columns

 >>> from sa_tools.latex import latex_table_columns
 >>> for t in latex_table_columns(tables[0], IMyPerson): print t
 mypersonid (personid)& Integer & Y & N &  &ID of the person\\
 \hline
 name1 & String(30) & N & N &  &First name{\bf DB: }DB-Specifics\\
 \hline

Print Indexes Table

 >>> from sa_tools.latex import latex_table_indexes
 >>> for t in latex_table_indexes(tables[0], index_dict['myperson']):
 ...     print t
 \parskip2ex
 \parbox{9cm}{
 Indexes for table myperson:\\
 \begin{tabular}{|l|l|l|}
 \hline
 {\bf Name} & {\bf Columns} & {\bf Unique}\\
 \hline
 myperson\_i1 & mypersonid, name1 & Y
 \\
 \hline
 myperson\_i2 & name1 & N
 \\
 \hline
 \end{tabular}
 }
 <BLANKLINE>

Print SQLAlchemy Properties

 >>> from sa_tools.latex import latex_table_props
 >>> for t in latex_table_props(classes_dict['myperson'][2], IMyPerson):
 ...   print t
 \parskip2ex
 \parbox{15cm}{
 Properties: \\
 \begin{tabular}{|l|l|l|l|l|p{5cm}|}
 \hline
 {\bf Name} & {\bf RelClass} & {\bf Lazy} & {\bf Sec}& {\bf BRef} & {\bf Description}\\
 \hline
 addresses & Address & Y &  & &
 \\
 \hline
 \end{tabular}
 }
 <BLANKLINE>

Print other class properties

 >>> from sa_tools.latex import latex_table_classprops
 >>> for t in latex_table_classprops(classes_dict['myperson'][1], IMyPerson): 
 ...     print t
 \parskip2ex
 \parbox{15cm}{
 Properties in class {\bf Person}: \\
 \begin{tabular}{|l|l|}
 \hline
 {\bf Name} & {\bf Description} \\
 \hline
 testprop & Test Property
 \\
 \hline
 \end{tabular}
 }
 <BLANKLINE>

And now just try if the sa2latex function succeeds

 >>> dummy = sa2latex(tables, index_dict, classes_dict)

