
    Ed             	         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rddl9m:Z: g dZ;i 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/d0d1d2d3d4d5d6d7d8i d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKd,dLdMdNdDdOdPdQdRdSdTdUdVdWdXdYdZd[Z<h d\Z=i d]d^ d_d` dadb dcdd dedf dgdh didj dkdl dmdn dodp dqdr dsdt dudv dwdx dydz d{d| d}d~ d d d d d d d dZ>de?d<    e@e          ZA e8jB        d           e8jB        d          fZCddZD G d de*          ZEddZF e+eE          d             ZGd ZHddZIdS )zC
A Printer which converts an expression into its LaTeX equivalent.
    )annotations)AnyCallableTYPE_CHECKINGN)AddFloatModMulNumberSSymbolExpr)greeks)Tuple)FunctionAppliedUndef
Derivative)AssocOp)Pow)default_sort_key)SympifyError)trueBooleanTrueBooleanFalse)	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argAlphaz
\mathrm{A}Betaz
\mathrm{B}Gamma\GammaDeltaz\DeltaEpsilonz
\mathrm{E}Zetaz
\mathrm{Z}Etaz
\mathrm{H}Thetaz\ThetaIotaz
\mathrm{I}Kappaz
\mathrm{K}Lambdaz\LambdaMuz
\mathrm{M}Nuz
\mathrm{N}Xiz\XiomicronoOmicronz
\mathrm{O}Piz\PiRhoz
\mathrm{P}Sigmaz\SigmaTauz
\mathrm{T}Upsilonz\UpsilonPhiz\PhiChiz
\mathrm{X}Psiz\PsiOmegaz\Omegalamdaz\lambdaLamdakhiz\chiKhi
varepsilonz\varepsilonvarkappaz	\varkappavarphiz\varphivarpiz\varpivarrhoz\varrhoz	\varsigmaz	\vartheta)varsigmavartheta>
   wpellethmhobethhbaralephgimeldalethhslashmathringc                    d| z   dz   S )Nz
\mathring{} ss    4lib/python3.11/site-packages/sympy/printing/latex.py<lambda>rt   Z   s    -/$.     ddddotc                    d| z   dz   S )Nz\ddddot{ro   rp   rq   s    rs   rt   rt   [   s    Ad* ru   dddotc                    d| z   dz   S )Nz\dddot{ro   rp   rq   s    rs   rt   rt   \       z!|D( ru   ddotc                    d| z   dz   S )Nz\ddot{ro   rp   rq   s    rs   rt   rt   ]   s    ik$& ru   dotc                    d| z   dz   S )Nz\dot{ro   rp   rq   s    rs   rt   rt   ^       XaZ_ ru   checkc                    d| z   dz   S )Nz\check{ro   rp   rq   s    rs   rt   rt   _   rz   ru   brevec                    d| z   dz   S )Nz\breve{ro   rp   rq   s    rs   rt   rt   `   rz   ru   acutec                    d| z   dz   S )Nz\acute{ro   rp   rq   s    rs   rt   rt   a   rz   ru   gravec                    d| z   dz   S )Nz\grave{ro   rp   rq   s    rs   rt   rt   b   rz   ru   tildec                    d| z   dz   S )Nz\tilde{ro   rp   rq   s    rs   rt   rt   c   rz   ru   hatc                    d| z   dz   S )Nz\hat{ro   rp   rq   s    rs   rt   rt   d   r   ru   barc                    d| z   dz   S )Nz\bar{ro   rp   rq   s    rs   rt   rt   e   r   ru   vecc                    d| z   dz   S )Nz\vec{ro   rp   rq   s    rs   rt   rt   f   r   ru   primec                    d| z   dz   S N{z}'rp   rq   s    rs   rt   rt   g   s    s1uTz ru   prmc                    d| z   dz   S r   rp   rq   s    rs   rt   rt   h   s    SU4Z ru   boldc                    d| z   dz   S Nz\boldsymbol{ro   rp   rq   s    rs   rt   rt   j   s    oa', ru   bmc                    d| z   dz   S r   rp   rq   s    rs   rt   rt   k   s    OA%d* ru   c                    d| z   dz   S )Nz	\mathcal{ro   rp   rq   s    rs   rt   rt   l       \!^D( ru   c                    d| z   dz   S )Nz	\mathscr{ro   rp   rq   s    rs   rt   rt   m   r   ru   c                    d| z   dz   S )Nz
\mathfrak{ro   rp   rq   s    rs   rt   rt   n   s    mAod* ru   c                    d| z   dz   S )Nz\left\|{z	}\right\|rp   rq   s    rs   rt   rt   p   s    k!mL0 ru   c                    d| z   dz   S )Nz\left\langle{z}\right\ranglerp   rq   s    rs   rt   rt   q   s    %a'(99 ru   c                    d| z   dz   S Nz\left|{z}\right|rp   rq   s    rs   rt   rt   r       Z\+- ru   c                    d| z   dz   S r   rp   rq   s    rs   rt   rt   s   r   ru   )calscrfraknormavgabsmagzdict[str, Callable[[str], str]]modifier_dictz[0-9][} ]*$z[0-9]rr   strreturnc                    |                      dd          } dD ]}|                      |d|z             } |                      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)rr   cs     rs   latex_escaper   ~   sm     	
		$)**A # #IIa""			#)**A			#*++AHru   c            	          e Zd ZU dZi 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ddi ddddddddddddddZded<   d\dZd]d"Zd]d#Zd^d]d$Z	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d0 Zdad3ZeZeZd4 Zd\d5Zd6 Zd7 Zd8 Zd9 Zd: Zd; Zd< Zd= Z d> Z!d? Z"dbdAZ#dB Z$dC Z%dcdEZ&dddGZ'dH Z(dI Z)dJ Z*dedLZ+dM Z,dN Z-dO Z.dP Z/dQ Z0dR Z1dS Z2dfdUZ3d\dgdWZ4dX Z5dY Z6e7dZ             Z8d[ Z9d\ Z:d] Z;d\d]d^Z<e<xZ=Z>d\d_Z?d\d`Z@d\daZAd\dbZBd\dcZCd\ddZDde ZEdf ZFdg ZGdh ZHdi ZId\djZJd\dkZKd\dlZLd\dmZMd\dnZNd\doZOd\dpZPd\dqZQd\drZRd\dsZSd\dtZTdhdvZUd\dwZVd\dxZWd\dyZXd\d]dzZYeYZZd\d{Z[d\d|Z\d\d}Z]d\d~Z^d\dZ_d\dZ`d\dZad\dZbd\dZcd\dZddidZed]dZfd\dZgd\dZhd\dZid\dZjd\dZkd\dZld\dZmd\dZnd\dZod\dZpdjd]dZqdjd]dZrd\dZsd\dZtd\dZud\dZvd\dZwd\dZxd\dZyd\dZz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dkdZd\dZd\dZd\dZd\dZd Zd ZdldmdZeZdldndZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd\dZdÄ ZdĄ Zdń ZdƄ ZdǄ ZdȄ ZdɄ Zdʄ Zd˄ Zdod̈́ZdpdЄZdф Zd҄ Zdӄ ZdԄ ZdՄ Zdք Zdׄ Zd؄ Zdل Zd\dڄZdۄ Zd܄ Zd݄ Zdބ Zd߄ Zd Zd Zd\dZd\dZd\dZd\dZd\dZd Zd Zd ZeZd ZŐd\dZƐd\dZǐd\dZȐd\dZɐd\dZʐd\dZd ZeZeZeZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zݐd  Zސd Zߐd Zd Zd Zd Zd Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd\dZd\dZdqdZd Zd Zd Zd Zd Zd Zd  Zd! Zd" Z d# Zd$ Zd% Zd& Zd\d'Zd( Zd) Zd* Zd+ Z	d, Z
d- Zd. Zd/ Zd0 Zd1 Zd2 Zd3 Zd4 Zd5 ZeZd6 Zd7 Zd8 Zd9 Zd: Zd; Zd< Zd= Zd> Zd? Zd@ ZdA Z dB Z!dC Z"dD Z#dE Z$dF Z%dG Z&dH Z'dI Z(dJ Z)dK Z*dL Z+dM Z,d\dNZ-d\dOZ.d\dPZ/d\dQZ0d\dRZ1d\dSZ2dT Z3dU Z4dV Z5dW Z6dX Z7dY Z8dZ Z9 fd[Z: xZ;S (r  LatexPrinter_latex	full_precFfold_frac_powersfold_func_bracketsfold_short_fracNinv_trig_styleabbreviateditexln_notationlong_frac_ratio	mat_delim[mat_strmodeplain
mul_symbolordersymbol_namesroot_notationTmat_symbol_styleimaginary_unitiperiodd)gothic_re_imdecimal_separatorperm_cyclicparenthesize_superminmaxdiff_operatorzdict[str, Any]_default_settingsc                6   t          j        | |           d| j        v r"g d}| j        d         |vrt          d          | j        d         | j        d         dk    r
d| j        d<   ddd	d
d}	 || j        d                  | j        d<   n%# t          $ r | j        d         | j        d<   Y nw xY w	 || j        d         pd         | j        d<   nW# t          $ rJ | j        d                                         dv r|d         | j        d<   n| j        d         | j        d<   Y nw xY w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   equationz	equation*zB'mode' must be one of 'inline', 'plain', 'equation' or 'equation*'r   r   T z \,.\,  \cdot  \times )Nldotr}   timesr   mul_symbol_latexr}   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settingsvalid_modesmul_symbol_tableimaginary_unit_table	imag_unitdiff_operator_tabler   s           rs   r   zLatexPrinter.__init__   sW   x(((T^# 	>( ( (K~f%[8 >  "= > > > >+, 	5v&(2	504DN,-  	
 
	- !=> N-.. 	- 	- 	-|, N-...	-
	1 !=!FG N566 	1 	1 	1|,2244BC 1 %U+ 9:: N<0 9:	1 "%3//  
  
 N#34	1E1I1I)U^1_1_-. 	
 
 70C0G0GWd0e0e,---s%   1B B/.B/3C AD%$D%r   r   c                ,    d                     |          S )Nz\left({}\right)formatr   rr   s     rs   _add_parenszLatexPrinter._add_parens   s    !((+++ru   c                ,    d                     |          S )Nz\left( {}\right)r   r  s     rs   _add_parens_lspacezLatexPrinter._add_parens_lspace   s    "))!,,,ru   c                   t          |          }|r*|r(|                     |                     |                    S ||k     s|s.||k    r(|                     |                     |                    S |                     |          S N)r   r  _print)r   itemlevelis_negstrictprec_vals         rs   parenthesizezLatexPrinter.parenthesize   s    )$// 	7f 	7##DKK$5$5666u 	%v 	%8u3D 	%##DKK$5$5666;;t$$$ru   c                |    d|v r7| 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  s     rs   r   zLatexPrinter.parenthesize_super   sK     !8 	*~23 *''***q)))ru   c                    t          j        | |          }| j        d         dk    r|S | j        d         dk    rd|z  S | j        d         rd|z  S | j        d         }d|d|d	|dS )
Nr   r   r   z$%s$r   z$$%s$$z\begin{ro   z\end{)r   doprintr   )r   exprtexenv_strs       rs   r  zLatexPrinter.doprint  s    odD))>&!W, 	EJ^F#x/ 	ES= ^F# 	Es?"nV,GG.5ggsssGGGDDru   boolc                \    |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  s     rs   _needs_bracketszLatexPrinter._needs_brackets  sH     _<)< J I$am*C +H.2.>%.GK 	Kru   c                    |                      |          sdS |j        r|                     |          sdS |j        r|                     |          sdS |j        s|j        r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.
        FT)r  is_Mul_mul_is_cleanis_Pow_pow_is_cleanis_Addis_Functionr  s     rs   _needs_function_bracketsz%LatexPrinter._needs_function_brackets  s     ##D)) 	5 { 	4#5#5d#;#; 	t T%7%7%=%= t  0 turu   c                Z   ddl m} ddlm} ddlm} j        r|s                                rdS n)t                    t          d         k     rdS j
        rdS j        rdS t          fdt          fD                       rdS |s t          fd|||fD                       rd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  B   K   | ]}                     |          V  d S r  has.0xr  s     rs   	<genexpr>z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>L  -      ++qtxx{{++++++ru   c              3  B   K   | ]}                     |          V  d S r  r*  r,  s     rs   r/  z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>O  s-      BBADHHQKKBBBBBBru   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(  s    `     rs   _needs_mul_bracketsz LatexPrinter._needs_mul_brackets5  s    	433333111111666666; 	 T::<< t#D))Ju,== 	4 	4 	4++++SF+++++ 	4 	BBBB(GS)ABBBBB	4uru   c                r    j         rdS t          fdt          fD                       rdS j        rd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  B   K   | ]}                     |          V  d S r  r*  r,  s     rs   r/  z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>\  r0  ru   F)r6  r8  r	   r"  r  s    `rs   _needs_add_bracketsz LatexPrinter._needs_add_bracketsT  sU      	4++++SF+++++ 	4; 	4uru   c                .    |j         D ]}|j        r dS dS )NFT)argsr#  )r   r  r<   s      rs   r  zLatexPrinter._mul_is_cleanb  s.    9 	 	C uutru   c                8    |                      |j                   S r  )r  baser  s     rs   r!  zLatexPrinter._pow_is_cleanh  s    ''	2222ru   r  c                    |	d|d|dS |S )N\left(	\right)^{ro   rp   r   r  exps      rs   _do_exponentzLatexPrinter._do_exponentk  s'     	 	.2ddCCC88Kru   c                                           |j        j                  }|j        r> fd|j        D             }d}|                    |d                    |                    S d                    |          S )Nc                :    g | ]}                     |          S rp   r  )r-  rM   r   s     rs   
<listcomp>z-LatexPrinter._print_Basic.<locals>.<listcomp>t  s#    444Q$++a..444ru   z"\operatorname{{{}}}\left({}\right), z\text{{{}}})_deal_with_super_sub	__class____name__r@  r   join)r   r  namelsrr   s   `    rs   _print_BasiczLatexPrinter._print_Basicq  sw    (()@AA9 	/4444$)444B5A88D$))B--000!((...ru   e!bool | BooleanTrue | BooleanFalsec                    d|z  S N	\text{%s}rp   r   rU  s     rs   _print_boolzLatexPrinter._print_boolz      aru   c                    d|z  S rX  rp   rZ  s     rs   _print_NoneTypezLatexPrinter._print_NoneType  r\  ru   c                   |                      ||          }d}t          |          D ]b\  }}|dk    rn"|                                r	|dz  }| }n|dz  }|                     |          }|                     |          rd|z  }||z  }c|S )N)r   r   r    -  + \left(%s\right))_as_ordered_terms	enumerater5  r  r>  )r   r  r   termsr  r   termterm_texs           rs   
_print_AddzLatexPrinter._print_Add  s    &&t5&99 '' 	 	GAtAv ..00 uuu{{4((H''-- 9-88OCC
ru   c                L   ddl m} |j        dk    rdS  ||          }|j        }|j        }|j        d         |dz
  k    r
||dz
  ggz   }d}|D ](}|t          |                              dd          z  })|                    d	d
          }|                    dd          }|S )Nr   Permutation\left( \right)   r   ,r   r   \left( r   \right)) sympy.combinatorics.permutationsrk  sizecyclic_form
