a
    RG5d                 %   @  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( ddl)m*Z*m+Z+ ddl,m-Z-m.Z. ddl'm/Z/m0Z0 ddl1m2Z2m3Z4 ddl5m6Z6m7Z7 ddl8Z8erHd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ZAe8BdWe8BdX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)	NDimArray)precedence_traditional)Printerprint_function)split_super_subrequires_partial)
precedence
PRECEDENCE)prec_to_dpsto_str)has_varietysift)BasisDependent)arcsinarccosarctansincostansinhcoshtanhsqrtlnlogseccsccotcothre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varrhovarsigmaZvartheta>
   ZhslashwpZhbarethZalephZdalethZmhoZbethellZgimelc                 C  s   d|  d S )Nz
\mathring{} sr]   r]   P/var/www/html/django/DPS/env/lib/python3.9/site-packages/sympy/printing/latex.py<lambda>Z       ra   c                 C  s   d|  d S )Nz\ddddot{r\   r]   r^   r]   r]   r`   ra   [   rb   c                 C  s   d|  d S )Nz\dddot{r\   r]   r^   r]   r]   r`   ra   \   rb   c                 C  s   d|  d S )Nz\ddot{r\   r]   r^   r]   r]   r`   ra   ]   rb   c                 C  s   d|  d S )Nz\dot{r\   r]   r^   r]   r]   r`   ra   ^   rb   c                 C  s   d|  d S )Nz\check{r\   r]   r^   r]   r]   r`   ra   _   rb   c                 C  s   d|  d S )Nz\breve{r\   r]   r^   r]   r]   r`   ra   `   rb   c                 C  s   d|  d S )Nz\acute{r\   r]   r^   r]   r]   r`   ra   a   rb   c                 C  s   d|  d S )Nz\grave{r\   r]   r^   r]   r]   r`   ra   b   rb   c                 C  s   d|  d S )Nz\tilde{r\   r]   r^   r]   r]   r`   ra   c   rb   c                 C  s   d|  d S )Nz\hat{r\   r]   r^   r]   r]   r`   ra   d   rb   c                 C  s   d|  d S )Nz\bar{r\   r]   r^   r]   r]   r`   ra   e   rb   c                 C  s   d|  d S )Nz\vec{r\   r]   r^   r]   r]   r`   ra   f   rb   c                 C  s   d|  d S N{z}'r]   r^   r]   r]   r`   ra   g   rb   c                 C  s   d|  d S rc   r]   r^   r]   r]   r`   ra   h   rb   c                 C  s   d|  d S Nz\boldsymbol{r\   r]   r^   r]   r]   r`   ra   j   rb   c                 C  s   d|  d S re   r]   r^   r]   r]   r`   ra   k   rb   c                 C  s   d|  d S )Nz	\mathcal{r\   r]   r^   r]   r]   r`   ra   l   rb   c                 C  s   d|  d S )Nz	\mathscr{r\   r]   r^   r]   r]   r`   ra   m   rb   c                 C  s   d|  d S )Nz
\mathfrak{r\   r]   r^   r]   r]   r`   ra   n   rb   c                 C  s   d|  d S )Nz\left\|{z	}\right\|r]   r^   r]   r]   r`   ra   p   rb   c                 C  s   d|  d S )Nz\left\langle{z}\right\rangler]   r^   r]   r]   r`   ra   q   rb   c                 C  s   d|  d S Nz\left|{z}\right|r]   r^   r]   r]   r`   ra   r   rb   c                 C  s   d|  d S rf   r]   r^   r]   r]   r`   ra   s   rb   )mathringddddotdddotddotdotcheckbreveacutegravetildehatbarvecprimeprmboldbmcalZscrZfraknormavgabsmagzdict[str, Callable[[str], str]]modifier_dictz[0-9][} ]*$z[0-9]str)r_   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)r_   cr]   r]   r`   latex_escape~   s    r   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Zded< duddZddddZddddZdvddddZ	dd Z
ddddZddddZdddd Zdwd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.d/d0d1ZeZeZd2d3 Zdxd4d5Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdDdE Z dFdG Z!dHdI Z"dJd)dKdLZ#dMdN Z$dOdP Z%dQd)dRdSZ&dddTdUdVZ'dWdX Z(dYdZ Z)d[d\ Z*d]d)d^d_Z+d`da Z,dbdc Z-ddde Z.dfdg Z/dhdi Z0djdk Z1dldm Z2dddndodpZ3dydqddrdsdtZ4dudv Z5dwdx Z6e7dydz Z8d{d| Z9d}d~ Z:dd Z;dzddddZ<e< Z=Z>d{ddZ?d|ddZ@d}ddZAd~ddZBddd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{dddZ|dd dZ}dddZ~dddZdddZddd	Zdd
dZdddZdddZdddZdddZdddZdddZdddZdddZdddZdddZdd d!Zd"d# Zd$d% Zdd&d)d'd(ZeZdddd)d*d+Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZdBdC ZdĐ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dXd)dYdZZd[d\d]d^Zd_d` Zdadb Zdcdd Zdedf Zdgdh Zdidj Zdkdl Zdmdn Zdodp ZdŐdqdrZdsdt Zdudv Zdwdx Zdydz 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 ZeZeZeZϐdd ZАdd Zѐdd ZҐdd ZӐdd ZԐdd ZՐdd Z֐dd Zאdd Zؐdd Zِdd Zڐdd Zېdd Zܐdd Zݐdd Zސdd Zߐdd ZdÐdĄ ZdŐdƄ ZdǐdȄ Zdɐdʄ Zdːd̄ Zd͐d΄ ZdϐdЄ Zdѐd҄ ZdӐdԄ ZdՐdք Zdאd؄ Zdِdڄ Zdېd܄ Zdݐdބ Zdߐd Zdd Zdd Zdd Zdd Zdd ZdѐddZdҐddZdӐddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zdd Z dd Zdd Zdd Zd	d
 ZdԐddZdd Zdd Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( ZeZd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Zd?d@ Z dAdB Z!dCdD Z"dEdF Z#dGdH Z$dIdJ Z%dKdL Z&dMdN Z'dOdP Z(dQdR Z)dSdT Z*dUdV Z+dWdX Z,dՐdYdZZ-d֐d[d\Z.dאd]d^Z/dؐd_d`Z0dِdadbZ1dڐdcddZ2dedf Z3dgdh Z4didj Z5dkdl Z6dmdn Z7dodp Z8dqdr Z9 fdsdtZ:  Z;S (  LatexPrinter_latexFNabbreviated[plainTiperiodd)	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_operatorz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   )inliner   Zequationz	equation*zB'mode' must be one of 'inline', 'plain', 'equation' or 'equation*'r   r   T z \,.\, z \cdot  \times )NZldotrk   timesr   mul_symbol_latexrk   mul_symbol_latex_numbers) r   r   z\,z\:\;z\quad)])(r   r   z
\mathrm{i}z\text{i}jz
\mathrm{j}z\text{j})Nr   ritir   rjtjr   imaginary_unit_latexr   z
\mathrm{d}z\text{d})Nr   rdtdr   diff_operator_latex)r   __init__	_settings
ValueErrorKeyErrorstrip_delim_dictget)selfsettingsZvalid_modesZmul_symbol_tableZimaginary_unit_table	imag_unitZdiff_operator_tabler   r]   r]   r`   r      sb    


	

zLatexPrinter.__init__r~   r   c                 C  s
   d |S )Nz\left({}\right)formatr   r_   r]   r]   r`   _add_parens   s    zLatexPrinter._add_parensc                 C  s
   d |S )Nz\left( {}\right)r   r   r]   r]   r`   _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_valr]   r]   r`   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.
        r   r   z{{{}}})r   r   r   r   r]   r]   r`   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   r   r   z$%s$r   z$$%s$$z\begin{%s}%s\end{%s})r   doprintr   )r   exprtexZenv_strr]   r]   r`   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)
is_Integeris_nonnegativeis_Atomr   NegativeOneis_Rationalr   r   r]   r]   r`   _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_cleanis_Pow_pow_is_cleanis_Addis_Functionr   r]   r]   r`   _needs_function_brackets  s    
z%LatexPrinter._needs_function_bracketsc                   s   ddl m} ddlm} ddlm}  jr<|sZ  rZdS nt t	d k rPdS  j
rZdS  jrddS t fddtfD rdS |st fd	d|||fD rdS d
S )a  
        Returns True if the expression needs to be wrapped in brackets when
        printed as part of a Mul, False otherwise. This is True for Add,
        but also for some container objects that would not need brackets
        when appearing last in a Mul, e.g. an Integral. ``last=True``
        specifies that this expr is the last to appear in a Mul.
        ``first=True`` specifies that this expr is the first to appear in
        a Mul.
        r   )Product)Sum)IntegralTr	   c                 3  s   | ]}  |V  qd S r   has.0xr   r]   r`   	<genexpr>L  rb   z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r   r   r]   r`   r   O  rb   F)sympy.concrete.productsr   sympy.concrete.summationsr   sympy.integrals.integralsr   r   could_extract_minus_signr   r!   is_Relationalis_Piecewiseanyr   )r   r   firstlastr   r   r   r]   r   r`   _needs_mul_brackets5  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   r]   r`   r   \  rb   z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>F)r   r   r   r   r   r]   r   r`   _needs_add_bracketsT  s    z LatexPrinter._needs_add_bracketsc                 C  s   |j D ]}|jr dS qdS )NFT)argsr   )r   r   r;   r]   r]   r`   r   b  s    
