U
    L?h                 %   @  s  U d Z ddlmZ ddlmZmZmZ ddlZddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z, ddl%m-Z-m.Z. ddl/m0Z0m1Z2 ddl3m4Z4m5Z5 ddl6Z6erHddl7m8Z8 ddl9m:Z: ddddddddddd d!d"d#d$d%d&d'd(d)d*gZ;d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDd5dEdAdFdGdHdIdJdKdLdM$Z<dNdOdPdQdRdSdTdUdVdWh
Z=dXdY dZdY d[dY d\dY d]dY d^dY d_dY d`dY dadY dbdY dcdY dddY dedY dfdY dgdY dhdY didY djdY dkdY dldY dmdY dndY dodY dpdY dqZ>dre?ds< e@eZAe6Bdte6BdufZCdvdvdwdxdyZDG dzd{ d{e(ZEdvdvdwd|d}ZFe)eEd~d ZGdd ZHdddZIdS )zC
A Printer which converts an expression into its LaTeX equivalent.
    )annotations)AnyCallableTYPE_CHECKINGN)AddFloatModMulNumberSSymbolExpr)greeks)Tuple)FunctionAppliedUndef
Derivative)AssocOp)Pow)default_sort_key)SympifyError)trueBooleanTrueBooleanFalse)precedence_traditional)Printerprint_function)split_super_subrequires_partial)
precedence
PRECEDENCE)prec_to_dpsto_str)has_varietysift)	NDimArray)BasisDependentZarcsinZarccosZarctansincostansinhcoshtanhsqrtlnlogsecZcscZcotZcothreZimfracrootargz
\mathrm{A}z
\mathrm{B}\Gammaz\Deltaz
\mathrm{E}z
\mathrm{Z}z
\mathrm{H}z\Thetaz
\mathrm{I}z
\mathrm{K}z\Lambdaz
\mathrm{M}z
\mathrm{N}z\Xioz
\mathrm{O}z\Piz
\mathrm{P}z\Sigmaz
\mathrm{T}z\Upsilonz\Phiz
\mathrm{X}z\Psiz\Omegaz\lambdaz\chiz\varepsilonz	\varkappaz\varphiz\varpiz\varrhoz	\varsigmaz	\vartheta)$AlphaBetaGammaDeltaEpsilonZetaEtaThetaIotaKappaLambdaMuNuXiomicronOmicronPiRhoSigmaTauUpsilonPhiChiPsiOmegalamdaZLamdaZkhiZKhiZ
varepsilonZvarkappaZvarphiZvarpiZvarrhoZvarsigmaZvarthetaZalephZbethZdalethZgimelZellethZhbarZhslashZmhoZwpc                 C  s   d|  d S )Nz
\mathring{} srS   rS   F/var/www/html/venv/lib/python3.8/site-packages/sympy/printing/latex.py<lambda>[       rW   c                 C  s   d|  d S )Nz\ddddot{rR   rS   rT   rS   rS   rV   rW   \   rX   c                 C  s   d|  d S )Nz\dddot{rR   rS   rT   rS   rS   rV   rW   ]   rX   c                 C  s   d|  d S )Nz\ddot{rR   rS   rT   rS   rS   rV   rW   ^   rX   c                 C  s   d|  d S )Nz\dot{rR   rS   rT   rS   rS   rV   rW   _   rX   c                 C  s   d|  d S )Nz\check{rR   rS   rT   rS   rS   rV   rW   `   rX   c                 C  s   d|  d S )Nz\breve{rR   rS   rT   rS   rS   rV   rW   a   rX   c                 C  s   d|  d S )Nz\acute{rR   rS   rT   rS   rS   rV   rW   b   rX   c                 C  s   d|  d S )Nz\grave{rR   rS   rT   rS   rS   rV   rW   c   rX   c                 C  s   d|  d S )Nz\tilde{rR   rS   rT   rS   rS   rV   rW   d   rX   c                 C  s   d|  d S )Nz\hat{rR   rS   rT   rS   rS   rV   rW   e   rX   c                 C  s   d|  d S )Nz\bar{rR   rS   rT   rS   rS   rV   rW   f   rX   c                 C  s   d|  d S )Nz\vec{rR   rS   rT   rS   rS   rV   rW   g   rX   c                 C  s   d|  d S N{z}'rS   rT   rS   rS   rV   rW   h   rX   c                 C  s   d|  d S rY   rS   rT   rS   rS   rV   rW   i   rX   c                 C  s   d|  d S Nz\boldsymbol{rR   rS   rT   rS   rS   rV   rW   k   rX   c                 C  s   d|  d S r[   rS   rT   rS   rS   rV   rW   l   rX   c                 C  s   d|  d S )Nz	\mathcal{rR   rS   rT   rS   rS   rV   rW   m   rX   c                 C  s   d|  d S )Nz	\mathscr{rR   rS   rT   rS   rS   rV   rW   n   rX   c                 C  s   d|  d S )Nz
\mathfrak{rR   rS   rT   rS   rS   rV   rW   o   rX   c                 C  s   d|  d S )Nz\left\|{z	}\right\|rS   rT   rS   rS   rV   rW   q   rX   c                 C  s   d|  d S )Nz\left\langle{z}\right\ranglerS   rT   rS   rS   rV   rW   r   rX   c                 C  s   d|  d S Nz\left|{z}\right|rS   rT   rS   rS   rV   rW   s   rX   c                 C  s   d|  d S r\   rS   rT   rS   rS   rV   rW   t   rX   )ZmathringZddddotZdddotZddotdotcheckZbreveacuteZgravetildeZhatbarvecprimeZprmboldbmcalZscrZfrakZnormavgabsmagzdict[str, Callable[[str], str]]modifier_dictz[0-9][} ]*$z(\d|\\frac{\d+}{\d+})str)rU   returnc                 C  sB   |  dd} dD ]}|  |d| } q|  dd} |  dd} | S )z
    Escape a string such that latex interprets it as plaintext.

    We cannot use verbatim easily with mathjax, so escaping is easier.
    Rules from https://tex.stackexchange.com/a/34586/41112.
    \z\textbackslashz&%$#_{}~z\textasciitilde^z\textasciicircum)replace)rU   crS   rS   rV   latex_escape   s    rr   c                      s  e Zd ZU dZdddddddddddddi ddddd	ddddd
ddZded< dddZddddZddddZdddddZ	dd Z
ddddZddddZddd d!Zdddd"d#Zddd$d%Zddd&d'Zddd(d)Zdd*d+d,Zd-d. Zd/d0d1d2ZeZeZd3d4 Zdd5d6Zd7d8 Zd9d: Zd;d< Zd=d> Zd?d@ ZdAdB ZdCdD ZdEdF Z dGdH Z!dIdJ Z"dKd*dLdMZ#dNdO Z$dPdQ Z%dRd*dSdTZ&dddUdVdWZ'dXdY Z(dZd[ Z)d\d] Z*d^d*d_d`Z+dadb Z,dcdd Z-dedf Z.dgdh Z/didj Z0dkdl Z1dmdn Z2dddodpdqZ3ddrddsdtduZ4dvdw Z5dxdy Z6e7dzd{ Z8d|d} Z9d~d Z:dd Z;dddddZ<e< Z=Z>dddZ?dddZ@dddZAdddZBdddZCdddZDdd ZEdd ZFdd ZGdd ZHdd ZIdddZJdddZKdddZLdddZMdddZNdddZOdddZPdddZQdddZRdddZSdddZTdddZUdddZVdddZWdddZXdddddZYeYZZdddZ[dddZ\dddZ]dddZ^dddĄZ_dddƄZ`dddȄZadddʄZbddd̄Zcddd΄ZddddϜddфZeddddӄZfdddՄZgdddׄZhdddلZidddۄZjddd݄Zkddd߄ZldddZmdddZndddZodddZpdddddZqdddddZrdddZsdddZtdddZudddZvdddZwdddZxdddZydddZzdddZ{ddd Z|dddZ}dddZ~dddZdddZdd	d
ZdddZdddZdÐddZdĐddZdŐddZdƐddZdǐddZdȐddZdɐddZdʐddZdːdd Zd̐d!d"Zd#d$ Zd%d& Zd͐d'd*d(d)ZeZdddd*d+d,Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Zd?d@ ZdAdB ZdCdD ZdϐdEdFZdGdH ZdIdJ ZdKdL ZdMdN ZdOdP ZdQdR ZdSdT ZdUdV ZdWdX ZdYd*dZd[Zd\d]d^d_Zd`da Zdbdc Zddde Zdfdg Zdhdi Zdjdk Zdldm Zdndo Zdpdq ZdАdrdsZdtdu Zdvdw Zdxdy Zdzd{ Zd|d} Zd~d Zdd ZdѐddZdҐddZdӐddZdԐddZdՐddZdd Zdd Zdd ZeZĐdd ZŐd֐ddZƐdאddZǐdؐddZȐdِddZɐdڐddZʐdېddZːdܐddZ̐dݐddZ͐dd ZeZeZeZѐdd ZҐdd ZӐdd ZԐdd ZՐdd Z֐dd Zאdd Zؐdd Zِdd Zڐdd Zېdd Zܐdd Zݐdd Zސdd ZߐddÄ ZdĐdń ZdƐdǄ ZdȐdɄ Zdʐd˄ Zd̐d̈́ Zdΐdτ ZdАdф ZdҐdӄ ZdԐdՄ Zd֐dׄ Zdؐdل Zdڐdۄ Zdܐd݄ Zdސd߄ Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdސddZdߐddZdddZdd Zdd Zdd Zdd Zdd Zd d Zdd Z dd Zdd Zdd	 Zd
d Zdd Zdd ZdddZdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- ZeZd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA Z dBdC Z!dDdE Z"dFdG Z#dHdI Z$dJdK Z%dLdM Z&dNdO Z'dPdQ Z(dRdS Z)dTdU Z*dVdW Z+dXdY Z,dZd[ Z-d\d] Z.d^d_ Z/dd`daZ0ddbdcZ1ddddeZ2ddfdgZ3ddhdiZ4ddjdkZ5dldm Z6dndo Z7dpdq Z8drds Z9dtdu Z:dvdw Z;dxdy Z<dzd{ Z=d|d} Z> fd~dZ?  Z@S (  LatexPrinterZ_latexFNabbreviated[plainTiperiodddagger)	full_precfold_frac_powersfold_func_bracketsfold_short_fracinv_trig_styleitexln_notationlong_frac_ratio	mat_delimmat_strmode
mul_symbolordersymbol_namesroot_notationmat_symbol_styleimaginary_unitgothic_re_imdecimal_separatorperm_cyclicparenthesize_superminmaxdiff_operatoradjoint_stylezdict[str, Any]_default_settingsc                 C  sz  t | | d| jkr8ddddg}| jd |kr8td| jd d kr^| jd dkr^d| jd< d	d
ddd}z|| jd  | jd< W n$ tk
r   | jd | jd< Y nX z|| jd pd | jd< W nH tk
r   | jd  dkr|d | jd< n| jd | jd< Y nX ddd| _dddddddd}| jd }|||| jd< ddd d!d"}| jd# }|||| jd$< d S )%Nr   inlinerv   Zequationz	equation*zB'mode' must be one of 'inline', 'plain', 'equation' or 'equation*'r~   T z \,.\, z \cdot  \times )NZldotr]   timesr   mul_symbol_latexr]   mul_symbol_latex_numbers) r   rm   z\,z\:\;z\quad)])(ru   rw   z
\mathrm{i}z\text{i}jz
\mathrm{j}z\text{j})Nrw   ritir   ZrjZtjr   Zimaginary_unit_latexry   z
\mathrm{d}z\text{d})Nry   rdtdr   diff_operator_latex)r   __init__	_settings
ValueErrorKeyErrorstrip_delim_dictget)selfsettingsZvalid_modesZmul_symbol_tableZimaginary_unit_tableZ	imag_unitZdiff_operator_tabler   rS   rS   rV   r      sf    


	

zLatexPrinter.__init__rk   rl   c                 C  s
   d |S )Nz\left({}\right)formatr   rU   rS   rS   rV   _add_parens   s    zLatexPrinter._add_parensc                 C  s
   d |S )Nz\left( {}\right)r   r   rS   rS   rV   _add_parens_lspace   s    zLatexPrinter._add_parens_lspacec                 C  sR   t |}|r |r | | |S ||k s4|sD||krD| | |S | |S d S N)r   r   _print)r   itemlevelis_negstrictZprec_valrS   rS   rV   parenthesize   s    zLatexPrinter.parenthesizec                 C  s*   d|kr&| j d r| |S d|S |S )z
        Protect superscripts in s

        If the parenthesize_super option is set, protect with parentheses, else
        wrap in braces.
        ro   r   z{{{}}})r   r   r   r   rS   rS   rV   r      s
    


zLatexPrinter.parenthesize_superc                 C  sb   t | |}| jd dkr|S | jd dkr4d| S | jd rFd| S | jd }d|||f S d S )Nr   rv   r   z$%s$r   z$$%s$$z\begin{%s}%s\end{%s})r   doprintr   )r   exprtexZenv_strrS   rS   rV   r   	  s    

zLatexPrinter.doprintboolc                 C  s(   |j r|jp$|jo$|tjk	o$|jdk S )z
        Returns True if the expression needs to be wrapped in brackets when
        printed, False otherwise. For example: a + b => True; a => False;
        10 => False; -10 => True.
        F)Z
is_IntegerZis_nonnegativeis_Atomr   NegativeOneis_Rationalr   r   rS   rS   rV   _needs_brackets  s    zLatexPrinter._needs_bracketsc                 C  sN   |  |sdS |jr"| |s"dS |jr6| |s6dS |jsB|jrFdS dS dS )a  
        Returns True if the expression needs to be wrapped in brackets when
        passed as an argument to a function, False otherwise. This is a more
        liberal version of _needs_brackets, in that many expressions which need
        to be wrapped in brackets when added/subtracted/raised to a power do
        not need them when passed to a function. Such an example is a*b.
        FTN)r   is_Mul_mul_is_cleanZis_Pow_pow_is_cleanis_Addis_Functionr   rS   rS   rV   _needs_function_brackets   s    
z%LatexPrinter._needs_function_bracketsc                   s   ddl m} ddlm} ddlm}  jr<|sZ  rZdS nt t	d k rPdS  j
rZdS  jrddS t fddtfD rdS |st fd	d|||fD rdS d
S )a  
        Returns True if the expression needs to be wrapped in brackets when
        printed as part of a Mul, False otherwise. This is True for Add,
        but also for some container objects that would not need brackets
        when appearing last in a Mul, e.g. an Integral. ``last=True``
        specifies that this expr is the last to appear in a Mul.
        ``first=True`` specifies that this expr is the first to appear in
        a Mul.
        r   )Product)Sum)IntegralTr	   c                 3  s   | ]}  |V  qd S r   has.0xr   rS   rV   	<genexpr>N  s     z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r   r   rS   rV   r   Q  s     F)Zsympy.concrete.productsr   Zsympy.concrete.summationsr   Zsympy.integrals.integralsr   r   could_extract_minus_signr   r    is_RelationalZis_Piecewiseanyr   )r   r   firstlastr   r   r   rS   r   rV   _needs_mul_brackets7  s&    
z LatexPrinter._needs_mul_bracketsc                   s4    j r
dS t fddtfD r&dS  jr0dS dS )z
        Returns True if the expression needs to be wrapped in brackets when
        printed as part of an Add, False otherwise.  This is False for most
        things.
        Tc                 3  s   | ]}  |V  qd S r   r   r   r   rS   rV   r   ^  s     z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>F)r   r   r   r   r   rS   r   rV   _needs_add_bracketsV  s    z LatexPrinter._needs_add_bracketsc                 C  s   |j D ]}|jr dS qdS )NFT)argsr   )r   r   r4   rS   rS   rV   r   d  s    