array_formr   r   )r   r  rk  	expr_permsizrg  r   s          rs   _print_CyclezLatexPrinter._print_Cycle  s    @@@@@@9> 	%$${4  $	i?2#') 	0!cAgYK/I 	3 	3AAsE222HH##C44##C44ru   c                    ddl m} ddlm} |j        }| |d| dddd	           n j                            d
d          }|r                     |          S |j        dk    rdS  fd|j	        D             } fdt          t          |                    D             }d                    |          }d                    |          }d                    ||f          }	d|	z  S )Nr   rj  )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   Trl  c                :    g | ]}                     |          S rp   rK  r-  r<   r   s     rs   rL  z3LatexPrinter._print_Permutation.<locals>.<listcomp>  s%    ===cS!!===ru   c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z3LatexPrinter._print_Permutation.<locals>.<listcomp>  s%    ???cS!!???ru    &  \\ z \begin{pmatrix} %s \end{pmatrix})rr  rk  sympy.utilities.exceptionsrz  print_cyclicr   r   rx  rs  ru  rangelenrQ  )
r   r  rk  rz  r   lowerupperrow1row2mats
   `         rs   _print_PermutationzLatexPrinter._print_Permutation  sF   @@@@@@HHHHHH!. 	B%%+6   */+P     .,,]DAAK 	+$$T***9> 	%$$====T_===????U3u::->->???zz%  zz%  llD$<((2S88ru   c                t    |j         \  }}d|                     |          d|                     |          dS )Nz\sigma_{z}(r   )r@  r  )r   r  permvars       rs   _print_AppliedPermutationz&LatexPrinter._print_AppliedPermutation  s>    I	cc%)[[%6%6%6%6C8H8H8H8HIIru   c                0   t          |j                  }| j        d         rdnd}d| j        v r| j        d         nd }d| j        v r| j        d         nd }t          |j        ||||          }| j        d         }d|v r_|                    d          \  }}	|	d	         d
k    r
|	dd          }	| j        d         dk    r|                    dd          }||d|	dS |dk    rdS |dk    rdS | j        d         dk    r|                    dd          }|S )Nr   FTr   r   )strip_zeros	min_fixed	max_fixedr   rU  r   +rn  r   comma.z{,}z10^{ro   z+infz\inftyz-infz- \infty)r#   _precr   mlib_to_str_mpf_splitr   )
r   r  dpsr   lowhighstr_real	separatormantrG  s
             rs   _print_FloatzLatexPrinter._print_Float  sZ   $*%%4>$','>HdnU##D(-(?It~e$$Ttz3ES\`aaa N#=>	(? 	"..--KT31v} !""g~12g= /||C..%)T999ccc:: 	9 	;~12g= 7#++C66Oru   c                    |j         }|j        }|                     |t          d                   d|                     |t          d                   S )Nr
   r   _expr1_expr2r  r"   r   r  vec1vec2s       rs   _print_CrosszLatexPrinter._print_Cross  sU    {{"&"3"3D*U:K"L"L"L"L"&"3"3D*U:K"L"L"LN 	Nru   c                X    |j         }d|                     |t          d                   z  S )Nz\nabla\times %sr
   _exprr  r"   r   r  r   s      rs   _print_CurlzLatexPrinter._print_Curl  s)    j!D$5$5c:e;L$M$MMMru   c                X    |j         }d|                     |t          d                   z  S )Nz\nabla\cdot %sr
   r  r  s      rs   _print_DivergencezLatexPrinter._print_Divergence  s)    j 4#4#4S*U:K#L#LLLru   c                    |j         }|j        }|                     |t          d                   d|                     |t          d                   S )Nr
   r   r  r  s       rs   
_print_DotzLatexPrinter._print_Dot  sU    {{!%!2!24E9J!K!K!K!K!%!2!24E9J!K!K!KM 	Mru   c                X    |j         }d|                     |t          d                   z  S )Nz	\nabla %sr
   r  r   r  funcs      rs   _print_GradientzLatexPrinter._print_Gradient  )    zd//j6GHHHHru   c                X    |j         }d|                     |t          d                   z  S )Nz	\Delta %sr
   r  r  s      rs   _print_LaplacianzLatexPrinter._print_Laplacian  r  ru   r   c                    ddl m ddlm ddlm}  j        d          j        d         d# fd	}d# fd
t          |t                    rG|j	        }|d         t          j        u s!t          d |dd          D                       r |          S d}|                                r| }d}|j        r|dz  }d}nd} ||d          \  }}|t          j        u r)t          ddd          |j	        vr| ||          z  }n ||          }	 ||          }
t!          |
                                          } j        d         } j        d         r:|dk    r4d|
vr0                     |d          r|d|	d|
z  }nn||	d|
z  }nb|St!          |	                                          ||z  k    r*                     |d          r|d|
dd|	dz  }n|j        rt          j        }t          j        }|j	        D ]n}                     |d          sJt!           |||z                                                      ||z  k    s|j        |j        cxu rdu r	n n||z  }i||z  }o                     |d          r%|d  ||          d!|
dd ||          d	z  }n=|d  ||          d!|
d ||          z  }n|d|
d|	z  }n|d |	d!|
dz  }|r|d"z  }|S )$Nr   )Quantity)Prefix)fractionr   r   r   r   c                >   | j         s"t                              |                     S j        dvr|                                 }nt          | j                  }t          |fdd          \  }}t          |fdd          \  }} ||z   |z             S )N)oldnonec                |    t          | f          p)t          | t                    ot          | j                  S r  )
isinstancer   rB  )r.  r  r  s    rs   rt   z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>  s@    z!hPVEW7X7X 8=)!S11  <)!&(;; ru   T)binaryc                $    t          |           S r  )r  )r.  r  s    rs   rt   z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>  s    
1f8M8M ru   )r  r   r  r   as_ordered_factorslistr@  r&   )	r  r@  unitsnonunitsprefixesr  r  convert_argsr   s	        rs   convertz(LatexPrinter._print_Mul.<locals>.convert  s    ; A4;;t,,---:_4 +2244DD	??D #'t .= .= .= .= .=EI#K #K #Kx #'u.M.M.M.MVZ"["["[%#|Hx$7%$?@@@ru   c           	        dx}}t          |           D ]\  }}	                    |          }t          |f          s	                    ||dk    |t	          |           dz
  k              rd|z  }t
          d                             |          r3t
          d                             t          |                    r|z  }n|r|
z  }n|r|
z  }||z  }|}|S )Nr   r   rn  )r9  r:  rb  )	rd  r  r  r;  r  _between_two_numbers_psearchmatchr   )r@  _texlast_term_texr   rf  rg  r  r  	numbersepr   r  s         rs   r  z-LatexPrinter._print_Mul.<locals>.convert_args  s   #%%D=$T?? ) )4;;t,,!$6(:;; &//Q!V673t99q=6H 0 K K A#5#@.q188GG *.q177D		BB* 	) *	) &I%D  (Kru   c              3  @   K   | ]}t          |t                    V  d S r  )r  r   )r-  r<   s     rs   r/  z*LatexPrinter._print_Mul.<locals>.<genexpr>;  s,      &S&S3z#v'>'>&S&S&S&S&S&Sru   rn  F- r   Tr   )exactrm  )evaluater   r      r   )r:  rD  z
\right) / z / z	\frac{1}{ro   rq  \frac{}{r   r   r   )sympy.physics.unitsr  sympy.physics.units.prefixesr  sympy.simplifyr  r   r  r
   r@  r   Oner8  r5  r"  r   r  r  r;  r  is_commutative)r   r  r  r  r@  include_parensr  numerdenomsnumersdenomldenomratioabr.  r  r  r  r  r  s   `               @@@@@rs   
_print_MulzLatexPrinter._print_Mul  s   000000777777++++++(:;	(BC		A 	A 	A 	A 	A 	A 	A 	A 	A 	 	 	 	 	 	 	 	 	 	: dC   	*9DAw!% *3&S&S$qrr(&S&S&S#S#S *#|D)))((** 	5DC{ &s
!%CxD111uAE> +	;c!R%888	I +	; 774== CC WU^^FWU^^F((FN#45E~/0 !;Vq[ !;v%!; ++E+>> 9CfffffEECC88CC ;''%,6; ++E+== MC!66999fff6 6CC\ MAA"Z # #33AE3BB # #GGAaCLL$6$6$8$8 9 9E&L H#!"!1Q5E# # # #IN# # # # # FAAFAA///== J&wqzzzz666999ggajjjj J J &wqzzzz66699ggajjj J J C&&&))VVLLCC666666:: 	3JC
ru   c                    |j         r9|                     |                                                                          S |                     |                                          S r  )
is_aliasedr  as_polyas_exprr  s     rs   _print_AlgebraicNumberz#LatexPrinter._print_AlgebraicNumber{  sL    ? 	/;;t||~~5577888;;t||~~...ru   c                    |                      |j                  }|j        rd| dS |                      |j                                                  }d| d| dS )NrD  rq  rM  )r  pis_inertalphar  )r   r  r  r  s       rs   _print_PrimeIdealzLatexPrinter._print_PrimeIdeal  sh    KK= 	('Q''''DJ..0011,,,e,,,,ru   r   c                   |j         j        r|j         j        }|j         j        }t	          |          dk    rh|dk    rb| j        d         rU|                     |j                  }|dk    rd|z  }n| j        d         rd||fz  }nd||fz  }|j         j        rd|z  S |S | j        d	         r|dk    r| 	                    |j        t          d
                   }|j        j        r|                     |          }|j        j        r!|                     |j        |d|          S |d|d|dS |j         j        r|j        j        r|j        dk    r|j        d|j         dS |j        j        r`|j        j        }|j        j        }||z  t	          |          k    r2|j         dk    r	d|d|dS d|d|dt	          |j                   dS |                     |          S |j        j        r4|                     |j        |                     |j                             S d}|                     ||          S )Nrn  r   r  z	\sqrt{%s}r   z\root{%d}{%s}z\sqrt[%d]{%s}z\frac{1}{%s}r   r   /rG  ^{ro   rm  z\frac{1}{\frac{r  }}z\frac{1}{(\frac{z})^{z%s^{%s})rG  r  r  qr   r   r  rB  is_negativer  r"   	is_Symbolr   r#  r  r  _helper_print_standard_power)r   r  r  r  rB  r  base_pbase_qs           rs   
_print_PowzLatexPrinter._print_Pow  s   8 %	-XZAXZA1vv{ "-qAv "-$.*I "-{{49--6 7&-CC^F+ 7*aY6CC*aY6C8' *S00J 23 -Q -((Ju4EFF9& 922488D9( H;;tyAA6F;GGG(,aaa33% -$)*B -9> >)-DHHH==9( g"&)+F"&)+F#f++5 g8r> g gAG#PPg IOPVPVPVX[\`\dXeXeXeXe#fft,,,9  	E;;tydkk$(.C.C;DDD00s;;;ru   templatec                   |                      |j                  }|                     |j        t          d                   }|j        j        r|                     |          }nct          |j        t                    rI|	                    d          r4t          j        d|          r|                    d          r
|dd         }|||fz  S )Nr   rD  z\\left\(\\d?d?dotrq     i)r  rG  r  rB  r"   r  r   r  r   
startswithr8   r  endswith)r   r  r  rG  rB  s        rs   r  z)LatexPrinter._helper_print_standard_power  s    kk$(##   Ju,=>>9 	**400DDJ// 		**	-t44	 j))	
 2;D4+%%ru   c                B    |                      |j        d                   S Nr   r  r@  r  s     rs   _print_UnevaluatedExprz#LatexPrinter._print_UnevaluatedExpr  s    {{49Q<(((ru   c                    t          |j                  dk    r*dt           fd|j        d         D                       z  }n4 fddt                              dfd|j        D                       z  }t          |j        t                    r!|d	                     |j                  z  z  }n|                     |j                  z  }|S )
Nrn  z\sum_{%s=%s}^{%s} c                :    g | ]}                     |          S rp   rK  r-  r   r   s     rs   rL  z+LatexPrinter._print_Sum.<locals>.<listcomp>  #    >>>!t{{1~~>>>ru   r   c                j    dt          fd| d         | d         | d         fD                       z  S )N%s \leq %s \leq %sc                :    g | ]}                     |          S rp   rK  r-  rr   r   s     rs   rL  zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>  #    FFFa4;;q>>FFFru   rn  r   r  tuplelr   s    rs   _format_ineqz-LatexPrinter._print_Sum.<locals>._format_ineq  E    ,FFFFAaD!A$!3EFFFGGH Hru   z\sum_{\substack{%s}} \\c                &    g | ]} |          S rp   rp   r-  r  r  s     rs   rL  z+LatexPrinter._print_Sum.<locals>.<listcomp>  !    !G!G!Ga,,q//!G!G!Gru   rb  	r  limitsr  r   rQ  r  functionr   r  r   r  r  r  s   `  @rs   
_print_SumzLatexPrinter._print_Sum  s    t{q  		I'>>>>t{1~>>>??@CCH H H H H +!G!G!G!G4;!G!G!GHHIC dmS)) 	.%DM(B(BBBCC4;;t}---C
ru   c                    t          |j                  dk    r*dt           fd|j        d         D                       z  }n4 fddt                              dfd|j        D                       z  }t          |j        t                    r!|d	                     |j                  z  z  }n|                     |j                  z  }|S )
Nrn  z\prod_{%s=%s}^{%s} c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z/LatexPrinter._print_Product.<locals>.<listcomp>  r  ru   r   c                j    dt          fd| d         | d         | d         fD                       z  S )Nr  c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>  r  ru   rn  r   r  r  r  s    rs   r  z1LatexPrinter._print_Product.<locals>._format_ineq  r  ru   z\prod_{\substack{%s}} r  c                &    g | ]} |          S rp   rp   r  s     rs   rL  z/LatexPrinter._print_Product.<locals>.<listcomp>  r  ru   rb  r  r!  s   `  @rs   _print_ProductzLatexPrinter._print_Product  s    t{q  		I(>>>>t{1~>>>??@CCH H H H H ,!G!G!G!G4;!G!G!GHHIC dmS)) 	.%DM(B(BBBCC4;;t}---C
ru   'BasisDependent'c                   ddl m} g }||j        k    r|j        j        S t	          ||          r'|                                                                }nd|fg}|D ]\  }}t          |j                                                  }|	                    d            |D ]\  }}	|	dk    r|
                    d|j        z              )|	dk    r|
                    d|j        z              Md	|                     |	          z   d
z   }
|
                    d|
z   |j        z              d                    |          }|d         dk    r|dd          }n
|dd          }|S )Nr   )Vectorc                6    | d                                          S r  )__str__)r.  s    rs   rt   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>  s    !A$,,.. ru   keyrn  ra  rm  r`  rD  rq  r   -   )sympy.vectorr+  zero_latex_formr  separateitemsr  
componentssortappendr  rQ  )r   r  r+  o1r6  systemvect
inneritemskvarg_stroutstrs               rs   _print_BasisDependentz"LatexPrinter._print_BasisDependent  s   ''''''49 	)9((dF## 	 MMOO))++EEYKE! 
	? 
	?LFDdo335566JOO 8 8O999" ? ?16 ?IIeam34444"W ?IIeam34444'$++a..8:EGIIego=>>>>? ''"++!9 	 ABBZFFABBZFru   c                    |                      |j                  }d|z   dz   dd                    t          | j         |j                            z  z   }|S )Nr   ro   _{%s}ro  )r  rB  rQ  mapindices)r   r  tex_baser  s       rs   _print_IndexedzLatexPrinter._print_Indexed  sU    ;;ty))(l3wT\***, *,  , ,
ru   c                6    |                      |j                  S r  )r  labelr  s     rs   _print_IndexedBasezLatexPrinter._print_IndexedBase  s    {{4:&&&ru   c                Z   |                      |j                  }|j        |                      |j                  }|j        |                      |j                  }n|                      t          j                  }d                    ||          }d                    ||          S |S )Nz%{lower}\mathrel{{..}}\nobreak {upper})r  r  z{{{label}}}_{{{interval}}})rJ  interval)r  rJ  r  r  r   Zeror   )r   r  rJ  r  r  rM  s         rs   
_print_IdxzLatexPrinter._print_Idx  s    DJ'': 		4KK
++Ez ,DJ//AF++@GG!5 H 2 2H/66( 7 4 4 4 ru   c           	        t          |j                  rd}n| j        d         }d}d}t          |j                  D ]u\  }}||z  }|dk    r||d|                     |          z  }.||d|                     |                     |                    d|                     |          dz  }v|dk    r
d	|d
|d}nd	|d|                     |          d|d}t          d |j        D                       r.|d| 	                    |j        t          d         dd          S |d| 	                    |j        t          d         dd          S )Nz\partialr   r   r   rn  r   r  ro   r  r  }}{c              3  >   K   | ]}|                                 V  d S r  r5  r-  r   s     rs   r/  z1LatexPrinter._print_Derivative.<locals>.<genexpr>9  s.      ??q))++??????ru   r
   Tr
  r  F)r    r  r   reversedvariable_countr  r   r8  r@  r  r"   )r   r  diff_symbolr  dimr.  nums          rs   _print_DerivativezLatexPrinter._print_Derivative#  s   DI&& 	@%KK.)>?Kt233 	: 	:FAs3JCax :;;;A??(,(?(?A(O(O(O(O(,C(8(8(8(8: : !8 	O 	O&1kk3337CC	O ,7;;C8H8H8H8H###NC??TY????? 	@"ssD$5$5di2<U2C9=9= %6 %? %? %? @ @
 33 1 1$)2<U2C9>9= !2 !? !? !? @ 	@ru   c                     |j         \  }}}                     |          } fd|D             } fd|D             }d                    d t          ||          D                       }d|d|dS )Nc              3  B   K   | ]}                     |          V  d S r  rK  r-  rU  r   s     rs   r/  z+LatexPrinter._print_Subs.<locals>.<genexpr>G  -      11T[[^^111111ru   c              3  B   K   | ]}                     |          V  d S r  rK  r^  s     rs   r/  z+LatexPrinter._print_Subs.<locals>.<genexpr>H  r_  ru   z\\ c              3  >   K   | ]}|d          dz   |d         z   V  dS )r   =rn  Nrp   )r-  rU  s     rs   r/  z+LatexPrinter._print_Subs.<locals>.<genexpr>I  sL       !B !B"#AaD3J1!B !B !B !B !B !Bru   z\left. z \right|_{\substack{ z }})r@  r  rQ  zip)	r   subsr  r  new