zLatexPrinter._mul_is_cleanc                 C  s   |  |j S r   )r   baser   r]   r]   r`   r   h  s    zLatexPrinter._pow_is_cleanr   c                 C  s   |d urd||f S |S d S )N\left(%s\right)^{%s}r]   r   r   expr]   r]   r`   _do_exponentk  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 r]   r   )r   r=   r   r]   r`   
<listcomp>t  rb   z-LatexPrinter._print_Basic.<locals>.<listcomp>z"\operatorname{{{}}}\left({}\right), z\text{{{}}})_deal_with_super_sub	__class____name__r   r   join)r   r   namelsr_   r]   r   r`   _print_Basicq  s    zLatexPrinter._print_Basicz!bool | BooleanTrue | BooleanFalse)ec                 C  s   d| S N	\text{%s}r]   r   r
  r]   r]   r`   _print_boolz  s    zLatexPrinter._print_boolc                 C  s   d| S r  r]   r  r]   r]   r`   _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))_as_ordered_terms	enumerater   r   r   )r   r   r   termsr   r   termterm_texr]   r]   r`   
_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   r   z\left( r   \right)) sympy.combinatorics.permutationsr  sizecyclic_form
array_formr~   r   )r   r   r  Z	expr_permsizr  r   r]   r]   r`   _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   )deprecated_since_versionactive_deprecations_target
stacklevelr   Tr  c                   s   g | ]}  |qS r]   r   r   r;   r   r]   r`   r    rb   z3LatexPrinter._print_Permutation.<locals>.<listcomp>c                   s   g | ]}  |qS r]   r   r+  r   r]   r`   r    rb    & z \\ z \begin{pmatrix} %s \end{pmatrix})r   r  sympy.utilities.exceptionsr&  print_cyclicr   r   r%  r!  r#  rangelenr  )
r   r   r  r&  r   lowerupperZrow1row2matr]   r   r`   _print_Permutation  s.    




zLatexPrinter._print_Permutationc                 C  s"   |j \}}d| || |f S )Nz\sigma_{%s}(%s))r   r   )r   r   permvarr]   r]   r`   _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 )Nr   FTr   r   )strip_zeros	min_fixed	max_fixedr   r
  r   +r  r   comma.z{,}z%s%s10^{%s}z+infz\inftyz-infz- \infty)r"   _precr   mlib_to_str_mpf_splitr   )
r   r   dpsr   lowhighZstr_real	separatormantr   r]   r]   r`   _print_Float  s(    

zLatexPrinter._print_Floatc                 C  s0   |j }|j}d| |td | |td f S )Nz%s \times %sr	   _expr1_expr2r   r!   r   r   vec1vec2r]   r]   r`   _print_Cross  s
    zLatexPrinter._print_Crossc                 C  s   |j }d| |td  S )Nz\nabla\times %sr	   _exprr   r!   r   r   rs   r]   r]   r`   _print_Curl  s    zLatexPrinter._print_Curlc                 C  s   |j }d| |td  S )Nz\nabla\cdot %sr	   rP  rR  r]   r]   r`   _print_Divergence  s    zLatexPrinter._print_Divergencec                 C  s0   |j }|j}d| |td | |td f S )Nz%s \cdot %sr	   rI  rL  r]   r]   r`   
_print_Dot  s
    zLatexPrinter._print_Dotc                 C  s   |j }d| |td  S )Nz	\nabla %sr	   rP  r   r   funcr]   r]   r`   _print_Gradient  s    zLatexPrinter._print_Gradientc                 C  s   |j }d| |td  S )Nz	\Delta %sr	   rP  rV  r]   r]   r`   _print_Laplacian  s    zLatexPrinter._print_Laplacianr   c                   s  ddl m ddlm  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 rtdddd|j	vr|||7 }n||}	||}
t|
 }jd }jd r|dkrd|
vr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sFt|||  || ksF|j|j  u rBdu rPn n
||9 }n||9 }qj|ddr|d |||
||f 7 }n|d!|||
||f 7 }n|d"|
|	f 7 }n|d#|	|
f 7 }|r|d$7 }|S )%Nr   )QuantityPrefix)fractionr   r   r~   r   c                   s|   | j st| S jdvr(|  }n
t| j}t| fdddd\}}t| fdddd\}}|| | S d S )N)oldnonec                   s$   t |  fp"t | to"t | jS r   )
isinstancer   r   r   )r\  rZ  r]   r`   ra     s   
z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>T)binaryc                   s
   t |  S r   )r`  ra  r[  r]   r`   ra     rb   )r   r~   r   r   as_ordered_factorslistr   r%   )r   r   unitsZnonunitsprefixes)r\  rZ  convert_argsr   r]   r`   convert  s    



z(LatexPrinter._print_Mul.<locals>.convertc                   s   d }}t | D ]\}}|}t| fsj||dk|t| d kdrXd| }td |rtd t|r|7 }q|r|7 }n|r|7 }||7 }|}q|S )Nr   r   r  )r   r   r  )	r  r   r`  r   r0  _between_two_numbers_psearchmatchr~   )r   Z_texZlast_term_texr   r  r  )r\  rZ  	numbersepr   rF  r]   r`   rg    s&    


z-LatexPrinter._print_Mul.<locals>.convert_argsc                 s  s   | ]}t |tV  qd S r   )r`  r
   r+  r]   r]   r`   r   ;  rb   z*LatexPrinter._print_Mul.<locals>.<genexpr>r  F- r   Tr   )exactr  )evaluater   r      r   )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   )sympy.physics.unitsrZ  Zsympy.physics.units.prefixesr\  Zsympy.simplifyr]  r   r`  r	   r   r   Oner   r   r   r   r0  rB  r   r   is_commutative)r   r   r]  rh  r   Zinclude_parensr   numerdenomZsnumerZsdenomZldenomratioabr   r]   )r\  rZ  rg  rl  r   rF  r`   
_print_Mul  s    


("




zLatexPrinter._print_Mulc                 C  s*   |j r| |  S | | S d S r   )
is_aliasedr   as_polyas_exprr   r]   r]   r`   _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alphar}  )r   r   r  r  r]   r]   r`   _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   rp  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   r  qr{   r   r   r   is_negativer   r!   	is_Symbolr   r   rt  rz  _helper_print_standard_power)r   r   r  r  r   r   Zbase_pbase_qr]   r]   r`   
_print_Pow  sF    






zLatexPrinter._print_Pow)templater   c                 C  sv   |  |j}| |jtd }|jjr2| |}n8t|jtrj|	drjt
d|rj|drj|dd }|||f S )Nr   r  z\\left\(\\d?d?dotr     i)r   r   r   r   r!   r  r   r`  r   
startswithr7   rk  endswith)r   r   r  r   r   r]   r]   r`   r    s    
z)LatexPrinter._helper_print_standard_powerc                 C  s   |  |jd S Nr   r   r   r   r]   r]   r`   _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 r]   r   r   r   r   r]   r`   r    rb   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 r]   r   r   r_   r   r]   r`   r    rb   zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>r  r   rp  tuplelr   r]   r`   _format_ineq  s    &z-LatexPrinter._print_Sum.<locals>._format_ineqz\sum_{\substack{%s}} \\c                   s   g | ]} |qS r]   r]   r   r  r  r]   r`   r    rb   r  	r0  limitsr  r~   r  r`  functionr   r   r   r   r   r]   r  r   r`   
_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 r]   r   r  r   r]   r`   r    rb   z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                   s,   dt  fdd| d | d | d fD  S )Nr  c                   s   g | ]}  |qS r]   r   r  r   r]   r`   r    rb   zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>r  r   rp  r  r  r   r]   r`   r    s    &z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} r  c                   s   g | ]} |qS r]   r]   r  r  r]   r`   r    rb   r  r  r  r]   r  r`   _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 r  )__str__ra  r]   r]   r`   ra     rb   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>keyr  r  r  r  r  r  r   -   )sympy.vectorr  zeroZ_latex_formr`  separateitemsrd  
componentssortappendr   r  )r   r   r  o1r  systemvect
inneritemskvarg_strZoutstrr]   r]   r`   _print_BasisDependent  s,    



z"LatexPrinter._print_BasisDependentc                 C  s4   |  |j}d| d ddt| j |j  }|S )Nrd   r\   _{%s}r  )r   r   r  mapindices)r   r   Ztex_baser   r]   r]   r`   _print_Indexed  s
    zLatexPrinter._print_Indexedc                 C  s   |  |jS r   )r   labelr   r]   r]   r`   _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})r1  r2  z{{{label}}}_{{{interval}}})r  interval)r   r  r2  r1  r   Zeror   )r   r   r  r2  r1  r  r]   r]   r`   