zLatexPrinter._mul_is_cleanc                 C  s   |  |j S r   )r   baser   rS   rS   rV   r   j  s    zLatexPrinter._pow_is_cleanr   c                 C  s   |d k	rd||f S |S d S )N\left(%s\right)^{%s}rS   r   r   exprS   rS   rV   _do_exponentm  s    zLatexPrinter._do_exponentc                   sL     |jj}|jr> fdd|jD }d}||d|S d|S d S )Nc                   s   g | ]}  |qS rS   r   )r   r6   r   rS   rV   
<listcomp>v  s     z-LatexPrinter._print_Basic.<locals>.<listcomp>z"\operatorname{{{}}}\left({}\right), z\text{{{}}})_deal_with_super_sub	__class____name__r   r   join)r   r   nameZlsrU   rS   r   rV   _print_Basics  s    zLatexPrinter._print_Basicz!bool | BooleanTrue | BooleanFalse)ec                 C  s   d| S N	\text{%s}rS   r   r   rS   rS   rV   _print_bool|  s    zLatexPrinter._print_boolc                 C  s   d| S r   rS   r   rS   rS   rV   _print_NoneType  s    zLatexPrinter._print_NoneTypec                 C  sv   | j ||d}d}t|D ]V\}}|dkr,n | rD|d7 }| }n|d7 }| |}| |rhd| }||7 }q|S )N)r   r   r    -  + \left(%s\right))Z_as_ordered_terms	enumerater   r   r   )r   r   r   termsr   rw   termterm_texrS   rS   rV   
_print_Add  s    


zLatexPrinter._print_Addc                 C  s   ddl m} |jdkrdS ||}|j}|j}|jd |d krP||d gg }d}|D ]}|t|dd7 }qX|d	d
}|dd}|S )Nr   Permutation\left( \right)   r   ,r   ru   z\left( r   \right)) sympy.combinatorics.permutationsr   sizeZcyclic_form
array_formrk   rp   )r   r   r   Z	expr_permZsizr   rw   rS   rS   rV   _print_Cycle  s    
zLatexPrinter._print_Cyclec           
        s   ddl m} ddlm} |j}|d k	r@|d| ddddd	 n jd
d}|r\ |S |jdkrjdS  fdd|j	D } fddt
t|D }d|}d|}d||f}	d|	 S )Nr   r   )sympy_deprecation_warningzw
                Setting Permutation.print_cyclic is deprecated. Instead use
                init_printing(perm_cyclic=z).
                z1.6z#deprecated-permutation-print_cyclic   )Zdeprecated_since_versionZactive_deprecations_target
stacklevelr   Tr   c                   s   g | ]}  |qS rS   r   r   r4   r   rS   rV   r     s     z3LatexPrinter._print_Permutation.<locals>.<listcomp>c                   s   g | ]}  |qS rS   r   r  r   rS   rV   r     s      & z \\ z \begin{pmatrix} %s \end{pmatrix})r  r   Zsympy.utilities.exceptionsr  Zprint_cyclicr   r   r  r  r  rangelenr   )
r   r   r   r  r   lowerupperZrow1Zrow2matrS   r   rV   _print_Permutation  s.    




zLatexPrinter._print_Permutationc                 C  s"   |j \}}d| || |f S )Nz\sigma_{%s}(%s))r   r   )r   r   permvarrS   rS   rV   _print_AppliedPermutation  s    
z&LatexPrinter._print_AppliedPermutationc           
      C  s   t |j}| jd rdnd}d| jkr0| jd nd }d| jkrH| jd nd }t|j||||d}| jd }d|kr|d\}}	|	d	 d
kr|	dd  }	| jd dkr|dd}d|||	f S |dkrdS |dkrdS | jd dkr|dd}|S d S )Nr{   FTr   r   )Zstrip_zerosZ	min_fixedZ	max_fixedr   r   r   +r   r   comma.z{,}z%s%s10^{%s}z+infz\inftyz-infz- \infty)r!   Z_precr   mlib_to_strZ_mpf_splitrp   )
r   r   Zdpsr   lowhighZstr_real	separatorZmantr   rS   rS   rV   _print_Float  s(    

zLatexPrinter._print_Floatc                 C  s0   |j }|j}d| |td | |td f S )Nz%s \times %sr	   Z_expr1Z_expr2r   r    r   r   Zvec1Zvec2rS   rS   rV   _print_Cross  s
    zLatexPrinter._print_Crossc                 C  s   |j }d| |td  S )Nz\nabla\times %sr	   Z_exprr   r    r   r   rb   rS   rS   rV   _print_Curl  s    zLatexPrinter._print_Curlc                 C  s   |j }d| |td  S )Nz\nabla\cdot %sr	   r  r   rS   rS   rV   _print_Divergence  s    zLatexPrinter._print_Divergencec                 C  s0   |j }|j}d| |td | |td f S )Nz%s \cdot %sr	   r  r  rS   rS   rV   
_print_Dot  s
    zLatexPrinter._print_Dotc                 C  s   |j }d| |td  S )Nz	\nabla %sr	   r  r   r   funcrS   rS   rV   _print_Gradient  s    zLatexPrinter._print_Gradientc                 C  s   |j }d| |td  S )Nz	\Delta %sr	   r  r$  rS   rS   rV   _print_Laplacian  s    zLatexPrinter._print_Laplacianr   c                   s  ddl m} jd jd dd fdd}ddfd	d
 t|tr|j}|d tjkstdd |dd  D r |S d}|	 r| }d}|j
r|d7 }d}nd}||dd\}}|tjkrtdddd|jkr|||7 }n||}	||}
t|
 }jd }jd rr|dkrrd|
krrj|ddr^|d|	|
f 7 }n|d|	|
f 7 }n6|d k	rt|	 || krj|ddr|d|
|	f 7 }n|jrtj}tj}|jD ]f}j|dds"t|||  || ks"|j|j  krdkr,n n
||9 }n||9 }qЈj|ddrf|d|||
||f 7 }n|d|||
||f 7 }n|d |
|	f 7 }n|d!|	|
f 7 }|r|d"7 }|S )#Nr   )fractionr   r   rk   r   c                   sr   | j st| S jdkr(|  }n
t| j}t|dd dd\}}t|dd dd\}} || | S d S )N)oldnonec                 S  s*   t | dp(t | dp(t| to(t | jdS )N_scale_factoris_physical_constant)hasattr
isinstancer   r   r   rS   rS   rV   rW     s   
z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>T)binaryc                 S  s
   t | dS )Nr+  )r-  r/  rS   rS   rV   rW     rX   )r   rk   r   r   as_ordered_factorslistr   r$   )r   r   ZunitsZnonunitsprefixes)convert_argsr   rS   rV   convert  s    




z(LatexPrinter._print_Mul.<locals>.convertc                   s   d }}t | D ]\}}|}t|dst|dsj||dk|t| d kdr^d| }td |rtd |r| 7 }q|r|7 }n|r|7 }||7 }|}q|S )Nr   r+  r,  r   r   )r   r   r   )r   r   r-  r   r  _between_two_numbers_psearchmatch)r   Z_texZlast_term_texrw   r   r   )	numbersepr   r  rS   rV   r4    s&    


z-LatexPrinter._print_Mul.<locals>.convert_argsc                 s  s   | ]}t |tV  qd S r   )r.  r
   r  rS   rS   rV   r   :  s     z*LatexPrinter._print_Mul.<locals>.<genexpr>r   F- r   Tr   )exactr   )evaluater   r~      ro   )r   z\left(%s\right) / %sz%s / %sz\frac{1}{%s}%s\left(%s\right)z\frac{%s}{%s}%s\left(%s\right)z\frac{%s}{%s}%s%sz\frac{1}{%s}%s%s\frac{%s}{%s}r   )Zsympy.simplifyr(  r   r.  r	   r   r   Oner   r   r   r   r  r  r   r   is_commutative)r   r   r(  r5  r   Zinclude_parensr   numerdenomZsnumerZsdenomZldenomratioabr   rS   )r4  r9  r   r  rV   
_print_Mul  s~    


(


 

zLatexPrinter._print_Mulc                 C  s*   |j r| |  S | | S d S r   )Z
is_aliasedr   Zas_polyas_exprr   rS   rS   rV   _print_AlgebraicNumberz  s    z#LatexPrinter._print_AlgebraicNumberc                 C  s@   |  |j}|jrd| dS |  |j }d| d| dS )N\left(r   r   )r   pZis_inertalpharG  )r   r   rJ  rK  rS   rS   rV   _print_PrimeIdeal  s
    zLatexPrinter._print_PrimeIdealr   c                 C  s  |j jr|j j}|j j}t|dkr|dkr| jd r| |j}|dkrVd| }n$| jd rnd||f }nd||f }|j jrd| S |S n| jd	 r|dkr| 	|jt
d
 }|jjr| |}|jjr| j|jd||f dS d|||f S |j jr|jjr|jdkr$d|j|j f S |jjr||jj}|jj}|| t|kr||j dkrhd||f S d||t|j f S | |S |jjr| j|j| |j dS d}| ||S )Nr   r   r=  z	\sqrt{%s}r   z\root{%d}{%s}z\sqrt[%d]{%s}z\frac{1}{%s}r|   r   z%s/%sr   z
%s^{%s/%s}%s^{%s}r   z\frac{1}{\frac{%s}{%s}}z\frac{1}{(\frac{%s}{%s})^{%s}})r   r   rJ  qrh   r   r   r   Zis_negativer   r    	is_Symbolr   r   r@  rF  _helper_print_standard_power)r   r   rJ  rO  r   r   Zbase_pZbase_qrS   rS   rV   
_print_Pow  sF    






zLatexPrinter._print_Pow)templaterl   c                 C  s   |  |j}| |jtd }|jjr2| |}nJ|jjrDd| }n8t|jt	r||
dr|td|r||dr||dd }|||f S )Nr   z{%s}rI  z\\left\(\\d?d?dotr      i)r   r   r   r   r    rP  r   Zis_Floatr.  r   
startswithr1   r8  endswith)r   r   rS  r   r   rS   rS   rV   rQ    s    

z)LatexPrinter._helper_print_standard_powerc                 C  s   |  |jd S Nr   r   r   r   rS   rS   rV   _print_UnevaluatedExpr  s    z#LatexPrinter._print_UnevaluatedExprc                   s   t |jdkr0dtfdd|jd D  }n,fdd dtd	 fd
d|jD  }t|jtr~|d|j 7 }n||j7 }|S )Nr   z\sum_{%s=%s}^{%s} c                   s   g | ]}  |qS rS   r   r   rw   r   rS   rV   r     s     z+LatexPrinter._print_Sum.<locals>.<listcomp>r   c                   s,   dt  fdd| d | d | d fD  S )N%s \leq %s \leq %sc                   s   g | ]}  |qS rS   r   r   rU   r   rS   rV   r     s     zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>r   r   r=  tuplelr   rS   rV   _format_ineq  s    &z-LatexPrinter._print_Sum.<locals>._format_ineqz\sum_{\substack{%s}} \\c                   s   g | ]} |qS rS   rS   r   r`  ra  rS   rV   r     s     r   	r  limitsr^  rk   r   r.  functionr   r   r   r   r   rS   ra  r   rV   
_print_Sum  s    zLatexPrinter._print_Sumc                   s   t |jdkr0dtfdd|jd D  }n,fdd dtd	 fd
d|jD  }t|jtr~|d|j 7 }n||j7 }|S )Nr   z\prod_{%s=%s}^{%s} c                   s   g | ]}  |qS rS   r   rZ  r   rS   rV   r     s     z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                   s,   dt  fdd| d | d | d fD  S )Nr[  c                   s   g | ]}  |qS rS   r   r\  r   rS   rV   r     s     zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>r   r   r=  r]  r_  r   rS   rV   ra    s    &z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} rb  c                   s   g | ]} |qS rS   rS   rc  rd  rS   rV   r     s     r   re  rh  rS   ri  rV   _print_Product  s    zLatexPrinter._print_Productz'BasisDependent'c                 C  s  ddl m} g }||jkr"|jjS t||r:|  }n
d|fg}|D ]\}}t|j }|j	dd d |D ]b\}}	|	dkr|
d|j  qr|	dkr|
d	|j  qrd
| |	 d }
|
d|
 |j  qrqHd|}|d dkr|dd  }n|dd  }|S )Nr   )Vectorc                 S  s   | d   S rW  )__str__r/  rS   rS   rV   rW     rX   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>keyr   r   r   r   rI  r   r   -   )Zsympy.vectorrl  zeroZ_latex_formr.  Zseparateitemsr2  
componentssortappendr   r   )r   r   rl  Zo1rs  systemZvectZ
inneritemskvZarg_strZoutstrrS   rS   rV   _print_BasisDependent  s,    



z"LatexPrinter._print_BasisDependentc                 C  s4   |  |j}d| d ddt| j |j  }|S )NrZ   rR   _{%s}r   )r   r   r   mapindices)r   r   Ztex_baser   rS   rS   rV   _print_Indexed  s
    zLatexPrinter._print_Indexedc                 C  s   |  |jS r   )r   labelr   rS   rS   rV   _print_IndexedBase  s    zLatexPrinter._print_IndexedBasec                 C  sf   |  |j}|jd k	rb|  |j}|jd k	r:|  |j}n|  tj}dj||d}dj||dS |S )Nz%{lower}\mathrel{{..}}\nobreak {upper})r  r  z{{{label}}}_{{{interval}}})r  interval)r   r  r  r  r   Zeror   )r   r   r  r  r  r  rS   rS   rV   
_print_Idx  s    

  zLatexPrinter._print_Idxc              	   C  s   t |jrd}n
| jd }d}d}t|jD ]T\}}||7 }|dkr\|d|| |f 7 }q,|d|| | || |f 7 }q,|dkrd||f }nd	|| ||f }td
d |jD rd|| j	|jt
d dddf S d|| j	|jt
d dddf S )Nz\partialr   r   r   r   %s %sz
%s %s^{%s}r>  z\frac{%s^{%s}}{%s}c                 s  s   | ]}|  V  qd S r   r   rZ  rS   rS   rV   r   :  s     z1LatexPrinter._print_Derivative.<locals>.<genexpr>r	   Tr   r   F)r   r   r   reversedZvariable_countr   r   r   r   r   r    )r   r   diff_symbolr   dimr   numrS   rS   rV   _print_Derivative$  s6    



zLatexPrinter._print_Derivativec           	        s`   |j \}}} |} fdd|D } fdd|D }ddd t||D }d||f S )Nc                 3  s   | ]}  |V  qd S r   r   r   r   r   rS   rV   r   H  s     z+LatexPrinter._print_Subs.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   I  s     z\\ c                 s  s"   | ]}|d  d |d  V  qdS )r   =r   NrS   r  rS   rS   rV   r   J  s    z#\left. %s \right|_{\substack{ %s }})r   r   r   zip)	r   subsr   r)  newZ
latex_exprZ	latex_oldZ	latex_newZ
latex_subsrS   r   rV   _print_SubsE  s    

zLatexPrinter._print_Subsc              	     s\  dg  }}j d  t|jdkrhtdd |jD rhddt|jd   d	 } fd
d|jD }nt|jD ]}|d }|d7 }t|dkrj d dkrj d s|d7 }t|dkr|d|d |d f 7 }t|dkr|d|d  7 }|dd |f  qrd|j|jt	d t
dd |jD ddd|f S )Nr   r      c                 s  s   | ]}t |d kV  qdS )r   N)r  )r   limrS   rS   rV   r   T  s     z/LatexPrinter._print_Integral.<locals>.<genexpr>z\irw   r   ntc                   s"   g | ]}d   |d f qS )\, %s%sr   r   r   symbolr  r   rS   rV   r   X  s   z0LatexPrinter._print_Integral.<locals>.<listcomp>r   z\intr   r   r   z\limitsrq  z
_{%s}^{%s}r=  ^{%s}r  z%s %s%sr	   c                 s  s   | ]}|  V  qd S r   r  rZ  rS   rS   rV   r   o  s     Tr  )r   r  rf  allr  r   insertr   rg  r    r   r   r   )r   r   r   symbolsr  r  rS   r  rV   _print_IntegralO  s:    

