a
    kh                 %   @  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: g dZ;dddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d!d1d-d2d3d4d5d6d7d8d9$Z<h d:Z=d;d< d=d< d>d< d?d< d@d< dAd< dBd< dCd< dDd< dEd< dFd< dGd< dHd< dId< dJd< dKd< dLd< dMd< dNd< dOd< dPd< dQd< dRd< dSd< dTZ>dUe?dV< e@eZAe6BdWe6BdXfZCdYdYdZd[d\ZDG d]d^ d^e(ZEdYdYdZd_d`ZFe)eEdadb ZGdcdd ZHdjdhdiZIdS )kzC
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)BasisDependent)Z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vartheta>
   ZbethZwpZgimelZmhoZellZhslashZalephZhbarethZdalethc                 C  s   d|  d S )Nz
\mathring{} srS   rS   B/var/www/auris/lib/python3.9/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absZ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    rq   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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)ZeZdd*d+d,d-Zdddd.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dEdF ZdGdH ZdIdJ ZdՐdKdLZdMdN ZdOdP ZdQdR ZdSdT ZdUdV ZdWdX ZdYdZ Zd[d\ Zd]d^ Zd_d*d`daZdbdc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d֐dxdyZdz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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d0d1 Zd2d3 Ze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`da Z/dbdc Z0ddde Z1ddfdgZ2ddhdiZ3ddjdkZ4ddldmZ5ddndoZ6ddpdqZ7drds Z8dtdu Z9dvdw Z:dxdy Z;dzd{ Z<d|d} Z=d~d Z>dd Z?dd Z@ fddZA  ZBS (  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_styledisable_split_super_subzdict[str, Any]_default_settingsc                 C  sr  t | | d| jv r4g d}| jd |vr4td| jd d u rZ| jd dkrZd| jd< ddd	d
d}z|| jd  | jd< W n" ty   | jd | jd< Y n0 z|| jd pd | jd< W nF ty   | jd  dv r|d | jd< n| jd | jd< Y n0 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   )inlineru   Zequationz	equation*zB'mode' must be one of 'inline', 'plain', 'equation' or 'equation*'r}   r   T z \,.\,  \cdot  \times )NZldotr]   timesr   mul_symbol_latexr]   mul_symbol_latex_numbers) r   rl   z\,z\:\;z\quad)])(rt   rv   z
\mathrm{i}z\text{i}jz
\mathrm{j}z\text{j})Nrv   riZtir   ZrjZtjr   Zimaginary_unit_latexrx   z
\mathrm{d}z\text{d})Nrx   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      sb    


	

zLatexPrinter.__init__rj   rk   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|v 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.
        rn   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   ru   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uo$|jdu  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   Zhas.0xr   rS   rV   	<genexpr>O  rX   z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r   r   rS   rV   r   R  rX   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_brackets8  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   _  rX   z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>F)r   r   r   r   r   rS   r   rV   _needs_add_bracketsW  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   e  s    
zLatexPrinter._mul_is_cleanc                 C  s   |  |j S r   )r   baser   rS   rS   rV   r   k  s    zLatexPrinter._pow_is_cleanr   c                 C  s   |d urd||f S |S d S )N\left(%s\right)^{%s}rS   r   r   exprS   rS   rV   _do_exponentn  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>w  rX   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_Basict  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   rv   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   rt   z\left( r   \right)) sympy.combinatorics.permutationsr   sizeZcyclic_form
array_formrj   ro   )r   r   r   Z	expr_permZsizr   rv   rS   rS   rV   _print_Cycle  s    
zLatexPrinter._print_Cyclec           
        s   ddl m} ddlm} |j}|d u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     rX   z3LatexPrinter._print_Permutation.<locals>.<listcomp>c                   s   g | ]}  |qS rS   r   r  r   rS   rV   r     rX    & 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v r0| jd nd }d| jv rH| jd nd }t|j||||d}| jd }d|v 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 )Nrz   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_splitro   )
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u stdd |dd  D r |S d}|	 r| }d}|j
r|d7 }d}nd}||dd\}}|tju rtdddd|jvr|||7 }n||}	||}
t|
 }jd }jd rr|dkrrd|
vrrj|ddr^|d|	|
f 7 }n|d|	|
f 7 }n6|d u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  u rdu 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   rj   r   c                   sr   | j st| S jdv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   rj   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_texrv   r   r   )	numbersepr   r  rS   rV   r3    s&    


z-LatexPrinter._print_Mul.<locals>.convert_argsc                 s  s   | ]}t |tV  qd S r   )r-  r
   r  rS   rS   rV   r   ;  rX   z*LatexPrinter._print_Mul.<locals>.<genexpr>r   F- r   Tr   )exactr   )evaluater   r}      rn   )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'  r4  r   Zinclude_parensr   numerdenomZsnumerZsdenomZldenomZratioabr   rS   )r3  r8  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_AlgebraicNumber{  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alpharE  )r   r   rH  rI  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   rH  qrh   r   r   r   Zis_negativer   r    	is_Symbolr   r   r?  rD  _helper_print_standard_power)r   r   rH  rM  r   r   Zbase_pZbase_qrS   rS   rV   
_print_Pow  sF    






zLatexPrinter._print_Pow)templaterk   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}rG  z\\left\(\\d?d?dotr      i)r   r   r   r   r    rN  r   Zis_Floatr-  r   
startswithr1   r7  endswith)r   r   rQ  r   r   rS   rS   rV   rO    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   rv   r   rS   rV   r     rX   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     rX   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^  r_  rS   rV   r     rX   r   	r
  limitsr\  rj   r   r-  functionr   r   r   r   r   rS   r_  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   rX  r   rS   rV   r     rX   z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                   s,   dt  fdd| d | d | d fD  S )NrY  c                   s   g | ]}  |qS rS   r   rZ  r   rS   rV   r     rX   zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>r   r   r<  r[  r]  r   rS   rV   r_    s    &z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} r`  c                   s   g | ]} |qS rS   rS   ra  rb  rS   rV   r     rX   r   rc  rf  rS   rg  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 rU  )__str__r.  rS   rS   rV   rW     rX   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>keyr   r   r   r   rG  r   r   -   )Zsympy.vectorrj  ZzeroZ_latex_formr-  Zseparateitemsr1  