_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}rq  z\frac{%s^{%s}}{%s}c                 s  s   | ]}|  V  qd S r   r   r  r]   r]   r`   r   9  rb   z1LatexPrinter._print_Derivative.<locals>.<genexpr>r	   Tr   r   F)r   r   r   reversedvariable_countr   r   r   r   r   r!   )r   r   diff_symbolr   dimr   numr]   r]   r`   _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   r]   r`   r   G  rb   z+LatexPrinter._print_Subs.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r  r   r]   r`   r   H  rb   z\\ c                 s  s"   | ]}|d  d |d  V  qdS )r   =r  Nr]   r  r]   r]   r`   r   I  s   z#\left. %s \right|_{\substack{ %s }})r   r   r  zip)	r   subsr   r^  newZ
latex_exprZ	latex_oldZ	latex_newZ
latex_subsr]   r   r`   _print_SubsD  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)r0  )r   limr]   r]   r`   r   S  rb   z/LatexPrinter._print_Integral.<locals>.<genexpr>z\ir   r  ntc                   s"   g | ]}d   |d f qS )\, %s%sr   r   r   symbolr  r   r]   r`   r  W  s   z0LatexPrinter._print_Integral.<locals>.<listcomp>r   z\intr   r   r   z\limitsr  z
_{%s}^{%s}rp  ^{%s}r  z%s %s%sr	   c                 s  s   | ]}|  V  qd S r   r  r  r]   r]   r`   r   n  rb   Tr  )r   r0  r  allr  r   insertr   r  r!   r   r   r  )r   r   r   symbolsr  r  r]   r  r`   _print_IntegralN  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   r~   r   InfinityNegativeInfinityr`  r   )r   r   r
  zz0dirr   r]   r]   r`   _print_Limitr  s    
zLatexPrinter._print_Limit)rW  r   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
        r   _z\%sr  r   r   z\operatorname{%s}%sNz\operatorname{%s})r  findaccepted_latex_functionsr0  r  r   )r   rW  ZsuperscriptidxZsubscriptidxr  r]   r]   r`   _hprint_Function  s0    



&



zLatexPrinter._hprint_Functionr   )r   r   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
        _print_c                   s   g | ]}t  |qS r]   )r~   r   r+  r   r]   r`   r    rb   z0LatexPrinter._print_Function.<locals>.<listcomp>r   Fr   r  r   )asinacosatanacscasecacotasinhacoshatanhacschasechacothr   fullr  harZarcNpowerTz\%s^{-1}z\operatorname{%s}^{-1}r  z {%s}%s{\left(%s \right)}r  r  )rW  r  hasattrr`  r   getattrr   r   r0  r   r  r  r   r  )r   r   r   rW  r   r   Zinv_trig_power_caseZcan_fold_bracketsZinv_trig_tabler  Zfunc_texr]   r   r`   _print_Function  sR    


"









zLatexPrinter._print_Functionc                 C  s   |  t|S r   )r  r~   r   r]   r]   r`   _print_UndefinedFunction  s    z%LatexPrinter._print_UndefinedFunctionc                 C  s   d|  |j|  |jf S )Nz{%s}_{\circ}\left({%s}\right))r   r  r   r   r]   r]   r`   _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)rT   z\deltar<   z\gammaz\operatorname{B}z\operatorname{Chi})(sympy.functions.special.tensor_functionsr   'sympy.functions.special.gamma_functionsr  r  &sympy.functions.special.beta_functionsr  'sympy.functions.special.delta_functionsr  'sympy.functions.special.error_functionsrT   )r   r   r  r  r  r  rT   r]   r]   r`   _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  r~   )r   r   clsr]   r]   r`   _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   r0  r   r  )r   r   r  r   r]   r]   r`   _print_Lambda	  s    
zLatexPrinter._print_Lambdac                 C  s   dS )Nz\left( x \mapsto x \right)r]   r   r]   r]   r`   _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 )Nr  c                   s   g | ]}d   | qS )r  r   r  r   r]   r`   r    rb   z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)r  r  )sortedr   r   r~   rW  r1  r  )r   r   r   r   Ztexargsr   r]   r   r`   _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   r  r  r   r   r   r   r]   r]   r`   _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   r  r  r  r]   r]   r`   _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)}r  )r   r   r   r  r]   r]   r`   
_print_log4  s    
zLatexPrinter._print_logc                 C  s0   d|  |jd  }|d ur(d||f S |S d S )N\left|{%s}\right|r   r  r  r  r]   r]   r`   
_print_Abs?  s    zLatexPrinter._print_Absc                 C  sN   | j d r&d| |jd td  }nd| |jd td }| ||S )Nr   z\Re{%s}r   Atomz\operatorname{{re}}{{{}}}r   r   r   r!   r   r   r  r]   r]   r`   	_print_reG  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  r]   r]   r`   	_print_imO  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  r]   r]   r`   
_print_NotW  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!  is_Notr   )r   r   charr;   r   r]   r]   r`   _print_LogOpb  s    zLatexPrinter._print_LogOpc                 C  s   t |jtd}| |dS )Nr  z\wedger  r   r   r%  r   r
  r   r]   r]   r`   
_print_Andq  s    zLatexPrinter._print_Andc                 C  s   t |jtd}| |dS )Nr  z\veer&  r'  r]   r]   r`   	_print_Oru  s    zLatexPrinter._print_Orc                 C  s   t |jtd}| |dS )Nr  z\veebarr&  r'  r]   r]   r`   
_print_Xory  s    zLatexPrinter._print_Xorc                 C  s   |  |j|pdS )Nz\Rightarrow)r%  r   )r   r
  altcharr]   r]   r`   r   }  s    zLatexPrinter._print_Impliesc                 C  s   t |jtd}| ||pdS )Nr  z\Leftrightarrowr&  )r   r
  r+  r   r]   r]   r`   r    s    zLatexPrinter._print_Equivalentc                 C  s0   d|  |jd  }|d ur(d||f S |S d S )Nz\overline{%s}r   r  r  r  r]   r]   r`   _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%sr  )r   r   r   rW  r;   r]   r]   r`   _print_polar_lift  s
    zLatexPrinter._print_polar_liftc                 C  s    d|  |jd  }| ||S )Nze^{%s}r   )r   r   r   r  r]   r]   r`   _print_ExpBase  s    zLatexPrinter._print_ExpBasec                 C  s   dS )Nr
  r]   r   r]   r]   r`   _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%sr  r  r]   r]   r`   _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%sr  r  r]   r]   r`   _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 )Nrp  r3  r   r  r  zE^{%s}%szE%sr0  r   r   r  r]   r]   r`   _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 )	Nr  z\left(%s; %s\middle| %s\right)r   r  rp  r3  z