"zLatexPrinter._print_Integralc                 C  s   |j \}}}}d| | }t|dks8|tjtjfkrL|d| | 7 }n|d| || |f 7 }t|trd|| |f S d|| |f S d S )Nz\lim_{%s \to z+-z%s}z%s^%s}%s\left(%s\right)r  )r   r   rk   r   InfinityNegativeInfinityr.  r   )r   r   r   zZz0dirr   rS   rS   rV   _print_Limits  s    
zLatexPrinter._print_Limit)r%  rl   c                 C  s   |  |}|d}|d}|tkr0d| }nt|dksV|dsV|dksV|dkr\|}n|dkr|dkrd|dt|| |t||d f }nT|dkrd|d| ||d f }n.|dkrd|d| ||d f }nd	| }|S )
ak  
        Logic to decide how to render a function to latex
          - if it is a recognized latex name, use the appropriate latex command
          - if it is a single letter, excluding sub- and superscripts, just use that letter
          - if it is a longer name, then put \operatorname{} around it and be
            mindful of undercores in the name
        ro   _z\%sr   rm   r   z\operatorname{%s}%sNz\operatorname{%s})r   findaccepted_latex_functionsr  rU  r   )r   r%  ZsuperscriptidxZsubscriptidxr   rS   rS   rV   _hprint_Function  s0    



&



zLatexPrinter._hprint_Functionr   )r   rl   c                   s  |j j}t d| r4t|ts4t d| ||S  fdd|jD } jd }d} jd o|t|dko| 	|jd  }d	d
ddddddddddg}||kr|dkrnN|dkr|d dkrdnd|dd  }n$|dkr|dd }d}|dk	rd}|r|t
krd| }	nd| }	n6|dk	rJ |}
 |
}
d |
|f }	n
 |}	|rx|t
krn|	d!7 }	n|	d"7 }	n|	d#7 }	|r|dk	r|	d$| 7 }	|	d%| S dS )&a#  
        Render functions to LaTeX, handling functions that LaTeX knows about
        e.g., sin, cos, ... by using the proper LaTeX command (\sin, \cos, ...).
        For single-letter function names, render them as regular LaTeX math
        symbols. For multi-letter function names that LaTeX does not know
        about, (e.g., Li, sech) use \operatorname{} so that the function name
        is rendered in Roman font and LaTeX handles spacing properly.

        expr is the expression involving the function
        exp is an exponent
        Z_print_c                   s   g | ]}t  |qS rS   )rk   r   r  r   rS   rV   r     s     z0LatexPrinter._print_Function.<locals>.<listcomp>r   Fr}   r   r   asinacosatanZacscZasecZacotasinhacoshatanhZacschZasechZacothrt   fullr   hararcNpowerTz\%s^{-1}z\operatorname{%s}^{-1}rN  z {%s}%s{\left(%s \right)}r  r   )r%  r   r-  r.  r   getattrr   r   r  r   r  r  r   r   )r   r   r   r%  r   r   Zinv_trig_power_caseZcan_fold_bracketsZinv_trig_tabler   Zfunc_texrS   r   rV   _print_Function  sj    


        "









zLatexPrinter._print_Functionc                 C  s   |  t|S r   )r  rk   r   rS   rS   rV   _print_UndefinedFunction  s    z%LatexPrinter._print_UndefinedFunctionc                 C  s   d|  |j|  |jf S )Nz{%s}_{\circ}\left({%s}\right))r   rg  r   r   rS   rS   rV   _print_ElementwiseApplyFunction  s    

z,LatexPrinter._print_ElementwiseApplyFunctionc                 C  s\   ddl m} ddlm}m} ddlm} ddlm} ddl	m
} |d|d|d	|d
|d|diS )Nr   )KroneckerDelta)gamma
lowergamma)beta)
DiracDelta)rM   z\deltar5   z\gammaz\operatorname{B}z\operatorname{Chi})Z(sympy.functions.special.tensor_functionsr  Z'sympy.functions.special.gamma_functionsr  r  Z&sympy.functions.special.beta_functionsr  Z'sympy.functions.special.delta_functionsr  Z'sympy.functions.special.error_functionsrM   )r   r  r  r  r  r  rM   rS   rS   rV   _special_function_classes  s"         z&LatexPrinter._special_function_classesc                 C  s>   | j D ](}t||r|j|jkr| j |   S q| t|S r   )r  
issubclassr   r  rk   )r   r   clsrS   rS   rV   _print_FunctionClass  s    
z!LatexPrinter._print_FunctionClassc                 C  sJ   |j \}}t|dkr&| |d }n| t|}d|| |f }|S )Nr   r   z\left( %s \mapsto %s \right))r   r  r   r^  )r   r   r  r   rS   rS   rV   _print_Lambda
  s    
zLatexPrinter._print_Lambdac                 C  s   dS )Nz\left( x \mapsto x \right)rS   r   rS   rS   rV   _print_IdentityFunction  s    z$LatexPrinter._print_IdentityFunctionc                   sX   t |jtd} fdd|D }dt|j d|f }|d k	rPd||f S |S d S )Nrn  c                   s   g | ]}d   | qS )r  r   r  r   rS   rV   r     s     z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)r   rN  )sortedr   r   rk   r%  r  r   )r   r   r   r   Ztexargsr   rS   r   rV   _hprint_variadic_function  s    z&LatexPrinter._hprint_variadic_functionc                 C  s0   d|  |jd  }|d k	r(d||f S |S d S )Nz\left\lfloor{%s}\right\rfloorr   rN  rX  r   r   r   r   rS   rS   rV   _print_floor%  s    zLatexPrinter._print_floorc                 C  s0   d|  |jd  }|d k	r(d||f S |S d S )Nz\left\lceil{%s}\right\rceilr   rN  rX  r  rS   rS   rV   _print_ceiling-  s    zLatexPrinter._print_ceilingc                 C  sP   | j d s d| |jd  }nd| |jd  }|d k	rHd||f S |S d S )Nr   z\log{\left(%s \right)}r   z\ln{\left(%s \right)}rN  )r   r   r   r  rS   rS   rV   
_print_log5  s    
zLatexPrinter._print_logc                 C  s0   d|  |jd  }|d k	r(d||f S |S d S )N\left|{%s}\right|r   rN  rX  r  rS   rS   rV   
_print_Abs@  s    zLatexPrinter._print_Absc                 C  sN   | j d r&d| |jd td  }nd| |jd td }| ||S )Nr   z\Re{%s}r   Atomz\operatorname{{re}}{{{}}}r   r   r   r    r   r   r  rS   rS   rV   	_print_reH  s    
zLatexPrinter._print_rec                 C  sN   | j d r&d| |jd td  }nd| |jd td }| ||S )Nr   z\Im{%s}r   r  z\operatorname{{im}}{{{}}}r  r  rS   rS   rV   	_print_imP  s    
zLatexPrinter._print_imc                 C  s   ddl m}m} t|jd |r2| |jd dS t|jd |rT| |jd dS |jd jrtd| |jd  S d| |jd  S d S )Nr   )
EquivalentImpliesz\not\Leftrightarrowz\not\Rightarrowz\neg \left(%s\right)z\neg %s)	sympy.logic.boolalgr  r  r.  r   _print_Equivalent_print_Implies
is_Booleanr   )r   r   r  r  rS   rS   rV   
_print_NotX  s    zLatexPrinter._print_Notc                 C  s   |d }|j r$|js$d| | }nd| | }|dd  D ]>}|j rf|jsf|d|| |f 7 }q>|d|| |f 7 }q>|S )Nr   r   r  r   z %s \left(%s\right)z %s %s)r  Zis_Notr   )r   r   charr4   r   rS   rS   rV   _print_LogOpc  s    zLatexPrinter._print_LogOpc                 C  s   t |jtd}| |dS )Nrn  z\wedger  r   r   r  r   r   r   rS   rS   rV   
_print_Andr  s    zLatexPrinter._print_Andc                 C  s   t |jtd}| |dS )Nrn  z\veer  r  rS   rS   rV   	_print_Orv  s    zLatexPrinter._print_Orc                 C  s   t |jtd}| |dS )Nrn  z\veebarr  r  rS   rS   rV   
_print_Xorz  s    zLatexPrinter._print_Xorc                 C  s   |  |j|pdS )Nz\Rightarrow)r  r   )r   r   altcharrS   rS   rV   r  ~  s    zLatexPrinter._print_Impliesc                 C  s   t |jtd}| ||pdS )Nrn  z\Leftrightarrowr  )r   r   r  r   rS   rS   rV   r    s    zLatexPrinter._print_Equivalentc                 C  s0   d|  |jd  }|d k	r(d||f S |S d S )Nz\overline{%s}r   rN  rX  r  rS   rS   rV   _print_conjugate  s    zLatexPrinter._print_conjugatec                 C  s>   d}d|  |jd  }|d k	r.d|||f S d||f S d S )Nz\operatorname{polar\_lift}r  r   	%s^{%s}%s%s%srX  )r   r   r   r%  r4   rS   rS   rV   _print_polar_lift  s
    zLatexPrinter._print_polar_liftc                 C  s    d|  |jd  }| ||S )Nze^{%s}r   )r   r   r   r  rS   rS   rV   _print_ExpBase  s    zLatexPrinter._print_ExpBasec                 C  s   dS )Nr   rS   r   rS   rS   rV   _print_Exp1  s    zLatexPrinter._print_Exp1c                 C  s4   d|  |jd  }|d k	r(d||f S d| S d S )Nr   r   zK^{%s}%szK%srX  r  rS   rS   rV   _print_elliptic_k  s    zLatexPrinter._print_elliptic_kc                 C  sD   d|  |jd |  |jd f }|d k	r8d||f S d| S d S )N\left(%s\middle| %s\right)r   r   zF^{%s}%szF%srX  r  rS   rS   rV   _print_elliptic_f  s    zLatexPrinter._print_elliptic_fc                 C  sh   t |jdkr4d| |jd | |jd f }nd| |jd  }|d k	r\d||f S d| S d S )Nr=  r  r   r   r   zE^{%s}%szE%sr  r   r   r  rS   rS   rV   _print_elliptic_e  s    zLatexPrinter._print_elliptic_ec                 C  s   t |jdkrBd| |jd | |jd | |jd f }n$d| |jd | |jd f }|d k	rzd||f S d| S d S )	Nrq  z\left(%s; %s\middle| %s\right)r   r   r=  r  z
\Pi^{%s}%sz\Pi%sr  r  rS   rS   rV   _print_elliptic_pi  s    zLatexPrinter._print_elliptic_pic                 C  s^   |j d }t|j dkr"|j d n|j d }d| d| d}|d k	rRd||f S d| S d S )Nr   r   rI  r   r   z\operatorname{B}^{%s}%sz\operatorname{B}%s)r   r  )r   r   r   r   yr   rS   rS   rV   _print_beta  s    
"zLatexPrinter._print_betaBc                   sf    fdd|j D }d|d |d f }|d k	rJd||d |d ||f S d	||d |d |f S d S )
Nc                   s   g | ]}  |qS rS   r   r  r   rS   rV   r     s     z/LatexPrinter._print_betainc.<locals>.<listcomp>\left(%s, %s\right)r   r   z#\operatorname{%s}_{(%s, %s)}^{%s}%sr=  rq  z\operatorname{%s}_{(%s, %s)}%s)r   )r   r   r   operatorlargsr   rS   r   rV   _print_betainc  s
    zLatexPrinter._print_betaincc                 C  s   | j ||ddS )NI)r  )r  r   rS   rS   rV   _print_betainc_regularized  s    z'LatexPrinter._print_betainc_regularizedc                 C  sD   d|  |jd |  |jd f }|d k	r8d||f S d| S d S )Nr  r   r   z\Gamma^{%s}%sz\Gamma%srX  r  rS   rS   rV   _print_uppergamma  s    zLatexPrinter._print_uppergammac                 C  sD   d|  |jd |  |jd f }|d k	r8d||f S d| S d S )Nr  r   r   z\gamma^{%s}%s\gamma%srX  r  rS   rS   rV   _print_lowergamma  s    zLatexPrinter._print_lowergammac                 C  sJ   d|  |jd  }|d k	r2d|  |j||f S d|  |j|f S d S Nr   r   r  r  )r   r   r%  r  rS   rS   rV   _hprint_one_arg_func  s    z!LatexPrinter._hprint_one_arg_funcc                 C  s4   d|  |jd  }|d k	r(d||f S d| S d S )Nr   r   z\operatorname{Chi}^{%s}%sz\operatorname{Chi}%srX  r  rS   rS   rV   
_print_Chi  s    zLatexPrinter._print_Chic                 C  sJ   d|  |jd  }|  |jd }|d k	r:d|||f S d||f S d S )Nr   r   r   z\operatorname{E}_{%s}^{%s}%sz\operatorname{E}_{%s}%srX  )r   r   r   r   nurS   rS   rV   _print_expint  s
    zLatexPrinter._print_expintc                 C  s4   d|  |jd  }|d k	r(d||f S d| S d S )Nr   r   zS^{%s}%szS%srX  r  rS   rS   rV   _print_fresnels
  s    zLatexPrinter._print_fresnelsc                 C  s4   d|  |jd  }|d k	r(d||f S d| S d S )Nr   r   zC^{%s}%szC%srX  r  rS   rS   rV   _print_fresnelc  s    zLatexPrinter._print_fresnelcc                 C  s6   d|  |jd td  }|d k	r.d||f S |S d S )Nz!%sr   Funcr   r   r   r    r  rS   rS   rV   _print_subfactorial  s    z LatexPrinter._print_subfactorialc                 C  s6   d|  |jd td  }|d k	r.d||f S |S d S )Nz%s!r   r  rN  r  r  rS   rS   rV   _print_factorial"  s    zLatexPrinter._print_factorialc                 C  s6   d|  |jd td  }|d k	r.d||f S |S d S )Nz%s!!r   r  rN  r  r  rS   rS   rV   _print_factorial2*  s    zLatexPrinter._print_factorial2c                 C  s@   d|  |jd |  |jd f }|d k	r8d||f S |S d S )Nz{\binom{%s}{%s}}r   r   rN  rX  r  rS   rS   rV   _print_binomial2  s    zLatexPrinter._print_binomialc                 C  s<   |j \}}d| |td  }d|| |f }| ||S )Nr  r  z{%s}^{\left(%s\right)}r   r   r    r   r   )r   r   r   nrx  r   r   rS   rS   rV   _print_RisingFactorial;  s    