componentssortappendr   r   )r   r   rj  Zo1rp  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 urb|  |j}|jd u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   rX  rS   rS   rV   r   ;  rX   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   I  rX   z+LatexPrinter._print_Subs.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   J  rX   z\\ c                 s  s"   | ]}|d  d |d  V  qdS )r   =r   NrS   r  rS   rS   rV   r   K  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_SubsF  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   U  rX   z/LatexPrinter._print_Integral.<locals>.<genexpr>z\irv   r   ntc                   s"   g | ]}d   |d f qS )\, %s%sr   r   r   symbolr  r   rS   rV   r   Y  s   z0LatexPrinter._print_Integral.<locals>.<listcomp>r   z\intr   r   r   z\limitsro  z
_{%s}^{%s}r<  ^{%s}r  z%s %s%sr	   c                 s  s   | ]}|  V  qd S r   r  rX  rS   rS   rV   r   p  rX   Tr  )r   r
  rd  allr  r   insertr   re  r    r   r   r   )r   r   r   symbolsr  r  rS   r  rV   _print_IntegralP  s:    

"zLatexPrinter._print_Integralc                 C  s   |j \}}}}d| | }t|dks8|tjtjfv 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   rj   r   InfinityNegativeInfinityr-  r   )r   r   r   zZz0dirr   rS   rS   rV   _print_Limitt  s    
zLatexPrinter._print_Limit)r$  rk   c                 C  s   |  |}|d}|d}|tv 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
        rn   _z\%sr   rl   r   z\operatorname{%s}%sNz\operatorname{%s})r   findaccepted_latex_functionsr
  rS  r   )r   r$  ZsuperscriptidxZsubscriptidxr   rS   rS   rV   _hprint_Function  s0    



&



zLatexPrinter._hprint_Functionr   )r   rk   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  }g d	}||v r|d
krnN|dkr|d dkrdnd|dd  }n$|dkr|dd }d}|durd}|r
|t
v r d| }	nd| }	n6|dur6 |}
 |
}
d|
|f }	n
 |}	|rd|t
v rZ|	d7 }	n|	d7 }	n|	d7 }	|r|du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   )rj   r   r  r   rS   rV   r     rX   z0LatexPrinter._print_Function.<locals>.<listcomp>r~   Fr|   r   r   )asinacosatanZacscZasecZacotasinhacoshatanhZacschZasechZacothrs   fullr   harZarcNpowerTz\%s^{-1}z\operatorname{%s}^{-1}rL  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  sR    


"









zLatexPrinter._print_Functionc                 C  s   |  t|S r   )r  rj   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   re  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  rj   )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 urPd||f S |S d S )Nrl  c                   s   g | ]}d   | qS )r  r   r  r   rS   rV   r     rX   z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)r   rL  )sortedr   r   rj   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 ur(d||f S |S d S )Nz\left\lfloor{%s}\right\rfloorr   rL  rV  r   r   r   r   rS   rS   rV   _print_floor&  s    zLatexPrinter._print_floorc                 C  s0   d|  |jd  }|d ur(d||f S |S d S )Nz\left\lceil{%s}\right\rceilr   rL  rV  r  rS   rS   rV   _print_ceiling.  s    zLatexPrinter._print_ceilingc                 C  sP   | j d s d| |jd  }nd| |jd  }|d urHd||f S |S d S )Nr   z\log{\left(%s \right)}r   z\ln{\left(%s \right)}rL  )r   r   r   r  rS   rS   rV   
_print_log6  s    
zLatexPrinter._print_logc                 C  s0   d|  |jd  }|d ur(d||f S |S d S )N\left|{%s}\right|r   rL  rV  r  rS   rS   rV   
_print_AbsA  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_reI  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_imQ  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_NotY  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_LogOpd  s    zLatexPrinter._print_LogOpc                 C  s   t |jtd}| |dS )Nrl  z\wedger  r   r   r  r   r   r   rS   rS   rV   
_print_Ands  s    zLatexPrinter._print_Andc                 C  s   t |jtd}| |dS )Nrl  z\veer  r  rS   rS   rV   	_print_Orw  s    zLatexPrinter._print_Orc                 C  s   t |jtd}| |dS )Nrl  z\veebarr  r  rS   rS   rV   
_print_Xor{  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 )Nrl  z\Leftrightarrowr  )r   r   r  r   rS   rS   rV   r    s    zLatexPrinter._print_Equivalentc                 C  s0   d|  |jd  }|d ur(d||f S |S d S )Nz\overline{%s}r   rL  rV  r  rS   rS   rV   _print_conjugate  s    zLatexPrinter._print_conjugatec                 C  s>   d}d|  |jd  }|d ur.d|||f S d||f S d S )Nz\operatorname{polar\_lift}r  r   	%s^{%s}%s%s%srV  )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 ur(d||f S d| S d S )Nr   r   zK^{%s}%szK%srV  r  rS   rS   rV   _print_elliptic_k  s    zLatexPrinter._print_elliptic_kc                 C  sD   d|  |jd |  |jd f }|d ur8d||f S d| S d S )N\left(%s\middle| %s\right)r   r   zF^{%s}%szF%srV  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 u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 urzd||f S d| S d S )	Nro  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 urRd||f S d| S d S )Nr   r   rG  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 urJd||d |d ||f S d	||d |d |f S d S )
Nc                   s   g | ]}  |qS rS   r   r  r   rS   rV   r     rX   z/LatexPrinter._print_betainc.<locals>.<listcomp>\left(%s, %s\right)r   r   z#\operatorname{%s}_{(%s, %s)}^{%s}%sr<  ro  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 ur8d||f S d| S d S )Nr  r   r   z\Gamma^{%s}%sz\Gamma%srV  r  rS   rS   rV   _print_uppergamma  s    zLatexPrinter._print_uppergammac                 C  sD   d|  |jd |  |jd f }|d ur8d||f S d| S d S )Nr  r   r   z\gamma^{%s}%s\gamma%srV  r  rS   rS   rV   _print_lowergamma  s    zLatexPrinter._print_lowergammac                 C  sJ   d|  |jd  }|d u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 ur(d||f S d| S d S )Nr   r   z\operatorname{Chi}^{%s}%sz\operatorname{Chi}%srV  r  rS   rS   rV   
_print_Chi  s    zLatexPrinter._print_Chic                 C  sJ   d|  |jd  }|  |jd }|d ur:d|||f S d||f S d S )Nr   r   r   z\operatorname{E}_{%s}^{%s}%sz\operatorname{E}_{%s}%srV  )r   r   r   r   nurS   rS   rV   _print_expint  s
    zLatexPrinter._print_expintc                 C  s4   d|  |jd  }|d ur(d||f S d| S d S )Nr   r   zS^{%s}%szS%srV  r  rS   rS   rV   _print_fresnels  s    zLatexPrinter._print_fresnelsc                 C  s4   d|  |jd  }|d ur(d||f S d| S d S )Nr   r   zC^{%s}%szC%srV  r  rS   rS   rV   _print_fresnelc  s    zLatexPrinter._print_fresnelcc                 C  s6   d|  |jd td  }|d u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 ur.d||f S |S d S )Nz%s!r   r  rL  r  r  rS   rS   rV   _print_factorial#  s    zLatexPrinter._print_factorialc                 C  s6   d|  |jd td  }|d ur.d||f S |S d S )Nz%s!!r   r  rL  r  r  rS   rS   rV   _print_factorial2+  s    zLatexPrinter._print_factorial2c                 C  s@   d|  |jd |  |jd f }|d ur8d||f S |S d S )Nz{\binom{%s}{%s}}r   r   rL  rV  r  rS   rS   rV   _print_binomial3  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   nru  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  ru  subr   rS   rS   rV   _print_FallingFactorialD  s    