\Pi^{%s}%sz\Pi%sr5  r  r]   r]   r`   _print_elliptic_pi  s    zLatexPrinter._print_elliptic_pic                 C  sD   d|  |jd |  |jd f }|d ur8d||f S d| S d S )N\left(%s, %s\right)r   r  z\operatorname{B}^{%s}%sz\operatorname{B}%sr  r  r]   r]   r`   _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 r]   r   r+  r   r]   r`   r    rb   z/LatexPrinter._print_betainc.<locals>.<listcomp>r8  r   r  z#\operatorname{%s}_{(%s, %s)}^{%s}%srp  r  z\operatorname{%s}_{(%s, %s)}%s)r   )r   r   r   operatorZlargsr   r]   r   r`   _print_betainc  s
    zLatexPrinter._print_betaincc                 C  s   | j ||ddS )NI)r;  )r<  r   r]   r]   r`   _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 )Nr8  r   r  z\Gamma^{%s}%sz\Gamma%sr  r  r]   r]   r`   _print_uppergamma  s    zLatexPrinter._print_uppergammac                 C  sD   d|  |jd |  |jd f }|d ur8d||f S d| S d S )Nr8  r   r  z\gamma^{%s}%s\gamma%sr  r  r]   r]   r`   _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   rW  r  r]   r]   r`   _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}%sr  r  r]   r]   r`   
_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}%sr  )r   r   r   r   nur]   r]   r`   _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%sr  r  r]   r]   r`   _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%sr  r  r]   r]   r`   _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  r]   r]   r`   _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   rI  r  rJ  r  r]   r]   r`   _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   rI  r  rJ  r  r]   r]   r`   _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  r  r  r  r]   r]   r`   _print_binomial/  s    zLatexPrinter._print_binomialc                 C  s<   |j \}}d| |td  }d|| |f }| ||S )Nr  rI  z{%s}^{\left(%s\right)}r   r   r!   r   r   )r   r   r   nr  r   r   r]   r]   r`   _print_RisingFactorial8  s    
z#LatexPrinter._print_RisingFactorialc                 C  s<   |j \}}d| |td  }d| ||f }| ||S )Nr  rI  z{\left(%s\right)}_{%s}rO  )r   r   r   rP  r  subr   r]   r]   r`   _print_FallingFactorial@  s    
z$LatexPrinter._print_FallingFactorial)symr   c                 C  sf   d| }d}|d ur4| ddkr0d||f }nd}d|| |j| |jf }|rb| ||}|S )Nr  Fr   r  r  T%s_{%s}\left(%s\right))r  r   r   argumentr   )r   r   r   rT  r   Zneed_expr]   r]   r`   _hprint_BesselBaseH  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   rs   r_   r   r]   r]   r`   _hprint_vecY  s    zLatexPrinter._hprint_vecc                 C  s   |  ||dS )NJrW  r   r]   r]   r`   _print_besseljb  s    zLatexPrinter._print_besseljc                 C  s   |  ||dS )Nr=  rZ  r   r]   r]   r`   _print_besselie  s    zLatexPrinter._print_besselic                 C  s   |  ||dS )NKrZ  r   r]   r]   r`   _print_besselkh  s    zLatexPrinter._print_besselkc                 C  s   |  ||dS )NYrZ  r   r]   r]   r`   _print_besselyk  s    zLatexPrinter._print_besselyc                 C  s   |  ||dS )NyrZ  r   r]   r]   r`   	_print_ynn  s    zLatexPrinter._print_ync                 C  s   |  ||dS )Nr   rZ  r   r]   r]   r`   	_print_jnq  s    zLatexPrinter._print_jnc                 C  s   |  ||dS )NzH^{(1)}rZ  r   r]   r]   r`   _print_hankel1t  s    zLatexPrinter._print_hankel1c                 C  s   |  ||dS )NzH^{(2)}rZ  r   r]   r]   r`   _print_hankel2w  s    zLatexPrinter._print_hankel2c                 C  s   |  ||dS )Nzh^{(1)}rZ  r   r]   r]   r`   
_print_hn1z  s    zLatexPrinter._print_hn1c                 C  s   |  ||dS )Nzh^{(2)}rZ  r   r]   r]   r`   
_print_hn2}  s    zLatexPrinter._print_hn2r   c                 C  s:   d|  |jd  }|d ur*d|||f S d||f S d S rB  r  r   r   r   notationr   r]   r]   r`   _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%sr  rh  r]   r]   r`   _hprint_airy_prime  s    zLatexPrinter._hprint_airy_primec                 C  s   |  ||dS NAirj  r   r]   r]   r`   _print_airyai  s    zLatexPrinter._print_airyaic                 C  s   |  ||dS NBirn  r   r]   r]   r`   _print_airybi  s    zLatexPrinter._print_airybic                 C  s   |  ||dS rl  rk  r   r]   r]   r`   _print_airyaiprime  s    zLatexPrinter._print_airyaiprimec                 C  s   |  ||dS rp  rs  r   r]   r]   r`   _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   r0  apbqrX  rV  r  r]   r]   r`   _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)}rv  )
r   r0  rw  rx  rw   anrX  aotherbotherrV  r  r]   r]   r`   _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%sr  r  r]   r]   r`   _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 )Nrp  r8  r  r   z\zeta^{%s}%sz\zeta%sr0  r   r  r  r   r  r]   r]   r`   _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 )Nrp  z_{%s}\left(%s\right)r  r   z\gamma%s^{%s}r@  r  r  r]   r]   r`   _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  r  r   r   r  r]   r]   r`   _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r  r   r   )r   r   r   r_   r  r   r]   r]   r`   _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)r  \right)^{%s}r  )r   r   r   rP  rx  ry  r   r   r]   r]   r`   _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)r  r  r  r   r   r   rP  rx  r   r   r]   r]   r`   _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)r  r  r  r   r   r   rP  r   r   r]   r]   r`   _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)r  r  r  r  r]   r]   r`   _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)r  r  r  r  r]   r]   r`   _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)r  r  r  r  r]   r]   r`   _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)r  r  r  r  r]   r]   r`   _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)r  r  r  r  r]   r]   r`   _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)r  r  r  r  r]   r]   r`   _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)r  r  r  r   r   r   rP  mthetaphir   r]   r]   r`   
_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)r  r  r  r  r]   r]   r`   
_print_Znm  s
    zLatexPrinter._print_Znmc           	      C  sB   t | j|\}}}|rdnd}|s&dnd| }d||||||f S )Nz	^{\prime}r   r  z%s%s\left(%s, %s, %s\right)%s)r  r   )	r   	characterr   rt   r   rx  r  r  supr]   r]   r`   Z__print_mathieu_functions&  s    z&LatexPrinter.__print_mathieu_functionsc                 C  s   | j d|j|dS )NCr  &_LatexPrinter__print_mathieu_functionsr   r   r]   r]   r`   _print_mathieuc,  s    zLatexPrinter._print_mathieucc                 C  s   | j d|j|dS )Nr   r  r  r   r]   r]   r`   _print_mathieus/  s    zLatexPrinter._print_mathieusc                 C  s   | j d|jd|dS )Nr  Trt   r   r  r   r]   r]   r`   _print_mathieucprime2  s    z!LatexPrinter._print_mathieucprimec                 C  s   | j d|jd|dS )Nr   Tr  r  r   r]   r]   r`   _print_mathieusprime5  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   rm  r   z	%s%d / %dz%s\frac{%d}{%d})r  r  r   r   )r   r   signr  r]   r]   r`   _print_Rational8  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   r  r]   r]   r`   r   G  rb   z,LatexPrinter._print_Order.<locals>.<genexpr>r  ; r   z\rightarrow zO\left(%s\right))r   r   pointr   r0  	variablesr   r   r_   r]   r]   r`   _print_OrderE  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   r  r  r]   r]   r`   _print_SymbolU  s    zLatexPrinter._print_Symbol)stringr   c                 C  s   d|v r|g g   }}}n2t |\}}}t|}dd |D }dd |D }|dkr^d|}|rt|dd| 7 }|r|d	d| 7 }|S )
Nrd   c                 S  s   g | ]}t |qS r]   	translater   r  r]   r]   r`   r  e  rb   z5LatexPrinter._deal_with_super_sub.<locals>.<listcomp>c                 S  s   g | ]}t |qS r]   r  r   rR  r]   r]   r`   r  f  rb   rv   \mathbf{{{}}}r  r   r  )r   r  r   r  )r   r  r  r  supersr  r]   r]   r`   r  ^  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   lhsrel_oprhs)r   r   gtltcharmapr]   r]   r`   _print_Relationalt  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
  r   r   r]   r`   r    s   z1LatexPrinter._print_Piecewise.<locals>.<listcomp>r  z%s & \text{otherwise}r  z\begin{cases} %s \end{cases}z \\)r   condr   r  r   r   r  )r   r   Zecpairsr   r]   r   r`   _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 r]   r   r  r   r]   r`   r    rb   z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>r   r   r   smallmatrix
   Tmatrixarray \begin{%MATSTR%}%s\end{%MATSTR%}%MATSTR%r  rd   r   z}%sr  )r/  rowsr  r  r   colsr   )r   r   linesliner   out_strr]   r   r`   _print_matrix_contents  s    ,
z#LatexPrinter._print_matrix_contentsc                 C  s@   |  |}| jd r<| jd }| j| }d| | d | }|S )Nr   \left\right)r  r   r   )r   r   r  
left_delimright_delimr]   r]   r`   _print_MatrixBase  s    