latex_expr	latex_old	latex_new
latex_subss	   `        rs   _print_SubszLatexPrinter._print_SubsD  s    c3[[&&
1111S111	1111S111	[[ !B !B'*9i'@'@!B !B !B B B

9C9CE 	Eru   c           
         dg }} j         d         t          |j                  dk    rTt          d |j        D                       r6ddt          |j                  dz
  z  z   dz   } fd	|j        D             }nt	          |j                  D ]}|d
         }|dz  }t          |          dk    r j         d         dk    r j         d         s|dz  }t          |          dk    r>|d                     |d                   d                     |d                   dz  }t          |          dk    r!|d                     |d                   z  z  }|                    d
d                     |                     |d                     |j        t          d         t          d |j        D                       d          d                    |          S )Nr   r      c              3  <   K   | ]}t          |          d k    V  dS )rn  N)r  )r-  lims     rs   r/  z/LatexPrinter._print_Integral.<locals>.<genexpr>S  s,      (N(N3SQ(N(N(N(N(N(Nru   z\ir   rn  ntc                P    g | ]"}d                      |d                   #S )\, r   rK  )r-  symbolrX  r   s     rs   rL  z0LatexPrinter._print_Integral.<locals>.<listcomp>W  sE     2 2 2!6 &1[$++fQi2H2H2HI 2 2 2ru   r   z\intr   r   r   z\limitsr1  _{}^{r  ro   ^{%s}rq  r   r
   c              3  >   K   | ]}|                                 V  d S r  rS  rT  s     rs   r/  z/LatexPrinter._print_Integral.<locals>.<genexpr>n  s/      >o>o`aq?Y?Y?[?[>o>o>o>o>o>oru   TrU  )r   r  r  allrV  r  insertr  r   r"   r8  r@  rQ  )r   r  r  symbolsrn  rr  rX  s   `     @rs   _print_IntegralzLatexPrinter._print_IntegralN  sA   2Wn%:; t{q  	SS(N(N$+(N(N(N%N%N 	S #s4;//!344t;C2 2 2 2 2%)[2 2 2GG  ,, S SQws88a< 	?~f-9 *$(N6$:*z)3xx1} Dt{{3q6/B/B/B/B/3{{3q6/B/B/B/B D D3xx1} ?w$++c!f*=*=>>qqT[[=P=P=P"QRRRR SS$"3"3DM4>u4E;>>o>oeien>o>o>o;o;o;? #4 #A #A #A  WWW---	/ 	/ru   c                   |j         \  }}}}d|                     |          z  }t          |          dk    s|t          j        t          j        fv r|d|                     |          z  z  }n1||                     |          d|                     |          dz  }t          |t                    r|d|                     |          dS |d|                     |          S )	Nz\lim_{%s \to z+-z%s}r   ro   rD  rq  r   )r@  r  r   r   InfinityNegativeInfinityr  r   )r   r  rU  zz0dirr  s          rs   _print_LimitzLatexPrinter._print_Limitr  s    	1b#Q/s88t 	Craj!2D%EE 	C6DKKOO++CCBS1A1A1A1ABBCa!! 	4+.33A??"ssDKKNNN33ru   r  c                   |                      |          }|                    d          }|                    d          }|t          v rd|z  }nt          |          dk    s!|                    d          s|dk    s|dk    r|}n|dk    r;|dk    r5d|dt          ||                   d	|t          ||          d         }nC|dk    rd|d|         d	||d         }n$|dk    rd|d|         d	||d         }nd
|z  }|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\%srn  r   r   \operatorname{Nro   z\operatorname{%s})rN  findaccepted_latex_functionsr  r  r   )r   r  superscriptidxsubscriptidxrR  s        rs   _hprint_FunctionzLatexPrinter._hprint_Function  s    ((..3yy~~++ 	3D=DDYY!^ 	3tt44 	38I 	3^_`M` 	3DD! 3lQ&6 3 3:#l>:::;;;\.99::;;=  !# 	3 	3.)))))+ ! 3 3,''''') ,d2ru   r   c                <    |j         j        }t           d|z             r2t          |t                    s t           d|z             ||          S  fd|j        D             } j        d         }d} j        d         o3t          |          dk    o  	                    |j        d                    }g d}||v r?|d	k    rn8|d
k    r|d         dk    rdnd|dd         z   }n|dk    r|dd         }d}|d}|r|t          v rd|z  }	nPd|z  }	nJ|3                     |          }
                     |
          }
|
d|d}	n                     |          }	|r|t          v r|	dz  }	n|	dz  }	n|	dz  }	|r
||	d|z  z  }	|	d                    |          z  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                T    g | ]$}t                              |                    %S rp   )r   r  r  s     rs   rL  z0LatexPrinter._print_Function.<locals>.<listcomp>  s-    ???cCC(())???ru   r   Fr   rn  r   )asinacosatanacscasecacotasinhacoshatanhacschasechacothr   fullrm  hararcNpowerTz\%s^{-1}z\operatorname{%s}^{-1}r  ro   z {%s}%s{\left(%s \right)}ru  ro  )r  rP  hasattrr  r   getattrr@  r   r  r$  r  r  r   rQ  )r   r  rG  r  r@  r   inv_trig_power_casecan_fold_bracketsinv_trig_tablerR  func_texs   `          rs   _print_FunctionzLatexPrinter._print_Function  sM    y!4T)** =	)t\22=	)274T!1224===????TY???D "^,<=N"' $/C D !@D		Q!@11$)A,???   N ~% 2!]2 
2#v- 2$(HO>DD$qrr(JDD#w. 28D*.'  2,1)" 
333 <&-DD4t;DD 30066228<<%-XXsss3,,T22  .33 " H$DDEMDD--" 's '3&#((4..((ru   c                F    |                      t          |                    S r  )r  r   r  s     rs   _print_UndefinedFunctionz%LatexPrinter._print_UndefinedFunction  s    $$SYY///ru   c                t    d|                      |j                  d|                      |j                  dS )Nr   z}_{\circ}\left({z}\right))r  r   r  r  s     rs   _print_ElementwiseApplyFunctionz,LatexPrinter._print_ElementwiseApplyFunction  s<     KK&&&&KK	""""
 	
ru   c                ^    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)rU   z\deltar@   \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_functionsrU   )r   r  r  r  r  r  rU   s          rs   _special_function_classesz&LatexPrinter._special_function_classes  s    KKKKKKMMMMMMMM??????FFFFFF??????		I)I*, 	,ru   c                    | j         D ]1}t          ||          r|j        |j        k    r| j         |         c S 2|                     t	          |                    S r  )r  
issubclassrP  r  r   )r   r  clss      rs   _print_FunctionClassz!LatexPrinter._print_FunctionClass  se    1 	; 	;C$$$ ;#,)F ;5c::::$$SYY///ru   c                    |j         \  }}t          |          dk    r|                     |d                   }n"|                     t          |                    }d|d|                     |          d}|S )Nrn  r   rp  z	 \mapsto  \right))r@  r  r  r  )r   r  ry  r  s       rs   _print_LambdazLatexPrinter._print_Lambda	  st    	w<<1 	2kk'!*--GGkk%..11G18$++d:K:K:K:KL
ru   c                    dS )Nz\left( x \mapsto x \right)rp   r  s     rs   _print_IdentityFunctionz$LatexPrinter._print_IdentityFunction  s    ,,ru   c                     t          |j        t                    } fd|D             }dt          |j                                                  dd                    |          d}||d|dS |S )	Nr.  c                @    g | ]}d                      |          z  S )r  rK  )r-  rr  r   s     rs   rL  z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>  s*    BBB654;;v...BBBru   r   rD  rM  rq  r  ro   )sortedr@  r   r   r  r  rQ  )r   r  rG  r@  texargsr  s   `     rs   _hprint_variadic_functionz&LatexPrinter._hprint_variadic_function  s    di%5666BBBBTBBB'*49~~';';'='='='='+yy'9'9'9'9; 	!$ccc**Jru   c                `    d|                      |j        d                   z  }||d|dS |S )Nz\left\lfloor{%s}\right\rfloorr   r  ro   r	  r   r  rG  r  s       rs   _print_floorzLatexPrinter._print_floor$  s>    .TYq\1J1JJ 	!$ccc**Jru   c                `    d|                      |j        d                   z  }||d|dS |S )Nz\left\lceil{%s}\right\rceilr   r  ro   r	  r  s       rs   _print_ceilingzLatexPrinter._print_ceiling,  s>    ,t{{49Q</H/HH 	!$ccc**Jru   c                    | j         d         s$d|                     |j        d                   z  }n#d|                     |j        d                   z  }||d|dS |S )Nr   z\log{\left(%s \right)}r   z\ln{\left(%s \right)}r  ro   )r   r  r@  r  s       rs   
_print_logzLatexPrinter._print_log4  sl    ~m, 	G+dkk$)A,.G.GGCC*T[[1-F-FFC 	!$ccc**Jru   c                `    d|                      |j        d                   z  }||d|dS |S )N\left|{%s}\right|r   r  ro   r	  r  s       rs   
_print_AbszLatexPrinter._print_Abs?  s>    "T[[1%>%>> 	!$ccc**Jru   c                &   | j         d         r0d|                     |j        d         t          d                   z  }n?d                    |                     |j        d         t          d                             }|                     ||          S )Nr   z\Re{%s}r   Atomz\operatorname{{re}}{{{}}}r   r  r@  r"   r   rH  r  s       rs   	_print_rezLatexPrinter._print_reG      >.) 	kt001z&?QRRRCC.55d6G6G	RSV`agVh6i6ijjC  c***ru   c                &   | j         d         r0d|                     |j        d         t          d                   z  }n?d                    |                     |j        d         t          d                             }|                     ||          S )Nr   z\Im{%s}r   r  z\operatorname{{im}}{{{}}}r  r  s       rs   	_print_imzLatexPrinter._print_imO  r  ru   c                   ddl m}m} t          |j        d         |          r!|                     |j        d         d          S t          |j        d         |          r!|                     |j        d         d          S |j        d         j        r#d|                     |j        d                   z  S d|                     |j        d                   z  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   rU  r  r  s       rs   
_print_NotzLatexPrinter._print_NotW  s    ========afQi,, 	M))!&)5KLLLafQi)) 	F&&qvay2DEEEF1I  	7*T[[-C-CCCAF1I 6 666ru   c                F   |d         }|j         r |j        sd|                     |          z  }nd|                     |          z  }|dd          D ]N}|j         r'|j        s |d|d|                     |          dz  }0|d|d|                     |          z  }O|S )Nr   rb  r  rn  r   z \left(rq  )r  is_Notr  )r   r@  charr<   r  s        rs   _print_LogOpzLatexPrinter._print_LogOpb  s    1g> 	+#* 	+$t{{3'7'77CC$++c***C8 	< 	<C~ <cj <t{{37G7G7G7GHHDDD$++c*:*:*:;;
ru   c                d    t          |j        t                    }|                     |d          S )Nr.  z\wedger  r@  r   r  r   rU  r@  s      rs   
_print_AndzLatexPrinter._print_Andq  s-    af"2333  y111ru   c                d    t          |j        t                    }|                     |d          S )Nr.  z\veer  r  s      rs   	_print_OrzLatexPrinter._print_Oru  s-    af"2333  w///ru   c                d    t          |j        t                    }|                     |d          S )Nr.  z\veebarr  r  s      rs   
_print_XorzLatexPrinter._print_Xory  s-    af"2333  z222ru   c                <    |                      |j        |pd          S )Nz\Rightarrow)r  r@  )r   rU  altchars      rs   r  zLatexPrinter._print_Implies}  s      )BNCCCru   c                h    t          |j        t                    }|                     ||pd          S )Nr.  z\Leftrightarrowr  )r   rU  r  r@  s       rs   r  zLatexPrinter._print_Equivalent  s3    af"2333  w'D2DEEEru   c                `    d|                      |j        d                   z  }||d|dS |S )Nz\overline{%s}r   r  ro   r	  r  s       rs   _print_conjugatezLatexPrinter._print_conjugate  s>    TYq\!:!:: 	!$ccc**Jru   c                p    d}d|                      |j        d                   z  }|
|d|d|S ||S )Nz\operatorname{polar\_lift}r  r   r  ro   r	  )r   r  rG  r  r<   s        rs   _print_polar_liftzLatexPrinter._print_polar_lift  sQ    ,#dkk$)A,&?&?? 	)#'44cc22"dCC((ru   c                t    d|                      |j        d                   z  }|                     ||          S )Nze^{%s}r   )r  r@  rH  r  s       rs   _print_ExpBasezLatexPrinter._print_ExpBase  s6     $++dil333  c***ru   c                    dS )NrU  rp   rF  s      rs   _print_Exp1zLatexPrinter._print_Exp1  s    sru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrb  r   zK^{ro   zK%sr	  r  s       rs   _print_elliptic_kzLatexPrinter._print_elliptic_k  sF     4;;ty|#<#<< 	  	 "%##ss++C<ru   c                    d|                      |j        d                   d|                      |j        d                   d}|d|d|S d|z  S )	NrD  r   	\middle| rn  rq  zF^{ro   zF%sr	  r  s       rs   _print_elliptic_fzLatexPrinter._print_elliptic_f  si     [[1&&&&DIaL(A(A(A(AC 	  	 "%##ss++C<ru   c                "   t          |j                  dk    rFd|                     |j        d                   d|                     |j        d                   d}n#d|                     |j        d                   z  }|d|d	|S d
|z  S )Nr  rD  r   r  rn  rq  rb  zE^{ro   zE%sr  r@  r  r  s       rs   _print_elliptic_ezLatexPrinter._print_elliptic_e  s    ty>>Q 	A 	ATYq\****DKK	!,E,E,E,EGCC %t{{49Q<'@'@@C 	  	 "%##ss++C<ru   c           	        t          |j                  dk    rgd|                     |j        d                   d|                     |j        d                   d|                     |j        d                   d}nEd|                     |j        d                   d|                     |j        d                   d}|d	|d
|S d|z  S )Nr1  rD  r   ; rn  r  r  rq  z\Pi^{ro   z\Pi%sr  r  s       rs   _print_elliptic_pizLatexPrinter._print_elliptic_pi  s    ty>>Q 	G 	GTYq\****DKK	!,E,E,E,ETYq\****,CC	G TYq\****DKK	!,E,E,E,EGC 	" 	"$'CC--c>!ru   c                    d|                      |j        d                   d|                      |j        d                   d}|d|d|S d|z  S )	NrD  r   rM  rn  rq  z\operatorname{B}^{ro   z\operatorname{B}%sr	  r  s       rs   _print_betazLatexPrinter._print_beta  sm     (,DIaL(A(A(A(A(,DIaL(A(A(A(AC  	/ 	/14cc::(3..ru   Bc           
           fd|j         D             }d|d         d|d         d}|d|d|d	         d|d
         d|d|
S d|d|d	         d|d
         d|S )Nc                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z/LatexPrinter._print_betainc.<locals>.<listcomp>  s%    777cS!!777ru   rD  r   rM  rn  rq  r  z}_{(r  r1  z)}^{ro   z)})r@  )r   r  rG  operatorlargsr  s   `     rs   _print_betainczLatexPrinter._print_betainc  s    7777TY777(-a%(((; 	[ 	[=EXXuQxxxQVWXQYQYQY[^[^[^`c`cdd	[ 9A%(((ERSHHHVYVYZZru   c                2    |                      ||d          S )NI)r  )r  rF  s      rs   _print_betainc_regularizedz'LatexPrinter._print_betainc_regularized  s    ""4s";;;ru   c                    d|                      |j        d                   d|                      |j        d                   d}|d|d|S d|z  S )	NrD  r   rM  rn  rq  z\Gamma^{ro   z\Gamma%sr	  r  s       rs   _print_uppergammazLatexPrinter._print_uppergamma  m     (,DIaL(A(A(A(A(,DIaL(A(A(A(AC  	% 	%'*ssCC00$$ru   c                    d|                      |j        d                   d|                      |j        d                   d}|d|d|S d|z  S )	NrD  r   rM  rn  rq  z\gamma^{ro   \gamma%sr	  r  s       rs   _print_lowergammazLatexPrinter._print_lowergamma  r  ru   c                    d|                      |j        d                   z  }|"|                      |j                  d|d|S |                      |j                  |S Nrb  r   r  ro   )r  r@  r  r  s       rs   _hprint_one_arg_funcz!LatexPrinter._hprint_one_arg_func  sk     4;;ty|#<#<< 	;#';;ty#9#9#9#9333DD"kk$)444cc::ru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrb  r   z\operatorname{Chi}^{ro   z\operatorname{Chi}%sr	  r  s       rs   
_print_ChizLatexPrinter._print_Chi  sG     4;;ty|#<#<< 	1 	13633<<*S00ru   c                    d|                      |j        d                   z  }|                      |j        d                   }|d|d|d|S d|d|S )Nrb  rn  r   z\operatorname{E}_{rt  ro   r	  )r   r  rG  r  nus        rs   _print_expintzLatexPrinter._print_expint  sq     4;;ty|#<#<<[[1&& 	: 	:68bb###ssCC	: 24SS99ru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrb  r   zS^{ro   zS%sr	  r  s       rs   _print_fresnelszLatexPrinter._print_fresnels  F     4;;ty|#<#<< 	  	 "%##ss++C<ru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrb  r   zC^{ro   zC%sr	  r  s       rs   _print_fresnelczLatexPrinter._print_fresnelc  r  ru   c                z    d|                      |j        d         t          d                   z  }|	d|d|dS |S )Nz!%sr   FuncrD  rE  ro   r  r@  r"   r  s       rs   _print_subfactorialz LatexPrinter._print_subfactorial  sL    t((1z&7IJJJ 	 	.1cc33377Jru   c                x    d|                      |j        d         t          d                   z  }||d|dS |S )Nz%s!r   r   r  ro   r!  r  s       rs   _print_factorialzLatexPrinter._print_factorial  sG    t((1z&7IJJJ 	!$ccc**Jru   c                x    d|                      |j        d         t          d                   z  }||d|dS |S )Nz%s!!r   r   r  ro   r!  r  s       rs   _print_factorial2zLatexPrinter._print_factorial2'  sG    ))$)A,
68JKKK 	!$ccc**Jru   c                    d|                      |j        d                   d|                      |j        d                   d}||d|dS |S )Nz{\binom{r   r  rn  r  r  ro   r	  r  s       rs   _print_binomialzLatexPrinter._print_binomial/  sd     %)[[1%>%>%>%>%)[[1%>%>%>%>@  	!$ccc**Jru   c                    |j         \  }}d|                     |t          d                   z  }d|d|                     |          d}|                     ||          S )Nr  r   r   	}^{\left(\right)}r@  r  r"   r  rH  )r   r  rG  nr>  rB  r  s          rs   _print_RisingFactorialz#LatexPrinter._print_RisingFactorial8  s`    y1t((Jv,>???+/44Q@  c***ru   c                    |j         \  }}d|                     |t          d                   z  }d|                     |          d|d}|                     ||          S )Nr  r   z{\left(z
\right)}_{ro   r,  )r   r  rG  r-  r>  subr  s          rs   _print_FallingFactorialz$LatexPrinter._print_FallingFactorial@  s`    y1d'':f+=>>>+/;;q>>>>333?  c***ru   symc                   d|z  }d}|$|                     d          dk    r	|d|d}nd}|d|                     |j                  d	|                     |j                  d
}|r|                     ||          }|S )Nr  Fr   rm  r  ro   Trs  }\left(rq  )r  r  r   argumentrH  )r   r  rG  r2  r  need_exps         rs   _hprint_BesselBasezLatexPrinter._hprint_BesselBaseH  s    sm 	 xx}}"  $'CC-+.33DJ0G0G0G0G+/;;t}+E+E+E+EG  	.##C--C
ru   c                    |sdS d}|d d         D ]}|d|                      |          z  z  }||                      |d                   z  }|S )Nr   rm  z%s, rK  )r   r   rr   r   s       rs   _hprint_veczLatexPrinter._hprint_vecY  se     	2SbS 	) 	)A$++a..((AA	T[[R!!!ru   c                0    |                      ||d          S )NJr7  rF  s      rs   _print_besseljzLatexPrinter._print_besseljb      &&tS#666ru   c                0    |                      ||d          S )Nr
  r<  rF  s      rs   _print_besselizLatexPrinter._print_besselie  r>  ru   c                0    |                      ||d          S )NKr<  rF  s      rs   _print_besselkzLatexPrinter._print_besselkh  r>  ru   c                0    |                      ||d          S )NYr<  rF  s      rs   _print_besselyzLatexPrinter._print_besselyk  r>  ru   c                0    |                      ||d          S )Nyr<  rF  s      rs   	_print_ynzLatexPrinter._print_ynn  r>  ru   c                0    |                      ||d          S )Nr   r<  rF  s      rs   	_print_jnzLatexPrinter._print_jnq  r>  ru   c                0    |                      ||d          S )NzH^{(1)}r<  rF  s      rs   _print_hankel1zLatexPrinter._print_hankel1t      &&tS)<<<ru   c                0    |                      ||d          S )NzH^{(2)}r<  rF  s      rs   _print_hankel2zLatexPrinter._print_hankel2w  rN  ru   c                0    |                      ||d          S )Nzh^{(1)}r<  rF  s      rs   
_print_hn1zLatexPrinter._print_hn1z  rN  ru   c                0    |                      ||d          S )Nzh^{(2)}r<  rF  s      rs   
_print_hn2zLatexPrinter._print_hn2}  rN  ru   r   c                l    d|                      |j        d                   z  }|
|d|d|S ||S r  r	  r   r  rG  notationr  s        rs   _hprint_airyzLatexPrinter._hprint_airy  sL     4;;ty|#<#<< 	-#+88SSS##66&h,,ru   c                p    d|                      |j        d                   z  }|d|d|d|S |d|S )Nrb  r   r   z
^\prime}^{ro   z^\primer	  rV  s        rs   _hprint_airy_primezLatexPrinter._hprint_airy_prime  sS     4;;ty|#<#<< 	4 	4,4HHccc33??%-XXss33ru   c                0    |                      ||d          S NAirX  rF  s      rs   _print_airyaizLatexPrinter._print_airyai        sD111ru   c                0    |                      ||d          S NBir^  rF  s      rs   _print_airybizLatexPrinter._print_airybi  r`  ru   c                0    |                      ||d          S r\  rZ  rF  s      rs   _print_airyaiprimezLatexPrinter._print_airyaiprime      &&tS$777ru   c                0    |                      ||d          S rb  rf  rF  s      rs   _print_airybiprimezLatexPrinter._print_airybiprime  rh  ru   c                d   d|                      t          |j                            d|                      t          |j                            d|                     |j                  d|                     |j                  d|                      |j                  d}|	d|d|d	}|S )
Nz{{}_{z}F_{}\left(\begin{matrix} r  z \end{matrix}\middle| {
} \right)}r   rt  ro   )r  r  apbqr9  r5  r  s       rs   _print_hyperzLatexPrinter._print_hyper  s      [[TW&&&&CLL(A(A(A(Atw'''')9)9$')B)B)B)Bkk$-((((	*  	, 	,"%##sss+C
ru   c                p   d|                      t          |j                            d|                      t          |j                            d|                      t          |j                            d|                      t          |j                            d|                     |j                  d|                     |j                  d|                     |j                  d|                     |j                  d|                      |j	                  d}|	d	|d|d
}|S )Nz{G_{rM  rt  rl  r   \\z \end{matrix} \middle| {rm  r   ro   )
r  r  rn  ro  r   anr9  aotherbotherr5  r  s       rs   _print_meijergzLatexPrinter._print_meijerg  s     [[TW&&&&CLL(A(A(A(Akk#dg,,''''S\\)B)B)B)Btw'''')9)9$+)F)F)F)Ftw'''')9)9$+)F)F)F)Fkk$-((((*  	, 	,"%##sss+C
ru   c                f    d|                      |j        d                   z  }|d|d|S d|z  S )Nrb  r   z\eta^{ro   z\eta%sr	  r  s       rs   _print_dirichlet_etaz!LatexPrinter._print_dirichlet_eta  sF     4;;ty|#<#<< 	/ 	/%(SS##..3ru   c                    t          |j                  dk    r+dt          t          | j        |j                            z  }n#d|                     |j        d                   z  }|d|d|S d|z  S )Nr  z\left(%s, %s\right)rb  r   z\zeta^{ro   z\zeta%sr  r@  r  rE  r  r  s       rs   _print_zetazLatexPrinter._print_zeta  s    ty>>Q 	A(5T[$)1L1L+M+MMCC$t{{49Q<'@'@@C 	0 	0&)cc33//Cru   c                    t          |j                  dk    r+dt          t          | j        |j                            z  }n#d|                     |j        d                   z  }|	d|d|dS d|z  S )	Nr  z_{%s}\left(%s\right)rD  r   r  r  ro   r  rz  r  s       rs   _print_stieltjeszLatexPrinter._print_stieltjes  s    ty>>Q 	7)E#dk492M2M,N,NNCCT[[1666C 	1 	1'*ssCCC00S  ru   c                t    dt          t          | j        |j                            z  }|d|z  S d|d|S )Nz\left(%s, %s, %s\right)z\Phi%sz\Phi^{ro   )r  rE  r  r@  r  s       rs   _print_lerchphizLatexPrinter._print_lerchphi  sJ    (5T[$)1L1L+M+MM 	#s?"	#!$cc**ru   c                p    t          | j        |j                  \  }}d|z  }|d|d|S d|d|d|S )Nrb  z\operatorname{Li}_{ro   rt  rE  r  r@  )r   r  rG  rr   r~  r  s         rs   _print_polylogzLatexPrinter._print_polylog  s]    4;	**1 1$ 	: 	:23!!SS99	:3411ccc33??ru   c           	     |    t          | j        |j                  \  }}}}d|d|d|d|d	}|d|z   d|z  z   }|S )NP_{r*  ro  \right)}\left(rq  rD  \right)^{%s}r  )r   r  rG  r-  r  r  r.  r  s           rs   _print_jacobizLatexPrinter._print_jacobi  s]    di00
1a?@qq!!!QQQJ 	<c/Os$;;C
ru   c                t    t          | j        |j                  \  }}}d|d|d|d}|d|z   d|z  z   }|S )NzC_{r*  r  rq  rD  r  r  r   r  rG  r-  r  r.  r  s          rs   _print_gegenbauerzLatexPrinter._print_gegenbauer  U    dk49--1aa<=AAqqq!!!D 	<c/Os$;;C
ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )NzT_{r4  rq  rD  r  r  r   r  rG  r-  r.  r  s         rs   _print_chebyshevtzLatexPrinter._print_chebyshevt  M    4;	**11*+!!QQQ/ 	<c/Os$;;C
ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )NzU_{r4  rq  rD  r  r  r  s         rs   _print_chebyshevuzLatexPrinter._print_chebyshevu  r  ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )Nr  r4  rq  rD  r  r  r  s         rs   _print_legendrezLatexPrinter._print_legendre  r  ru   c                t    t          | j        |j                  \  }}}d|d|d|d}|d|z   d|z  z   }|S )Nr  r*  r  rq  rD  r  r  r  s          rs   _print_assoc_legendrez"LatexPrinter._print_assoc_legendre  r  ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )NzH_{r4  rq  rD  r  r  r  s         rs   _print_hermitezLatexPrinter._print_hermite  r  ru   c                l    t          | j        |j                  \  }}d|d|d}|d|z   d|z  z   }|S )NL_{r4  rq  rD  r  r  r  s         rs   _print_laguerrezLatexPrinter._print_laguerre
  r  ru   c                t    t          | j        |j                  \  }}}d|d|d|d}|d|z   d|z  z   }|S )Nr  r*  r  rq  rD  r  r  r  s          rs   _print_assoc_laguerrez"LatexPrinter._print_assoc_laguerre  r  ru   c           	     |    t          | j        |j                  \  }}}}d|d|d|d|d	}|d|z   d|z  z   }|S )NzY_{rt  r4  ro  rq  rD  r  r  r   r  rG  r-  mthetaphir  s           rs   