z$LatexPrinter._print_FallingFactorial)symrk   c                 C  sf   d| }d}|d ur4| ddkr0d||f }nd}d|| |j| |jf }|rb| ||}|S )Nr  Frn   r   rL  T%s_{%s}\left(%s\right))r  r   r   argumentr   )r   r   r   r  r   Zneed_exprS   rS   rV   _hprint_BesselBaseL  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   rv   rS   rS   rV   _hprint_vec]  s    zLatexPrinter._hprint_vecc                 C  s   |  ||dS )NJr  r   rS   rS   rV   _print_besseljf  s    zLatexPrinter._print_besseljc                 C  s   |  ||dS )Nr  r  r   rS   rS   rV   _print_besselii  s    zLatexPrinter._print_besselic                 C  s   |  ||dS )NKr  r   rS   rS   rV   _print_besselkl  s    zLatexPrinter._print_besselkc                 C  s   |  ||dS )NYr  r   rS   rS   rV   _print_besselyo  s    zLatexPrinter._print_besselyc                 C  s   |  ||dS )Nr  r  r   rS   rS   rV   	_print_ynr  s    zLatexPrinter._print_ync                 C  s   |  ||dS )Nr   r  r   rS   rS   rV   	_print_jnu  s    zLatexPrinter._print_jnc                 C  s   |  ||dS )NzH^{(1)}r  r   rS   rS   rV   _print_hankel1x  s    zLatexPrinter._print_hankel1c                 C  s   |  ||dS )NzH^{(2)}r  r   rS   rS   rV   _print_hankel2{  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 ur*d|||f S d||f S d S r  rV  r   r   r   notationr   rS   rS   rV   _hprint_airy  s    zLatexPrinter._hprint_airyc                 C  s:   d|  |jd  }|d ur*d|||f S d||f S d S )Nr   r   z{%s^\prime}^{%s}%sz%s^\prime%srV  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 u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 u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 ur(d||f S d| S )Nr   r   z\eta^{%s}%sz\eta%srV  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 urNd||f S d| S )Nr<  r  r   r   z\zeta^{%s}%sz\zeta%sr
  r   r\  ry  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 urNd||f S d| S )Nr<  z_{%s}\left(%s\right)rx  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 u r&d| S d||f S )Nz\left(%s, %s, %s\right)z\Phi%sz\Phi^{%s}%s)r\  ry  r   r   r  rS   rS   rV   _print_lerchphi  s    zLatexPrinter._print_lerchphic                 C  s<   t | j|j\}}d| }|d u r.d||f S d|||f S )Nr   z\operatorname{Li}_{%s}%sz\operatorname{Li}_{%s}^{%s}%sry  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 ur>d| d|  }|S )Nz*P_{%s}^{\left(%s,%s\right)}\left(%s\right)rG  \right)^{%s}r/  )r   r   r   r  rB  rC  r   r   rS   rS   rV   _print_jacobi  s
    zLatexPrinter._print_jacobic                 C  s>   t | j|j\}}}d|||f }|d ur:d| d|  }|S )Nz'C_{%s}^{\left(%s\right)}\left(%s\right)rG  r1  r/  r   r   r   r  rB  r   r   rS   rS   rV   _print_gegenbauer  s
    zLatexPrinter._print_gegenbauerc                 C  s:   t | j|j\}}d||f }|d ur6d| d|  }|S )NzT_{%s}\left(%s\right)rG  r1  r/  r   r   r   r  r   r   rS   rS   rV   _print_chebyshevt  s
    zLatexPrinter._print_chebyshevtc                 C  s:   t | j|j\}}d||f }|d ur6d| d|  }|S )NzU_{%s}\left(%s\right)rG  r1  r/  r5  rS   rS   rV   _print_chebyshevu  s
    zLatexPrinter._print_chebyshevuc                 C  s:   t | j|j\}}d||f }|d ur6d| d|  }|S )NzP_{%s}\left(%s\right)rG  r1  r/  r5  rS   rS   rV   _print_legendre  s
    zLatexPrinter._print_legendrec                 C  s>   t | j|j\}}}d|||f }|d ur:d| d|  }|S )Nz'P_{%s}^{\left(%s\right)}\left(%s\right)rG  r1  r/  r3  rS   rS   rV   _print_assoc_legendre   s
    z"LatexPrinter._print_assoc_legendrec                 C  s:   t | j|j\}}d||f }|d ur6d| d|  }|S )NzH_{%s}\left(%s\right)rG  r1  r/  r5  rS   rS   rV   _print_hermite  s
    zLatexPrinter._print_hermitec                 C  s:   t | j|j\}}d||f }|d ur6d| d|  }|S )NzL_{%s}\left(%s\right)rG  r1  r/  r5  rS   rS   rV   _print_laguerre  s
    zLatexPrinter._print_laguerrec                 C  s>   t | j|j\}}}d|||f }|d ur:d| d|  }|S )Nz'L_{%s}^{\left(%s\right)}\left(%s\right)rG  r1  r/  r3  rS   rS   rV   _print_assoc_laguerre  s
    z"LatexPrinter._print_assoc_laguerrec                 C  sB   t | j|j\}}}}d||||f }|d ur>d| d|  }|S )NzY_{%s}^{%s}\left(%s,%s\right)rG  r1  r/  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 ur>d| d|  }|S )NzZ_{%s}^{%s}\left(%s,%s\right)rG  r1  r/  r=  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)ry  r   )	r   	characterr   rc   r   rB  rM  r  suprS   rS   rV   Z__print_mathieu_functions*  s    z&LatexPrinter.__print_mathieu_functionsc                 C  s   | j d|j|dS )NCrK  &_LatexPrinter__print_mathieu_functionsr   r   rS   rS   rV   _print_mathieuc0  s    zLatexPrinter._print_mathieucc                 C  s   | j d|j|dS )Nr   rK  rF  r   rS   rS   rV   _print_mathieus3  s    zLatexPrinter._print_mathieusc                 C  s   | j d|jd|dS )NrE  Trc   r   rF  r   rS   rS   rV   _print_mathieucprime6  s    z!LatexPrinter._print_mathieucprimec                 C  s   | j d|jd|dS )Nr   TrJ  rF  r   rS   rS   rV   _print_mathieusprime9  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   r9  r}   z	%s%d / %dz%s\frac{%d}{%d})rM  rH  r   r   )r   r   signrH  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   rH  rS   rS   rV   r   K  rX   z,LatexPrinter._print_Order.<locals>.<genexpr>r   ; r   z\rightarrow zO\left(%s\right))r   r   Zpointr   r
  	variablesr   r   rU   rS   rS   rV   _print_OrderI  s    zLatexPrinter._print_Orderr   c                 C  s,   | j d |}|d ur|S | j|j|dS )Nr   style)r   r   r   r   )r   r   rT  r   rS   rS   rV   _print_SymbolY  s    zLatexPrinter._print_Symbolz tuple[str, list[str], list[str]])r   rk   c                 C  s   |d u sd|v r|g g fS | j d rF|ddddg g   }}}nt|\}}}t|}dd |D }d	d |D }|||fS )