z#LatexPrinter._print_RisingFactorialc                 C  s<   |j \}}d| |td  }d| ||f }| ||S )Nr  r  z{\left(%s\right)}_{%s}r  )r   r   r   r  rx  subr   rS   rS   rV   _print_FallingFactorialC  s    
z$LatexPrinter._print_FallingFactorial)symrl   c                 C  sf   d| }d}|d k	r4| ddkr0d||f }nd}d|| |j| |jf }|rb| ||}|S )Nr  Fro   r   rN  T%s_{%s}\left(%s\right))r  r   r   argumentr   )r   r   r   r	  r   Zneed_exprS   rS   rV   _hprint_BesselBaseK  s    
zLatexPrinter._hprint_BesselBasec                 C  sF   |sdS d}|d d D ]}|d|  | 7 }q||  |d 7 }|S )Nr   r   z%s, r   )r   rb   rU   rw   rS   rS   rV   _hprint_vec\  s    zLatexPrinter._hprint_vecc                 C  s   |  ||dS )NJr  r   rS   rS   rV   _print_besselje  s    zLatexPrinter._print_besseljc                 C  s   |  ||dS )Nr  r  r   rS   rS   rV   _print_besselih  s    zLatexPrinter._print_besselic                 C  s   |  ||dS )NKr  r   rS   rS   rV   _print_besselkk  s    zLatexPrinter._print_besselkc                 C  s   |  ||dS )NYr  r   rS   rS   rV   _print_besselyn  s    zLatexPrinter._print_besselyc                 C  s   |  ||dS )Nr  r  r   rS   rS   rV   	_print_ynq  s    zLatexPrinter._print_ync                 C  s   |  ||dS )Nr   r  r   rS   rS   rV   	_print_jnt  s    zLatexPrinter._print_jnc                 C  s   |  ||dS )NzH^{(1)}r  r   rS   rS   rV   _print_hankel1w  s    zLatexPrinter._print_hankel1c                 C  s   |  ||dS )NzH^{(2)}r  r   rS   rS   rV   _print_hankel2z  s    zLatexPrinter._print_hankel2c                 C  s   |  ||dS )Nzh^{(1)}r  r   rS   rS   rV   
_print_hn1}  s    zLatexPrinter._print_hn1c                 C  s   |  ||dS )Nzh^{(2)}r  r   rS   rS   rV   
_print_hn2  s    zLatexPrinter._print_hn2r   c                 C  s:   d|  |jd  }|d k	r*d|||f S d||f S d S r  rX  r   r   r   notationr   rS   rS   rV   _hprint_airy  s    zLatexPrinter._hprint_airyc                 C  s:   d|  |jd  }|d k	r*d|||f S d||f S d S )Nr   r   z{%s^\prime}^{%s}%sz%s^\prime%srX  r  rS   rS   rV   _hprint_airy_prime  s    zLatexPrinter._hprint_airy_primec                 C  s   |  ||dS NZAir  r   rS   rS   rV   _print_airyai  s    zLatexPrinter._print_airyaic                 C  s   |  ||dS NZBir!  r   rS   rS   rV   _print_airybi  s    zLatexPrinter._print_airybic                 C  s   |  ||dS r   r  r   rS   rS   rV   _print_airyaiprime  s    zLatexPrinter._print_airyaiprimec                 C  s   |  ||dS r#  r%  r   rS   rS   rV   _print_airybiprime  s    zLatexPrinter._print_airybiprimec                 C  sZ   d|  t|j|  t|j| |j| |j|  |jf }|d k	rVd||f }|S )NzN{{}_{%s}F_{%s}\left(\begin{matrix} %s \\ %s \end{matrix}\middle| {%s} \right)}	{%s}^{%s})r   r  apbqr  r  r  rS   rS   rV   _print_hyper  s    
 

zLatexPrinter._print_hyperc                 C  s   d|  t|j|  t|j|  t|j|  t|j| |j| |j| |j| |j|  |j	f	 }|d k	rd||f }|S )Nz^{G_{%s, %s}^{%s, %s}\left(\begin{matrix} %s & %s \\%s & %s \end{matrix} \middle| {%s} \right)}r(  )
r   r  r)  r*  re   anr  ZaotherZbotherr  r  rS   rS   rV   _print_meijerg  s     
 

 

zLatexPrinter._print_meijergc                 C  s0   d|  |jd  }|d k	r(d||f S d| S )Nr   r   z\eta^{%s}%sz\eta%srX  r  rS   rS   rV   _print_dirichlet_eta  s    z!LatexPrinter._print_dirichlet_etac                 C  sV   t |jdkr&dtt| j|j }nd| |jd  }|d k	rNd||f S d| S )Nr=  r  r   r   z\zeta^{%s}%sz\zeta%sr  r   r^  r|  r   r  rS   rS   rV   _print_zeta  s    zLatexPrinter._print_zetac                 C  sV   t |jdkr&dtt| j|j }nd| |jd  }|d k	rNd||f S d| S )Nr=  z_{%s}\left(%s\right)r{  r   z\gamma%s^{%s}r  r/  r  rS   rS   rV   _print_stieltjes  s    zLatexPrinter._print_stieltjesc                 C  s2   dt t| j|j }|d kr&d| S d||f S )Nz\left(%s, %s, %s\right)z\Phi%sz\Phi^{%s}%s)r^  r|  r   r   r  rS   rS   rV   _print_lerchphi  s    zLatexPrinter._print_lerchphic                 C  s<   t | j|j\}}d| }|d kr.d||f S d|||f S )Nr   z\operatorname{Li}_{%s}%sz\operatorname{Li}_{%s}^{%s}%sr|  r   r   )r   r   r   rU   r  r   rS   rS   rV   _print_polylog  s
    zLatexPrinter._print_polylogc                 C  sB   t | j|j\}}}}d||||f }|d k	r>d| d|  }|S )Nz*P_{%s}^{\left(%s,%s\right)}\left(%s\right)rI  \right)^{%s}r3  )r   r   r   r  rD  rE  r   r   rS   rS   rV   _print_jacobi  s
    zLatexPrinter._print_jacobic                 C  s>   t | j|j\}}}d|||f }|d k	r:d| d|  }|S )Nz'C_{%s}^{\left(%s\right)}\left(%s\right)rI  r5  r3  r   r   r   r  rD  r   r   rS   rS   rV   _print_gegenbauer  s
    zLatexPrinter._print_gegenbauerc                 C  s:   t | j|j\}}d||f }|d k	r6d| d|  }|S )NzT_{%s}\left(%s\right)rI  r5  r3  r   r   r   r  r   r   rS   rS   rV   _print_chebyshevt  s
    zLatexPrinter._print_chebyshevtc                 C  s:   t | j|j\}}d||f }|d k	r6d| d|  }|S )NzU_{%s}\left(%s\right)rI  r5  r3  r9  rS   rS   rV   _print_chebyshevu  s
    zLatexPrinter._print_chebyshevuc                 C  s:   t | j|j\}}d||f }|d k	r6d| d|  }|S )NzP_{%s}\left(%s\right)rI  r5  r3  r9  rS   rS   rV   _print_legendre  s
    zLatexPrinter._print_legendrec                 C  s>   t | j|j\}}}d|||f }|d k	r:d| d|  }|S )Nz'P_{%s}^{\left(%s\right)}\left(%s\right)rI  r5  r3  r7  rS   rS   rV   _print_assoc_legendre  s
    z"LatexPrinter._print_assoc_legendrec                 C  s:   t | j|j\}}d||f }|d k	r6d| d|  }|S )NzH_{%s}\left(%s\right)rI  r5  r3  r9  rS   rS   rV   _print_hermite  s
    zLatexPrinter._print_hermitec                 C  s:   t | j|j\}}d||f }|d k	r6d| d|  }|S )NzL_{%s}\left(%s\right)rI  r5  r3  r9  rS   rS   rV   _print_laguerre  s
    zLatexPrinter._print_laguerrec                 C  s>   t | j|j\}}}d|||f }|d k	r:d| d|  }|S )Nz'L_{%s}^{\left(%s\right)}\left(%s\right)rI  r5  r3  r7  rS   rS   rV   _print_assoc_laguerre  s
    z"LatexPrinter._print_assoc_laguerrec                 C  sB   t | j|j\}}}}d||||f }|d k	r>d| d|  }|S )NzY_{%s}^{%s}\left(%s,%s\right)rI  r5  r3  r   r   r   r  mthetaphir   rS   rS   rV   
_print_Ynm  s
    zLatexPrinter._print_Ynmc                 C  sB   t | j|j\}}}}d||||f }|d k	r>d| d|  }|S )NzZ_{%s}^{%s}\left(%s,%s\right)rI  r5  r3  rA  rS   rS   rV   
_print_Znm"  s
    zLatexPrinter._print_Znmc           	      C  sB   t | j|\}}}|rdnd}|s&dnd| }d||||||f S )Nz	^{\prime}r   r  z%s%s\left(%s, %s, %s\right)%s)r|  r   )	r   	characterr   rc   r   rD  rO  r  suprS   rS   rV   Z__print_mathieu_functions)  s    z&LatexPrinter.__print_mathieu_functionsc                 C  s   | j d|j|dS )NCrM  &_LatexPrinter__print_mathieu_functionsr   r   rS   rS   rV   _print_mathieuc/  s    zLatexPrinter._print_mathieucc                 C  s   | j d|j|dS )Nr   rM  rJ  r   rS   rS   rV   _print_mathieus2  s    zLatexPrinter._print_mathieusc                 C  s   | j d|jd|dS )NrI  Trc   r   rJ  r   rS   rS   rV   _print_mathieucprime5  s    z!LatexPrinter._print_mathieucprimec                 C  s   | j d|jd|dS )Nr   TrN  rJ  r   rS   rS   rV   _print_mathieusprime8  s    z!LatexPrinter._print_mathieusprimec                 C  sb   |j dkrRd}|j}|jdk r(d}| }| jd rBd|||j f S d|||j f S | |jS d S )Nr   r   r   r:  r~   z	%s%d / %dz%s\frac{%d}{%d})rO  rJ  r   r   )r   r   signrJ  rS   rS   rV   _print_Rational;  s    


zLatexPrinter._print_Rationalc                 C  s   |  |j}|jr&tdd |jD s4t|jdkr|d7 }t|jdkr\||  |j7 }n|jrv||  |jd 7 }|d7 }t|jdkr||  |j7 }n||  |jd 7 }d| S )Nc                 s  s   | ]}|t jkV  qd S r   )r   r  )r   rJ  rS   rS   rV   r   J  s     z,LatexPrinter._print_Order.<locals>.<genexpr>r   ; r   z\rightarrow zO\left(%s\right))r   r   pointr   r  	variablesr   r   rU   rS   rS   rV   _print_OrderH  s    zLatexPrinter._print_Orderr   c                 C  s,   | j d |}|d k	r|S | j|j|dS )Nr   style)r   r   r   r   )r   r   rY  r   rS   rS   rV   _print_SymbolX  s    zLatexPrinter._print_Symbol)stringrl   c                 C  s   d|kr|g g   }}}n2t |\}}}t|}dd |D }dd |D }|dkr^d|}|rt|dd| 7 }|r|d	d| 7 }|S )
NrZ   c                 S  s   g | ]}t |qS rS   	translater   rH  rS   rS   rV   r   h  s     z5LatexPrinter._deal_with_super_sub.<locals>.<listcomp>c                 S  s   g | ]}t |qS rS   r\  r   r  rS   rS   rV   r   i  s     rd   \mathbf{{{}}}r  r   r{  )r   r]  r   r   )r   r[  rY  r   supersr  rS   rS   rV   r   a  s    
z!LatexPrinter._deal_with_super_subc                 C  sR   | j d rd}d}nd}d}d||ddd	d
}d| |j||j | |jf S )Nr   z\gtz\lt><r  z\geqz\leqz\neq)z==rb  rc  z>=z<=z!=z%s %s %s)r   r   lhsZrel_oprhs)r   r   gtltcharmaprS   rS   rV   _print_Relationalw  s     
	 
zLatexPrinter._print_Relationalc                   s    fdd|j d d D }|j d jtkrJ|d |j d j  n.|d |j d j |j d jf  d}|d| S )Nc                   s(   g | ] \}}d   |  |f qS )%s & \text{for}\: %sr   )r   r   rq   r   rS   rV   r     s   z1LatexPrinter._print_Piecewise.<locals>.<listcomp>r   z%s & \text{otherwise}rj  z\begin{cases} %s \end{cases}z \\)r   Zcondr   rv  r   r   r   )r   r   Zecpairsr   rS   r   rV   _print_Piecewise  s    
zLatexPrinter._print_Piecewisec              
     s   g }t |jD ].}|d fdd||d d f D  q jd }|d kr| jd dkrdd}n|jdkd	krxd
}nd}d}|d|}|dkr|ddd|j  d }|d| S )Nr	  c                   s   g | ]}  |qS rS   r   rZ  r   rS   rV   r     s     z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>r   r   r   smallmatrix
   Tmatrixarray \begin{%MATSTR%}%s\end{%MATSTR%}%MATSTR%r  rZ   rq   }%srb  )r
  rowsrv  r   r   colsrp   )r   r   linesliner   out_strrS   r   rV   _print_matrix_contents  s    ,
z#LatexPrinter._print_matrix_contentsc                 C  s@   |  |}| jd r<| jd }| j| }d| | d | }|S )Nr   \left\right)rx  r   r   )r   r   rw  
left_delimright_delimrS   rS   rV   _print_MatrixBase  s    




zLatexPrinter._print_MatrixBasec                 C  sF   | j |jtd dd}| |j d| |j }d| d| dS )Nr  Tr   r   rZ   z}_{rR   )r   parentr    r   rw   r   )r   r   Zmatrix_partZ
index_partrS   rS   rV   _print_MatrixElement  s    z!LatexPrinter._print_MatrixElementc                   sN    fdd} j |jtd ddd ||j|jj d ||j|jj d S )	Nc                   sZ   t | } | d dkr| d= | d dkr.d | d< | d |krBd | d< d fdd| D S )Nr=  r   r   :c                 3  s$   | ]}|d k	r  |ndV  qd S )Nr   r   )r   xir   rS   rV   r     s     zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>)r2  r   )r   r  r   rS   rV   
latexslice  s    z3LatexPrinter._print_MatrixSlice.<locals>.latexslicer  Tr~  \left[r   \right])r   r  r    Zrowslicers  Zcolslicert  )r   r   r  rS   r   rV   _print_MatrixSlice  s    	zLatexPrinter._print_MatrixSlicec                 C  s   |  |jS r   )r   blocksr   rS   rS   rV   _print_BlockMatrix  s    zLatexPrinter._print_BlockMatrixc                 C  sl   |j }ddlm}m} t||s>t||s>|jr>d| | S | |t|d}d|kr`d| S d| S d S )Nr   MatrixSymbolBlockMatrixz\left(%s\right)^{T}Tro   z%s^{T})	r4   sympy.matricesr  r  r.  is_MatrixExprr   r   r   )r   r   r  r  r  rU   rS   rS   rV   _print_Transpose  s    
zLatexPrinter._print_Transposec                 C  s   |j }d| | S )Nz!\operatorname{tr}\left(%s \right))r4   r   r   r   r  rS   rS   rV   _print_Trace  s    zLatexPrinter._print_Tracec                 C  s   dddd}| | jd d}|j}ddlm}m} t||s`t||s`|jr`d| ||f S | 	|t
|d	}d
|krd||f S d||f S d S )Nz\daggerz\astz
\mathsf{H})rz   starZ	hermitianr   r   r  r   Tro   rN  )r   r   r4   r  r  r  r.  r  r   r   r   )r   r   Zstyle_to_latexr   r  r  r  rU   rS   rS   rV   _print_Adjoint  s"    
zLatexPrinter._print_Adjointc                   s~   ddl m   fdd}tj} rj|d dkrH|dd  }n|d  |d< ddt|| S dt||S d S )	Nr   )MatMulc                   s0   t | trt |  s| S | tdS NF)r.  r	   r   r   r   r/  r  r   r   rS   rV   rW     s   z,LatexPrinter._print_MatMul.<locals>.<lambda>r   r   r:  r   )Zsympyr  r2  r   r   r   r|  )r   r   parensr   rS   r  rV   _print_MatMul  s    
zLatexPrinter._print_MatMulc                 C  sN   |j }|jr@ddlm} t||r2d| |j S d| | S d| | S )Nr   )r  r  )r4   r  Z&sympy.matrices.expressions.blockmatrixr  r.  rx  r  r   )r   r   r  r  rS   rS   rV   _print_Determinant  s    
zLatexPrinter._print_Determinantc                 C  sz   |d k	rBd| j |jd td dd| j |jd td dd|f S d| j |jd td dd| j |jd td ddf S )Nz\left(%s \bmod %s\right)^{%s}r   r	   Tr~  r   z%s \bmod %sr  r   rS   rS   rV   
_print_Mod  s(    zLatexPrinter._print_Modc                   s.   |j }td | j d fdd|D S )Nr   z \circ c                 3  s   | ]} |d dV  qdS Tr~  NrS   r  r  precrS   rV   r   !  s     z6LatexPrinter._print_HadamardProduct.<locals>.<genexpr>r   r    r   r   r   r   r   rS   r  rV   _print_HadamardProduct  s    z#LatexPrinter._print_HadamardProductc                 C  s(   t |jtd k rd}nd}| ||S )Nr	   z%s^{\circ \left({%s}\right)}z%s^{\circ {%s}})r   r   r    rQ  )r   r   rS  rS   rS   rV   _print_HadamardPower#  s    z!LatexPrinter._print_HadamardPowerc                   s.   |j }td | j d fdd|D S )Nr   	 \otimes c                 3  s   | ]} |d dV  qdS r  rS   r  r  rS   rV   r   0  s     z7LatexPrinter._print_KroneckerProduct.<locals>.<genexpr>r  r  rS   r  rV   _print_KroneckerProduct*  s    z$LatexPrinter._print_KroneckerProductc                 C  s|   |j |j }}ddlm} t||sB|jrBd| || |f S | |}d|krfd|| |f S d|| |f S d S )Nr   )r  r   ro   rN  )r   r   r  r  r.  r  r   )r   r   r   r   r  Zbase_strrS   rS   rV   _print_MatPow2  s    