zLatexPrinter._print_MatrixBasec                 C  s2   | j |jtd ddd| |j| |jf  S )Nr  Tr   z	_{%s, %s})r   parentr!   r   r   r   r   r]   r]   r`   _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 )Nrp  r  r   :c                 3  s$   | ]}|d ur  |ndV  qd S )Nr   r   )r   xir   r]   r`   r     rb   zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>)rd  r  )r   r  r   r]   r`   
latexslice  s    z3LatexPrinter._print_MatrixSlice.<locals>.latexslicer  Tr  \left[r  \right])r   r  r!   rowslicer  colslicer  )r   r   r  r]   r   r`   _print_MatrixSlice  s    	zLatexPrinter._print_MatrixSlicec                 C  s   |  |jS r   )r   blocksr   r]   r]   r`   _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}Tr   z%s^{T}	r;   sympy.matricesr  r  r`  is_MatrixExprr   r   r   r   r   r4  r  r  r_   r]   r]   r`   _print_Transpose  s    
zLatexPrinter._print_Transposec                 C  s   |j }d| | S )Nz!\operatorname{tr}\left(%s \right))r;   r   r   r   r4  r]   r]   r`   _print_Trace  s    zLatexPrinter._print_Tracec                 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   r  z\left(%s\right)^{\dagger}Tr   z%s^{\dagger}r  r  r]   r]   r`   _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   ra  r  r   r   r]   r`   ra     s   z,LatexPrinter._print_MatMul.<locals>.<lambda>r  r  rm  r   )sympyr  rd  r   r   r  r  )r   r   parensr   r]   r  r`   _print_MatMul  s    
zLatexPrinter._print_MatMulc                 C  sN   |j }|jr@ddlm} t||r2d| |j S d| | S d| | S )Nr   )r  r  )r;   r  &sympy.matrices.expressions.blockmatrixr  r`  r  r  r   )r   r   r4  r  r]   r]   r`   _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	   Tr  r  z%s \bmod %srJ  r   r]   r]   r`   
_print_Mod  s(    zLatexPrinter._print_Modc                   s.   |j }td | j dt fdd|S )Nr   z \circ c                   s    | ddS NTr  r]   r;   r  precr]   r`   ra     rb   z5LatexPrinter._print_HadamardProduct.<locals>.<lambda>r   r!   r   r  r  r   r   r   r]   r  r`   _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!   r  )r   r   r  r]   r]   r`   _print_HadamardPower  s    z!LatexPrinter._print_HadamardPowerc                   s.   |j }td | j dt fdd|S )Nr   	 \otimes c                   s    | ddS r  r]   r  r  r]   r`   ra   &  rb   z6LatexPrinter._print_KroneckerProduct.<locals>.<lambda>r  r  r]   r  r`   _print_KroneckerProduct   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   r   r  )r   r   r  r  r`  r  r   )r   r   r   r   r  Zbase_strr]   r]   r`   _print_MatPow(  s    

zLatexPrinter._print_MatPowc                 C  s   | j || jd dS )Nr   r  )r  r   r   r]   r]   r`   _print_MatrixSymbol5  s    
z LatexPrinter._print_MatrixSymbolc                 C  s   | j d dkrdS dS )Nr   r   0z
\mathbf{0}r   )r   Zr]   r]   r`   _print_ZeroMatrix9  s    zLatexPrinter._print_ZeroMatrixc                 C  s   | j d dkrdS dS )Nr   r   1z
\mathbf{1}r  )r   Or]   r]   r`   _print_OneMatrix=  s    zLatexPrinter._print_OneMatrixc                 C  s   | j d dkrdS dS )Nr   r   z
\mathbb{I}z
\mathbf{I}r  )r   r=  r]   r]   r`   _print_IdentityA  s    zLatexPrinter._print_Identityc                 C  s   |  |jd }d| S )Nr   zP_{%s}r  )r   PZperm_strr]   r]   r`   _print_PermutationMatrixE  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}| 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 r\ q|	r||
 	d||
d   nR||
 	|d||
d    t
||
d  dkrd||
 d  d ||
 d< |	 }	g ||
d < q6q|d d }|  d dkr|| }|S )Nr   r]   r   r   r   r  r  r  r  r  r  r  r  z{}%sr   r  r  r   c                 S  s   g | ]}g qS r]   r]   r  r]   r]   r`   r  d  rb   z1LatexPrinter._print_NDimArray.<locals>.<listcomp>r  c                 S  s   g | ]}t t|qS r]   )rd  r/  r  r]   r]   r`   r  e  rb   Tr,  r  r  r  rp  )rankr   r   shaper   r   r/  	itertoolsproductr  r0  r  )r   r   r   Z	block_strr  r  	level_strshape_rangesouter_ievenback_outer_ir  r]   r]   r`   _print_NDimArrayI  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  r\   z{}^{z{}_{r   r  TF)r   is_upr   )	r   r  r  r  r  last_valenceprev_mapindexZnew_valencer]   r]   r`   _printer_tensor_indices  s2    