_print_YnmzLatexPrinter._print_Ynm  ^    t{DI661eSS23!!QQQsssC 	<c/Os$;;C
ru   c           	     |    t          | j        |j                  \  }}}}d|d|d|d|d	}|d|z   d|z  z   }|S )NzZ_{rt  r4  ro  rq  rD  r  r  r  s           rs   
_print_ZnmzLatexPrinter._print_Znm  r  ru   c           
     v    t          | j        |          \  }}}|rdnd}|sdnd|z  }||d|d|d|d|
S )Nz	^{\prime}r   ru  rD  rM  rq  )rE  r  )	r   	characterr@  r   rG  r  r  r~  sups	            rs   __print_mathieu_functionsz&LatexPrinter.__print_mathieu_functions&  s`    dk4((1a#+ll.bb33<9ccc111aaaCCPPru   c                <    |                      d|j        |          S )NCr  &_LatexPrinter__print_mathieu_functionsr@  rF  s      rs   _print_mathieuczLatexPrinter._print_mathieuc,      --c49#-FFFru   c                <    |                      d|j        |          S )Nr   r  r  rF  s      rs   _print_mathieuszLatexPrinter._print_mathieus/  r  ru   c                >    |                      d|j        d|          S )Nr  Tr   rG  r  rF  s      rs   _print_mathieucprimez!LatexPrinter._print_mathieucprime2  !    --c49Dc-RRRru   c                >    |                      d|j        d|          S )Nr   Tr  r  rF  s      rs   _print_mathieusprimez!LatexPrinter._print_mathieusprime5  r  ru   c                    |j         dk    r@d}|j        }|j        dk     rd}| }| j        d         rd|||j         fz  S d|||j         fz  S |                     |j                  S )Nrn  r   r   r  r   z	%s%d / %dz%s\frac{%d}{%d})r  r  r   r  )r   r  signr  s       rs   _print_RationalzLatexPrinter._print_Rational8  s    6Q; 
	'DAvz B~/0 8#tQ&777%q$&(999;;tv&&&ru   c                @   |                      |j                  }|j        rt          d |j        D                       st	          |j                  dk    r|dz  }t	          |j                  dk    r||                      |j                  z  }n*|j        r#||                      |j        d                   z  }|dz  }t	          |j                  dk    r||                      |j                  z  }n#||                      |j        d                   z  }d|z  S )Nc              3  6   K   | ]}|t           j        k    V  d S r  )r   rN  )r-  r  s     rs   r/  z,LatexPrinter._print_Order.<locals>.<genexpr>G  s(      >>aa16k>>>>>>ru   rn  r  r   \rightarrow zO\left(%s\right))r  r  pointr8  r  	variables)r   r  rr   s      rs   _print_OrderzLatexPrinter._print_OrderE  s   KK	"": 	0#>>4:>>>>> 	0t~"	0IA4>""Q& 4T[[000 4T[[!2333 A4:" 0T[[,,,T[[A///"Q&&ru   r   c                    | j         d                             |          }||S |                     |j        |          S )Nr   style)r   r   rN  rR  )r   r  r  rR  s       rs   _print_SymbolzLatexPrinter._print_SymbolU  sD    N>266t<< 	K((%(@@@ru   stringc                :   d|v r|g g }}}n:t          |          \  }}}t          |          }d |D             }d |D             }|dk    rd                    |          }|r|dd                    |          z  z  }|r|dd                    |          z  z  }|S )	Nr   c                ,    g | ]}t          |          S rp   	translater-  r  s     rs   rL  z5LatexPrinter._deal_with_super_sub.<locals>.<listcomp>e      777inn777ru   c                ,    g | ]}t          |          S rp   r  r-  r0  s     rs   rL  z5LatexPrinter._deal_with_super_sub.<locals>.<listcomp>f      333sIcNN333ru   r   \mathbf{{{}}}ru  r   rD  )r   r  r   rQ  )r   r  r  rR  supersrd  s         rs   rN  z!LatexPrinter._deal_with_super_sub^  s    &= 	4!'R$&DD!0!8!8D&$T??D77777F33d333D F? 	1#**400D  	/Gchhv....D 	-Gchhtnn,,Dru   c                    | j         d         rd}d}nd}d}d||ddd	d
}|                     |j                  d||j                 d|                     |j                  S )Nr   z\gtz\lt><rb  z\geqz\leqz\neq)z==r  r  z>=z<=z!=r   )r   r  lhsrel_oprhs)r   r  gtltcharmaps        rs   _print_RelationalzLatexPrinter._print_Relationalt  s    >&! 	BBBBB 
 
 "[[2222$T[1114;;tx3H3H3HJ 	Jru   c                     fd|j         d d         D             }|j         d         j        t          k    r<|                    d                     |j         d         j                  z             n`|                                         |j         d         j                  d                     |j         d         j                             d}|d                    |          z  S )Nc                p    g | ]2\  }}                     |          d                      |          3S ) & \text{for}\: rK  )r-  rU  r   r   s      rs   rL  z1LatexPrinter._print_Piecewise.<locals>.<listcomp>  sL     / / /q! /3kk!nnnndkk!nnnM / / /ru   rm  z%s & \text{otherwise}r  z\begin{cases} %s \end{cases}rr  )r@  condr   r9  r  r  rQ  )r   r  ecpairsr  s   `   rs   _print_PiecewisezLatexPrinter._print_Piecewise  s    / / / /#y"~/ / /9R=% 	>NN3;;ty}'9::; < < < < NN KK	"(:;;;; KK	"(:;;;= > > > .V[[))))ru   c           
         g }t          |j                  D ]@}|                    d                     fd||d d f         D                                  A j        d         }|& j        d         dk    rd}n|j        dk    du rd	}nd
}d}|                    d|          }|d
k    r$|                    ddd|j        z  z   dz             }|d                    |          z  S )Nr  c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>  s#    $K$K$KT[[^^$K$K$Kru   r   r   r   smallmatrix
   Tmatrixarray \begin{%MATSTR%}%s\end{%MATSTR%}%MATSTR%r  r   r   z}%sr  )r  rowsr9  rQ  r   colsr   )r   r  linesliner   out_strs   `     rs   _print_matrix_contentsz#LatexPrinter._print_matrix_contents  s   $)$$ 	N 	NDLL$K$K$K$KT$']$K$K$KLLMMMM.+ 	&~f%1 &'IO, &&GG%G5//*g66g 	IoodC#di-,?%,GHHGE****ru   c                    |                      |          }| j        d         r(| j        d         }| j        |         }d|z   |z   dz   |z   }|S )Nr   \left\right)r  r   r   )r   r  r  