zLatexPrinter._print_MatPowc                 C  s   | j || jd dS )Nr   rX  )rZ  r   r   rS   rS   rV   _print_MatrixSymbol?  s    
z LatexPrinter._print_MatrixSymbolc                 C  s   | j d dkrdS dS )Nr   rv   0z
\mathbf{0}r   )r   ZrS   rS   rV   _print_ZeroMatrixC  s    zLatexPrinter._print_ZeroMatrixc                 C  s   | j d dkrdS dS )Nr   rv   1z
\mathbf{1}r  )r   OrS   rS   rV   _print_OneMatrixG  s    zLatexPrinter._print_OneMatrixc                 C  s   | j d dkrdS dS )Nr   rv   z
\mathbb{I}z
\mathbf{I}r  )r   r  rS   rS   rV   _print_IdentityK  s    zLatexPrinter._print_Identityc                 C  s   |  |jd }d| S )Nr   zP_{%s}rX  )r   PZperm_strrS   rS   rV   _print_PermutationMatrixO  s    z%LatexPrinter._print_PermutationMatrixr%   c              
   C  s(  |  dkr| |d S | jd }|d krd| jd dkr@d}n$|  dksZ|jd dkr`d	}nd
}d}|d|}|d
kr|ddd|jd   d }| jd r| jd }| j| }d| | d | }|  dkr|d S dd t|  d D }dd |jD }tj| D ]}|d 	| ||  d}	t|  d ddD ]}
t
||
d  |j|
 k rn q|	r||
 	d||
d   nR||
 	|d||
d    t
||
d  dkrd||
 d  d ||
 d< |	 }	g ||
d < qHq|d d }|  d dkr$|| }|S )Nr   rS   r   r   r   rl  r   rm  rn  ro  rp  rq  r  rZ   rq   rr  r   ry  rz  r   c                 S  s   g | ]}g qS rS   rS   rZ  rS   rS   rV   r   o  s     z1LatexPrinter._print_NDimArray.<locals>.<listcomp>r   c                 S  s   g | ]}t t|qS rS   )r2  r
  rZ  rS   rS   rV   r   p  s     Tr	  rb  r  r  r=  )rankr   r   shaperp   r   r
  	itertoolsproductrv  r  r   )r   r   r   Z	block_strr{  r|  Z	level_strZshape_rangesZouter_iZevenZback_outer_irw  rS   rS   rV   _print_NDimArrayS  sd    





zLatexPrinter._print_NDimArraydict)	index_mapc           	      C  s   |  |}d }d }|D ]}|j}||ks,|r<||kr<|d7 }||krl|d k	rT|d7 }|jrd|d7 }n|d7 }||  |jd 7 }||kr|d7 }||  || 7 }d}nd}|}q|d k	r|d7 }|S )	Nr   rR   z{}^{z{}_{r   r  TF)r   is_upr   )	r   r   r}  r  rw  Zlast_valenceZprev_mapindexZnew_valencerS   rS   rV   _printer_tensor_indices  s2    

z$LatexPrinter._printer_tensor_indicesc                 C  s&   |j d j d }| }| ||i S rW  )r   get_indicesr  )r   r   r   r}  rS   rS   rV   _print_Tensor  s    zLatexPrinter._print_Tensorc                 C  s0   |j jd jd }|j  }|j}| |||S rW  )r   r   r  r  r  )r   r   r   r}  r  rS   rS   rV   _print_TensorElement  s    
z!LatexPrinter._print_TensorElementc                   s*      \}}|d fdd|D  S )Nr   c                   s   g | ]} |t qS rS   )r   r   r  r   r   rS   rV   r     s     z/LatexPrinter._print_TensMul.<locals>.<listcomp>)Z!_get_args_for_traditional_printerr   )r   r   rQ  r   rS   r  rV   _print_TensMul  s    zLatexPrinter._print_TensMulc                 C  sL   g }|j }|D ]}|| |t| q|  d|}|dd}|S )Nr   z+ -r:  )r   rv  r   r   ru  r   rp   )r   r   rD  r   r   rU   rS   rS   rV   _print_TensAdd  s    
zLatexPrinter._print_TensAddc                 C  s"   d|j rdnd| |jd f S )Nz{}%s{%s}ro   r  r   )r  r   r   r   rS   rS   rV   _print_TensorIndex  s    zLatexPrinter._print_TensorIndexc                   st   t |jdkr6d |jd  |jtd df S dt |jd fdd	|jD  |jtd df S d S )
Nr   z"\frac{\partial}{\partial {%s}}{%s}r   r	   Fz\frac{\partial^{%s}}{%s}{%s}r   c                   s   g | ]}d   | qS )z\partial {%s}r   rZ  r   rS   rV   r     s     z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>)r  rU  r   r   r   r    r   r   rS   r   rV   _print_PartialDerivative  s    z%LatexPrinter._print_PartialDerivativec                 C  s   |  |jS r   )r   r   r   rS   rS   rV   _print_ArraySymbol  s    zLatexPrinter._print_ArraySymbolc                   s2   d  |jtd dd fdd|jD f S )Nz{{%s}_{%s}}r  Tr   c                   s   g | ]}  | qS rS   r   rZ  r   rS   rV   r     s     z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>)r   r   r    r   r}  r   rS   r   rV   _print_ArrayElement  s    z LatexPrinter._print_ArrayElementc                 C  s   dS )Nz
\mathbb{U}rS   r   rS   rS   rV   _print_UniversalSet  s    z LatexPrinter._print_UniversalSetc                 C  s8   |d krd|  |jd  S d|  |jd |f S d S )Nz$\operatorname{frac}{\left(%s\right)}r   z)\operatorname{frac}{\left(%s\right)}^{%s}rX  r   rS   rS   rV   _print_frac  s     zLatexPrinter._print_fracc                   sz    j d dkrd}n j d dkr(d}ntdt|dkrT  |d | S  |d	  fd
d|D S d S )Nr   r  ;rx   r   Unknown Decimal Separatorr   r   z \  c                   s   g | ]}  |qS rS   r   rZ  r   rS   rV   r     s     z-LatexPrinter._print_tuple.<locals>.<listcomp>)r   r   r  r   r   r   )r   r   seprS   r   rV   _print_tuple  s    zLatexPrinter._print_tuplec                   s    fdd|j D }d|S )Nc                   s   g | ]}  |qS rS   r   r   rD  r   rS   rV   r     s     z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>r  r   r   r   r   elementsrS   r   rV   _print_TensorProduct  s    z!LatexPrinter._print_TensorProductc                   s    fdd|j D }d|S )Nc                   s   g | ]}  |qS rS   r   r  r   rS   rV   r     s     z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>z \wedge r  r  rS   r   rV   _print_WedgeProduct  s    z LatexPrinter._print_WedgeProductc                 C  s
   |  |S r   )r  r   rS   rS   rV   _print_Tuple  s    zLatexPrinter._print_Tuplec                   s`    j d dkr*dd fdd|D  S  j d dkrTdd fd	d|D  S td
d S )Nr   r  z\left[ %s\right]z; \  c                   s   g | ]}  |qS rS   r   rZ  r   rS   rV   r     s     z,LatexPrinter._print_list.<locals>.<listcomp>rx   , \  c                   s   g | ]}  |qS rS   r   rZ  r   rS   rV   r     s     r  )r   r   r   r   rS   r   rV   _print_list  s    zLatexPrinter._print_listc                 C  sR   t | td}g }|D ]*}|| }|d| || |f  qdd| S )Nrn  z%s : %sz\left\{ %s\right\}r  )r  keysr   rv  r   r   )r   ry   r  rs  ro  valrS   rS   rV   _print_dict  s     zLatexPrinter._print_dictc                 C  s
   |  |S r   )r  r   rS   rS   rV   _print_Dict  s    zLatexPrinter._print_Dictc                 C  sj   t |jdks|jd dkr2d| |jd  }n$d| |jd | |jd f }|rfd||f }|S )Nr   r   z\delta\left(%s\right)z+\delta^{\left( %s \right)}\left( %s \right)r   r  r  rS   rS   rV   _print_DiracDelta  s     zLatexPrinter._print_DiracDeltac                 C  sP   |  |jd |jd  }|  |jd }d||f }|d k	rLd|||f }|S )Nr   r   r=  z${\left\langle %s \right\rangle}^{%s}z-{\left({\langle %s \rangle}^{%s}\right)}^{%s}rX  )r   r   r   shiftr  r   rS   rS   rV   _print_SingularityFunction#  s    z'LatexPrinter._print_SingularityFunctionc                   s6   d  fdd|jD }d| }|r2d||f }|S )Nr   c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   ,  s     z0LatexPrinter._print_Heaviside.<locals>.<genexpr>z\theta\left(%s\right)r   )r   pargs)r   r   r   r  r   rS   r   rV   _print_Heaviside+  s
    zLatexPrinter._print_Heavisidec                 C  sj   |  |jd }|  |jd }|jd jrF|jd jrFd||f }nd||f }|d k	rfd||f }|S )Nr   r   z\delta_{%s %s}z\delta_{%s, %s}r   )r   r   r   )r   r   r   rw   r   r   rS   rS   rV   _print_KroneckerDelta2  s    z"LatexPrinter._print_KroneckerDeltac                 C  sT   t | j|j}tdd |jD r2dd| }ndd| }|rPd||f }|S )Nc                 s  s   | ]}|j V  qd S r   )r   r   rS   rS   rV   r   ?  s     z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}r   r   r   )r|  r   r   r  r   )r   r   r   r}  r   rS   rS   rV   _print_LeviCivita=  s    zLatexPrinter._print_LeviCivitac                 C  sn   t |drd| |  S t |drFd| |j d | |j S t |dr`d| |j S | d S d S )N
as_booleanz\text{Domain: }setz \in r  z\text{Domain on })r-  r   r  r  r  )r   ry   rS   rS   rV   _print_RandomDomainG  s    



z LatexPrinter._print_RandomDomainc                 C  s   t |jtd}| |S )Nrn  )r  r   r   
_print_setr   rU   rs  rS   rS   rV   _print_FiniteSetR  s    zLatexPrinter._print_FiniteSetc                 C  s`   t |td}| jd dkr.dt| j|}n*| jd dkrPdt| j|}ntdd| S )	Nrn  r   r  rS  rx   r   r  \left\{%s\right\})r  r   r   r   r|  r   r   r  rS   rS   rV   r  V  s    zLatexPrinter._print_setc                   s  fdd}t   jjrLjjrLjjr< ddd f}q ddd f}njjrn d j d f}n|jjrt}t|t| f}nXjd k	rj	dk dkrt
}qjrt}t|t| d f}q| S n| S dd	 fd
d|D  d S )Nc                    s    j d dkrJ j d dkr. j d } qdfdd j D } nL j d dkr|dfdd j d d D } ndfdd j D } d	|  d
S )Nr   r=  r   r   c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   j  s     zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   m  s     c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   o  s     z\text{Range}\left(r   )r   r   r   )cont)rU   r   rS   rV   _print_symbolic_ranged  s    $z8LatexPrinter._print_Range.<locals>._print_symbolic_ranger   r   r   r  Tz\left\{r   c                 3  s$   | ]}| k	r |nd V  qdS z\ldotsNr   r   eldotsr   rS   rV   r     s     z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})objectstartis_infinitestopstepZis_positiveiternextZis_emptyr  r^  Zis_iterabler   )r   rU   r  printsetitrS   )r  rU   r   rV   _print_Rangec  s0    

zLatexPrinter._print_Rangec                 C  s   t |jdkrd|d k	r>d|| |jd || |jd f S d|| |jd | |jd f S d|| |jd f }|d k	rd||f }|S )Nr=  z%s_{%s}^{%s}\left(%s\right)r   r   r
  z%s_{%s}rN  r  )r   r   letterr   r   rS   rS   rV   Z__print_number_polynomial  s      z&LatexPrinter.__print_number_polynomialc                 C  s   |  |d|S )Nr  &_LatexPrinter__print_number_polynomialr   rS   rS   rV   _print_bernoulli  s    zLatexPrinter._print_bernoullic                 C  s   |  |d|S )NGr  r   rS   rS   rV   _print_genocchi  s    zLatexPrinter._print_genocchic                   s   t |jdkrxd |jd  |jd f }dd fdd|jd	 D  }|d k	rld
|||f }n|| }|S  |d|S )Nrq  z
B_{%s, %s}r   r   r   r   c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r     s   z+LatexPrinter._print_bell.<locals>.<genexpr>r=  r  r  )r  r   r   r   r  )r   r   r   Ztex1Ztex2r   rS   r   rV   _print_bell  s    
zLatexPrinter._print_bellc                 C  s   |  |d|S NFr  r   rS   rS   rV   _print_fibonacci  s    zLatexPrinter._print_fibonaccic                 C  s,   d|  |jd  }|d k	r(d||f }|S )NzL_{%s}r   rN  rX  r  rS   rS   rV   _print_lucas  s    zLatexPrinter._print_lucasc                 C  s   |  |d|S )NTr  r   rS   rS   rV   _print_tribonacci  s    zLatexPrinter._print_tribonaccic                 C  s4   |d krd|  |jd  S d||  |jd f S )Nz\mu\left(%s\right)r   z\mu^{%s}\left(%s\right)rX  r   rS   rS   rV   _print_mobius  s    zLatexPrinter._print_mobiusc                   s   t   t|jjdks&t|jjdkrZd|j|jd |j|jf S |jtj	kr|j} |
|d |
|d |
|d |
|f}n6|jtjks|jdkr|d d }|  nt|}dd fd	d
|D  d S )Nr   z\left\{%s\right\}_{%s=%s}^{%s}rq  r=  r   r  r  r   c                 3  s$   | ]}| k	r |nd V  qdS r  r   r  r  rS   rV   r     s     z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>r  )r  r  r  Zfree_symbolsr  r   formularU  r   r  coeffr  lengthrv  r^  r   )r   rU   r  r  rS   r  rV   _print_SeqFormula  s.     


 zLatexPrinter._print_SeqFormulac                 C  s`   |j |jkrd| |j  S |jr(d}nd}|jr8d}nd}d|| |j | |j|f S d S )Nr  r   ru   r   r   z\left%s%s, %s\right%s)r  endr   Z	left_openZ