z$LatexPrinter._printer_tensor_indicesc                 C  s&   |j d j d }| }| ||i S r  )r   get_indicesr  )r   r   r  r  r]   r]   r`   _print_Tensor  s    zLatexPrinter._print_Tensorc                 C  s0   |j jd jd }|j  }|j}| |||S r  )r   r   r  r  r  )r   r   r  r  r  r]   r]   r`   _print_TensorElement  s    
z!LatexPrinter._print_TensorElementc                   s*      \}}|d fdd|D  S )Nr   c                   s   g | ]} |t qS r]   )r   r    r+  r   r   r]   r`   r    rb   z/LatexPrinter._print_TensMul.<locals>.<listcomp>)!_get_args_for_traditional_printerr  )r   r   r  r   r]   r  r`   _print_TensMul  s    zLatexPrinter._print_TensMulc                 C  sL   g }|j }|D ]}|| |t| q|  d|}|dd}|S )Nr  z+ -rm  )r   r  r   r    r  r  r   )r   r   rx  r   r   r_   r]   r]   r`   _print_TensAdd  s    
zLatexPrinter._print_TensAddc                 C  s"   d|j rdnd| |jd f S )Nz{}%s{%s}r   r  r   )r  r   r   r   r]   r]   r`   _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   r  r   r]   r`   r    rb   z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>)r0  r  r   r   r   r!   r  r   r]   r   r`   _print_PartialDerivative  s    z%LatexPrinter._print_PartialDerivativec                 C  s   |  |jS r   )r   r  r   r]   r]   r`   _print_ArraySymbol  s    zLatexPrinter._print_ArraySymbolc                   s2   d  |jtd dd fdd|jD f S )Nz{{%s}_{%s}}rI  Tr  c                   s   g | ]}  | qS r]   r   r  r   r]   r`   r    rb   z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>)r   r  r!   r  r  r   r]   r   r`   _print_ArrayElement  s    z LatexPrinter._print_ArrayElementc                 C  s   dS )Nz
\mathbb{U}r]   r   r]   r]   r`   _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}r  r   r]   r]   r`   _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=  ;r   r  Unknown Decimal Separatorr  r   z \  c                   s   g | ]}  |qS r]   r   r  r   r]   r`   r    rb   z-LatexPrinter._print_tuple.<locals>.<listcomp>)r   r   r0  r   r   r  )r   r   sepr]   r   r`   _print_tuple  s    zLatexPrinter._print_tuplec                   s    fdd|j D }d|S )Nc                   s   g | ]}  |qS r]   r   r   rx  r   r]   r`   r    rb   z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>r  r   r  r   r   elementsr]   r   r`   _print_TensorProduct  s    z!LatexPrinter._print_TensorProductc                   s    fdd|j D }d|S )Nc                   s   g | ]}  |qS r]   r   r(  r   r]   r`   r    rb   z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>z \wedge r)  r*  r]   r   r`   _print_WedgeProduct  s    z LatexPrinter._print_WedgeProductc                 C  s
   |  |S r   )r'  r   r]   r]   r`   _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 r]   r   r  r   r]   r`   r    rb   z,LatexPrinter._print_list.<locals>.<listcomp>r   , \  c                   s   g | ]}  |qS r]   r   r  r   r]   r`   r    rb   r%  )r   r  r   r   r]   r   r`   _print_list  s    zLatexPrinter._print_listc                 C  sR   t | td}g }|D ]*}|| }|d| || |f  qdd| S )Nr  z%s : %sz\left\{ %s\right\}r/  )r  keysr   r  r   r  )r   r   r1  r  r  valr]   r]   r`   _print_dict  s     zLatexPrinter._print_dictc                 C  s
   |  |S r   )r3  r   r]   r]   r`   _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   r5  r  r]   r]   r`   _print_DiracDelta  s    zLatexPrinter._print_DiracDeltac                 C  sP   |  |jd |jd  }|  |jd }d||f }|d urLd|||f }|S )Nr   r  rp  z${\left\langle %s \right\rangle}^{%s}z-{\left({\langle %s \rangle}^{%s}\right)}^{%s}r  )r   r   r   shiftr  r   r]   r]   r`   _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   r]   r`   r   !  rb   z0LatexPrinter._print_Heaviside.<locals>.<genexpr>z\theta\left(%s\right)r   )r  pargs)r   r   r   r8  r   r]   r   r`   _print_Heaviside   s
    zLatexPrinter._print_Heavisidec                 C  sj   |  |jd }|  |jd }|jd jrF|jd jrFd||f }nd||f }|d urfd||f }|S )Nr   r  z\delta_{%s %s}z\delta_{%s, %s}r   )r   r   r   )r   r   r   r   r   r   r]   r]   r`   _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   r]   r]   r`   r   4  rb   z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}r   r  r   )r  r   r   r  r  )r   r   r   r  r   r]   r]   r`   _print_LeviCivita2  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   r   r]   r]   r`   _print_RandomDomain<  s    



z LatexPrinter._print_RandomDomainc                 C  s   t |jtd}| |S )Nr  )r  r   r   
_print_setr   r_   r  r]   r]   r`   _print_FiniteSetG  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 )	Nr  r   r=  r  r   r  r%  \left\{%s\right\})r  r   r   r  r  r   r   r@  r]   r]   r`   r?  K  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   rp  r  r  c                 3  s   | ]}  |V  qd S r   r   r+  r   r]   r`   r   _  rb   zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>c                 3  s   | ]}  |V  qd S r   r   r+  r   r]   r`   r   b  rb   c                 3  s   | ]}  |V  qd S r   r   r+  r   r]   r`   r   d  rb   z\text{Range}\left(r  )r   r   r  )cont)r_   r   r]   r`   _print_symbolic_rangeY  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   r]   r`   r     rb   z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})objectstartis_infinitestopstepis_positiveiternextis_emptyr!  r  is_iterabler  )r   r_   rD  printsetitr]   )rI  r_   r   r`   _print_RangeX  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 )Nrp  z%s_{%s}^{%s}\left(%s\right)r   r  rU  z%s_{%s}r  r5  )r   r   letterr   r   r]   r]   r`   Z__print_number_polynomial  s    z&LatexPrinter.__print_number_polynomialc                 C  s   |  |d|S )Nr:  &_LatexPrinter__print_number_polynomialr   r]   r]   r`   _print_bernoulli  s    zLatexPrinter._print_bernoullic                   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 )Nr  z
B_{%s, %s}r   r  r  r  c                 3  s   | ]}  |V  qd S r   r   rF  r   r]   r`   r     s   z+LatexPrinter._print_bell.<locals>.<genexpr>rp  r-  r:  )r0  r   r   r  rY  )r   r   r   Ztex1Ztex2r   r]   r   r`   _print_bell  s    
zLatexPrinter._print_bellc                 C  s   |  |d|S NFrX  r   r]   r]   r`   _print_fibonacci  s    zLatexPrinter._print_fibonaccic                 C  s,   d|  |jd  }|d ur(d||f }|S )NzL_{%s}r   r  r  r  r]   r]   r`   _print_lucas  s    zLatexPrinter._print_lucasc                 C  s   |  |d|S )NTrX  r   r]   r]   r`   _print_tribonacci  s    zLatexPrinter._print_tribonaccic                   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}r  rp  r  r  r  r  c                 3  s$   | ]}| ur |nd V  qdS rE  r   rF  rH  r]   r`   r     rb   z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>r  )rJ  r0  rK  free_symbolsrM  r   formular  r   r  coeffr  lengthr  r  r  )r   r_   rM  rT  r]   rH  r`   _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 )NrB  r   r   r   r   z\left%s%s, %s\right%s)rK  endr   	left_open
right_open)r   r   leftrightr]   r]   r`   _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   r   r]   r]   r`   _print_AccumulationBounds  s    z&LatexPrinter._print_AccumulationBoundsc                   s(   t |  fdd|jD }d|S )Nc                   s   g | ]} | qS r]   r   r  r  r   r]   r`   r    rb   z-LatexPrinter._print_Union.<locals>.<listcomp>z \cup r   r   r  r   uargs_strr]   rp  r`   _print_Union  s    zLatexPrinter._print_Unionc                   s(   t |  fdd|jD }d|S )Nc                   s   g | ]} | qS r]   ro  r  rp  r]   r`   r    rb   z2LatexPrinter._print_Complement.<locals>.<listcomp>z \setminus rq  rr  r]   rp  r`   _print_Complement  s    zLatexPrinter._print_Complementc                   s(   t |  fdd|jD }d|S )Nc                   s   g | ]} | qS r]   ro  r  rp  r]   r`   r    rb   z4LatexPrinter._print_Intersection.<locals>.<listcomp>z \cap rq  rr  r]   rp  r`   _print_Intersection  s    z LatexPrinter._print_Intersectionc                   s(   t |  fdd|jD }d|S )Nc                   s   g | ]} | qS r]   ro  r  rp  r]   r`   r    rb   z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>z \triangle rq  rr  r]   rp  r`   _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   ro  )r   r=  rp  r]   r`   r     s   z1LatexPrinter._print_ProductSet.<locals>.<genexpr>)r   r0  setsr$   r   r  r   r  r]   rp  r`   _print_ProductSet  s     zLatexPrinter._print_ProductSetc                 C  s   dS )Nz	\emptysetr]   r  r]   r]   r`   _print_EmptySet  s    zLatexPrinter._print_EmptySetc                 C  s   dS )Nz
\mathbb{N}r]   r   rP  r]   r]   r`   _print_Naturals  s    zLatexPrinter._print_Naturalsc                 C  s   dS )Nz\mathbb{N}_0r]   r}  r]   r]   r`   _print_Naturals0  s    zLatexPrinter._print_Naturals0c                 C  s   dS Nz
\mathbb{Z}r]   rm  r]   r]   r`   _print_Integers	  s    zLatexPrinter._print_Integersc                 C  s   dS Nz
\mathbb{Q}r]   rm  r]   r]   r`   _print_Rationals	  s    zLatexPrinter._print_Rationalsc                 C  s   dS Nz
\mathbb{R}r]   rm  r]   r]   r`   _print_Reals	  s    zLatexPrinter._print_Realsc                 C  s   dS Nz
\mathbb{C}r]   rm  r]   r]   r`   _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   ra  r   r]   r`   r   	  rb   z/LatexPrinter._print_ImageSet.<locals>.<genexpr>r  c                 s  s   | ]}d | V  qdS )	%s \in %sNr]   )r   xyr]   r]   r`   r   	  rb   z!\left\{%s\; \middle|\; %s\right\})rW   r   	signaturer  	base_setsr  r   )r   r_   r   sigZxysZxinysr]   r   r`   _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 r]   r   r   r7  r   r]   r`   r  	  rb   z4LatexPrinter._print_ConditionSet.<locals>.<listcomp>z"\left\{%s\; \middle|\; %s \right\}z3\left\{%s\; \middle|\; %s \in %s \wedge %s \right\})r  r   rT  base_setr   UniversalSetr   	conditionr   r_   Z
vars_printr]   r   r`   _print_ConditionSet	  s    

z LatexPrinter._print_ConditionSetc                 C  s   |  |jd }d|S )Nr   z\mathcal{{P}}\left({}\right)r   r   r   )r   r   Z	arg_printr]   r]   r`   _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 r]   r   r  r   r]   r`   r  &	  rb   z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z)\left\{%s\; \middle|\; %s \in %s \right\})r  r  r   r   ry  r  r]   r   r`   _print_ComplexRegion%	  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   r]   r`   r   -	  rb   z/LatexPrinter._print_Contains.<locals>.<genexpr>)r  r   r  r]   r   r`   _print_Contains,	  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)	rz  rc  r   r  bnr   a0r  truncater   r]   r]   r`   _print_FourierSeries/	  s    z!LatexPrinter._print_FourierSeriesc                 C  s   |  |jS r   )r  infiniter   r]   r]   r`   _print_FormalPowerSeries4	  s    z%LatexPrinter._print_FormalPowerSeriesc                 C  s
   d|j  S )Nz\mathbb{F}_{%s})modr   r]   r]   r`   _print_FiniteField7	  s    zLatexPrinter._print_FiniteFieldc                 C  s   dS r  r]   r   r]   r]   r`   _print_IntegerRing:	  s    zLatexPrinter._print_IntegerRingc                 C  s   dS r  r]   r   r]   r]   r`   _print_RationalField=	  s    z!LatexPrinter._print_RationalFieldc                 C  s   dS r  r]   r   r]   r]   r`   _print_RealField@	  s    zLatexPrinter._print_RealFieldc                 C  s   dS r  r]   r   r]   r]   r`   _print_ComplexFieldC	  s    z LatexPrinter._print_ComplexFieldc                 C  s,   |  |j}dt| j |j}d||f S )Nr  z%s\left[%s\right]r   domainr  r  r  r   r   r  r  r]   r]   r`   _print_PolynomialRingF	  s    z"LatexPrinter._print_PolynomialRingc                 C  s,   |  |j}dt| j |j}d||f S )Nr  r  r  r  r]   r]   r`   _print_FractionFieldK	  s    z!LatexPrinter._print_FractionFieldc                 C  s<   |  |j}dt| j |j}d}|js.d}d|||f S )Nr  r   zS_<^{-1}z%s%s\left[%s\right])r   r  r  r  r  is_Poly)r   r   r  r  invr]   r]   r`   _print_PolynomialRingBaseP	  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<  r  r   )r  r<  z	domain=%sr  z\%s {\left(%s \right)}z$\operatorname{%s}{\left( %s \right)})r  r  r  r  r   genspowr   r   rs  extendr   r  popr  rd  r  
get_domainr  )r   polyr  r  monomrd  s_monomr   r   s_coeffs_termmodifierr   r  r  r   r   r]   r]   r`   _print_PolyX	  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 )NComplexRootOfCRootOfz\%s {\left(%s, %d\right)}z'\operatorname{%s} {\left(%s, %d\right)})r  r  r   r   r  r  )r   r:   r  r   r  r]   r]   r`   _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   funr   IdentityFunctionr  r  r  )r   r   r  r   r]   r]   r`   _print_RootSum	  s    zLatexPrinter._print_RootSumc                 C  s   dS )N\omegar]   r   r]   r]   r`   _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^{{{}}}r  )r   r   )r   r   r   mulr]   r]   r`   _print_OmegaPower	  s    