NrZ   r   r  z\_rn   z\^c                 S  s   g | ]}t |qS rS   	translate)r   rD  rS   rS   rV   r   j  rX   z1LatexPrinter._split_super_sub.<locals>.<listcomp>c                 S  s   g | ]}t |qS rS   rV  )r   r  rS   rS   rV   r   k  rX   )r   ro   r   rW  )r   r   supersr  rS   rS   rV   _split_super_subb  s    

"zLatexPrinter._split_super_sub)stringrk   c                 C  sR   |  |\}}}|dkr"d|}|r8|dd| 7 }|rN|dd| 7 }|S )Nrd   \mathbf{{{}}}r  r   rx  )rY  r   r   )r   rZ  rT  r   rX  r  rS   rS   rV   r   n  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==r\  r]  z>=z<=z!=z%s %s %s)r   r   lhsZrel_oprhs)r   r   gtltcharmaprS   rS   rV   _print_Relational}  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   rp   r   rS   rV   r     s   z1LatexPrinter._print_Piecewise.<locals>.<listcomp>r   z%s & \text{otherwise}rd  z\begin{cases} %s \end{cases}z \\)r   Zcondr   rs  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 u r| jd dkrdd}n|jdkd	u rxd
}nd}d}|d|}|dkr|ddd|j  d }|d| S )Nr  c                   s   g | ]}  |qS rS   r   rX  r   rS   rV   r     rX   z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>r   r   r   smallmatrix
   Tmatrixarray \begin{%MATSTR%}%s\end{%MATSTR%}%MATSTR%r  rZ   rp   }%sr`  )r	  rowsrs  r   r   colsro   )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)rr  r   r   )r   r   rq  
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   rv   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 ur  |ndV  qd S )Nr   r   )r   xir   rS   rV   r     rX   zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>)r1  r   )r   r  r   rS   rV   
latexslice  s    z3LatexPrinter._print_MatrixSlice.<locals>.latexslicer  Trx  \left[r   \right])r   ry  r    Zrowslicerm  Zcolslicern  )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|v r`d| S d| S d S )Nr   MatrixSymbolBlockMatrixz\left(%s\right)^{T}Trn   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
|v rd||f S d||f S d S )Nz\daggerz\astz
\mathsf{H})ry   ZstarZ	hermitianr   r   r  r   Trn   rL  )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   r9  r   )Zsympyr  r1  r   r   r   ry  )r   r   parensr   rS   r  rV   _print_MatMul  s    
zLatexPrinter._print_MatMulc                 C  s0   t |}|j\}}| || d| || S )Nr   )r   r   r   )r   r   r   leftrightrS   rS   rV   _print_DotProduct  s    
zLatexPrinter._print_DotProductc                 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-  rr  r  r   )r   r   r  r  rS   rS   rV   _print_Determinant  s    
zLatexPrinter._print_Determinantc                 C  sz   |d u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	   Trx  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 Trx  NrS   r  r  precrS   rV   r   ,  rX   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    rO  )r   r   rQ  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   ;  rX   z7LatexPrinter._print_KroneckerProduct.<locals>.<genexpr>r  r  rS   r  rV   _print_KroneckerProduct5  s    z$LatexPrinter._print_KroneckerProductc                 C  s|   |j |j }}ddlm} t||sB|jrBd| || |f S | |}d|v rfd|| |f S d|| |f S d S )Nr   )r  r   rn   rL  )r   r   r  r  r-  r  r   )r   r   r   r   r  Zbase_strrS   rS   rV   _print_MatPow=  s    