right_open)r   rw   leftrightrS   rS   rV   _print_Interval  s    zLatexPrinter._print_Intervalc                 C  s   d|  |j|  |jf S )Nz \left\langle %s, %s\right\rangle)r   r   r   r   rw   rS   rS   rV   _print_AccumulationBounds  s    z&LatexPrinter._print_AccumulationBoundsc                   s(   t |  fdd|jD }d|S )Nc                   s   g | ]} | qS rS   r   rZ  r  r   rS   rV   r     s     z-LatexPrinter._print_Union.<locals>.<listcomp>z \cup r   r   r   r   uargs_strrS   r  rV   _print_Union  s    zLatexPrinter._print_Unionc                   s(   t |  fdd|jD }d|S )Nc                   s   g | ]} | qS rS   r  rZ  r  rS   rV   r     s     z2LatexPrinter._print_Complement.<locals>.<listcomp>z \setminus r  r  rS   r  rV   _print_Complement  s    zLatexPrinter._print_Complementc                   s(   t |  fdd|jD }d|S )Nc                   s   g | ]} | qS rS   r  rZ  r  rS   rV   r     s     z4LatexPrinter._print_Intersection.<locals>.<listcomp>z \cap r  r  rS   r  rV   _print_Intersection  s    z LatexPrinter._print_Intersectionc                   s(   t |  fdd|jD }d|S )Nc                   s   g | ]} | qS rS   r  rZ  r  rS   rV   r   	  s     z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>z \triangle r  r  rS   r  rV   _print_SymmetricDifference  s    z'LatexPrinter._print_SymmetricDifferencec                   s\   t | t|jdkr@t|js@|jd  dt|j  S d fdd|jD S )Nr   r   z^{%d}r   c                 3  s   | ]} | V  qd S r   r  )r   r  r  rS   rV   r   	  s    z1LatexPrinter._print_ProductSet.<locals>.<genexpr>)r   r  setsr#   r   r   r   rJ  rS   r  rV   _print_ProductSet	  s     zLatexPrinter._print_ProductSetc                 C  s   dS )Nz	\emptysetrS   r   rS   rS   rV   _print_EmptySet	  s    zLatexPrinter._print_EmptySetc                 C  s   dS )Nz
\mathbb{N}rS   r   r  rS   rS   rV   _print_Naturals	  s    zLatexPrinter._print_Naturalsc                 C  s   dS )Nz\mathbb{N}_0rS   r  rS   rS   rV   _print_Naturals0	  s    zLatexPrinter._print_Naturals0c                 C  s   dS Nz
\mathbb{Z}rS   r  rS   rS   rV   _print_Integers	  s    zLatexPrinter._print_Integersc                 C  s   dS Nz
\mathbb{Q}rS   r  rS   rS   rV   _print_Rationals	  s    zLatexPrinter._print_Rationalsc                 C  s   dS Nz
\mathbb{R}rS   r  rS   rS   rV   _print_Reals	  s    zLatexPrinter._print_Realsc                 C  s   dS Nz
\mathbb{C}rS   r  rS   rS   rV   _print_Complexes	  s    zLatexPrinter._print_Complexesc                   sP   |j j}|j j} fddt||jD }ddd |D }d ||f S )Nc                 3  s&   | ]\}}  |  |fV  qd S r   r   )r   r   r  r   rS   rV   r   #	  s     z/LatexPrinter._print_ImageSet.<locals>.<genexpr>r   c                 s  s   | ]}d | V  qdS )	%s \in %sNrS   )r   ZxyrS   rS   rV   r   $	  s     z!\left\{%s\; \middle|\; %s\right\})rP   r   	signaturer  Z	base_setsr   r   )r   rU   r   sigZxysZxinysrS   r   rV   _print_ImageSet 	  s
    zLatexPrinter._print_ImageSetc                   s^   d  fddt|jD }|jtjkr>d| |jf S d|| |j |jf S )Nr   c                   s   g | ]}  |qS rS   r   r   r  r   rS   rV   r   (	  s     z4LatexPrinter._print_ConditionSet.<locals>.<listcomp>z"\left\{%s\; \middle|\; %s \right\}z3\left\{%s\; \middle|\; %s \in %s \wedge %s \right\})r   r   r	  Zbase_setr   ZUniversalSetr   	conditionr   rU   Z
vars_printrS   r   rV   _print_ConditionSet'	  s    

z LatexPrinter._print_ConditionSetc                 C  s   |  |jd }d|S )Nr   z\mathcal{{P}}\left({}\right)r   r   r   )r   r   Z	arg_printrS   rS   rV   _print_PowerSet3	  s    zLatexPrinter._print_PowerSetc                   s8   d  fdd|jD }d |j| |jf S )Nr   c                   s   g | ]}  |qS rS   r   r*  r   rS   rV   r   8	  s     z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z)\left\{%s\; \middle|\; %s \in %s \right\})r   rU  r   r   r  r,  rS   r   rV   _print_ComplexRegion7	  s    

z!LatexPrinter._print_ComplexRegionc                   s   dt  fdd|jD  S )Nr&  c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   ?	  s     z/LatexPrinter._print_Contains.<locals>.<genexpr>)r^  r   r   rS   r   rV   _print_Contains>	  s    zLatexPrinter._print_Containsc                 C  s:   |j jtjkr(|jjtjkr(| |jS | | d S )Nz	 + \ldots)	r,  r  r   r  Zbnr   Za0r   truncater   rS   rS   rV   _print_FourierSeriesA	  s    z!LatexPrinter._print_FourierSeriesc                 C  s   |  |jS r   )r   Zinfiniter   rS   rS   rV   _print_FormalPowerSeriesF	  s    z%LatexPrinter._print_FormalPowerSeriesc                 C  s
   d|j  S )Nz\mathbb{F}_{%s})modr   rS   rS   rV   _print_FiniteFieldI	  s    zLatexPrinter._print_FiniteFieldc                 C  s   dS r  rS   r   rS   rS   rV   _print_IntegerRingL	  s    zLatexPrinter._print_IntegerRingc                 C  s   dS r   rS   r   rS   rS   rV   _print_RationalFieldO	  s    z!LatexPrinter._print_RationalFieldc                 C  s   dS r"  rS   r   rS   rS   rV   _print_RealFieldR	  s    zLatexPrinter._print_RealFieldc                 C  s   dS r$  rS   r   rS   rS   rV   _print_ComplexFieldU	  s    z LatexPrinter._print_ComplexFieldc                 C  s,   |  |j}dt| j |j}d||f S )Nr   z%s\left[%s\right]r   domainr   r|  r  r   r   r<  r  rS   rS   rV   _print_PolynomialRingX	  s    z"LatexPrinter._print_PolynomialRingc                 C  s,   |  |j}dt| j |j}d||f S )Nr   r  r;  r=  rS   rS   rV   _print_FractionField]	  s    z!LatexPrinter._print_FractionFieldc                 C  s<   |  |j}dt| j |j}d}|js.d}d|||f S )Nr   r   zS_<^{-1}z%s%s\left[%s\right])r   r<  r   r|  r  Zis_Poly)r   r   r<  r  invrS   rS   rV   _print_PolynomialRingBaseb	  s    z&LatexPrinter._print_PolynomialRingBasec                 C  s  |j j}g }| D ]\}}d}t|D ]H\}}|dkr*|dkrX|| |j| 7 }q*|| t|j| |7 }q*|jr|rd| | }	q| |}	nB|r|tj	kr|
d|g q|tjkr|
d|g q| |}	|s|	}
n|	d | }
|
dr|
d|
dd  g q|
d|
g q|d dkrX|d}|dkrXd|d  |d< d|}tt| j|j}d	| |  }d
|g| |g }|tkrd||f }nd||f }|S )Nr   r   r   r   r  rp  r   )rp  r  z	domain=%sr   z\%s {\left(%s \right)}z$\operatorname{%s}{\left( %s \right)})r   r   r   r   r   genspowr   r   r?  extendr   rU  popr   r2  r|  Z
get_domainr  )r   polyr  r   Zmonomr  Zs_monomrw   r   Zs_coeffZs_termmodifierr   rB  r<  r   r   rS   rS   rV   _print_Polyj	  sN    






zLatexPrinter._print_Polyc                 C  sN   |j j}|dkrd}| |j}|j}|tkr<d|||f S d|||f S d S )NZComplexRootOfZCRootOfz\%s {\left(%s, %d\right)}z'\operatorname{%s} {\left(%s, %d\right)})r   r   r   r   r  r  )r   r3   r  r   r  rS   rS   rV   _print_ComplexRootOf	  s    z!LatexPrinter._print_ComplexRootOfc                 C  sd   |j j}| |jg}|jtjk	r4|| |j |tkrNd|d	|f S d|d	|f S d S )Nz\%s {\left(%s\right)}r   z#\operatorname{%s} {\left(%s\right)})
r   r   r   r   Zfunr   ZIdentityFunctionrv  r  r   )r   r   r  r   rS   rS   rV   _print_RootSum	  s    zLatexPrinter._print_RootSumc                 C  s   dS )N\omegarS   r   rS   rS   rV   _print_OrdinalOmega	  s    z LatexPrinter._print_OrdinalOmegac                 C  sL   |j \}}|dkr2|dkr&d||S d|S n|dkrDd|S dS d S )Nr   z{} \omega^{{{}}}z	{} \omegaz\omega^{{{}}}rK  )r   r   )r   r   r   mulrS   rS   rV   _print_OmegaPower	  s    

zLatexPrinter._print_OmegaPowerc                   s   d  fdd|jD S )Nr   c                   s   g | ]}  |qS rS   r   r  r   rS   rV   r   	  s     z/LatexPrinter._print_Ordinal.<locals>.<listcomp>)r   r   r   rS   r   rV   _print_Ordinal	  s    zLatexPrinter._print_Ordinalc                 C  s   | j d }|| td|S )Nr   z	{%s}^{%d})r   rk   r    )r   rF  r   rS   rS   rV   _print_PolyElement	  s    
zLatexPrinter._print_PolyElementc                 C  s>   |j dkr| |jS | |j}| |j }d||f S d S )Nr   r>  )rB  r   rA  )r   r2   rA  rB  rS   rS   rV   _print_FracElement	  s
    
zLatexPrinter._print_FracElementc                 C  sf   t |jdkr|jd d fn|j\}}d| | }|d k	rHd||f }|d k	rbd|| |f }|S )Nr   r   zE_{%s}rN  r  r  )r   r   r   rB  r   r   rS   rS   rV   _print_euler	  s    &zLatexPrinter._print_eulerc                 C  s,   d|  |jd  }|d k	r(d||f }|S )NzC_{%s}r   rN  rX  r  rS   rS   rV   _print_catalan	  s    zLatexPrinter._print_catalanc              
   C  s>   d ||rdnd| |jd | |jd | |jd S )Nz5\mathcal{{{}}}{}_{{{}}}\left[{}\right]\left({}\right)z^{-1}r   r   r   r=  r   r   r   )r   r   rU   ZinverserS   rS   rV   _print_UnifiedTransform	  s    z$LatexPrinter._print_UnifiedTransformc                 C  s   |  |dS )NMrU  r   rS   rS   rV   _print_MellinTransform	  s    z#LatexPrinter._print_MellinTransformc                 C  s   |  |ddS )NrV  TrW  r   rS   rS   rV   _print_InverseMellinTransform	  s    z*LatexPrinter._print_InverseMellinTransformc                 C  s   |  |dS )NLrW  r   rS   rS   rV   _print_LaplaceTransform	  s    z$LatexPrinter._print_LaplaceTransformc                 C  s   |  |ddS )NrZ  TrW  r   rS   rS   rV   _print_InverseLaplaceTransform	  s    z+LatexPrinter._print_InverseLaplaceTransformc                 C  s   |  |dS r  rW  r   rS   rS   rV   _print_FourierTransform	  s    z$LatexPrinter._print_FourierTransformc                 C  s   |  |ddS )Nr  TrW  r   rS   rS   rV   _print_InverseFourierTransform	  s    z+LatexPrinter._print_InverseFourierTransformc                 C  s   |  |dS )NSINrW  r   rS   rS   rV   _print_SineTransform	  s    z!LatexPrinter._print_SineTransformc                 C  s   |  |ddS )Nr_  TrW  r   rS   rS   rV   _print_InverseSineTransform
  s    z(LatexPrinter._print_InverseSineTransformc                 C  s   |  |dS )NCOSrW  r   rS   rS   rV   _print_CosineTransform
  s    z#LatexPrinter._print_CosineTransformc                 C  s   |  |ddS )Nrb  TrW  r   rS   rS   rV   _print_InverseCosineTransform
  s    z*LatexPrinter._print_InverseCosineTransformc                 C  sF   z"|j d k	r | |j |W S W n tk
r6   Y nX | t|S r   )ringr   to_sympyr   reprr  rS   rS   rV   
_print_DMP
  s    
zLatexPrinter._print_DMPc                 C  s
   |  |S r   )rh  r  rS   rS   rV   
_print_DMF
  s    zLatexPrinter._print_DMFc                 C  s   |  t|jS r   r   r   r   )r   r  rS   rS   rV   _print_Object
  s    zLatexPrinter._print_Objectc                 C  sd   |  |jd }|d k	r"d|f nd}t|jdkrBd||f }n|  |jd }d|||}|S )Nr   r  r   r   zW%s\left(%s\right)zW{0}_{{{1}}}\left({2}\right))r   r   r  r   )r   r   r   Zarg0resultZarg1rS   rS   rV   _print_LambertW
  s    zLatexPrinter._print_LambertWc                 C  s   d | |jd S )Nz!\operatorname{{E}}\left[{}\right]r   rT  r   rS   rS   rV   _print_Expectation$
  s    zLatexPrinter._print_Expectationc                 C  s   d | |jd S )Nz#\operatorname{{Var}}\left({}\right)r   rT  r   rS   rS   rV   _print_Variance'
  s    zLatexPrinter._print_Variancec                   s    d d fdd|jD S )Nz#\operatorname{{Cov}}\left({}\right)r   c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   +
  s     z1LatexPrinter._print_Covariance.<locals>.<genexpr>)r   r   r   r   rS   r   rV   _print_Covariance*
  s    zLatexPrinter._print_Covariancec                 C  s   d | |jd S )Nz!\operatorname{{P}}\left({}\right)r   rT  r   rS   rS   rV   _print_Probability-
  s    zLatexPrinter._print_Probabilityc                 C  s$   |  |j}|  |j}d||f S )Nz%s\rightarrow %s)r   r<  codomain)r   morphismr<  rr  rS   rS   rV   _print_Morphism0
  s    zLatexPrinter._print_Morphismc                 C  s&   |  |j|  |j }}d||f S )Nr>  )r   r  den)r   r   r  ru  rS   rS   rV   _print_TransferFunction5
  s    z$LatexPrinter._print_TransferFunctionc                   s(   t  j} fdd}dt||S )Nc                   s    | t dS r  )r   r   r/  r  rS   rV   rW   ;
  s   z,LatexPrinter._print_Series.<locals>.<lambda>r   )r2  r   r   r|  r   r   r   r  rS   r  rV   _print_Series9
  s    