zLatexPrinter._print_OmegaPowerc                   s   d  fdd|jD S )Nr  c                   s   g | ]}  |qS r]   r   r+  r   r]   r`   r  	  rb   z/LatexPrinter._print_Ordinal.<locals>.<listcomp>)r  r   r   r]   r   r`   _print_Ordinal	  s    zLatexPrinter._print_Ordinalc                 C  s   | j d }|| td|S )Nr   z	{%s}^{%d})r   r~   r!   )r   r  r   r]   r]   r`   _print_PolyElement	  s    
zLatexPrinter._print_PolyElementc                 C  s>   |j dkr| |jS | |j}| |j }d||f S d S )Nr  rq  )rv  r   ru  )r   r9   ru  rv  r]   r]   r`   _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}r  r  r5  )r   r   r   r  r   r   r]   r]   r`   _print_euler	  s    &zLatexPrinter._print_eulerc                 C  s,   d|  |jd  }|d ur(d||f }|S )NzC_{%s}r   r  r  r  r]   r]   r`   _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   rp  r   r   r   )r   r   r_   inverser]   r]   r`   _print_UnifiedTransform	  s    z$LatexPrinter._print_UnifiedTransformc                 C  s   |  |dS )NMr  r   r]   r]   r`   _print_MellinTransform	  s    z#LatexPrinter._print_MellinTransformc                 C  s   |  |ddS )Nr  Tr  r   r]   r]   r`   _print_InverseMellinTransform	  s    z*LatexPrinter._print_InverseMellinTransformc                 C  s   |  |dS )NLr  r   r]   r]   r`   _print_LaplaceTransform	  s    z$LatexPrinter._print_LaplaceTransformc                 C  s   |  |ddS )Nr  Tr  r   r]   r]   r`   _print_InverseLaplaceTransform	  s    z+LatexPrinter._print_InverseLaplaceTransformc                 C  s   |  |dS r\  r  r   r]   r]   r`   _print_FourierTransform	  s    z$LatexPrinter._print_FourierTransformc                 C  s   |  |ddS )Nr]  Tr  r   r]   r]   r`   _print_InverseFourierTransform	  s    z+LatexPrinter._print_InverseFourierTransformc                 C  s   |  |dS )NSINr  r   r]   r]   r`   _print_SineTransform	  s    z!LatexPrinter._print_SineTransformc                 C  s   |  |ddS )Nr  Tr  r   r]   r]   r`   _print_InverseSineTransform	  s    z(LatexPrinter._print_InverseSineTransformc                 C  s   |  |dS )NCOSr  r   r]   r]   r`   _print_CosineTransform	  s    z#LatexPrinter._print_CosineTransformc                 C  s   |  |ddS )Nr  Tr  r   r]   r]   r`   _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   reprrz  r]   r]   r`   
_print_DMP	  s    
zLatexPrinter._print_DMPc                 C  s
   |  |S r   )r  rz  r]   r]   r`   
_print_DMF
  s    zLatexPrinter._print_DMFc                 C  s   |  t|jS r   r   r   r  )r   rJ  r]   r]   r`   _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   r0  r   )r   r   r   arg0resultarg1r]   r]   r`   _print_LambertW
  s    zLatexPrinter._print_LambertWc                 C  s   d | |jd S )Nz!\operatorname{{E}}\left[{}\right]r   r  r   r]   r]   r`   _print_Expectation
  s    zLatexPrinter._print_Expectationc                 C  s   d | |jd S )Nz#\operatorname{{Var}}\left({}\right)r   r  r   r]   r]   r`   _print_Variance
  s    zLatexPrinter._print_Variancec                   s    d d fdd|jD S )Nz#\operatorname{{Cov}}\left({}\right)r  c                 3  s   | ]}  |V  qd S r   r   r+  r   r]   r`   r   
  rb   z1LatexPrinter._print_Covariance.<locals>.<genexpr>)r   r  r   r   r]   r   r`   _print_Covariance
  s    zLatexPrinter._print_Covariancec                 C  s   d | |jd S )Nz!\operatorname{{P}}\left({}\right)r   r  r   r]   r]   r`   _print_Probability
  s    zLatexPrinter._print_Probabilityc                 C  s$   |  |j}|  |j}d||f S )Nz%s\rightarrow %s)r   r  codomain)r   morphismr  r  r]   r]   r`   _print_Morphism
  s    zLatexPrinter._print_Morphismc                 C  s&   |  |j|  |j }}d||f S )Nrq  )r   r  den)r   r   r  r  r]   r]   r`   _print_TransferFunction#
  s    z$LatexPrinter._print_TransferFunctionc                   s(   t  j} fdd}dt||S )Nc                   s    | t dS r  )r   r   ra  r  r]   r`   ra   )
  s   z,LatexPrinter._print_Series.<locals>.<lambda>r   )rd  r   r  r  r   r   r   r  r]   r  r`   _print_Series'
  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   ra  r  r   r   r]   r`   ra   0
  s
    z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>z\cdot)sympy.physics.control.ltir  rd  r   r  r  r  r]   r  r`   _print_MIMOSeries-
  s    zLatexPrinter._print_MIMOSeriesc                 C  s   d t| j|jS Nr  r  r  r   r   r   r]   r]   r`   _print_Parallel4
  s    zLatexPrinter._print_Parallelc                 C  s   d t| j|jS r  r  r   r]   r]   r`   _print_MIMOParallel7
  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<  r  z\frac{%s}{%s %s %s})sympy.physics.controlr  r  sys1r7  r`  rd  r   sys2r   r  )r   r   r  r  r  tfnum_arg_listden_arg_listZ
den_term_1Z
den_term_2ru  Zdenom_1Zdenom_2_signr]   r]   r`   _print_Feedback:
  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<  r  z)\left(I_{\tau} %s %s\right)^{-1} \cdot %s)r  r  r   r  r  r  )r   r   r  inv_matr  r  r]   r]   r`   _print_MIMOFeedback^
  s
    z LatexPrinter._print_MIMOFeedbackc                 C  s   |  |j}d| S )Nz%s_\tau)r   	_expr_matr  r]   r]   r`   _print_TransferFunctionMatrixe
  s    z*LatexPrinter._print_TransferFunctionMatrixc                 C  s   d |jj|jS )Nz\text{{{}}}_{{{}}})r   r  r  rP  r   r]   r]   r`   
_print_DFTi
  s    zLatexPrinter._print_DFTc                 C  s&   |  t|j}| |}d||f S )Nz%s:%s)r   r   r  r  )r   r  pretty_namepretty_morphismr]   r]   r`   _print_NamedMorphismm
  s    
z!LatexPrinter._print_NamedMorphismc                 C  s"   ddl m} | ||j|jdS )Nr   )NamedMorphismid)sympy.categoriesr
  r	  r  r  )r   r  r
  r]   r]   r`   _print_IdentityMorphismr
  s    
z$LatexPrinter._print_IdentityMorphismc                   s<    fdd|j D }|  d|d } |}|| S )Nc                   s   g | ]}  t|jqS r]   r  )r   	componentr   r]   r`   r  z
  s   z9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z\circ r  )r  reverser  r  )r   r  component_names_listcomponent_namesr  r]   r   r`   _print_CompositeMorphismw
  s    

z%LatexPrinter._print_CompositeMorphismc                 C  s   d | t|jS Nr  )r   r   r   r  )r   r  r]   r]   r`   _print_Category
  s    zLatexPrinter._print_Categoryc                 C  s<   |j s| tjS | |j }|jr8|d| |j 7 }|S )Nz\Longrightarrow %s)premisesr   r   EmptySetconclusions)r   diagramlatex_resultr]   r]   r`   _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}
r   r   r  & r  
z\end{array}
)widthr/  heightlatex)r   gridr  r   r   r]   r]   r`   _print_DiagramGrid
  s    

zLatexPrinter._print_DiagramGridc                 C  s   d | |j| |jS )Nz{{{}}}^{{{}}})r   r   r  r  r   r  r]   r]   r`   _print_FreeModule
  s    zLatexPrinter._print_FreeModulec                   s   d d fdd|D S )Nz\left[ {} \right]r  c                 3  s    | ]}d   | d V  qdS rd   r\   Nr   r   r   r]   r`   r   
  s   z8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>)r   r  r   r  r]   r   r`   _print_FreeModuleElement
  s    z%LatexPrinter._print_FreeModuleElementc                   s    d d fdd|jD S )N\left\langle {} \right\rangler  c                 3  s    | ]}d   | d V  qdS r$  r   r   r   r]   r`   r   
  s   z0LatexPrinter._print_SubModule.<locals>.<genexpr>)r   r  r  r%  r]   r   r`   _print_SubModule
  s    zLatexPrinter._print_SubModulec                   s"   d d fdd|jjD S )Nr'  r  c                 3  s"   | ]\}d   | d V  qdS r$  r   r   r   r]   r`   r   
  s   z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>)r   r  _moduler  r%  r]   r   r`   _print_ModuleImplementedIdeal
  s    z*LatexPrinter._print_ModuleImplementedIdealc                   sD    fdd|j D }|d gdd t|dd  dD  }d|S )Nc                   s    g | ]} j |td  ddqS )r	   Tr  )r   r!   r  r   r]   r`   r  
  s   z2LatexPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]\}}|d  | qS )r   r]   )r   r   r   r]   r]   r`   r  
  rb   r  ijkr  )r   r  r  )r   r   r_   rx  r]   r   r`   _print_Quaternion
  s
    
