
    ?wgA                     $    d Z ddlZ G d d      Zy)zbTablib - LaTeX table export support.

   Generates a LaTeX booktabs-style table from the dataset.
    Nc            
          e Zd ZdZdZdZ eg d      Z ej                  ddj                   eej                  ej                                     z        Zed        Zed        Zed	        Zed
        Zed        Zed        Zy)LATEXFormatlatex)texz%% Note: add \usepackage{booktabs} to your preamble
%%
\begin{table}[!htbp]
  \centering
  %(CAPTION)s
  \begin{tabular}{%(COLSPEC)s}
    \toprule
%(HEADER)s
    %(MIDRULE)s
%(BODY)s
    \bottomrule
  \end{tabular}
\end{table}
)
)\z\textbackslash{}){z\{)}z\})$z\$)&z\&)#z\#)^z\textasciicircum{})_z\_)~z\textasciitilde{})%z\%z(%s)|c                    |j                   rd|j                   z  nd}| j                  |j                        }|j                  r| j	                  |j                        nd}| j                  |j                        }dj                  |D cg c]  }| j	                  |       c}      }| j                  t        |||||      z  S c c}w )zReturns LaTeX representation of dataset

        :param dataset: dataset to serialize
        :type dataset: tablib.core.Dataset
        z\caption{%s}r    
)CAPTIONCOLSPECHEADERMIDRULEBODY)	title_colspecwidthheaders_serialize_row_midrulejoinTABLE_TEMPLATEdict)clsdatasetcaptioncolspecheadermidrulerowbodys           L/var/www/horilla/myenv/lib/python3.12/site-packages/tablib/formats/_latex.py
export_setzLATEXFormat.export_set,   s     6=]]/GMM1,,w}}-8?##GOO4R,,w}}-yyWEc#,,S1EF!!D'06d%T T 	T Fs   Cc                 6    d}t        d|      D ]  }|dz  }	 |S )a:  Generates the column specification for the LaTeX `tabular` environment
        based on the dataset width.

        The first column is justified to the left, all further columns are aligned
        to the right.

        .. note:: This is only a heuristic and most probably has to be fine-tuned
        post export. Column alignment should depend on the data type, e.g., textual
        content should usually be aligned to the left while numeric content almost
        always should be aligned to the right.

        :param dataset_width: width of the dataset
        l   r)range)r#   dataset_widthspecr   s       r+   r   zLATEXFormat._colspec<   s-      q-( 	ACKD	    c           	          |r|dk(  rydj                  t        d|dz         D cg c]  }| j                  ||       c}      S c c}w )zGenerates the table `midrule`, which may be composed of several
        `cmidrules`.

        :param dataset_width: width of the dataset to serialize
        r/   z\midrule )r    r1   	_cmidrule)r#   r2   colindexs      r+   r   zLATEXFormat._midruleQ   sP      2xxq-!"346Hx? 6 7 	7 6s   Ac                 J    d}|dk(  r|d||fz  S ||k(  r|d||fz  S |d||fz  S )zGenerates the `cmidrule` for a single column with appropriate trimming
        based on the column position.

        :param colindex: Column index
        :param dataset_width: width of the dataset
        z\cmidrule(%s){%d-%d}r/   r0   r.   lr )r#   r8   r2   rules       r+   r7   zLATEXFormat._cmidrule^   sN     'q=3(333}$3(333tXx000r4   c                     |D cg c]   }|r| j                  t        |            nd" }}ddj                  |      z   dz   S c c}w )z_Returns string representation of a single row.

        :param row: single dataset row
        r   z      z & z \\)_escape_tex_reserved_symbolsstrr    )r#   r)   itemnew_rows       r+   r   zLATEXFormat._serialize_rowq   sW      #$ CG333CI>BN $ $G,,w66$s   %Ac                 F      fd} j                   j                  ||      S )zpEscapes all TeX reserved symbols ('_', '~', etc.) in a string.

        :param string: String to escape
        c                 >    j                   | j                            S )N)TEX_RESERVED_SYMBOLS_MAPgroup)matchr#   s    r+   replacez9LATEXFormat._escape_tex_reserved_symbols.<locals>.replace   s    //>>r4   )TEX_RESERVED_SYMBOLS_REsub)r#   stringrG   s   `  r+   r>   z(LATEXFormat._escape_tex_reserved_symbols|   s!    	?**..w??r4   N)__name__
__module____qualname__r   
extensionsr!   r"   rD   recompiler    mapescapekeysrH   classmethodr,   r   r   r7   r   r>   r;   r4   r+   r   r      s    EJN   $ %   )bjj#bii)A)F)F)HIJJL T T  ( 
7 
7 1 1$ 7 7 @ @r4   r   )__doc__rO   r   r;   r4   r+   <module>rV      s    
|@ |@r4   