zLatexPrinter._print_MatPowc                 C  s   | j || jd dS )Nr   rS  )rU  r   r   rS   rS   rV   _print_MatrixSymbolJ  s    
z LatexPrinter._print_MatrixSymbolc                 C  s   | j d dkrdS dS )Nr   ru   0z
\mathbf{0}r   )r   ZrS   rS   rV   _print_ZeroMatrixN  s    zLatexPrinter._print_ZeroMatrixc                 C  s   | j d dkrdS dS )Nr   ru   1z
\mathbf{1}r  )r   OrS   rS   rV   _print_OneMatrixR  s    zLatexPrinter._print_OneMatrixc                 C  s   | j d dkrdS dS )Nr   ru   z
\mathbb{I}z
\mathbf{I}r  )r   r  rS   rS   rV   _print_IdentityV  s    zLatexPrinter._print_Identityc                 C  s   |  |jd }d| S )Nr   zP_{%s}rV  )r   PZperm_strrS   rS   rV   _print_PermutationMatrixZ  s    z%LatexPrinter._print_PermutationMatrixr%   c              
   C  s(  |  dkr| |d S | jd }|d u 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   rf  r   rg  rh  ri  rj  rk  r  rZ   rp   rl  r   rs  rt  r   c                 S  s   g | ]}g qS rS   rS   rX  rS   rS   rV   r   z  rX   z1LatexPrinter._print_NDimArray.<locals>.<listcomp>r   c                 S  s   g | ]}t t|qS rS   )r1  r	  rX  rS   rS   rV   r   {  rX   Tr  r`  r~  r  r<  )rankr   r   shapero   r   r	  	itertoolsproductrs  r
  r   )r   r   r   Z	block_strru  rv  Z	level_strZshape_rangesZouter_iZevenZback_outer_irq  rS   rS   rV   _print_NDimArray^  sd    





zLatexPrinter._print_NDimArraydict)	index_mapc           	      C  s   |  |}d }d }|D ]}|j}||v s,|r<||kr<|d7 }||krl|d urT|d7 }|jrd|d7 }n|d7 }||  |jd 7 }||v r|d7 }||  || 7 }d}nd}|}q|d ur|d7 }|S )	Nr   rR   z{}^{z{}_{r   r  TF)r   is_upr   )	r   r   rz  r  rq  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 rU  )r   get_indicesr  )r   r   r   rz  rS   rS   rV   _print_Tensor  s    zLatexPrinter._print_Tensorc                 C  s0   |j jd jd }|j  }|j}| |||S rU  )r   r   r  r  r  )r   r   r   rz  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     rX   z/LatexPrinter._print_TensMul.<locals>.<listcomp>)Z!_get_args_for_traditional_printerr   )r   r   rM  r   rS   r  rV   _print_TensMul  s    zLatexPrinter._print_TensMulc                 C  sL   g }|j }|D ]}|| |t| q|  d|}|dd}|S )Nr   z+ -r9  )r   rs  r   r   rr  r   ro   )r   r   rB  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}rn   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   rX  r   rS   rV   r     rX   z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>)r
  rP  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   rX  r   rS   rV   r     rX   z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>)r   r   r    r   rz  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 u 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}rV  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  ;rw   r   Unknown Decimal Separatorr   r   z \  c                   s   g | ]}  |qS rS   r   rX  r   rS   rV   r     rX   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   rB  r   rS   rV   r     rX   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     rX   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   rX  r   rS   rV   r     rX   z,LatexPrinter._print_list.<locals>.<listcomp>rw   , \  c                   s   g | ]}  |qS rS   r   rX  r   rS   rV   r     rX   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 )Nrl  z%s : %sz\left\{ %s\right\}r  )r  keysr   rs  r   r   )r   rx   r  rp  rm  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 urLd|||f }|S )Nr   r   r<  z${\left\langle %s \right\rangle}^{%s}z-{\left({\langle %s \rangle}^{%s}\right)}^{%s}rV  )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   7  rX   z0LatexPrinter._print_Heaviside.<locals>.<genexpr>z\theta\left(%s\right)r   )r   pargs)r   r   r   r  r   rS   r   rV   _print_Heaviside6  s
    zLatexPrinter._print_Heavisidec                 C  sj   |  |jd }|  |jd }|jd jrF|jd jrFd||f }nd||f }|d urfd||f }|S )Nr   r   z\delta_{%s %s}z\delta_{%s, %s}r   )r   r   r   )r   r   r   rv   r   r   rS   rS   rV   _print_KroneckerDelta=  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   J  rX   z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}r   r   r   )ry  r   r   r  r   )r   r   r   rz  r   rS   rS   rV   _print_LeviCivitaH  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   rx   rS   rS   rV   _print_RandomDomainR  s    



z LatexPrinter._print_RandomDomainc                 C  s   t |jtd}| |S )Nrl  )r  r   r   
_print_setr   rU   rp  rS   rS   rV   _print_FiniteSet]  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 )	Nrl  r   r  rO  rw   r   r  \left\{%s\right\})r  r   r   r   ry  r   r   r  rS   rS   rV   r  a  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 u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   u  rX   zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   x  rX   c                 3  s   | ]}  |V  qd S r   r   r  r   rS   rV   r   z  rX   z\text{Range}\left(r   )r   r   r   )Zcont)rU   r   rS   rV   _print_symbolic_rangeo  s    $z8LatexPrinter._print_Range.<locals>._print_symbolic_ranger   r   r   r  Tz\left\{r   c                 3  s$   | ]}| ur |nd V  qdS z\ldotsNr   r   eldotsr   rS   rV   r     rX   z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})objectstartis_infinitestopstepZis_positiveiternextZis_emptyr  r\  is_iterabler   )r   rU   r  printsetitrS   )r  rU   r   rV   _print_Rangen  s0    

zLatexPrinter._print_Rangec                 C  s   t |jdkrd|d ur>d|| |jd || |jd f S d|| |jd | |jd f S d|| |jd f }|d urd||f }|S )Nr<  z%s_{%s}^{%s}\left(%s\right)r   r   r  z%s_{%s}rL  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 urld
|||f }n|| }|S  |d|S )Nro  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 ur(d||f }|S )NzL_{%s}r   rL  rV  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 u rd|  |jd  S d||  |jd f S )Nz\mu\left(%s\right)r   z\mu^{%s}\left(%s\right)rV  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	u r|j} |
|d |
|d |
|d |
|f}n6|jtju 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}ro  r<  r   r  r~  r   c                 3  s$   | ]}| ur |nd V  qdS r  r   r  r  rS   rV   r     rX   z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>r  )r  r
  r  Zfree_symbolsr  r   formularP  r   r  coeffr  lengthrs  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   rt   r   r   z\left%s%s, %s\right%s)r  endr   Z	left_openZ
right_open)r   rv   r  r  rS   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   rv   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   rX  r  r   rS   rV   r     rX   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  rX  r  rS   rV   r   	  rX   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  rX  r  rS   rV   r   	  rX   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  rX  r  rS   rV   r   	  rX   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   rH  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   .	  rX   z/LatexPrinter._print_ImageSet.<locals>.<genexpr>r   c                 s  s   | ]}d | V  qdS )	%s \in %sNrS   )r   ZxyrS   rS   rV   r   /	  rX   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u r>d| |jf S d|| |j |jf S )Nr   c                   s   g | ]}  |qS rS   r   r   r  r   rS   rV   r   3	  rX   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_ConditionSet2	  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_PowerSet>	  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   C	  rX   z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z)\left\{%s\; \middle|\; %s \in %s \right\})r   rP  r   r   r  r&  rS   r   rV   _print_ComplexRegionB	  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   J	  rX   z/LatexPrinter._print_Contains.<locals>.<genexpr>)r\  r   r   rS   r   rV   _print_ContainsI	  s    zLatexPrinter._print_Containsc                 C  s:   |j jtju r(|jjtju r(| |jS | | d S )Nz	 + \ldots)	r(  r  r   r  Zbnr   Za0r   truncater   rS   rS   rV   _print_FourierSeriesL	  s    z!LatexPrinter._print_FourierSeriesc                 C  s   |  |jS r   )r   Zinfiniter   rS   rS   rV   _print_FormalPowerSeriesQ	  s    z%LatexPrinter._print_FormalPowerSeriesc                 C  s
   d|j  S )Nz\mathbb{F}_{%s})modr   rS   rS   rV   _print_FiniteFieldT	  s    zLatexPrinter._print_FiniteFieldc                 C  s   dS r  rS   r   rS   rS   rV   _print_IntegerRingW	  s    zLatexPrinter._print_IntegerRingc                 C  s   dS r  rS   r   rS   rS   rV   _print_RationalFieldZ	  s    z!LatexPrinter._print_RationalFieldc                 C  s   dS r  rS   r   rS   rS   rV   _print_RealField]	  s    zLatexPrinter._print_RealFieldc                 C  s   dS r  rS   r   rS   rS   rV   _print_ComplexField`	  s    z LatexPrinter._print_ComplexFieldc                 C  s,   |  |j}dt| j |j}d||f S )Nr   z%s\left[%s\right]r   domainr   ry  r  r   r   r6  r  rS   rS   rV   _print_PolynomialRingc	  s    z"LatexPrinter._print_PolynomialRingc                 C  s,   |  |j}dt| j |j}d||f S )Nr   r  r5  r7  rS   rS   rV   _print_FractionFieldh	  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   r6  r   ry  r  Zis_Poly)r   r   r6  r  invrS   rS   rV   _print_PolynomialRingBasem	  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	u r|