left_delimright_delims        rs   _print_MatrixBasezLatexPrinter._print_MatrixBase  sa    --d33>+& 	."n[9J*:6K+g5 "-.Gru   c                    |                      |j        t          d         d          d|                     |j                  d|                     |j                  dz   S )Nr  Tr  rs  rM  ro   )r  parentr"   r  r   r   r  s     rs   _print_MatrixElementz!LatexPrinter._print_MatrixElement  s`      j.@ NNN![[0000$++df2E2E2E2EFG 	Gru   c                      fd}                      |j        t          d         d          dz    ||j        |j        j                  z   dz    ||j        |j        j                  z   dz   S )Nc                    t          |           } | d         dk    r| d= | d         dk    rd | d<   | d         |k    rd | d<   d                    fd| D                       S )Nr  rn  r   :c              3  J   K   | ]}|                     |          ndV  d S Nr   rK  )r-  xir   s     rs   r/  zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>  s6      RR"rEDKKOOO2RRRRRRru   )r  rQ  )r.  rY  r   s     rs   
latexslicez3LatexPrinter._print_MatrixSlice.<locals>.latexslice  s    QAtqy aDtqy !ts{ !88RRRRPQRRRRRRru   r  Tr  \left[rM  \right])r  r  r"   rowslicer  colslicer  )r   r  r  s   `  rs   _print_MatrixSlicezLatexPrinter._print_MatrixSlice  s    	S 	S 	S 	S 	S !!$+z&/A$!OOR[[
4=$+*:;;<>BC
4=$+*:;;<>HI 	Jru   c                6    |                      |j                  S r  )r  blocksr  s     rs   _print_BlockMatrixzLatexPrinter._print_BlockMatrix  s    {{4;'''ru   c                   |j         }ddlm}m} t	          ||          s/t	          ||          s|j        rd|                     |          z  S |                     |t          |          d          }d|v rd|z  S d|z  S )Nr   MatrixSymbolBlockMatrixz\left(%s\right)^{T}Tr   z%s^{T}	r<   sympy.matricesr
  r  r  is_MatrixExprr  r  r   r   r  r  r
  r  rr   s         rs   _print_TransposezLatexPrinter._print_Transpose  s    h<<<<<<<<3-- 	$3,,	$141B	$)DKK,<,<<<!!#'=d'C'CTJJAax $-11!|#ru   c                @    |j         }d|                     |          z  S )Nz!\operatorname{tr}\left(%s \right))r<   r  r   r  r  s      rs   _print_TracezLatexPrinter._print_Trace  s     h3dkk#6F6FFFru   c                   |j         }ddlm}m} t	          ||          s/t	          ||          s|j        rd|                     |          z  S |                     |t          |          d          }d|v rd|z  S d|z  S )Nr   r	  z\left(%s\right)^{\dagger}Tr   z%s^{\dagger}r  r  s         rs   _print_AdjointzLatexPrinter._print_Adjoint  s    h<<<<<<<<3-- 	+3,,	+141B	+/$++c2B2BBB!!#'=d'C'CTJJAax +3a77&**ru   c                J    ddl m  fd}t          j                  }                                rI|d         dk    r|dd          }n|d          |d<   dd                    t          ||                    z   S d                    t          ||                    S )Nr   )MatMulc                    t          | t                    r%t          |           s                    |           n#                    | t	                    d          S NF)r  r
   r  r  r   )r.  r  r  r   s    rs   rt   z,LatexPrinter._print_MatMul.<locals>.<lambda>  sZ    Z3-?-? F
STV\H]H] F4;;q>>>a!7!=!=uEE ru   rm  rn  r  r   )sympyr  r  r@  r5  rQ  rE  )r   r  parensr@  r  s   ``  @rs   _print_MatMulzLatexPrinter._print_MatMul  s          F F F F F F DI((** 	/Aw"} #ABBx7(Q#((3vt#4#4555588C--...ru   c                    |j         }|j        rKddlm} t	          ||          rd|                     |j                  z  S d|                     |          z  S d|                     |          z  S )Nr   )r  r  )r<   r  &sympy.matrices.expressions.blockmatrixr  r  r  r  r  )r   r  r  r  s       rs   _print_DeterminantzLatexPrinter._print_Determinant  s    h 	;JJJJJJ#{++ V+d.I.I#*.U.UUU'$++c*:*:::#d&A&A#&F&FFFru   c                   |dd|                      |j        d         t          d         d          d|                      |j        d         t          d         d          d|d	S |                      |j        d         t          d         d          d|                      |j        d         t          d         d          S )
NrD  r   r
   Tr  z \bmod rn  rE  ro   r!  rF  s      rs   
_print_ModzLatexPrinter._print_Mod  s    	 	""49Q<E1B*. # 0 0 0 0""49Q<E1B*. # 0 0 0 0  "&!2!249Q<3=e3D:> "3 "@ "@ "@ "@ "&!2!249Q<3=e3D:> "3 "@ "@ "@A 	Aru   c                    |j         }t          d         | j        d                    t	          fd|                    S )Nr   z \circ c                      | d          S NTr  rp   r<   r  precs    rs   rt   z5LatexPrinter._print_HadamardProduct.<locals>.<lambda>      FF3T::: ru   r@  r"   r  rQ  rE  r   r  r@  r  r&  s      @@rs   _print_HadamardProductz#LatexPrinter._print_HadamardProduct  sP    y% ":::::DAAC C 	Cru   c                ~    t          |j                  t          d         k     rd}nd}|                     ||          S )Nr
   z%s^{\circ \left({%s}\right)}z%s^{\circ {%s}})r   rG  r"   r  )r   r  r  s      rs   _print_HadamardPowerz!LatexPrinter._print_HadamardPower  s@    !$(++j.?? 	*6HH)H00x@@@ru   c                    |j         }t          d         | j        d                    t	          fd|                    S )Nr   	 \otimes c                      | d          S r$  rp   r%  s    rs   rt   z6LatexPrinter._print_KroneckerProduct.<locals>.<lambda>&  r'  ru   r(  r)  s      @@rs   _print_KroneckerProductz$LatexPrinter._print_KroneckerProduct   sR    y% "  :::::DAAC C 	Cru   c                V   |j         |j        }}ddlm} t	          ||          s6|j        r/d|                     |          d|                     |          dS |                     |          }d|v rd|d|                     |          dS |d|                     |          dS )Nr   )r
  rD  rE  ro   r   r  )rB  rG  r  r
  r  r  r  )r   r  rB  rG  r
  base_strs         rs   _print_MatPowzLatexPrinter._print_MatPow(  s    Itxc//////$-- 	@$2D 	@ 	@/3{{4/@/@/@/@.2kk#.>.>.>.>@ @ {{4((Hh @ @2:((DKK<L<L<L<LMM$,HHdkk#.>.>.>.>??ru   c                F    |                      || j        d                   S )Nr   r  )r  r   r  s     rs   _print_MatrixSymbolz LatexPrinter._print_MatrixSymbol5  s+    !!$dn/ ! ! ! 	!ru   c                ,    | j         d         dk    rdndS )Nr   r   0z
\mathbf{0}r   )r   Zs     rs   _print_ZeroMatrixzLatexPrinter._print_ZeroMatrix9  (    n #*+ >ss0=	>ru   c                ,    | j         d         dk    rdndS )Nr   r   1z
\mathbf{1}r8  )r   Os     rs   _print_OneMatrixzLatexPrinter._print_OneMatrix=  r;  ru   c                ,    | j         d         dk    rdndS )Nr   r   z
\mathbb{I}z
\mathbf{I}r8  )r   r
  s     rs   _print_IdentityzLatexPrinter._print_IdentityA  s(     $! #*!+ >}}0=	>ru   c                L    |                      |j        d                   }d|z  S )Nr   zP_{%s}r	  )r   Pperm_strs      rs   _print_PermutationMatrixz%LatexPrinter._print_PermutationMatrixE  s$    ;;qvay))(""ru   r   c           
        |                                 dk    r|                     |d                   S | j        d         }|B| j        d         dk    rd}n.|                                 dk    s|j        d         dk    rd	}nd
}d}|                    d|          }|d
k    r|                    dd          }| j        d         r(| j        d         }| j        |         }d|z   |z   dz   |z   }|                                 dk    r|dz  S d t          |                                 dz             D             }d |j        D             }t          j        | D ]C}|d         	                    |                     ||                              d}	t          |                                 dz
  dd          D ]}
t          ||
dz                      |j        |
         k     r n|	r8||
         	                    d                    ||
dz                                 ns||
         	                    |d                    ||
dz                      z             t          ||
dz                      dk    rd||
         d         z   dz   ||
         d<   |	 }	g ||
dz   <   E|d         d         }|                                 dz  dk    r||z  }|S )Nr   rp   r   r   r   r  rm  r  r  r  r  r  r  z{}%sr   r  r  r   c                    g | ]}g S rp   rp   rT  s     rs   rL  z1LatexPrinter._print_NDimArray.<locals>.<listcomp>d  s    %I%I%IQb%I%I%Iru   rn  c                F    g | ]}t          t          |                    S rp   )r  r  rT  s     rs   rL  z1LatexPrinter._print_NDimArray.<locals>.<listcomp>e  s$    ;;;1U1XX;;;ru   Tr  r  r   r  r  )rankr  r   shaper   r   r  	itertoolsproductr9  r  rQ  )r   r  r   	block_strr  r  	level_strshape_rangesouter_ievenback_outer_ir  s               rs   _print_NDimArrayzLatexPrinter._print_NDimArrayI  s!   99;;! 	);;tBx(((.+ 	&~f%1 &'IIKK1$ &$*R.B*> &&GG%G7	%%j'::	g 	6 ((f55I>+& 	0"n[9J*:6K :-	9!"$/0I 99;;! 	"r>!%I%I%		a2H2H%I%I%I	;;
;;; (,7 	/ 	/GbM  T']!;!;<<<D %diikk!mR < < / /ya011DJ|4LL E El+22Il1n$=>>@ @ @ @ l+22!UZZ	,q.0I%J%JKM M M9\!^455: E6?%l3B778:D7E	,/3x,.	,q.))A,q/99;;?a 	*')Gru   	index_mapdictc                `   |                      |          }d }d }|D ]}|j        }||v s|r||k    r|dz  }||k    r||dz  }|j        r|dz  }n|dz  }||                      |j        d                   z  }||v r&|dz  }||                      ||                   z  }d}nd}|}||dz  }|S )	Nro  ro   z{}^{z{}_{r   rb  TF)r  is_upr@  )	r   rR  rF  rT  r  last_valenceprev_mapindexnew_valences	            rs   _printer_tensor_indicesz$LatexPrinter._printer_tensor_indices  s   ++d## 	' 	'E+K)#   K/3{* & #sNG; &v%GGv%Gt{{5:a=111G	! !34;;y'7888 &LL 	sNGru   c                    |j         d         j         d         }|                                }|                     ||i           S r  )r@  get_indicesr\  )r   r  rR  rF  s       rs   _print_TensorzLatexPrinter._print_Tensor  s>    y| #""$$++D'2>>>ru   c                    |j         j        d         j        d         }|j                                         }|j        }|                     |||          S r  )r  r@  r^  rT  r\  )r   r  rR  rF  rT  s        rs   _print_TensorElementz!LatexPrinter._print_TensorElement  sJ    y~a %a()''))N	++D'9EEEru   c                ~                                      \  }}|d                     fd|D                       z   S )Nr   c                V    g | ]%}                     |t                              &S rp   )r  r!   )r-  r<   r  r   s     rs   rL  z/LatexPrinter._print_TensMul.<locals>.<listcomp>  s1    FFF#TsJt$4$455FFFru   )!_get_args_for_traditional_printerrQ  )r   r  r  r@  s   ``  rs   _print_TensMulzLatexPrinter._print_TensMul  sP    ;;==
dbggFFFFFFFF
 
 
 	
ru   c           	        g }|j         }|D ]8}|                    |                     |t          |                               9|                                 d                    |          }|                    dd          }|S )Nra  z+ -r  )r@  r9  r  r!   r8  rQ  r   )r   r  r  r@  r.  rr   s         rs   _print_TensAddzLatexPrinter._print_TensAdd  s~    y 	= 	=AHHT&&q*T*:*:;;<<<<	JJqMMIIeT""ru   c                b    d|j         rdndd|                     |j        d                   dS )Nz{}r   r  r   r   ro   )rW  r  r@  r  s     rs   _print_TensorIndexzLatexPrinter._print_TensorIndex  s=     :&CC3&&KK	!%%%%
 	
ru   c           
         t          |j                  dk    rLd                     |j        d                   d                     |j        t
          d         d          dS dt          |j                  dd	                     fd
|j        D                       d                     |j        t
          d         d          dS )Nrn  z\frac{\partial}{\partial {r   rQ  r
   Fro   z\frac{\partial^{r   c                @    g | ]}d                      |          z  S )z\partial {%s}rK  r  s     rs   rL  z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>  s)    TTT*T[[^^;TTTru   r  )r  r  r  r  r  r"   rQ  r  s   ` rs   _print_PartialDerivativez%LatexPrinter._print_PartialDerivative  s    t~!# 
	 
	DN1-....!!$)Z->FFFF 
	 DN####TTTTT^TTTUUUU!!$)Z->FFFF ru   c                6    |                      |j                  S r  )r  rR  r  s     rs   _print_ArraySymbolzLatexPrinter._print_ArraySymbol  s    {{49%%%ru   c                     d                      |j        t          d         d          dd                     fd|j        D                       dS )Nz{{r   T}_{rM  c                <    g | ]}                     |           S rp   rK  r  s     rs   rL  z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>  s&    AAAq$++a..*AAAru   r  )r  rR  r"   rQ  rF  r  s   ` rs   _print_ArrayElementz LatexPrinter._print_ArrayElement  s_     diF);TBBBBIIAAAADLAAABBBBD 	Dru   c                    dS )Nz
\mathbb{U}rp   r  s     rs   _print_UniversalSetz LatexPrinter._print_UniversalSet      }ru   c                    |#d|                      |j        d                   z  S d|                      |j        d                   d|dS )Nz$\operatorname{frac}{\left(%s\right)}r   z\operatorname{frac}{\left(z
\right)}^{ro   r	  rF  s      rs   _print_fraczLatexPrinter._print_frac  sZ     	4:T[[ST=V=VVV	4 KK	!----sss4 4ru   c                h     j         d         dk    rd}n# j         d         dk    rd}nt          d          t          |          dk    r1                                          |d                   |z             S                      |d	z                        fd
|D                                 S )Nr   r  ;r   ro  Unknown Decimal Separatorrn  r   z \  c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z-LatexPrinter._print_tuple.<locals>.<listcomp>  s#    %C%C%Cdkk!nn%C%C%Cru   )r   r   r  r  r  rQ  )r   r  seps   `  rs   _print_tuplezLatexPrinter._print_tuple  s    >-.'9 	:CC^/0H< 	:CC8999t99> 	F**4;;tAw+?+?#+EFFF**w$$%C%C%C%Cd%C%C%CDDF F Fru   c                T      fd|j         D             }d                    |          S )Nc                :    g | ]}                     |          S rp   rK  r-  r  r   s     rs   rL  z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>  #    666qDKKNN666ru   r.  r@  rQ  r   r  elementss   `  rs   _print_TensorProductz!LatexPrinter._print_TensorProduct  s2    6666DI666  ***ru   c                T      fd|j         D             }d                    |          S )Nc                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>  r  ru    \wedge r  r  s   `  rs   _print_WedgeProductz LatexPrinter._print_WedgeProduct  s2    6666DI666)))ru   c                ,    |                      |          S r  )r}  r  s     rs   _print_TuplezLatexPrinter._print_Tuple  s      &&&ru   c                      j         d         dk    r$dd                     fd|D                       z  S  j         d         dk    r$dd                     fd|D                       z  S t          d	          )
Nr   r  z\left[ %s\right]z; \  c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z,LatexPrinter._print_list.<locals>.<listcomp>  #    <<<!t{{1~~<<<ru   r   , \  c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z,LatexPrinter._print_list.<locals>.<listcomp>  r  ru   rz  )r   rQ  r   r  s   ` rs   _print_listzLatexPrinter._print_list  s    >-.'9 	:&<<<<t<<<==> >^/0H< 	:&<<<<t<<<==> > 8999ru   c                    t          |                                t                    }g }|D ]J}||         }|                    |                     |          d|                     |                     Kdd                    |          z  S )Nr.  z : z\left\{ %s\right\}r  )r  keysr   r9  r  rQ  )r   r   r  r6  r/  vals         rs   _print_dictzLatexPrinter._print_dict  s    affhh$4555 	K 	KCC&CLLdkk#&6&6&6&6C8H8H8HIJJJJ$x}}U';';;;ru   c                ,    |                      |          S r  )r  r  s     rs   _print_DictzLatexPrinter._print_Dict  s    %%%ru   c                @   t          |j                  dk    s|j        d         dk    r$d|                     |j        d                   z  }nEd|                     |j        d                   d|                     |j        d                   d}|r	d|d|d	}|S )
Nrn  r   z\delta\left(%s\right)z\delta^{\left( z \right)}\left( r  rD  rE  ro   r  r  s       rs   _print_DiracDeltazLatexPrinter._print_DiracDelta  s    ty>>Q 	F$)A,!"3 	F*T[[1-F-FFCC	F DIaL))))4;;ty|+D+D+D+DFC 	7 	7-0SS###6C
ru   c                    |                      |j        d         |j        d         z
            }|                      |j        d                   }d|d|d}|d|d|d	|d}|S )
Nr   rn  r  z{\left\langle z \right\rangle}^{ro   z{\left({\langle z \rangle}^{z}\right)}^{r	  )r   r  rG  shiftr  r  s         rs   _print_SingularityFunctionz'LatexPrinter._print_SingularityFunction  s~    DIaL49Q<788DIaL))9>F 	Y 	YFKeeUUUTWTWTWXC
ru   c                t     d                      fd|j        D                       }d|z  }|r	d|d|d}|S )NrM  c              3  B   K   | ]}                     |          V  d S r  rK  r  s     rs   r/  z0LatexPrinter._print_Heaviside.<locals>.<genexpr>!  s/      AAs$++c**AAAAAAru   z\theta\left(%s\right)rD  rE  ro   )rQ  pargs)r   r  rG  r  r  s   `    rs   _print_HeavisidezLatexPrinter._print_Heaviside   sY    		AAAAdjAAAAA&. 	7 	7-0SS###6C
ru   c                
   |                      |j        d                   }|                      |j        d                   }|j        d         j        r|j        d         j        r
d|d|d}n	d|d|d}|	d|d|d}|S )	Nr   rn  z\delta_{r   ro   rM  rD  rE  )r  r@  r  )r   r  rG  r   r   r  s         rs   _print_KroneckerDeltaz"LatexPrinter._print_KroneckerDelta'  s    KK	!%%KK	!%%9Q< 	.DIaL$8 	. 	.'(qq!!!,CC()111-C 	7 	7-0SS###6C
ru   c                    t          | j        |j                  }t          d |j        D                       rdd                    |          z  }ndd                    |          z  }|r	d|d|d}|S )Nc              3  $   K   | ]}|j         V  d S r  )r  )r-  r.  s     rs   r/  z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>4  s$      ,,Qqy,,,,,,ru   z\varepsilon_{%s}r   rM  rD  rE  ro   )rE  r  r@  rw  rQ  )r   r  rG  rF  r  s        rs   _print_LeviCivitazLatexPrinter._print_LeviCivita2  s    dk49--,,$),,,,, 	;%(9(99CC%		'(:(::C 	7 	7-0SS###6C
ru   c                   t          |d          r*d|                     |                                          z   S t          |d          r;d|                     |j                  z   dz   |                     |j                  z   S t          |d          rd|                     |j                  z   S |                     d           S )N
as_booleanz\text{Domain: }set \in ry  z\text{Domain on })r  r  r  ry  r  )r   r   s     rs   _print_RandomDomainz LatexPrinter._print_RandomDomain<  s    1l## 	%%ALLNN(C(CCCQ 	%&QY)?)??(JKK&&' (Q	"" 	%'$++ai*@*@@@;;t$$$ru   c                b    t          |j        t                    }|                     |          S )Nr.  )r  r@  r   
_print_setr   rr   r6  s      rs   _print_FiniteSetzLatexPrinter._print_FiniteSetG  s)    qv#3444u%%%ru   c                >   t          |t                    }| j        d         dk    r)d                    t	          | j        |                    }nI| j        d         dk    r)d                    t	          | j        |                    }nt          d          d|z  S )	Nr.  r   r  r  r   rM  rz  \left\{%s\right\})r  r   r   rQ  rE  r  r   r  s      rs   r  zLatexPrinter._print_setK  s    q.///>-.'9 	:IIc$+u5566EE^/0H< 	:IIc$+u5566EE8999#e++ru   c                     fd}t                      j        j        r(j        j        rj        j        rdddf}ndddf}n؉j        j        rd         j        z
  d         f}nj        j        r/t                    }t          |          t          |          f}nwj        fj	        dk     dk    rt                    }nQj        r6t                    }t          |          t          |          d         f}n |            S  |            S dd                     fd	|D                       z   d
z   S )Nc                    j         d         dk    rYj         d         dk    r!                    j         d                   } nd                    fdj         D                       } nfj         d         dk    r/d                    fdj         d d         D                       } n&d                    fdj         D                       } d|  d	S )
Nr   r  rn  rM  c              3  B   K   | ]}                     |          V  d S r  rK  r  s     rs   r/  zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>_  /      $H$H#T[[%5%5$H$H$H$H$H$Hru   c              3  B   K   | ]}                     |          V  d S r  rK  r  s     rs   r/  zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>b  s/      $L$L#T[[%5%5$L$L$L$L$L$Lru   c              3  B   K   | ]}                     |          V  d S r  rK  r  s     rs   r/  zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>d  r  ru   z\text{Range}\left(rq  )r@  r  rQ  )contrr   r   s    rs   _print_symbolic_rangez8LatexPrinter._print_Range.<locals>._print_symbolic_rangeY  s    vayA~ 	I6!9> I;;qvay11DD99$H$H$H$H$H$H$HHHDD6!9> I99$L$L$L$L$L$L$LLLDD99$H$H$H$H$H$H$HHHD:D:::;ru   rm  r   rn  rl  T\left\{rM  c              3  N   K   | ]}|ur                     |          nd V   dS z\ldotsNrK  r-  eldotsr   s     rs   r/  z,LatexPrinter._print_Range.<locals>.<genexpr>  ;      __PRbnK4;;r???)______ru   \right\})objectstartis_infinitestopstepis_positiveiternextis_emptyrs  r  is_iterablerQ  )r   rr   r  printsetitr  s   ``   @rs   _print_RangezLatexPrinter._print_RangeX  s   	< 	< 	< 	< 	< 	< xx7 	+16#5 	+v! 0Q4/Ar4/W  	+QrUQV^QrU2HHV 	+aBBxxb4/HHZ 		+
t# / 88 /!WW88T"XXtQrU:,,...((***

_____V^_____` 	ru   c           
        t          |j                  dk    r|J|d|                     |j        d                   d|d|                     |j        d                   dS |d|                     |j        d                   d|                     |j        d                   dS |d|                     |j        d                   d}||d	|d}|S )
Nr  rs  r   rt  r4  rn  rq  ro   r  r  )r   r  letterrG  r  s        rs   __print_number_polynomialz&LatexPrinter.__print_number_polynomial  s    ty>>Q 	N 79? KK	!5555sss KK	!55557 7 17DIaL11114;;ty|3L3L3L3LN N #FFDKK	!$=$=$=$=> 	* #SSS)C
ru   c                0    |                      |d|          S Nr  &_LatexPrinter__print_number_polynomialrF  s      rs   _print_bernoullizLatexPrinter._print_bernoulli      --dC===ru   c                r    t          |j                  dk    rd                     |j        d                   d                     |j        d                   d}dd                     fd|j        d	         D                       z  }||d
|d|}n||z   }|S                      |d|          S )Nr1  zB_{r   rM  rn  ro   rb  c              3  B   K   | ]}                     |          V  d S r  rK  )r-  r  r   s     rs   r/  z+LatexPrinter._print_bell.<locals>.<genexpr>  sI       3C 3C/1 48;;r?? 3C 3C 3C 3C 3C 3Cru   r  r  r  )r  r@  r  rQ  r  )r   r  rG  tex1tex2r  s   `     rs   _print_bellzLatexPrinter._print_bell  s    ty>>Q 		 		$(KK	!$=$=$=$= $DIaL 9 9 9 9;D%

 3C 3C 3C 3C59Yq\3C 3C 3C )C )C CD "&*ddCCC6TkJ--dC===ru   c                0    |                      |d|          S NFr  rF  s      rs   _print_fibonaccizLatexPrinter._print_fibonacci  r  ru   c                `    d|                      |j        d                   z  }||d|d}|S )NzL_{%s}r   r  ro   r	  r  s       rs   _print_lucaszLatexPrinter._print_lucas  =    $++dil333 	* #SSS)C
ru   c                0    |                      |d|          S )NTr  rF  s      rs   _print_tribonaccizLatexPrinter._print_tribonacci  r  ru   c           
     X    t                      t          |j        j                  dk    st          |j        j                  dk    rud                     |j                  d                     |j        d                   d                     |j                  d                     |j                  d	S |j        t          j	        u rd|j        }|
                    |dz
            |
                    |dz
            |
                    |d	z
            |
                    |          f}nM|j        t          j        u s|j        d
k    r |d d
         }|                               nt          |          }dd                     fd|D                       z   dz   S )Nr   r  z
\right\}_{rb  rt  ro   r1  r  rn  rl  r   rM  c              3  N   K   | ]}|ur                     |          nd V   dS r  rK  r  s     rs   r/  z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>  r  ru   r  )r  r  r  free_symbolsr  r  formular  r   r}  coeffr|  lengthr9  r  rQ  )r   rr   r  r  r  s   `   @rs   _print_SeqFormulazLatexPrinter._print_SeqFormula  s   xxqw#$$q( 	C0C,D,Dq,H 	AI&&&&AKN++++AG$$$$AF####	  7a(( 	 6DaggdQh//1B1Bq))1774==:HHVqz! 	 QX\ 	 !uHOOD!!!!QxxH

_____V^_____` 	ru   c                   |j         |j        k    rd|                     |j                   z  S |j        rd}nd}|j        rd}nd}d||                     |j                   d|                     |j                  d|S )	Nr  r   r   r   r   r  rM  r  )r  endr  	left_open
right_open)r   r   leftrights       rs   _print_IntervalzLatexPrinter._print_Interval  s    7ae 	K'$++ag*>*>>> { |  D$++ag....AE0B0B0B0BEEK Kru   c                t    d|                      |j                  d|                      |j                  dS )Nz\left\langle rM  z\right\rangle)r  r   r   r   r   s     rs   _print_AccumulationBoundsz&LatexPrinter._print_AccumulationBounds  s;     QU####T[[%7%7%7%79 	9ru   c                v     t          |           fd|j        D             }d                    |          S )Nc                <    g | ]}                     |          S rp   r  r-  r   r&  r   s     rs   rL  z-LatexPrinter._print_Union.<locals>.<listcomp>  )    ???1D%%a..???ru   z \cup r   r@  rQ  r   uargs_strr&  s   `  @rs   _print_UnionzLatexPrinter._print_Union  A    %a((????????~~h'''ru   c                v     t          |           fd|j        D             }d                    |          S )Nc                <    g | ]}                     |          S rp   r  r  s     rs   rL  z2LatexPrinter._print_Complement.<locals>.<listcomp>  r  ru   z \setminus r  r  s   `  @rs   _print_ComplementzLatexPrinter._print_Complement  C    %a((????????""8,,,ru   c                v     t          |           fd|j        D             }d                    |          S )Nc                <    g | ]}                     |          S rp   r  r  s     rs   rL  z4LatexPrinter._print_Intersection.<locals>.<listcomp>  r  ru   z \cap r  r  s   `  @rs   _print_Intersectionz LatexPrinter._print_Intersection  r  ru   c                v     t          |           fd|j        D             }d                    |          S )Nc                <    g | ]}                     |          S rp   r  r  s     rs   rL  z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>  r  ru   z \triangle r  r  s   `  @rs   _print_SymmetricDifferencez'LatexPrinter._print_SymmetricDifference  r  ru   c                <    t          |          t          |j                  dk    rMt          |j                  s9                     |j        d                   dt          |j                  z  z   S d                     fd|j        D                       S )Nrn  r   z^{%d}r   c              3  D   K   | ]}                     |          V  d S r  r  )r-  r  r&  r   s     rs   r/  z1LatexPrinter._print_ProductSet.<locals>.<genexpr>  sD        <  <-0Dc4(( <  <  <  <  <  <ru   )r   r  setsr%   r  rQ  )r   r  r&  s   ` @rs   _print_ProductSetzLatexPrinter._print_ProductSet  s    %a((qv;;! 	NK$7$7 	N$$QVAY55#af++8MMM  <  <  <  <  <45F <  <  < < < 	<ru   c                    dS )Nz	\emptysetrp   rZ  s     rs   _print_EmptySetzLatexPrinter._print_EmptySet  s    |ru   c                    dS )Nz
\mathbb{N}rp   r   r-  s     rs   _print_NaturalszLatexPrinter._print_Naturals  ru  ru   c                    dS )Nz\mathbb{N}_0rp   r  s     rs   _print_Naturals0zLatexPrinter._print_Naturals0  s    ru   c                    dS Nz
\mathbb{Z}rp   r  s     rs   _print_IntegerszLatexPrinter._print_Integers	  ru  ru   c                    dS Nz
\mathbb{Q}rp   r  s     rs   _print_RationalszLatexPrinter._print_Rationals	  ru  ru   c                    dS Nz
\mathbb{R}rp   r  s     rs   _print_RealszLatexPrinter._print_Reals	  ru  ru   c                    dS Nz
\mathbb{C}rp   r  s     rs   _print_ComplexeszLatexPrinter._print_Complexes	  ru  ru   c                     |j         j        }|j         j        } fdt          ||j                  D             }d                    d |D                       }d                     |          d|dS )Nc              3  r   K   | ]1\  }}                     |                               |          fV  2d S r  rK  )r-  r.  rH  r   s      rs   r/  z/LatexPrinter._print_ImageSet.<locals>.<genexpr>	  s@      RRDAqAA/RRRRRRru   rM  c              3      K   | ]	}d |z  V  
dS )	%s \in %sNrp   )r-  xys     rs   r/  z/LatexPrinter._print_ImageSet.<locals>.<genexpr>	  s'      ;;<",;;;;;;ru   r  \; \middle|\; r  )rX   r  	signaturerc  	base_setsrQ  r  )r   rr   r  sigxysxinyss   `     rs   _print_ImageSetzLatexPrinter._print_ImageSet	  s~    w|gRRRRCQ[<Q<QRRR