zLatexPrinter._print_Seriesc                   s@   ddl m  tjd d d } fdd}dt||S )Nr   )MIMOParallelr   c                   s&   t |  r| tdS | S r  )r.  r   r   r   r/  ry  r   r   rS   rV   rW   B
  s
    z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>z\cdot)Zsympy.physics.control.ltiry  r2  r   r   r|  rw  rS   rz  rV   _print_MIMOSeries?
  s    zLatexPrinter._print_MIMOSeriesc                 C  s   d t| j|jS Nr   r   r|  r   r   r   rS   rS   rV   _print_ParallelF
  s    zLatexPrinter._print_Parallelc                 C  s   d t| j|jS r|  r}  r   rS   rS   rV   _print_MIMOParallelI
  s    z LatexPrinter._print_MIMOParallelc                 C  s|  ddl m}m} |j|dd|j }}t||r:t|jn|g}t|j|rXt|jjn|jg}|}t||rt|j|r||| }	nt||rt|j|r|j|kr|| }	n||||jf f}	nrt||rt|j|r||kr|| }	n||f| }	n6||kr|| }	n"|j|kr.|| }	n||| }	| 	|}
| 	|}| 	|	}|j
dkrhdnd}d|
|||f S )Nr   )TransferFunctionSeriesr   r   r  rp  z\frac{%s}{%s %s %s})sympy.physics.controlr  r  sys1r  r.  r2  r   sys2r   rQ  )r   r   r  r  r  tfZnum_arg_listZden_arg_listZ
den_term_1Z
den_term_2rA  Zdenom_1Zdenom_2_signrS   rS   rV   _print_FeedbackL
  s8    









zLatexPrinter._print_Feedbackc                 C  sL   ddl m} | ||j|j}| |j}|jdkr:dnd}d|||f S )Nr   )
MIMOSeriesr   r  rp  z)\left(I_{\tau} %s %s\right)^{-1} \cdot %s)r  r  r   r  r  rQ  )r   r   r  Zinv_matr  r  rS   rS   rV   _print_MIMOFeedbackp
  s
    z LatexPrinter._print_MIMOFeedbackc                 C  s   |  |j}d| S )Nz%s_\tau)r   Z	_expr_matr  rS   rS   rV   _print_TransferFunctionMatrixw
  s    z*LatexPrinter._print_TransferFunctionMatrixc                 C  s   d |jj|jS )Nz\text{{{}}}_{{{}}})r   r   r   r  r   rS   rS   rV   
_print_DFT{
  s    zLatexPrinter._print_DFTc                 C  s&   |  t|j}| |}d||f S )Nz%s:%s)r   r   r   rt  )r   rs  pretty_namepretty_morphismrS   rS   rV   _print_NamedMorphism
  s    
z!LatexPrinter._print_NamedMorphismc                 C  s"   ddl m} | ||j|jdS )Nr   )NamedMorphismid)Zsympy.categoriesr  r  r<  rr  )r   rs  r  rS   rS   rV   _print_IdentityMorphism
  s      z$LatexPrinter._print_IdentityMorphismc                   s<    fdd|j D }|  d|d } |}|| S )Nc                   s   g | ]}  t|jqS rS   rj  )r   	componentr   rS   rV   r   
  s   z9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z\circ r  )rt  reverser   rt  )r   rs  Zcomponent_names_listZcomponent_namesr  rS   r   rV   _print_CompositeMorphism
  s    

z%LatexPrinter._print_CompositeMorphismc                 C  s   d | t|jS Nr`  )r   r   r   r   )r   rs  rS   rS   rV   _print_Category
  s    zLatexPrinter._print_Categoryc                 C  s<   |j s| tjS | |j }|jr8|d| |j 7 }|S )Nz\Longrightarrow %s)Zpremisesr   r   ZEmptySetZconclusions)r   Zdiagramlatex_resultrS   rS   rV   _print_Diagram
  s    
zLatexPrinter._print_Diagramc                 C  s   dd|j   }t|jD ]p}t|j D ]B}|||f rJ|t|||f 7 }|d7 }||j d kr&|d7 }q&||jd kr|d7 }|d7 }q|d7 }|S )	Nz\begin{array}{%s}
rq   r   r   & rb  
z\end{array}
)widthr
  heightlatex)r   gridr  rw   r   rS   rS   rV   _print_DiagramGrid
  s    

zLatexPrinter._print_DiagramGridc                 C  s   d | |j| |jS )Nz{{{}}}^{{{}}})r   r   re  r  r   rV  rS   rS   rV   _print_FreeModule
  s    zLatexPrinter._print_FreeModulec                   s   d d fdd|D S )N\left[ {} \right]r   c                 3  s    | ]}d   | d V  qdS rZ   rR   Nr   r   r   rS   rV   r   
  s    z8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>)r   r   )r   rB  rS   r   rV   _print_FreeModuleElement
  s    z%LatexPrinter._print_FreeModuleElementc                   sJ   fddj D }dd  dd d fdd|D }d	|S )
Nc                   s    g | ]} fd d|D qS )c                   s   g | ]}  j|qS rS   )r   re  rf  r   rB  r   rS   rV   r   
  s     z<LatexPrinter._print_SubModule.<locals>.<listcomp>.<listcomp>rS   r   gr  rS   rV   r   
  s     z1LatexPrinter._print_SubModule.<locals>.<listcomp>c                 S  s   d|  d S )NrZ   rR   rS   r6   rS   rS   rV   rW   
  rX   z/LatexPrinter._print_SubModule.<locals>.<lambda>c                 S  s   d|  d S )Nz\left[ z \right]rS   r  rS   rS   rV   rW   
  rX   r   c                 3  s.   | ]&} d   fdd|D V  qdS )r   c                 3  s   | ]} |V  qd S r   rS   r   )curlyrS   rV   r   
  s     z:LatexPrinter._print_SubModule.<locals>.<genexpr>.<genexpr>N)r   r  )r  squarerS   rV   r   
  s     z0LatexPrinter._print_SubModule.<locals>.<genexpr>\left\langle {} \right\rangle)rB  r   r   r   rB  rB  
gens_latexrS   )r  rB  r   r  rV   _print_SubModule
  s
    zLatexPrinter._print_SubModulec                   s$   d  fdd|jD }d|S )Nr   c                   s   g | ]}d   | d qS )rZ   rR   r   r  r   rS   rV   r   
  s     z9LatexPrinter._print_SubQuotientModule.<locals>.<listcomp>r  )r   rB  r   )r   rB  r  rS   r   rV   _print_SubQuotientModule
  s    z%LatexPrinter._print_SubQuotientModulec                   s8    fdd j jD }dfdd|D }d|S )Nc                   s   g | ]\} j |qS rS   )re  rf  r   rB  rS   rV   r   
  s     z>LatexPrinter._print_ModuleImplementedIdeal.<locals>.<listcomp>r   c                 3  s    | ]}d   | d V  qdS r  r   r   r   rS   rV   r   
  s     z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>r  )_modulerB  r   r   r  rS   r  rV   _print_ModuleImplementedIdeal
  s    z*LatexPrinter._print_ModuleImplementedIdealc                   sD    fdd|j D }|d gdd t|dd  dD  }d|S )Nc                   s    g | ]} j |td  ddqS )r	   Tr~  )r   r    rZ  r   rS   rV   r   
  s   z2LatexPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]\}}|d  | qS )r   rS   )r   rw   r   rS   rS   rV   r   
  s     r   Zijkr   )r   r  r   )r   r   rU   rD  rS   r   rV   _print_Quaternion
  s
    
&zLatexPrinter._print_Quaternionc                 C  s   d | |j| |jS Nz\frac{{{}}}{{{}}})r   r   re  
base_ideal)r   RrS   rS   rV   _print_QuotientRing
  s    
z LatexPrinter._print_QuotientRingc                 C  s(   |  |j|}d||  |jjS )N{{{}}} + {{{}}})r   re  rf  r   r  )r   r   Zx_latexrS   rS   rV   _print_QuotientRingElement
  s    z'LatexPrinter._print_QuotientRingElementc                   sH    fdd j D }ddfdd|D }d| jjS )Nc                   s   g | ]} j j|qS rS   )modulere  rf  r   r  rS   rV   r   
  s     z=LatexPrinter._print_QuotientModuleElement.<locals>.<listcomp>r  r   c                 3  s    | ]}d   | d V  qdS r  r   r   r   rS   rV   r   
  s    z<LatexPrinter._print_QuotientModuleElement.<locals>.<genexpr>r  )datar   r   r   r  killed_module)r   rB  r  Z
data_latexrS   r  rV   _print_QuotientModuleElement
  s    
z)LatexPrinter._print_QuotientModuleElementc                 C  s   d | |j| |jS r  )r   r   r   r  r  rS   rS   rV   _print_QuotientModule
  s    
z"LatexPrinter._print_QuotientModulec                 C  s(   d | | | |j| |jS )Nz{{{}}} : {{{}}} \to {{{}}})r   r   Z_sympy_matrixr<  rr  )r   r  rS   rS   rV   _print_MatrixHomomorphism
  s    
 
z&LatexPrinter._print_MatrixHomomorphismc                 C  s   |j j }d|kr"|g g   }}}n2t|\}}}t|}dd |D }dd |D }d| }|rr|dd| 7 }|r|dd| 7 }|S )	NrZ   c                 S  s   g | ]}t |qS rS   r\  r^  rS   rS   rV   r   
  s     z0LatexPrinter._print_Manifold.<locals>.<listcomp>c                 S  s   g | ]}t |qS rS   r\  r_  rS   rS   rV   r   
  s     r   r  r   r{  )r   r   r]  r   )r   manifoldr[  r   ra  r  rS   rS   rV   _print_Manifold
  s    zLatexPrinter._print_Manifoldc                 C  s   d|  |j|  |jf S )Nz\text{%s}_{%s})r   r   r  )r   patchrS   rS   rV   _print_Patch  s    zLatexPrinter._print_Patchc                 C  s(   d|  |j|  |jj|  |jf S )Nz\text{%s}^{\text{%s}}_{%s})r   r   r  r  )r   ZcoordsysrS   rS   rV   _print_CoordSystem  s
    
  
zLatexPrinter._print_CoordSystemc                 C  s   d|  |j S )Nz\mathbb{\nabla}_{%s})r   Z_wrt)r   ZcvdrS   rS   rV   _print_CovarDerivativeOp
  s    z%LatexPrinter._print_CovarDerivativeOpc                 C  s$   |j j|j j}d| t|S r  
_coord_sysr  _indexr   r   r   r   r   fieldr[  rS   rS   rV   _print_BaseScalarField  s    z#LatexPrinter._print_BaseScalarFieldc                 C  s$   |j j|j j}d| t|S )Nz\partial_{{{}}}r  r  rS   rS   rV   _print_BaseVectorField  s    z#LatexPrinter._print_BaseVectorFieldc                 C  sL   |j }t|dr4|jj|j j}d| t|S | |}d|S d S )Nr  z\operatorname{{d}}{}z!\operatorname{{d}}\left({}\right))	Z_form_fieldr-  r  r  r  r   r   r   r   )r   diffr  r[  rS   rS   rV   _print_Differential  s    

z LatexPrinter._print_Differentialc                 C  s   |  |jd }d|S )Nr   z"\operatorname{{tr}}\left({}\right)r.  )r   rJ  contentsrS   rS   rV   	_print_Tr  s    zLatexPrinter._print_Trc                 C  s4   |d k	r d|  |jd |f S d|  |jd  S )Nz%\left(\phi\left(%s\right)\right)^{%s}r   z\phi\left(%s\right)rX  r   rS   rS   rV   _print_totient#  s
    zLatexPrinter._print_totientc                 C  s4   |d k	r d|  |jd |f S d|  |jd  S )Nz(\left(\lambda\left(%s\right)\right)^{%s}r   z\lambda\left(%s\right)rX  r   rS   rS   rV   _print_reduced_totient)  s
    z#LatexPrinter._print_reduced_totientc                 C  sd   t |jdkr4dtt| j|jd |jd f }nd| |jd  }|d k	r\d||f S d| S )Nr=  _%s\left(%s\right)r   r   r   z\sigma^{%s}%sz\sigma%sr/  r  rS   rS   rV   _print_divisor_sigma/  s    

z!LatexPrinter._print_divisor_sigmac                 C  sd   t |jdkr4dtt| j|jd |jd f }nd| |jd  }|d k	r\d||f S d| S )Nr=  r  r   r   r   z\sigma^*^{%s}%sz
\sigma^*%sr/  r  rS   rS   rV   _print_udivisor_sigma9  s    

z"LatexPrinter._print_udivisor_sigmac                 C  s4   |d k	r d|  |jd |f S d|  |jd  S )Nz$\left(\nu\left(%s\right)\right)^{%s}r   z\nu\left(%s\right)rX  r   rS   rS   rV   _print_primenuC  s
    zLatexPrinter._print_primenuc                 C  s4   |d k	r d|  |jd |f S d|  |jd  S )Nz'\left(\Omega\left(%s\right)\right)^{%s}r   z\Omega\left(%s\right)rX  r   rS   rS   rV   _print_primeomegaI  s
    zLatexPrinter._print_primeomegac                 C  s
   t |jS r   )rk   r   r   rS   rS   rV   
_print_StrO  s    zLatexPrinter._print_Strc                 C  s   |  t|S r   )r   r   r   rS   rS   rV   _print_floatR  s    zLatexPrinter._print_floatc                 C  s   t |S r   rk   r   rS   rS   rV   
_print_intU  s    zLatexPrinter._print_intc                 C  s   t |S r   r  r   rS   rS   rV   
_print_mpzX  s    zLatexPrinter._print_mpzc                 C  s   t |S r   r  r   rS   rS   rV   
_print_mpq[  s    zLatexPrinter._print_mpqc                 C  s   t |S r   r  r   rS   rS   rV   _print_fmpz^  s    zLatexPrinter._print_fmpzc                 C  s   t |S r   r  r   rS   rS   rV   _print_fmpqa  s    zLatexPrinter._print_fmpqc                 C  s   d tt|jS )Nz"\operatorname{{Q}}_{{\text{{{}}}}})r   rr   rk   r   r   rS   rS   rV   _print_Predicated  s    zLatexPrinter._print_Predicatec                   s:   |j }|j} |}d fdd|D }d||f S )Nr   c                   s   g | ]}  |qS rS   r   r  r   rS   rV   r   k  s     z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>z%s(%s))rg  	argumentsr   r   )r   r   predr   Z
pred_latexZ
args_latexrS   r   rV   _print_AppliedPredicateg  s
    
z$LatexPrinter._print_AppliedPredicatec                   s   t  |}dt| S )Nz\mathtt{\text{%s}})superemptyPrinterrr   rV  r   rS   rV   r  n  s    zLatexPrinter.emptyPrinter)N)FF)FF)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)Nr  )N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)Nr   )Nr   )N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)FN)N)N)N)N)rv   )rv   )N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)F)N)N)N)N)N)N)N(A  r   
__module____qualname__Zprintmethodr   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Z_print_BooleanTrueZ_print_BooleanFalser   r   r  r  r  r  r  r!  r"  r#  r&  r'  rF  rH  rL  rR  rQ  rY  rj  rk  rz  r~  r  r  r  r  r  r  r  r  r  r  propertyr  r  r  r  r  Z
_print_MinZ
_print_Maxr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Z_print_gammar  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r$  r&  r'  r+  r-  r.  r0  r1  r2  r4  r6  r8  r:  r;  r<  r=  r>  r?  r@  rE  rF  rK  rL  rM  rO  rP  rR  rW  rZ  Z_print_RandomSymbolr   ri  rk  rx  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Z_print_frozensetr  r  r  r  r  r  r  r  r  r  Z_print_SeqPerZ_print_SeqAddZ_print_SeqMulr
  r  r  r  r  r  r  r  r  r  r  r!  r#  r%  r)  r-  r/  r0  r1  r3  r4  r6  r7  r8  r9  r:  r>  r?  rA  rH  rI  rJ  rL  rN  rO  rP  rQ  rR  rS  rU  rX  rY  r[  r\  r]  r^  r`  ra  rc  rd  rh  ri  rk  rm  rn  ro  rp  rq  rt  rv  rx  r{  r~  r  r  r  r  r  Z_print_IDFTr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  __classcell__rS   rS   r  rV   rs      s  
=

	!s-!
$ L

										
7



*9		
$	

rs   c                 C  s   t | }|r|S |  tkr*d|   S | tkr:d|  S tt tddD ]D}|  	|rLt| t|krLt| t
| dt|    S qL| S dS )a  
    Check for a modifier ending the string.  If present, convert the
    modifier to latex and translate the rest recursively.

    Given a description of a Greek letter or other special character,
    return the appropriate latex.

    Let everything else pass as given.

    >>> from sympy.printing.latex import translate
    >>> translate('alphahatdotprime')
    "{\\dot{\\hat{\\alpha}}}'"
    rm   T)ro  r  N)tex_greek_dictionaryr   r  greek_letters_setother_symbolsr  rj   r  r  rV  r]  )rU   r   ro  rS   rS   rV   r]  u  s    