d|g q|tju r|
d|g q| |}	|s|	}
n|	d | }
|
dr|
d|
dd  g q|
d|
g q|d dv rX|d}|dkrXd|d  |d< d|}tt| j|j}d	| |  }d
|g| |g }|tv rd||f }nd||f }|S )Nr   r   r   r   r  rn  r   )rn  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   rS  popr   r1  ry  Z
get_domainr  )r   polyr  r   Zmonomr   Zs_monomrv   r   Zs_coeffZs_termmodifierr   r<  r6  r   r   rS   rS   rV   _print_Polyu	  sN    






zLatexPrinter._print_Polyc                 C  sN   |j j}|dkrd}| |j}|j}|tv 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ur4|| |j |tv 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IdentityFunctionrs  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^{{{}}}rE  )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   	  rX   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   rj   r    )r   r@  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=  )rA  r   r@  )r   r2   r@  rA  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 urHd||f }|d urbd|| |f }|S )Nr   r   zE_{%s}rL  r  r  )r   r   r   r>  r   r   rS   rS   rV   _print_euler	  s    &zLatexPrinter._print_eulerc                 C  s,   d|  |jd  }|d ur(d||f }|S )NzC_{%s}r   rL  rV  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rO  r   rS   rS   rV   _print_MellinTransform	  s    z#LatexPrinter._print_MellinTransformc                 C  s   |  |ddS )NrP  TrQ  r   rS   rS   rV   _print_InverseMellinTransform	  s    z*LatexPrinter._print_InverseMellinTransformc                 C  s   |  |dS )NLrQ  r   rS   rS   rV   _print_LaplaceTransform	  s    z$LatexPrinter._print_LaplaceTransformc                 C  s   |  |ddS )NrT  TrQ  r   rS   rS   rV   _print_InverseLaplaceTransform
  s    z+LatexPrinter._print_InverseLaplaceTransformc                 C  s   |  |dS r  rQ  r   rS   rS   rV   _print_FourierTransform
  s    z$LatexPrinter._print_FourierTransformc                 C  s   |  |ddS )Nr  TrQ  r   rS   rS   rV   _print_InverseFourierTransform
  s    z+LatexPrinter._print_InverseFourierTransformc                 C  s   |  |dS )NSINrQ  r   rS   rS   rV   _print_SineTransform

  s    z!LatexPrinter._print_SineTransformc                 C  s   |  |ddS )NrY  TrQ  r   rS   rS   rV   _print_InverseSineTransform
  s    z(LatexPrinter._print_InverseSineTransformc                 C  s   |  |dS )NCOSrQ  r   rS   rS   rV   _print_CosineTransform
  s    z#LatexPrinter._print_CosineTransformc                 C  s   |  |ddS )Nr\  TrQ  r   rS   rS   rV   _print_InverseCosineTransform
  s    z*LatexPrinter._print_InverseCosineTransformc                 C  sD   z"|j d ur | |j |W S W n ty4   Y n0 | t|S r   )ringr   to_sympyr   reprr  rS   rS   rV   