;;s;;;;;7;{{47H7H7H7H%%%PPru   c           
     P    d                      fdt          |j                  D                       }|j        t          j        u r!d|d                     |j                  dS d|d|d                     |j                  d                     |j                  d	S )NrM  c                :    g | ]}                     |          S rp   rK  r-  r  r   s     rs   rL  z4LatexPrinter._print_ConditionSet.<locals>.<listcomp>	  s%    IIISC 0 0IIIru   r  r(  	 \right\}r  r  )rQ  r   r2  base_setr   UniversalSetr  	conditionr   rr   
vars_prints   `  rs   _print_ConditionSetz LatexPrinter._print_ConditionSet	  s    YYIIIIE!%LLIIIJJ
:' 	7 	7T[[55557 7	7
 JJJJKK
####KK$$$$	& 	&ru   c                l    |                      |j        d                   }d                    |          S )Nr   z\mathcal{{P}}\left({}\right)r  r@  r   )r   r  	arg_prints      rs   _print_PowerSetzLatexPrinter._print_PowerSet!	  s-    KK	!--	.55i@@@ru   c                     d                      fd|j        D                       }d                     |j                  d|d                     |j                  dS )NrM  c                :    g | ]}                     |          S rp   rK  r1  s     rs   rL  z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>&	  s%    HHHSC 0 0HHHru   r  r(  r  r2  )rQ  r  r  r  r  r6  s   `  rs   _print_ComplexRegionz!LatexPrinter._print_ComplexRegion%	  sl    YYHHHHAKHHHII

KKJJKK! 	!ru   c                J     dt           fd|j        D                       z  S )Nr&  c              3  B   K   | ]}                     |          V  d S r  rK  r  s     rs   r/  z/LatexPrinter._print_Contains.<locals>.<genexpr>-	  s-      #C#CqDKKNN#C#C#C#C#C#Cru   )r  r@  rZ  s   ` rs   _print_ContainszLatexPrinter._print_Contains,	  s-    e#C#C#C#CAF#C#C#CCCCCru   c                    |j         j        t          j        u r2|j        j        t          j        u r|                     |j                  S |                     |                                          dz   S )Nz	 + \ldots)	rs  r  r   rN  bnr  a0rh  truncater  s     rs   _print_FourierSeriesz!LatexPrinter._print_FourierSeries/	  sZ    4<16! 	%adlaf&< 	%;;qt$$$qzz||,,|;;ru   c                6    |                      |j                  S r  )rh  infiniter  s     rs   _print_FormalPowerSeriesz%LatexPrinter._print_FormalPowerSeries4	  s    qz***ru   c                    d|j         z  S )Nz\mathbb{F}_{%s})modr  s     rs   _print_FiniteFieldzLatexPrinter._print_FiniteField7	  s    !DH,,ru   c                    dS r  rp   r  s     rs   _print_IntegerRingzLatexPrinter._print_IntegerRing:	  ru  ru   c                    dS r  rp   r  s     rs   _print_RationalFieldz!LatexPrinter._print_RationalField=	  ru  ru   c                    dS r  rp   r  s     rs   _print_RealFieldzLatexPrinter._print_RealField@	  ru  ru   c                    dS r!  rp   r  s     rs   _print_ComplexFieldz LatexPrinter._print_ComplexFieldC	  ru  ru   c                    |                      |j                  }d                    t          | j         |j                            }|d|dS )NrM  r   r  r  domainrQ  rE  ry  r   r  rX  ry  s       rs   _print_PolynomialRingz"LatexPrinter._print_PolynomialRingF	  G    T[))))CT\::;;'-vvwww77ru   c                    |                      |j                  }d                    t          | j         |j                            }|d|dS )NrM  rD  rq  rW  rY  s       rs   _print_FractionFieldz!LatexPrinter._print_FractionFieldK	  r[  ru   c                    |                      |j                  }d                    t          | j         |j                            }d}|j        sd}||d|dS )NrM  r   zS_<^{-1}r   r  )r  rX  rQ  rE  ry  is_Poly)r   r  rX  ry  invs        rs   _print_PolynomialRingBasez&LatexPrinter._print_PolynomialRingBaseP	  s_    T[))))CT\::;;| 	C),fffggg>>ru   c           	        |j         j        }g }|                                D ]t\  }}d}t          |          D ]f\  }}|dk    r[|dk    r$||                     |j        |                   z  }5||                     t          |j        |         |                    z  }g|j        r1|rd|                     |          z  }	nz|                     |          }	nd|rM|t          j	        u r|
                    d|g           |t          j        u r|
                    d|g           |                     |          }	|s|	}
n|	dz   |z   }
|
                    d          r!|
                    d|
dd          g           ]|
                    d|
g           v|d         dv r)|                    d          }|dk    rd|d         z   |d<   d                    |          }t          t!          | j        |j                            }d	|                     |                                          z  }d
                    |g|z   |gz             }|t$          v r