$r]  c                 K  s   t || S )a%  Convert the given expression to LaTeX string representation.

    Parameters
    ==========
    full_prec: boolean, optional
        If set to True, a floating point number is printed with full precision.
    fold_frac_powers : boolean, optional
        Emit ``^{p/q}`` instead of ``^{\frac{p}{q}}`` for fractional powers.
    fold_func_brackets : boolean, optional
        Fold function brackets where applicable.
    fold_short_frac : boolean, optional
        Emit ``p / q`` instead of ``\frac{p}{q}`` when the denominator is
        simple enough (at most two terms and no powers). The default value is
        ``True`` for inline mode, ``False`` otherwise.
    inv_trig_style : string, optional
        How inverse trig functions should be displayed. Can be one of
        ``'abbreviated'``, ``'full'``, or ``'power'``. Defaults to
        ``'abbreviated'``.
    itex : boolean, optional
        Specifies if itex-specific syntax is used, including emitting
        ``$$...$$``.
    ln_notation : boolean, optional
        If set to ``True``, ``\ln`` is used instead of default ``\log``.
    long_frac_ratio : float or None, optional
        The allowed ratio of the width of the numerator to the width of the
        denominator before the printer breaks off long fractions. If ``None``
        (the default value), long fractions are not broken up.
    mat_delim : string, optional
        The delimiter to wrap around matrices. Can be one of ``'['``, ``'('``,
        or the empty string ``''``. Defaults to ``'['``.
    mat_str : string, optional
        Which matrix environment string to emit. ``'smallmatrix'``,
        ``'matrix'``, ``'array'``, etc. Defaults to ``'smallmatrix'`` for
        inline mode, ``'matrix'`` for matrices of no more than 10 columns, and
        ``'array'`` otherwise.
    mode: string, optional
        Specifies how the generated code will be delimited. ``mode`` can be one
        of ``'plain'``, ``'inline'``, ``'equation'`` or ``'equation*'``.  If
        ``mode`` is set to ``'plain'``, then the resulting code will not be
        delimited at all (this is the default). If ``mode`` is set to
        ``'inline'`` then inline LaTeX ``$...$`` will be used. If ``mode`` is
        set to ``'equation'`` or ``'equation*'``, the resulting code will be
        enclosed in the ``equation`` or ``equation*`` environment (remember to
        import ``amsmath`` for ``equation*``), unless the ``itex`` option is
        set. In the latter case, the ``$$...$$`` syntax is used.
    mul_symbol : string or None, optional
        The symbol to use for multiplication. Can be one of ``None``,
        ``'ldot'``, ``'dot'``, or ``'times'``.
    order: string, optional
        Any of the supported monomial orderings (currently ``'lex'``,
        ``'grlex'``, or ``'grevlex'``), ``'old'``, and ``'none'``. This
        parameter does nothing for `~.Mul` objects. Setting order to ``'old'``
        uses the compatibility ordering for ``~.Add`` defined in Printer. For
        very large expressions, set the ``order`` keyword to ``'none'`` if
        speed is a concern.
    symbol_names : dictionary of strings mapped to symbols, optional
        Dictionary of symbols and the custom strings they should be emitted as.
    root_notation : boolean, optional
        If set to ``False``, exponents of the form 1/n are printed in fractonal
        form. Default is ``True``, to print exponent in root form.
    mat_symbol_style : string, optional
        Can be either ``'plain'`` (default) or ``'bold'``. If set to
        ``'bold'``, a `~.MatrixSymbol` A will be printed as ``\mathbf{A}``,
        otherwise as ``A``.
    imaginary_unit : string, optional
        String to use for the imaginary unit. Defined options are ``'i'``
        (default) and ``'j'``. Adding ``r`` or ``t`` in front gives ``\mathrm``
        or ``\text``, so ``'ri'`` leads to ``\mathrm{i}`` which gives
        `\mathrm{i}`.
    gothic_re_im : boolean, optional
        If set to ``True``, `\Re` and `\Im` is used for ``re`` and ``im``, respectively.
        The default is ``False`` leading to `\operatorname{re}` and `\operatorname{im}`.
    decimal_separator : string, optional
        Specifies what separator to use to separate the whole and fractional parts of a
        floating point number as in `2.5` for the default, ``period`` or `2{,}5`
        when ``comma`` is specified. Lists, sets, and tuple are printed with semicolon
        separating the elements when ``comma`` is chosen. For example, [1; 2; 3] when
        ``comma`` is chosen and [1,2,3] for when ``period`` is chosen.
    parenthesize_super : boolean, optional
        If set to ``False``, superscripted expressions will not be parenthesized when
        powered. Default is ``True``, which parenthesizes the expression when powered.
    min: Integer or None, optional
        Sets the lower bound for the exponent to print floating point numbers in
        fixed-point format.
    max: Integer or None, optional
        Sets the upper bound for the exponent to print floating point numbers in
        fixed-point format.
    diff_operator: string, optional
        String to use for differential operator. Default is ``'d'``, to print in italic
        form. ``'rd'``, ``'td'`` are shortcuts for ``\mathrm{d}`` and ``\text{d}``.
    adjoint_style: string, optional
        String to use for the adjoint symbol. Defined options are ``'dagger'``
        (default),``'star'``, and ``'hermitian'``.

    Notes
    =====

    Not using a print statement for printing, results in double backslashes for
    latex commands since that's the way Python escapes backslashes in strings.

    >>> from sympy import latex, Rational
    >>> from sympy.abc import tau
    >>> latex((2*tau)**Rational(7,2))
    '8 \\sqrt{2} \\tau^{\\frac{7}{2}}'
    >>> print(latex((2*tau)**Rational(7,2)))
    8 \sqrt{2} \tau^{\frac{7}{2}}

    Examples
    ========

    >>> from sympy import latex, pi, sin, asin, Integral, Matrix, Rational, log
    >>> from sympy.abc import x, y, mu, r, tau

    Basic usage:

    >>> print(latex((2*tau)**Rational(7,2)))
    8 \sqrt{2} \tau^{\frac{7}{2}}

    ``mode`` and ``itex`` options:

    >>> print(latex((2*mu)**Rational(7,2), mode='plain'))
    8 \sqrt{2} \mu^{\frac{7}{2}}
    >>> print(latex((2*tau)**Rational(7,2), mode='inline'))
    $8 \sqrt{2} \tau^{7 / 2}$
    >>> print(latex((2*mu)**Rational(7,2), mode='equation*'))
    \begin{equation*}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation*}
    >>> print(latex((2*mu)**Rational(7,2), mode='equation'))
    \begin{equation}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation}
    >>> print(latex((2*mu)**Rational(7,2), mode='equation', itex=True))
    $$8 \sqrt{2} \mu^{\frac{7}{2}}$$
    >>> print(latex((2*mu)**Rational(7,2), mode='plain'))
    8 \sqrt{2} \mu^{\frac{7}{2}}
    >>> print(latex((2*tau)**Rational(7,2), mode='inline'))
    $8 \sqrt{2} \tau^{7 / 2}$
    >>> print(latex((2*mu)**Rational(7,2), mode='equation*'))
    \begin{equation*}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation*}
    >>> print(latex((2*mu)**Rational(7,2), mode='equation'))
    \begin{equation}8 \sqrt{2} \mu^{\frac{7}{2}}\end{equation}
    >>> print(latex((2*mu)**Rational(7,2), mode='equation', itex=True))
    $$8 \sqrt{2} \mu^{\frac{7}{2}}$$

    Fraction options:

    >>> print(latex((2*tau)**Rational(7,2), fold_frac_powers=True))
    8 \sqrt{2} \tau^{7/2}
    >>> print(latex((2*tau)**sin(Rational(7,2))))
    \left(2 \tau\right)^{\sin{\left(\frac{7}{2} \right)}}
    >>> print(latex((2*tau)**sin(Rational(7,2)), fold_func_brackets=True))
    \left(2 \tau\right)^{\sin {\frac{7}{2}}}
    >>> print(latex(3*x**2/y))
    \frac{3 x^{2}}{y}
    >>> print(latex(3*x**2/y, fold_short_frac=True))
    3 x^{2} / y
    >>> print(latex(Integral(r, r)/2/pi, long_frac_ratio=2))
    \frac{\int r\, dr}{2 \pi}
    >>> print(latex(Integral(r, r)/2/pi, long_frac_ratio=0))
    \frac{1}{2 \pi} \int r\, dr

    Multiplication options:

    >>> print(latex((2*tau)**sin(Rational(7,2)), mul_symbol="times"))
    \left(2 \times \tau\right)^{\sin{\left(\frac{7}{2} \right)}}

    Trig options:

    >>> print(latex(asin(Rational(7,2))))
    \operatorname{asin}{\left(\frac{7}{2} \right)}
    >>> print(latex(asin(Rational(7,2)), inv_trig_style="full"))
    \arcsin{\left(\frac{7}{2} \right)}
    >>> print(latex(asin(Rational(7,2)), inv_trig_style="power"))
    \sin^{-1}{\left(\frac{7}{2} \right)}

    Matrix options:

    >>> print(latex(Matrix(2, 1, [x, y])))
    \left[\begin{matrix}x\\y\end{matrix}\right]
    >>> print(latex(Matrix(2, 1, [x, y]), mat_str = "array"))
    \left[\begin{array}{c}x\\y\end{array}\right]
    >>> print(latex(Matrix(2, 1, [x, y]), mat_delim="("))
    \left(\begin{matrix}x\\y\end{matrix}\right)

    Custom printing of symbols:

    >>> print(latex(x**2, symbol_names={x: 'x_i'}))
    x_i^{2}

    Logarithms:

    >>> print(latex(log(10)))
    \log{\left(10 \right)}
    >>> print(latex(log(10), ln_notation=True))
    \ln{\left(10 \right)}

    ``latex()`` also supports the builtin container types :class:`list`,
    :class:`tuple`, and :class:`dict`:

    >>> print(latex([2/x, y], mode='inline'))
    $\left[ 2 / x, \  y\right]$

    Unsupported types are rendered as monospaced plaintext:

    >>> print(latex(int))
    \mathtt{\text{<class 'int'>}}
    >>> print(latex("plain % text"))
    \mathtt{\text{plain \% text}}

    See :ref:`printer_method_example` for an example of how to override
    this behavior for your own types by implementing ``_latex``.

    .. versionchanged:: 1.7.0
        Unsupported types no longer have their ``str`` representation treated as valid latex.

    )rs   r   r   r   rS   rS   rV   r    s     Xr  c                 K  s   t t| f| dS )z`Prints LaTeX representation of the given expression. Takes the same
    settings as ``latex()``.N)printr  r  rS   rS   rV   print_latexn  s    r  r   align*Fc              
   K  s  t f |}|dkr(d}d}d}	d}
d}nJ|dkrFd}d}d}	d	}
d}n,|d
krdd}d}d}	d}
d}ntd|d}|r~d}| }t|}d}t|D ]}|| }d}d}d}||kr|rd}nd}d}||kr||d k r||	 d d }nd}| d dkrd| }d}|dkrP|dkr,d}|d|| |||||7 }n|d|||||7 }|d7 }q||
7 }|S )a  
    This function generates a LaTeX equation with a multiline right-hand side
    in an ``align*``, ``eqnarray`` or ``IEEEeqnarray`` environment.

    Parameters
    ==========

    lhs : Expr
        Left-hand side of equation

    rhs : Expr
        Right-hand side of equation

    terms_per_line : integer, optional
        Number of terms per line to print. Default is 1.

    environment : "string", optional
        Which LaTeX wnvironment to use for the output. Options are "align*"
        (default), "eqnarray", and "IEEEeqnarray".

    use_dots : boolean, optional
        If ``True``, ``\\dots`` is added to the end of each line. Default is ``False``.

    Examples
    ========

    >>> from sympy import multiline_latex, symbols, sin, cos, exp, log, I
    >>> x, y, alpha = symbols('x y alpha')
    >>> expr = sin(alpha*y) + exp(I*alpha) - cos(log(y))
    >>> print(multiline_latex(x, expr))
    \begin{align*}
    x = & e^{i \alpha} \\
    & + \sin{\left(\alpha y \right)} \\
    & - \cos{\left(\log{\left(y \right)} \right)}
    \end{align*}

    Using at most two terms per line:
    >>> print(multiline_latex(x, expr, 2))
    \begin{align*}
    x = & e^{i \alpha} + \sin{\left(\alpha y \right)} \\
    & - \cos{\left(\log{\left(y \right)} \right)}
    \end{align*}

    Using ``eqnarray`` and dots:
    >>> print(multiline_latex(x, expr, terms_per_line=2, environment="eqnarray", use_dots=True))
    \begin{eqnarray}
    x & = & e^{i \alpha} + \sin{\left(\alpha y \right)} \dots\nonumber\\
    & & - \cos{\left(\log{\left(y \right)} \right)}
    \end{eqnarray}

    Using ``IEEEeqnarray``:
    >>> print(multiline_latex(x, expr, environment="IEEEeqnarray"))
    \begin{IEEEeqnarray}{rCl}
    x & = & e^{i \alpha} \nonumber\\
    & & + \sin{\left(\alpha y \right)} \nonumber\\
    & & - \cos{\left(\log{\left(y \right)} \right)}
    \end{IEEEeqnarray}

    Notes
    =====

    All optional parameters from ``latex`` can also be used.

    Zeqnarrayz\begin{eqnarray}
z& = &z	\nonumberz
\end{eqnarray}TZIEEEeqnarrayz\begin{IEEEeqnarray}{rCl}
z
\end{IEEEeqnarray}r  z\begin{align*}
z= &r   z
\end{align*}FzUnknown environment: {}z\dotsr   r  z& & r  rb  r  r   r   rp  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s})rs   r   r   Zas_ordered_termsr  r
  r1  r   )rd  re  Zterms_per_lineenvironmentZuse_dotsr   r`  rl  Z
first_termZnonumberZend_termZdoubleetr  r   Zn_termsZ
term_countrw   r   Z
term_startZterm_endrQ  rS   rS   rV   multiline_latexu  sv    C


   
 
r  )r   r  F)J__doc__
__future__r   typingr   r   r   r  Z
sympy.corer   r   r   r	   r
   r   r   r   Zsympy.core.alphabetsr   Zsympy.core.containersr   Zsympy.core.functionr   r   r   Zsympy.core.operationsr   Zsympy.core.powerr   Zsympy.core.sortingr   Zsympy.core.sympifyr   r  r   r   r   Zsympy.printing.precedencer   Zsympy.printing.printerr   r   Zsympy.printing.conventionsr   r   r   r    Zmpmath.libmp.libmpfr!   r"   r  Zsympy.utilities.iterablesr#   r$   r1   Zsympy.tensor.arrayr%   Zsympy.vector.basisdependentr&   r  r  r  rj   r  	frozensetr  compiler6  rr   rs   r]  r  r  r  rS   rS   rS   rV   <module>   s  (            '                       |
 Z