_print_DMP
  s    
zLatexPrinter._print_DMPc                 C  s
   |  |S r   )rb  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 u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   rN  r   rS   rS   rV   _print_Expectation/
  s    zLatexPrinter._print_Expectationc                 C  s   d | |jd S )Nz#\operatorname{{Var}}\left({}\right)r   rN  r   rS   rS   rV   _print_Variance2
  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   6
  rX   z1LatexPrinter._print_Covariance.<locals>.<genexpr>)r   r   r   r   rS   r   rV   _print_Covariance5
  s    zLatexPrinter._print_Covariancec                 C  s   d | |jd S )Nz!\operatorname{{P}}\left({}\right)r   rN  r   rS   rS   rV   _print_Probability8
  s    zLatexPrinter._print_Probabilityc                 C  s$   |  |j}|  |j}d||f S )Nz%s\rightarrow %s)r   r6  codomain)r   morphismr6  rl  rS   rS   rV   _print_Morphism;
  s    zLatexPrinter._print_Morphismc                 C  s&   |  |j|  |j }}d||f S )Nr=  )r   r  den)r   r   r  ro  rS   rS   rV   _print_TransferFunction@
  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   F
  s   z,LatexPrinter._print_Series.<locals>.<lambda>r   )r1  r   r   ry  r   r   r   r  rS   r  rV   _print_SeriesD
  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.  rs  r   r   rS   rV   rW   M
  s
    z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>z\cdot)Zsympy.physics.control.ltirs  r1  r   r   ry  rq  rS   rt  rV   _print_MIMOSeriesJ
  s    zLatexPrinter._print_MIMOSeriesc                 C  s   d t| j|jS Nr   r   ry  r   r   r   rS   rS   rV   _print_ParallelQ
  s    zLatexPrinter._print_Parallelc                 C  s   d t| j|jS rv  rw  r   rS   rS   rV   _print_MIMOParallelT
  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|g ||R  }	nt||rt|j|r|j|kr|| }	n||g ||jR  f}	n|t||rt|j|r||kr || }	n||g|R  }	n<||kr&|| }	n(|j|kr<|| }	n|g ||R  }	| 	|}
| 	|}| 	|	}|j
dkr|dnd}d|
|||f S )Nr   )TransferFunctionSeriesr   r   r  rn  z\frac{%s}{%s %s %s})sympy.physics.controlrz  r{  sys1r  r-  r1  r   sys2r   rM  )r   r   rz  r{  r  tfZnum_arg_listZden_arg_listZ
den_term_1Z
den_term_2r@  Zdenom_1Zdenom_2_signrS   rS   rV   _print_FeedbackW
  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  rn  z)\left(I_{\tau} %s %s\right)^{-1} \cdot %s)r|  r  r   r~  r}  rM  )r   r   r  Zinv_matr}  r  rS   rS   rV   _print_MIMOFeedback{
  s
    z LatexPrinter._print_MIMOFeedbackc                 C  s   |  |j}d| S )Nz%s_\tau)r   Z	_expr_matr  rS   rS   rV   _print_TransferFunctionMatrix
  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   rn  )r   rm  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  r6  rl  )r   rm  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   rd  )r   	componentr   rS   rV   r   
  s   z9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z\circ r{  )rq  reverser   rn  )r   rm  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   rm  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}
rp   r   r   & r`  
z\end{array}
)widthr	  heightlatex)r   Zgridr  rv   r   rS   rS   rV   _print_DiagramGrid
  s    

zLatexPrinter._print_DiagramGridc                 C  s   d | |j| |jS )Nz{{{}}}^{{{}}})r   r   r_  r  r   rP  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   r>  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   r_  r`  r   r>  r   rS   rV   r   
  rX   z<LatexPrinter._print_SubModule.<locals>.<listcomp>.<listcomp>rS   r   gr  rS   rV   r   
  rX   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   
  rX   z:LatexPrinter._print_SubModule.<locals>.<genexpr>.<genexpr>N)r   r  )r  squarerS   rV   r   
  rX   z0LatexPrinter._print_SubModule.<locals>.<genexpr>\left\langle {} \right\rangle)r<  r   r   r   r>  r<  