d|d|d}n	d|d|d}|S )Nr   r   rn  rb  r  r0  r   )r0  r  z	domain=%srM  r    {\left(z	 \right)}r  z	}{\left( )rO  rP  re  rd  r  genspowr"  r   r  extendr  r  poprQ  r  rE  
get_domainr  )r   polyr  re  monomr  s_monomr   rG  s_coeffs_termmodifierr  rd  rX  r@  r  s                    rs   _print_PolyzLatexPrinter._print_PolyX	  s   n% JJLL "	, "	,LE5G#E** G G37 Gax G4;;ty|#<#<<4;;s49Q</E/E#F#FF| - 104;;u3E3EEGG"kk%00GG !~ !c7^444 - !c7^444 ++e,, 1  30  %% ,c6!"":.////c6]++++8z! 	*yy||H3 *q>axxCTY//00t{{4??+<+<===yy$$&122** 	H 	H/2ssDDD9CC	H >ASS$$$GC
ru   c                    |j         j        }|dk    rd}|                     |j                  }|j        }|t
          v rd|||fz  S d|||fz  S )NComplexRootOfCRootOfz\%s {\left(%s, %d\right)}z'\operatorname{%s} {\left(%s, %d\right)})rO  rP  r  r  rZ  r  )r   r;   r  r  rZ  s        rs   _print_ComplexRootOfz!LatexPrinter._print_ComplexRootOf	  sv    n%/! 	C{{49%%
** 	H/3e2DDD=dAFAH H Hru   c                R   |j         j        }|                     |j                  g}|j        t
          j        ur-|                    |                     |j                             |t          v rd|dd	                    |          dS d|dd	                    |          dS )Nr   rc  rM  r+  r  z	} {\left()
rO  rP  r  r  funr   IdentityFunctionr9  r  rQ  )r   r  r  r@  s       rs   _print_RootSumzLatexPrinter._print_RootSum	  s    n%DI&&'81-- 	/KKDH--...** 	N 	N/2ssDIIdOOOODD	N >ASS=AYYt____N Nru   c                    dS )N\omegarp   r  s     rs   _print_OrdinalOmegaz LatexPrinter._print_OrdinalOmega	  s    yru   c                    |j         \  }}|dk    r1|dk    rd                    ||          S d                    |          S |dk    rd                    |          S dS )Nrn  z{} \omega^{{{}}}z	{} \omegaz\omega^{{{}}}ry  )r@  r   )r   r  rG  muls       rs   _print_OmegaPowerzLatexPrinter._print_OmegaPower	  st    9S!8 		!ax 0*11#s;;;#**3///ax !'..s333 yru   c                P     d                      fd|j        D                       S )Nra  c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z/LatexPrinter._print_Ordinal.<locals>.<listcomp>	  s%    AAA4;;s++AAAru   )rQ  r@  r  s   ` rs   _print_OrdinalzLatexPrinter._print_Ordinal	  s,    zzAAAAtyAAABBBru   c                V    | j         d         }|                    | t          d|          S )Nr   z	{%s}^{%d})r   r   r"   )r   ri  r   s      rs   _print_PolyElementzLatexPrinter._print_PolyElement	  s'    ^$67
xxj+zBBBru   c                    |j         dk    r|                     |j                  S |                     |j                  }|                     |j                   }d|d|dS )Nrn  r  r  ro   )r  r  r  )r   r:   r  r  s       rs   _print_FracElementzLatexPrinter._print_FracElement	  s_    :? 	5;;tz***KK
++EKK
++EE',uueee44ru   c                    t          |j                  dk    r|j        d         d fn|j        \  }}d|                     |          z  }||d|d}||d|                     |          d}|S )Nrn  r   zE_{%s}r  ro   rD  rq  r  )r   r  rG  r  r.  r  s         rs   _print_eulerzLatexPrinter._print_euler	  s    '*49~~':I	!d##	1$++a..( 	* #SSS)C 	?*-##t{{1~~~~>C
ru   c                `    d|                      |j        d                   z  }||d|d}|S )NzC_{%s}r   r  ro   r	  r  s       rs   _print_catalanzLatexPrinter._print_catalan	  r  ru   c           
         d                     ||rdnd|                     |j        d                   |                     |j        d                   |                     |j        d                             S )Nz5\mathcal{{{}}}{}_{{{}}}\left[{}\right]\left({}\right)z^{-1}r   rn  r   r  r   r  r@  )r   r  rr   inverses       rs   _print_UnifiedTransformz$LatexPrinter._print_UnifiedTransform	  s    GNNq]dRlRYRYjlnrnynyz~  {D  EF  {G  oH  oH  JN  JU  JU  VZ  V_  `a  Vb  Jc  Jc  ei  ep  ep  qu  qz  {|  q}  e~  e~      	ru   c                .    |                      |d          S )NMr  r  s     rs   _print_MellinTransformz#LatexPrinter._print_MellinTransform	      ++D#666ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseMellinTransformz*LatexPrinter._print_InverseMellinTransform	      ++D#t<<<ru   c                .    |                      |d          S )NLr  r  s     rs   _print_LaplaceTransformz$LatexPrinter._print_LaplaceTransform	  r  ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseLaplaceTransformz+LatexPrinter._print_InverseLaplaceTransform	  r  ru   c                .    |                      |d          S r  r  r  s     rs   _print_FourierTransformz$LatexPrinter._print_FourierTransform	  r  ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseFourierTransformz+LatexPrinter._print_InverseFourierTransform	  r  ru   c                .    |                      |d          S )NSINr  r  s     rs   _print_SineTransformz!LatexPrinter._print_SineTransform	      ++D%888ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseSineTransformz(LatexPrinter._print_InverseSineTransform	      ++D%>>>ru   c                .    |                      |d          S )NCOSr  r  s     rs   _print_CosineTransformz#LatexPrinter._print_CosineTransform	  r  ru   c                0    |                      |dd          S )Nr  Tr  r  s     rs   _print_InverseCosineTransformz*LatexPrinter._print_InverseCosineTransform	  r  ru   c                    	 |j         -|                     |j                             |                    S n# t          $ r Y nw xY w|                     t	          |                    S r  )ringr  to_sympyr   reprr   r  s     rs   
_print_DMPzLatexPrinter._print_DMP	  sp    	v 7{{16??1#5#56667  	 	 	D	{{477###s   37 
AAc                ,    |                      |          S r  )r  r  s     rs   
_print_DMFzLatexPrinter._print_DMF
  s    q!!!ru   c                P    |                      t          |j                            S r  r  r   rR  )r   r  s     rs   _print_ObjectzLatexPrinter._print_Object
  s    {{6&+..///ru   c                   |                      |j        d                   }|d|dnd}t          |j                  dk    r
d|d|d}n7|                      |j        d                   }d	                    |||          }|S )
Nr   r  ro   r   rn  WrD  rq  zW{0}_{{{1}}}\left({2}\right))r  r@  r  r   )r   r  rG  arg0resultarg1s         rs   _print_LambertWzLatexPrinter._print_LambertW
  s    {{49Q<((#&::###ty>>Q 	N 	N.1cc4448FF;;ty|,,D5<<S$MMFru   c                h    d                     |                     |j        d                             S )Nz!\operatorname{{E}}\left[{}\right]r   r  r  s     rs   _print_ExpectationzLatexPrinter._print_Expectation
  )    3::4;;tyQR|;T;TUUUru   c                h    d                     |                     |j        d                             S )Nz#\operatorname{{Var}}\left({}\right)r   r  r  s     rs   _print_VariancezLatexPrinter._print_Variance
  s)    5<<T[[ST=V=VWWWru   c                v     d                     d                     fd|j        D                                 S )Nz#\operatorname{{Cov}}\left({}\right)rM  c              3  B   K   | ]}                     |          V  d S r  rK  r  s     rs   r/  z1LatexPrinter._print_Covariance.<locals>.<genexpr>
  s1      FmFm\_t{{SVGWGWFmFmFmFmFmFmru   )r   rQ  r@  r  s   ` rs   _print_CovariancezLatexPrinter._print_Covariance
  s<    5<<TYYFmFmFmFmcgclFmFmFm=m=mnnnru   c                h    d                     |                     |j        d                             S )Nz!\operatorname{{P}}\left({}\right)r   r  r  s     rs   _print_ProbabilityzLatexPrinter._print_Probability
  r  ru   c                x    |                      |j                  }|                      |j                  }|d|S )Nr  )r  rX  codomain)r   morphismrX  r  s       rs   _print_MorphismzLatexPrinter._print_Morphism
  s:    X_--;;x011&,ffhh77ru   c                |    |                      |j                  |                      |j                  }}d|d|dS )Nr  r  ro   )r  rZ  den)r   r  rZ  r  s       rs   _print_TransferFunctionz$LatexPrinter._print_TransferFunction#
  s<    ;;tx(($++dh*?*?S#&33,,ru   c                     t          j                  } fd}d                    t          ||                    S )Nc                L                         | t                    d          S r  )r  r   )r.  r  r   s    rs   rt   z,LatexPrinter._print_Series.<locals>.<lambda>)
  s'    4,,Q0Ft0L0L,13 3 ru   r   )r  r@  rQ  rE  )r   r  r@  r  s   ``  rs   _print_SerieszLatexPrinter._print_Series'
  sH    DI3 3 3 3 3xxFD))***ru   c                     ddl m t          j                  d d d         } fd}d                    t          ||                    S )Nr   )MIMOParallelrm  c                    t          |           r$                    | t                    d          n                    |           S r  )r  r  r   r  )r.  r  r  r   s    rs   rt   z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>0
  sT    7A!\7R7Rg4,,Q0Ft0L0L-24 4 4X\XcXcdeXfXf ru   z\cdot)sympy.physics.control.ltir  r  r@  rQ  rE  )r   r  r@  r  r  s   ``  @rs   _print_MIMOSerieszLatexPrinter._print_MIMOSeries-
  sq    ::::::DIttt$g g g g g g}}S..///ru   c                \    d                     t          | j        |j                            S Nra  rQ  rE  r  r@  r  s     rs   _print_ParallelzLatexPrinter._print_Parallel4
  "    zz#dk4955666ru   c                \    d                     t          | j        |j                            S r  r  r  s     rs   _print_MIMOParallelz LatexPrinter._print_MIMOParallel7
  r  ru   c           	     p   ddl m}m} |j         |dd|j                  }}t          ||          rt          |j                  n|g}t          |j        |          rt          |j        j                  n|j        g}|}t          ||          r t          |j        |          r |g ||R  }	nt          ||          r8t          |j        |          r#|j        |k    r || }	nt| |g ||j        R  f}	nbt          ||          r+t          |j        |          r||k    r || }	n1 ||g|R  }	n'||k    r || }	n|j        |k    r || }	n
 |g ||R  }	| 	                    |          }
| 	                    |          }| 	                    |	          }|j
        dk    rdnd}d|
d|d	|d	|d
	S )Nr   )TransferFunctionSeriesrn  rm  r  r0  r  r  r   ro   )sympy.physics.controlr  r  sys1r  r  r  r@  sys2r  r  )r   r  r  r  rZ  tfnum_arg_listden_arg_list
den_term_1
den_term_2r  denom_1denom_2_signs                 rs   _print_FeedbackzLatexPrinter._print_Feedback:
  sO   BBBBBBBB)--aDH==R)3C)@)@KtCH~~~sety&));tDIN+++04	{ 	
c6"" 	Bz$)V'D'D 	B=====JJV$$ 	BDI?O)P)P 	ByB B#V\2

!A!Aty!A!A!AA

-.. 	B:di3P3P 	Bby 8#V\2

#VC7,777

by B#V\2

b B#V\2

#VA\ALAAA
C  ++j))++j))yB/C).HHru   c                    ddl m} |                      ||j        |j                            }|                     |j                  }|j        dk    rdnd}d|d|d|S )	Nr   )
MIMOSeriesrm  r  r0  z\left(I_{\tau} r   z\right)^{-1} \cdot )r  r  r  r  r  r  )r   r  r  inv_matr  r  s         rs   _print_MIMOFeedbackz LatexPrinter._print_MIMOFeedback^
  su    444444++jjDI>>??{{49%%yB/C?DuugggttTTru   c                @    |                      |j                  }d|z  S )Nz%s_\tau)r  	_expr_matr  s      rs   _print_TransferFunctionMatrixz*LatexPrinter._print_TransferFunctionMatrixe
  s     kk$.))Cru   c                L    d                     |j        j        |j                  S )Nz\text{{{}}}_{{{}}})r   rO  rP  r-  r  s     rs   