&zLatexPrinter._print_Quaternionc                 C  s   d | |j| |jS Nz\frac{{{}}}{{{}}})r   r   r  
base_ideal)r   Rr]   r]   r`   _print_QuotientRing
  s    
z LatexPrinter._print_QuotientRingc                 C  s   d | |j| |jjS Nz{{{}}} + {{{}}})r   r   datar  r.  )r   r   r]   r]   r`   _print_QuotientRingElement
  s    z'LatexPrinter._print_QuotientRingElementc                 C  s   d | |j| |jjS r1  )r   r   r2  modulekilled_moduler%  r]   r]   r`   _print_QuotientModuleElement
  s    z)LatexPrinter._print_QuotientModuleElementc                 C  s   d | |j| |jS r-  )r   r   r   r5  r"  r]   r]   r`   _print_QuotientModule
  s    
z"LatexPrinter._print_QuotientModulec                 C  s(   d | | | |j| |jS )Nz{{{}}} : {{{}}} \to {{{}}})r   r   _sympy_matrixr  r  )r   r  r]   r]   r`   _print_MatrixHomomorphism
  s    z&LatexPrinter._print_MatrixHomomorphismc                 C  s   |j j }d|v r"|g g   }}}n2t|\}}}t|}dd |D }dd |D }d| }|rr|dd| 7 }|r|dd| 7 }|S )	Nrd   c                 S  s   g | ]}t |qS r]   r  r  r]   r]   r`   r  
  rb   z0LatexPrinter._print_Manifold.<locals>.<listcomp>c                 S  s   g | ]}t |qS r]   r  r  r]   r]   r`   r  
  rb   r  r  r   r  )r  r   r  r  )r   manifoldr  r  r  r  r]   r]   r`   _print_Manifold
  s    zLatexPrinter._print_Manifoldc                 C  s   d|  |j|  |jf S )Nz\text{%s}_{%s})r   r  r:  )r   patchr]   r]   r`   _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coordsysr]   r]   r`   _print_CoordSystem
  s     zLatexPrinter._print_CoordSystemc                 C  s   d|  |j S )Nz\mathbb{\nabla}_{%s})r   Z_wrt)r   Zcvdr]   r]   r`   _print_CovarDerivativeOp
  s    z%LatexPrinter._print_CovarDerivativeOpc                 C  s$   |j j|j j}d| t|S r  
_coord_sysr  _indexr  r   r   r   r   fieldr  r]   r]   r`   _print_BaseScalarField
  s    z#LatexPrinter._print_BaseScalarFieldc                 C  s$   |j j|j j}d| t|S )Nz\partial_{{{}}}r@  rC  r]   r]   r`   _print_BaseVectorField
  s    z#LatexPrinter._print_BaseVectorFieldc                 C  sL   |j }t|dr4|jj|j j}d| t|S | |}d|S d S )NrA  z\operatorname{{d}}{}z!\operatorname{{d}}\left({}\right))	_form_fieldr  rA  r  rB  r  r   r   r   )r   diffrD  r  r]   r]   r`   _print_Differential
  s    

z LatexPrinter._print_Differentialc                 C  s   |  |jd }d|S )Nr   z"\operatorname{{tr}}\left({}\right)r  )r   r  contentsr]   r]   r`   	_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)r  r   r]   r]   r`   _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)r  r   r]   r]   r`   _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 )Nrp  _%s\left(%s\right)r  r   r  z\sigma^{%s}%sz\sigma%sr  r  r]   r]   r`   _print_divisor_sigma  s    

z!LatexPrinter._print_divisor_sigmac                 C  sd   t |jdkr4dtt| j|jd |jd f }nd| |jd  }|d ur\d||f S d| S )Nrp  rN  r  r   r  z\sigma^*^{%s}%sz
\sigma^*%sr  r  r]   r]   r`   _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)r  r   r]   r]   r`   _print_primenu%  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)r  r   r]   r]   r`   _print_primeomega+  s
    zLatexPrinter._print_primeomegac                 C  s
   t |jS r   )r~   r  r   r]   r]   r`   
_print_Str1  s    zLatexPrinter._print_Strc                 C  s   |  t|S r   )r   r   r   r]   r]   r`   _print_float4  s    zLatexPrinter._print_floatc                 C  s   t |S r   r~   r   r]   r]   r`   
_print_int7  s    zLatexPrinter._print_intc                 C  s   t |S r   rU  r   r]   r]   r`   
_print_mpz:  s    zLatexPrinter._print_mpzc                 C  s   t |S r   rU  r   r]   r]   r`   
_print_mpq=  s    zLatexPrinter._print_mpqc                 C  s   d tt|jS )Nz"\operatorname{{Q}}_{{\text{{{}}}}})r   r   r~   r  r   r]   r]   r`   _print_Predicate@  s    zLatexPrinter._print_Predicatec                   s:   |j }|j} |}d fdd|D }d||f S )Nr  c                   s   g | ]}  |qS r]   r   r(  r   r]   r`   r  G  rb   z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>z%s(%s))r  	argumentsr   r  )r   r   predr   Z
pred_latexZ
args_latexr]   r   r`   _print_AppliedPredicateC  s
    
z$LatexPrinter._print_AppliedPredicatec                   s   t  |}dt| S )Nz\mathtt{\text{%s}})superemptyPrinterr   r  r  r]   r`   r^  J  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)r   )r   )N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)F)N)N)N)N)N)N)N(<  r  
__module____qualname__printmethodr   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r	  r  _print_BooleanTrue_print_BooleanFalser  r  r%  r5  r8  rH  rO  rS  rT  rU  rX  rY  rz  r~  r  r  r  r  r  r  r  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/  r0  r1  r2  r4  r6  r7  r9  r<  r>  r?  rA  rC  _print_gammarD  rF  rG  rH  rK  rL  rM  rN  rQ  rS  rW  rX  r[  r\  r^  r`  rb  rc  rd  re  rf  rg  rj  rk  ro  rr  rt  ru  ry  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  _print_RandomSymbolr  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.  r0  r3  r4  r5  r7  r9  r:  r;  r>  rA  r?  _print_frozensetrV  rY  rZ  r[  r^  r_  ra  rf  _print_SeqPer_print_SeqAdd_print_SeqMulrl  rn  ru  rv  rw  rx  r{  r|  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  Z_print_IDFTr	  r  r  r  r  r!  r#  r&  r(  r*  r,  r0  r3  r6  r7  r9  r;  r=  r>  r?  rE  rF  rI  rK  rL  rM  rO  rP  rQ  rR  rS  rT  rV  rW  rX  rY  r\  r^  __classcell__r]   r]   r_  r`   r      s  
=

	!v-!
$ L

											
6



*9		
$	

r   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}}}'"
    r   T)r  r  N)tex_greek_dictionaryr   r1  greek_letters_setother_symbolsr  r}   r1  r0  r  r  )r_   r   r  r]   r]   r`   r  Q  s    
$r  c                 K  s   t || S )a %  Convert the given expression to LaTeX string representation.

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

    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.

    )r   r   r   r   r]   r]   r`   r  p  s     Ur  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  rq  r]   r]   r`   print_latexG  s    rs  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}rt  z\begin{align*}
z= &r   z
\end{align*}FzUnknown environment: {}z\dotsr  r<  z& & r  r  r  r   r  r  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s})r   r   r   as_ordered_termsr0  r/  rc  r   )r  r  Zterms_per_lineenvironmentZuse_dotsr   r  r  Z
first_termZnonumberZend_termZdoubleetrI  r  Zn_termsZ
term_countr   r  Z
term_startZterm_endr  r]   r]   r`   multiline_latexN  sn    C




rw  )r  rt  F)J__doc__
__future__r   typingr   r   r   r  
sympy.corer   r   r   r	   r
   r   r   r   sympy.core.alphabetsr   sympy.core.containersr   sympy.core.functionr   r   r   Zsympy.core.operationsr   sympy.core.powerr   sympy.core.sortingr   sympy.core.sympifyr   r  r   r   r   sympy.tensor.arrayr   sympy.printing.precedencer   sympy.printing.printerr   r   sympy.printing.conventionsr   r   r    r!   Zmpmath.libmp.libmpfr"   r#   r@  sympy.utilities.iterablesr$   r%   r7   Zsympy.vector.basisdependentr&   r  rn  rp  r}   rc  	frozensetro  compileri  r   r   r  r  rs  rw  r]   r]   r]   r`   <module>   s   ('                     Y
 W