gens_latexrS   )r  r>  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   
  rX   z9LatexPrinter._print_SubQuotientModule.<locals>.<listcomp>r  )r   r<  r   )r   r>  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   )r_  r`  r   r>  rS   rV   r   
  rX   z>LatexPrinter._print_ModuleImplementedIdeal.<locals>.<listcomp>r   c                 3  s    | ]}d   | d V  qdS r  r   r   r   rS   rV   r   
  rX   z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>r  )_moduler<  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	   Trx  )r   r    rX  r   rS   rV   r   
  s   z2LatexPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]\}}|d  | qS )r   rS   )r   rv   r   rS   rS   rV   r   
  rX   r   Zijkr   )r   r  r   )r   r   rU   rB  rS   r   rV   _print_Quaternion
  s
    
&zLatexPrinter._print_Quaternionc                 C  s   d | |j| |jS Nz\frac{{{}}}{{{}}})r   r   r_  
base_ideal)r   RrS   rS   rV   _print_QuotientRing
  s    
z LatexPrinter._print_QuotientRingc                 C  s(   |  |j|}d||  |jjS )N{{{}}} + {{{}}})r   r_  r`  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   )moduler_  r`  r   r  rS   rV   r   
  rX   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   r>  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_matrixr6  rl  )r   r  rS   rS   rV   _print_MatrixHomomorphism
  s    z&LatexPrinter._print_MatrixHomomorphismc                 C  sL   |  |jj\}}}d| }|r2|dd| 7 }|rH|dd| 7 }|S )Nr   r  r   rx  )rY  r   r   )r   manifoldr   rX  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   fieldrZ  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  rZ  rS   rS   rV   _print_Differential  s    

z LatexPrinter._print_Differentialc                 C  s   |  |jd }d|S )Nr   z"\operatorname{{tr}}\left({}\right)r(  )r   rH  contentsrS   rS   rV   	_print_Tr!  s    zLatexPrinter._print_Trc                 C  s4   |d ur d|  |jd |f S d|  |jd  S )Nz%\left(\phi\left(%s\right)\right)^{%s}r   z\phi\left(%s\right)rV  r   rS   rS   rV   _print_totient&  s
    zLatexPrinter._print_totientc                 C  s4   |d ur d|  |jd |f S d|  |jd  S )Nz(\left(\lambda\left(%s\right)\right)^{%s}r   z\lambda\left(%s\right)rV  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 u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_sigma2  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 ur\d||f S d| S )Nr<  r  r   r   r   z\sigma^*^{%s}%sz
\sigma^*%sr+  r  rS   rS   rV   _print_udivisor_sigma<  s    

z"LatexPrinter._print_udivisor_sigmac                 C  s4   |d ur d|  |jd |f S d|  |jd  S )Nz$\left(\nu\left(%s\right)\right)^{%s}r   z\nu\left(%s\right)rV  r   rS   rS   rV   _print_primenuF  s
    zLatexPrinter._print_primenuc                 C  s4   |d ur d|  |jd |f S d|  |jd  S )Nz'\left(\Omega\left(%s\right)\right)^{%s}r   z\Omega\left(%s\right)rV  r   rS   rS   rV   _print_primeomegaL  s
    zLatexPrinter._print_primeomegac                 C  s
   t |jS r   )rj   r   r   rS   rS   rV   
_print_StrR  s    zLatexPrinter._print_Strc                 C  s   |  t|S r   )r   r   r   rS   rS   rV   _print_floatU  s    zLatexPrinter._print_floatc                 C  s   t |S r   rj   r   rS   rS   rV   
_print_intX  s    zLatexPrinter._print_intc                 C  s   t |S r   r  r   rS   rS   rV   
_print_mpz[  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_fmpza  s    zLatexPrinter._print_fmpzc                 C  s   t |S r   r  r   rS   rS   rV   _print_fmpqd  s    zLatexPrinter._print_fmpqc                 C  s   d tt|jS )Nz"\operatorname{{Q}}_{{\text{{{}}}}})r   rq   rj   r   r   rS   rS   rV   _print_Predicateg  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   n  rX   z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>z%s(%s))re  	argumentsr   r   )r   r   predr   Z
pred_latexZ
args_latexrS   r   rV   _print_AppliedPredicatej  s
    
z$LatexPrinter._print_AppliedPredicatec                   s   t  |}dt| S )Nz\mathtt{\text{%s}})superemptyPrinterrq   rQ  r   rS   rV   r  q  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)ru   )ru   )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(C  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&  rD  rF  rJ  rP  rO  rW  rh  ri  rw  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*  r,  r-  r.  r0  r2  r4  r6  r7  r8  r9  r:  r;  r<  rA  rB  rG  rH  rI  rK  rL  rN  rR  rU  Z_print_RandomSymbolrY  r   rc  re  rr  rw  rz  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)  r*  r+  r-  r.  r0  r1  r2  r3  r4  r8  r9  r;  rB  rC  rD  rF  rH  rI  rJ  rK  rL  rM  rO  rR  rS  rU  rV  rW  rX  rZ  r[  r]  r^  rb  rc  re  rg  rh  ri  rj  rk  rn  rp  rr  ru  rx  ry  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   rr      s  
=

	!s-!
$ L

										
7



*9		
$	

rr   c                 C  s   t | }|r|S |  tv r*d|   S | tv 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}}}'"
    rl   T)rm  r  N)tex_greek_dictionaryr   r  greek_letters_setother_symbolsr  ri   r  r
  rT  rW  )rU   r   rm  rS   rS   rV   rW  x  s    
$rW  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.

    )rr   r   r   r   rS   rS   rV   r    s     Xr  c                 K  s   t t| fi | dS )z`Prints LaTeX representation of the given expression. Takes the same
    settings as ``latex()``.N)printr  r  rS   rS   rV   print_latexq  s    r  r   align*Fc              
   K  s  t f i |}|dkr,d}d}d}	d}
d}nJ|dkrJd}d}d}	d	}
d}n,|d
krhd}d}d}	d}
d}ntd|d}|rd}| }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rT|dkr0d}|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  r`  r  r   r   rn  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s})rr   r   r   Zas_ordered_termsr
  r	  r0  r   )r^  r_  Zterms_per_lineenvironmentZuse_dotsr   r^  rf  Z
first_termZnonumberZend_termZdoubleetr  r   Zn_termsZ
term_countrv   r   Z
term_startZterm_endrM  rS   rS   rV   multiline_latexx  sn    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  ri   r  	frozensetr  compiler5  rq   rr   rW  r  r  r  rS   rS   rS   rV   <module>   s   ('                       
 Z