_print_DFTzLatexPrinter._print_DFTi
  s    $++DN,CTVLLLru   c                    |                      t          |j                            }|                     |          }|d|S )Nr  )r  r   rR  r  )r   r  pretty_namepretty_morphisms       rs   _print_NamedMorphismz!LatexPrinter._print_NamedMorphismm
  sA    kk&"7"788..x88%++77ru   c                b    ddl m} |                      ||j        |j        d                    S )Nr   )NamedMorphismid)sympy.categoriesr  r  rX  r  )r   r  r  s      rs   _print_IdentityMorphismz$LatexPrinter._print_IdentityMorphismr
  sF    222222((OX.*6 *6 7 7 	7ru   c                      fd|j         D             }|                                 d                    |          dz   }                     |          }||z   S )Nc                ^    g | ])}                     t          |j                            *S rp   r  )r-  	componentr   s     rs   rL  z9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z
  sE      B  B  B ) !%F9>,B,B C C  B  B  Bru   z\circ r  )r7  reverserQ  r  )r   r  component_names_listcomponent_namesr  s   `    rs   _print_CompositeMorphismz%LatexPrinter._print_CompositeMorphismw
  s}     B  B  B  B-5-@ B  B  B$$&&&#..)=>>D..x8800ru   c                v    d                     |                     t          |j                                      S Nr  )r   r  r   rR  )r   r  s     rs   _print_CategoryzLatexPrinter._print_Category
  s,    &&t{{6(-3H3H'I'IJJJru   c                    |j         s|                     t          j                  S |                     |j                   }|j        r |d|                     |j                  z  z  }|S )Nz\Longrightarrow %s)premisesr  r   EmptySetconclusions)r   diagramlatex_results      rs   _print_DiagramzLatexPrinter._print_Diagram
  sl     	+;;qz***{{7#344 	=1 KK(;<<= =L ru   c                .   dd|j         z  z  }t          |j                  D ]m}t          |j                   D ]>}|||f         r|t          |||f                   z  }|dz  }||j         dz
  k    r|dz  }?||j        dz
  k    r|dz  }|dz  }n|dz  }|S )	Nz\begin{array}{%s}
r   r   rn  & r  
z\end{array}
)widthr  heightlatex)r   gridr  r   r   s        rs   _print_DiagramGridzLatexPrinter._print_DiagramGrid
  s    -tz1ABt{## 
	! 
	!A4:&& ) )1: 6 E$q!t*$5$55L#
Q& ) D(LDK!O# '&D LL((ru   c                    d                     |                     |j                  |                     |j                            S )Nz{{{}}}^{{{}}})r   r  r  rI  r   r  s     rs   _print_FreeModulezLatexPrinter._print_FreeModule
  s4    %%dkk!&&9&94;;qv;N;NOOOru   c                l     d                     d                     fd|D                                 S )Nz\left[ {} \right]ro  c              3  N   K   | ]}d                      |          z   dz   V   dS r   ro   NrK  r-  r.  r   s     rs   r/  z8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>
  sH       43 43+,C$++a.. 3&43 43 43 43 43 43ru   )r   rQ  r   r  s   ` rs   _print_FreeModuleElementz%LatexPrinter._print_FreeModuleElement
  sQ    #**388 43 43 43 430143 43 43 ,3 ,3 4 4 	4ru   c                v     d                     d                     fd|j        D                                 S )N\left\langle {} \right\ranglero  c              3  N   K   | ]}d                      |          z   dz   V   dS r  rK  r  s     rs   r/  z0LatexPrinter._print_SubModule.<locals>.<genexpr>
  sP       @8 @8+,C$++a.. 3&@8 @8 @8 @8 @8 @8ru   )r   rQ  rd  r  s   ` rs   _print_SubModulezLatexPrinter._print_SubModule
  sZ    /66sxx @8 @8 @8 @801@8 @8 @8 88 88 9 9 	9ru   c                     d                     d                     fd|j        j        D                                 S )Nr  ro  c              3  R   K   | ]!\  }d                      |          z   dz   V  "dS r  rK  r  s     rs   r/  z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>
  sZ       @B @B+.AC$++a.. 3&@B @B @B @B @B @Bru   )r   rQ  _modulerd  r  s   ` rs   _print_ModuleImplementedIdealz*LatexPrinter._print_ModuleImplementedIdeal
  sh    /66sxx @B @B @B @B23).@B @B @B 8B 8B C C 	Cru   c                      fd|j         D             }|d         gd t          |dd          d          D             z   }d                    |          S )Nc                V    g | ]%}                     |t          d          d          &S )r
   Tr  )r  r"   r  s     rs   rL  z2LatexPrinter._print_Quaternion.<locals>.<listcomp>
  sC     ! ! ! q*U"3DAA ! ! !ru   r   c                $    g | ]\  }}|d z   |z   S )r   rp   )r-  r   r   s      rs   rL  z2LatexPrinter._print_Quaternion.<locals>.<listcomp>
  s$    <<<$!QaeAg<<<ru   rn  ijkra  )r@  rc  rQ  )r   r  rr   r  s   `   rs   _print_QuaternionzLatexPrinter._print_Quaternion
  sn    ! ! ! !i! ! !qTF<<#aeU*;*;<<<<zz!}}ru   c                    d                     |                     |j                  |                     |j                            S Nz\frac{{{}}}{{{}}})r   r  r  
base_ideal)r   Rs     rs   _print_QuotientRingz LatexPrinter._print_QuotientRing
  s;    #**4;;qv+>+>Q\**, , 	,ru   c                    d                     |                     |j                  |                     |j        j                            S Nz{{{}}} + {{{}}})r   r  datar  r-  )r   r.  s     rs   _print_QuotientRingElementz'LatexPrinter._print_QuotientRingElement
  s>    !((QV)<)<QV.//1 1 	1ru   c                    d                     |                     |j                  |                     |j        j                            S r1  )r   r  r2  modulekilled_moduler  s     rs   _print_QuotientModuleElementz)LatexPrinter._print_QuotientModuleElement
  s>    !((QV)<)<QX3446 6 	6ru   c                    d                     |                     |j                  |                     |j                            S r,  )r   r  rB  r6  r  s     rs   _print_QuotientModulez"LatexPrinter._print_QuotientModule
  s;    #**4;;qv+>+>Q_--/ / 	/ru   c                    d                     |                     |                                          |                     |j                  |                     |j                            S )Nz{{{}}} : {{{}}} \to {{{}}})r   r  _sympy_matrixrX  r  )r   r  s     rs   _print_MatrixHomomorphismz&LatexPrinter._print_MatrixHomomorphism
  sS    ,33DKK@Q@Q4R4RKK!!4;;qz#:#:< < 	<ru   c                &   |j         j         }d|v r|g g }}}n:t          |          \  }}}t          |          }d |D             }d |D             }d|z  }|r|dd                    |          z  z  }|r|dd                    |          z  z  }|S )Nr   c                ,    g | ]}t          |          S rp   r  r  s     rs   rL  z0LatexPrinter._print_Manifold.<locals>.<listcomp>
  r  ru   c                ,    g | ]}t          |          S rp   r  r  s     rs   rL  z0LatexPrinter._print_Manifold.<locals>.<listcomp>
  r  ru   rY  ru  r   rD  )rR  r   r  rQ  )r   manifoldr  rR  r  rd  s         rs   _print_ManifoldzLatexPrinter._print_Manifold
  s    #&= 	4!'R$&DD!0!8!8D&$T??D77777F33d333Dd" 	/Gchhv....D 	-Gchhtnn,,Dru   c                t    d|                      |j                  d|                      |j                  dS )N\text{rp  ro   )r  rR  r@  )r   patchs     rs   _print_PatchzLatexPrinter._print_Patch
  s7     $(KK
$;$;$;$;T[[=X=X=X=XYYru   c                    d|                      |j                  d|                      |j        j                  d|                      |j                  dS )NrC  z	}^{\text{z}}_{ro   )r  rR  rD  r@  )r   coordsyss     rs   _print_CoordSystemzLatexPrinter._print_CoordSystem
  sV     KK&&&&HN4G(H(H(H(H$++V^VgJhJhJhJh
 	
ru   c                <    d|                      |j                  z  S )Nz\mathbb{\nabla}_{%s})r  _wrt)r   cvds     rs   _print_CovarDerivativeOpz%LatexPrinter._print_CovarDerivativeOp
  s    &SX)>)>>>ru   c                    |j         j        |j                 j        }d                    |                     t          |                              S r  
_coord_sysry  _indexrR  r   r  r   r   fieldr  s      rs   _print_BaseScalarFieldz#LatexPrinter._print_BaseScalarField
  s=    !)%,7<&&t{{6&>>'B'BCCCru   c                    |j         j        |j                 j        }d                    |                     t          |                              S )Nz\partial_{{{}}}rN  rQ  s      rs   _print_BaseVectorFieldz#LatexPrinter._print_BaseVectorField
  s=    !)%,7<!((VF^^)D)DEEEru   c                &   |j         }t          |d          rQ|j        j        |j                 j        }d                    |                     t          |                              S |                     |          }d                    |          S )NrO  z\operatorname{{d}}{}z!\operatorname{{d}}\left({}\right))	_form_fieldr  rO  ry  rP  rR  r   r  r   )r   diffrR  r  s       rs   _print_Differentialz LatexPrinter._print_Differential
  s}     5,'' 	G%-el;@F*11$++fVnn2M2MNNN[[''F7>>vFFFru   c                l    |                      |j        d                   }d                    |          S )Nr   z"\operatorname{{tr}}\left({}\right)r:  )r   r  contentss      rs   	_print_TrzLatexPrinter._print_Tr   s-    ;;qvay))4;;HEEEru   c                    |'d|                      |j        d                   d|dS d|                      |j        d                   z  S )Nz\left(\phi\left(r   \right)\right)^{ro   z\phi\left(%s\right)r	  rF  s      rs   _print_totientzLatexPrinter._print_totient  sW     	1 	1TYq\****CCC1 1%DIaL(A(AAAru   c                    |'d|                      |j        d                   d|dS d|                      |j        d                   z  S )Nz\left(\lambda\left(r   r^  ro   z\lambda\left(%s\right)r	  rF  s      rs   _print_reduced_totientz#LatexPrinter._print_reduced_totient  sW     	1 	1TYq\****CCC1 1(4;;ty|+D+DDDru   c           	        t          |j                  dk    r>dt          t          | j        |j        d         |j        d         f                    z  }n#d|                     |j        d                   z  }|d|d|S d|z  S )	Nr  _%s\left(%s\right)rn  r   rb  z\sigma^{ro   z\sigma%srz  r  s       rs   _print_divisor_sigmaz!LatexPrinter._print_divisor_sigma  s    ty>>Q 	A'%DK151ty|0L1N 1N +O +O OCC %t{{49Q<'@'@@C 	1 	1'*ssCC00S  ru   c           	        t          |j                  dk    r>dt          t          | j        |j        d         |j        d         f                    z  }n#d|                     |j        d                   z  }|d|d|S d|z  S )	Nr  rc  rn  r   rb  z
\sigma^*^{ro   z
\sigma^*%srz  r  s       rs   _print_udivisor_sigmaz"LatexPrinter._print_udivisor_sigma  s    ty>>Q 	A'%DK151ty|0L1N 1N +O +O OCC %t{{49Q<'@'@@C 	3 	3),cc22s""ru   c                    |'d|                      |j        d                   d|dS d|                      |j        d                   z  S )Nz\left(\nu\left(r   r^  ro   z\nu\left(%s\right)r	  rF  s      rs   _print_primenuzLatexPrinter._print_primenu%  sW     	1 	1TYq\****CCC1 1$t{{49Q<'@'@@@ru   c                    |'d|                      |j        d                   d|dS d|                      |j        d                   z  S )Nz\left(\Omega\left(r   r^  ro   z\Omega\left(%s\right)r	  rF  s      rs   _print_primeomegazLatexPrinter._print_primeomega+  sW     	1 	1TYq\****CCC1 1'$++dil*C*CCCru   c                *    t          |j                  S r  )r   rR  r  s     rs   
_print_StrzLatexPrinter._print_Str1  s    16{{ru   c                F    |                      t          |                    S r  )r  r   r  s     rs   _print_floatzLatexPrinter._print_float4  s    {{5;;'''ru   c                     t          |          S r  r   r  s     rs   
_print_intzLatexPrinter._print_int7      4yyru   c                     t          |          S r  rp  r  s     rs   
_print_mpzzLatexPrinter._print_mpz:  rr  ru   c                     t          |          S r  rp  r  s     rs   
_print_mpqzLatexPrinter._print_mpq=  rr  ru   c                j    d                     t          t          |j                                      S )Nz"\operatorname{{Q}}_{{\text{{{}}}}})r   r   r   rR  r  s     rs   _print_PredicatezLatexPrinter._print_Predicate@  s&    4;;LTY<X<XYYYru   c                     |j         }|j        }                     |          }d                     fd|D                       }|d|dS )NrM  c                :    g | ]}                     |          S rp   rK  r  s     rs   rL  z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>G  s#    ===1A===ru   r   r   )r   	argumentsr  rQ  )r   r  predr@  
pred_latex
args_latexs   `     rs   _print_AppliedPredicatez$LatexPrinter._print_AppliedPredicateC  s[    }~[[&&
YY=======>>
%::zzz22ru   c                j    t                                          |          }dt          |          z  S )Nz\mathtt{\text{%s}})superemptyPrinterr   )r   r  rr   rO  s      rs   r  zLatexPrinter.emptyPrinterJ  s+    GG  &&$|A66ru   r  r  )FF)r   r  )r  r   )rU  rV  )r  r   )r  r   )r  r   r   r   )r  r)  )r  r   r   r   )r  r   r   r   r  )r2  r   r   r   r  )FN)r   )r  r   )r  r   r   r   )r  r   )rT  rU  )F(<  rP  
__module____qualname__printmethodr   __annotations__r   r  r  r  r   r  r  r$  r;  r>  r  r!  rH  rT  r[  _print_BooleanTrue_print_BooleanFalser^  rh  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r"  r(  rB  rH  rK  rO  r[  rj  rz  r  r  r  r  r  propertyr  r  r  r  r  
_print_Min
_print_Maxr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  _print_gammar  r  r  r  r"  r$  r&  r(  r.  r1  r7  r9  r=  r@  rC  rF  rI  rK  rM  rP  rR  rT  rX  rZ  r_  rd  rg  rj  rp  rv  rx  r{  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_RandomSymbolrN  r  r  r  r  r  r  r  r  r  r  r  r  r!  r*  r,  r0  r3  r5  r:  r?  rA  rE  rS  r\  r_  ra  re  rg  ri  rl  rn  rr  rt  rw  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_frozensetr  r  r  r  r  r  r  r  _print_SeqPer_print_SeqAdd_print_SeqMulr  r  r   r  r  r  r  r  r  r  r  r  r  r"  r.  r8  r<  r?  rB  rG  rJ  rM  rO  rQ  rS  rU  rZ  r]  ra  ro  rs  rw  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_IDFTr  r  r  r  r  r  r  r  r!  r%  r*  r/  r3  r7  r9  r<  rA  rE  rH  rL  rS  rU  rY  r\  r_  ra  rd  rf  rh  rj  rl  rn  rq  rt  rv  rx  r  r  __classcell__)rO  s   @rs   r   r      sg        K)U)E) 	e) 	4	)
 	-) 	) 	u) 	4) 	S) 	4) 	) 	d) 	) 	) 	)  	G!)" 	##)$ %"1) ) )    6;f ;f ;f ;fz, , , ,- - - -% % % % %  E E E EK K K K   .    >      3 3 3 3   / / /        %%        &   9 9 9BJ J J  <N N NN N NM M MM M MI I II I It t t tl/ / /- - -+< +< +< +<Z& & & &) ) )  &  &   <  ' ' '  @ @ @BE E E"/ "/ "/H4 4 4   @J) J) J) J) J)X0 0 0
 
 
 , , X,0 0 0
 
 
- - -     87J      	 	 	 	   + + + ++ + + +	7 	7 	7  2 2 20 0 03 3 3D D D DF F F F   ) ) ) )+ + + +                 	  	  	  	 " " " "/ / / /[ [ [ [< < < <% % % %% % % %; ; ; ; ; (L1 1 1 1: : : :                          + + + ++ + + +   "   7 7 7 77 7 7 77 7 7 77 7 7 77 7 7 77 7 7 7= = = == = = == = = == = = =- - - - -4 4 4 4 42 2 2 22 2 2 28 8 8 88 8 8 8	 	 	 	             ! ! ! !+ + + +@ @ @ @                                 Q Q Q QG G G GG G G GS S S SS S S S' ' '' ' ' A A A A A (    ,J J J(* * *+ + +,  G G GJ J J( ( ($ $ $G G G+ + +/ / /"G G GA A A AC C CA A AC C C@ @ @! ! !> > >> > >> > ># # #4 4 4 4l   8? ? ?
F F F
 
 
  
 
 
  & & &D D D
  4 4 4 4F F F+ + +* * *' ' ': : :< < <& & &         	 	 	 	   	% 	% 	%& & &, , , "( ( (T   > > > >> > > >> > > >   > > > >  . &M%M%MK K K$9 9 9( ( (
- - -
( ( (
- - -
< < <              Q Q Q
& 
& 
&A A A! ! !D D D< < <
+ + +- - -        8 8 8
8 8 8
? ? ?7 7 7r
H 
H 
HN N N  ! ! !C C CC C C5 5 5         7 7 7= = =7 7 7= = =7 7 7= = =9 9 9? ? ?9 9 9? ? ?$ $ $" " "0 0 0   V V VX X Xo o oV V V8 8 8
- - -+ + +0 0 07 7 77 7 7"I "I "IHU U U     M M MK8 8 8
7 7 7
	1 	1 	1K K K
 
 
  $P P P4 4 4
9 9 9C C C  , , ,
1 1 16 6 6/ / /
< < <  &Z Z Z
 
 

? ? ?D D DF F FG G GF F F
B B B BE E E E! ! ! !# # # #A A A AD D D D  ( ( (      Z Z Z3 3 37 7 7 7 7 7 7 7 7ru   r   c           
     &   t                               |           }|r|S |                                 t          v rd|                                 z   S | t          v rd| z   S t          t                                          t          d          D ]}|                                 	                    |          rZt          |           t          |          k    r:t          |         t          | dt          |                                        c S | 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   r  greek_letters_setother_symbolsr  r   r  r  r  r  )rr   r  r/  s      rs   r  r  Q  s     
"
"1
%
%C
 
	
'	' 	aggii	
m	 ax -,,..CFFF 	D 	DCwwyy!!#&& D3q66CHH+< D$S))AjCyjM*B*BCCCCCru   c                F    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   s     rs   r  r  p  s!    h !!))$///ru   c                :    t          t          | fi |           dS )z`Prints LaTeX representation of the given expression. Takes the same
    settings as ``latex()``.N)printr  r  s     rs   print_latexr  G  s(     
%
!
!
!
!"""""ru   rn  align*Fc           
        t          di |}|dk    rd}d}d}	d}
d}nD|dk    rd}d}d}	d	}
d}n3|d
k    rd}d}d}	d}
d}n"t          d                    |                    d}|rd}|                                }t	          |          }d}t          |          D ]}||         }d}d}d}||k    r	|rd}nd}d}||k    r||dz
  k     r||	z   dz   dz   }nd}|                                d         dk    rd|z  }d}|dk    rK|dk    rd}|d                    |                    |           |||                    |          |          z  }n.|d                    |||                    |          |          z  }|dz  }||
z  }|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.

    eqnarrayz\begin{eqnarray}
z& = &z	\nonumberz
\end{eqnarray}TIEEEeqnarrayz\begin{IEEEeqnarray}{rCl}
z
\end{IEEEeqnarray}r  z\begin{align*}
z= &r   z
\end{align*}FzUnknown environment: {}z\dotsrn  r  z& & r  r  r  r   rm  r0  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s}rp   )r   r   r   as_ordered_termsr  r  r  r  )r  r  terms_per_lineenvironmentuse_dotsr   r  r  
first_termnonumberend_termdoubleetr  re  n_terms
term_countr   rf  
term_startterm_endr  s                        rs   multiline_latexr  N  sC   F 	  x  Aj  H+
&		& H4
*		  H)
%299+FFGGGD   ""E%jjGJ7^^  Qx
& 	 "#

!
J' 	719} (?U2T9""$$Q'2- 	d7DD6 	3s{ 077		#"D!))D//8E E EFF +22:t		$3 3 3Fa


hFMru   )rr   r   r   r   )rn  r  F)J__doc__
__future__r   typingr   r   r   rK  
sympy.corer   r   r	   r
   r   r   r   r   sympy.core.alphabetsr   sympy.core.containersr   sympy.core.functionr   r   r   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"   mpmath.libmp.libmpfr#   r$   r  sympy.utilities.iterablesr%   r&   r8   sympy.vector.basisdependentr'   r  r  r  r   r  	frozensetr  compiler  r   r   r  r  r  r  rp   ru   rs   <module>r     s7     # " " " " " / / / / / / / / / /     D D D D D D D D D D D D D D D D D D D D ' ' ' ' ' ' ' ' ' ' ' ' B B B B B B B B B B ) ) ) ) ) )             / / / / / / + + + + + + ? ? ? ? ? ? ? ? ? ? ( ( ( ( ( ( = < < < < < : : : : : : : : H H H H H H H H < < < < < < < < B B B B B B B B 7 7 7 7 7 7 7 7 				 ;::::::   %]%
M% Y% Y	%
 }% M% 
=% Y% M% ]% j% 	-% 	-% 	&% s%  }!%" 	&#% %$ 
=%%& Y'%( 
=)%* {+%, 
7-%. 
=/%0 
71%2 Y3%4 Z5%6 Z7%8 
79%: 
=;%< .=%> ?%@ jA%B YC%D jE% %F I% % % N, , ,2..2 **2 ((	2
 &&2 
$$2 ((2 ((2 ((2 ((2 ((2 
$$2 
$$2 
$$2 !!2  
!2$ ,,%2& 	
*
*'2( )(((**0099----72 2 2    < If%%  BJ~BJx    A+7 A+7 A+7 A+7 A+77 A+7 A+7 A+7HV   > S0 S0 S0l# # #~ ~ ~ ~ ~ ~ru   