o
    oh                 	   @  s  U d Z ddlmZ ddlmZmZmZ ddlZddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z, ddl%m-Z-m.Z. ddl/m0Z0m1Z2 ddl3m4Z4m5Z5 ddl6Z6erddl7m8Z8 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`dad_ dbdcd_ ddded_ dfdgd_ dhdid_ djdkd_ dldmd_ dndod_ dpdqd_ drdsd_ dtdud_ dvdwd_ dxdyd_ dzd{d_ d|d}d_ d~dd_ dd_ dd_ dd_ dd_ dd_ dd_ dd_ dZ>de?d< e@eZAe6Bde6BdfZCdddZDG dd de(ZEdddZFe)eEdd ZGdd ZHdddZIdS )zC
A Printer which converts an expression into its LaTeX equivalent.
    )annotations)AnyCallableTYPE_CHECKINGN)AddFloatModMulNumberSSymbolExpr)greeks)Tuple)FunctionAppliedUndef
Derivative)AssocOp)Pow)default_sort_key)SympifyError)trueBooleanTrueBooleanFalse)precedence_traditional)Printerprint_function)split_super_subrequires_partial)
precedence
PRECEDENCE)prec_to_dpsto_str)has_varietysift)	NDimArray)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                 C     d|  d S )Nz
\mathring{} sro   ro   h/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/printing/latex.py<lambda>[       rs   ddddotc                 C  rm   )Nz\ddddot{rn   ro   rp   ro   ro   rr   rs   \   rt   dddotc                 C  rm   )Nz\dddot{rn   ro   rp   ro   ro   rr   rs   ]   rt   ddotc                 C  rm   )Nz\ddot{rn   ro   rp   ro   ro   rr   rs   ^   rt   dotc                 C  rm   )Nz\dot{rn   ro   rp   ro   ro   rr   rs   _   rt   checkc                 C  rm   )Nz\check{rn   ro   rp   ro   ro   rr   rs   `   rt   brevec                 C  rm   )Nz\breve{rn   ro   rp   ro   ro   rr   rs   a   rt   acutec                 C  rm   )Nz\acute{rn   ro   rp   ro   ro   rr   rs   b   rt   gravec                 C  rm   )Nz\grave{rn   ro   rp   ro   ro   rr   rs   c   rt   tildec                 C  rm   )Nz\tilde{rn   ro   rp   ro   ro   rr   rs   d   rt   hatc                 C  rm   )Nz\hat{rn   ro   rp   ro   ro   rr   rs   e   rt   barc                 C  rm   )Nz\bar{rn   ro   rp   ro   ro   rr   rs   f   rt   vecc                 C  rm   )Nz\vec{rn   ro   rp   ro   ro   rr   rs   g   rt   primec                 C  rm   N{z}'ro   rp   ro   ro   rr   rs   h   rt   prmc                 C  rm   r   ro   rp   ro   ro   rr   rs   i   rt   boldc                 C  rm   Nz\boldsymbol{rn   ro   rp   ro   ro   rr   rs   k   rt   bmc                 C  rm   r   ro   rp   ro   ro   rr   rs   l   rt   c                 C  rm   )Nz	\mathcal{rn   ro   rp   ro   ro   rr   rs   m   rt   c                 C  rm   )Nz	\mathscr{rn   ro   rp   ro   ro   rr   rs   n   rt   c                 C  rm   )Nz
\mathfrak{rn   ro   rp   ro   ro   rr   rs   o   rt   c                 C  rm   )Nz\left\|{z	}\right\|ro   rp   ro   ro   rr   rs   q   rt   c                 C  rm   )Nz\left\langle{z}\right\ranglero   rp   ro   ro   rr   rs   r   rt   c                 C  rm   Nz\left|{z}\right|ro   rp   ro   ro   rr   rs   s   rt   c                 C  rm   r   ro   rp   ro   ro   rr   rs   t   rt   )calscrfraknormavgabsmagzdict[str, Callable[[str], str]]modifier_dictz[0-9][} ]*$z(\d|\\frac{\d+}{\d+})rq   strreturnc                 C  sB   |  dd} dD ]
}|  |d| } q|  dd} |  dd} | S )z
    Escape a string such that latex interprets it as plaintext.

    We cannot use verbatim easily with mathjax, so escaping is easier.
    Rules from https://tex.stackexchange.com/a/34586/41112.
    \z\textbackslashz&%$#_{}~z\textasciitilde^z\textasciicircum)replace)rq   cro   ro   rr   latex_escape   s   r   c                
      s  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dZded< dd d!Zdd$d%Zdd&d'Zddd(d)Z	d*d+ Z
dd,d-Zdd/d0Zdd1d2Zddd3d4Zdd5d6Zdd7d8Zdd9d:Zdd<d=Zd>d? ZddBdCZeZeZdDdE ZddFdGZdHdI ZdJdK ZdLdM ZdNdO ZdPdQ ZdRdS ZdTdU ZdVdW Z dXdY Z!dZd[ Z"dd]d^Z#d_d` Z$dadb Z%ddddeZ&ddgdhZ'didj Z(dkdl Z)dmdn Z*ddpdqZ+drds Z,dtdu Z-dvdw Z.dxdy Z/dzd{ Z0d|d} Z1d~d Z2dddZ3ddddZ4dd Z5dd Z6e7dd Z8dd Z9dd Z:dd Z;ddddZ<e< Z=Z>dddZ?dddZ@dddZAdddZBdddZCdddZDdd ZEdd ZFdd ZGdd ZHdd ZIdddZJdddZKdddZLdddZMdddZNdddZOdddZPdddZQdddZRdddZSdddZTdddZUdddĄZVdddƄZWdddȄZXddddʄZYeYZZddd̄Z[ddd΄Z\dddЄZ]ddd҄Z^dddԄZ_dddքZ`ddd؄ZadddڄZbddd܄ZcdddބZddddZedddZfdddZgdddZhdddZidddZjdddZkdddZldddZmdddZndddZodddZpddddZqddddZrdddZsddd ZtdddZudddZvdddZwdddZxdd	d
ZydddZzdddZ{dddZ|dddZ}dddZ~dddZdddZdddZdddZdddZddd Zdd!d"Zdd#d$Zdd%d&Zdd'd(Zdd)d*Zdd+d,Zdd-d.Zdd/d0Zdd1d2Zd3d4 Zd5d6 Zddd8d9ZeZddd;d<Zd=d> Zd?d@ ZdAdB ZdCdD ZdEdF ZdGdH ZdIdJ ZdKdL ZdMdN ZdOdP ZdQdR ZdSdT ZddUdVZdWdX ZdYdZ Zd[d\ Zd]d^ Zd_d` Zdadb Zdcdd Zdedf Zdgdh ZddjdkZddndoZdpdq Zdrds Zdtdu Zdvdw Zdxdy Zdzd{ Zd|d} Zd~d Zdd ZdddZdd Zdd Zdd Zdd Zdd Zdd Zdd ZdddZdddZdddZdddZdddZdd Zdd Zdd ZeZĐdd ZŐdddZƐdddZǐdddZȐdddZɐdddZʐdddZːdddZ̐dddZ͐dd ZeZeZeZѐdd ZҐdd ZӐdd ZԐdd ZՐdd Z֐dd ZאddÄ ZؐdĐdń ZِdƐdǄ ZڐdȐdɄ Zېdʐd˄ Zܐd̐d̈́ Zݐdΐdτ ZސdАdф ZߐdҐdӄ ZdԐdՄ Zd֐dׄ Zdؐdل Zdڐdۄ Zdܐd݄ Zdސd߄ Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd dZdddZdddZdd Zdd	 Zd
d Zdd Zdd Zdd Zdd Z dd Zdd Zdd Zdd Zdd Zdd Zdd d!Zd"d# Zd$d% Z	d&d' Z
d(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= ZeZd>d? Zd@dA ZdBdC ZdDdE ZdFdG ZdHdI ZdJdK ZdLdM ZdNdO ZdPdQ Z dRdS Z!dTdU Z"dVdW Z#dXdY Z$dZd[ Z%d\d] Z&d^d_ Z'd`da Z(dbdc Z)ddde Z*dfdg Z+dhdi Z,djdk Z-dldm Z.dndo Z/ddpdqZ0ddrdsZ1ddtduZ2ddvdwZ3ddxdyZ4ddzd{Z5d|d} Z6d~d Z7dd Z8dd Z9dd Z:dd Z;dd Z<dd Z=dd Z> fddZ?  Z@S (  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dagger)gothic_re_imdecimal_separatorperm_cyclicparenthesize_superminmaxdiff_operatoradjoint_stylezdict[str, Any]_default_settingsc                 C  sp  t | | d| jv rg d}| jd |vrtd| jd d u r-| jd dkr-d| jd< ddd	d
d}z|| jd  | jd< W n tyQ   | jd | jd< Y nw z|| jd pZd | jd< W n" ty   | jd  dv rx|d | jd< n| jd | jd< Y n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 \,.\, z \cdot  \times )Nldotrx   timesr   mul_symbol_latexrx   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   ro   ro   rr   r      sf   


	
	
zLatexPrinter.__init__r   r   c                 C  
   d |S )Nz\left({}\right)formatr   rq   ro   ro   rr   _add_parens      
zLatexPrinter._add_parensc                 C  r   )Nz\left( {}\right)r   r   ro   ro   rr   _add_parens_lspace   r   zLatexPrinter._add_parens_lspacec                 C  sN   t |}|r|r| | |S ||k s|s"||kr"| | |S | |S N)r   r   _print)r   itemlevelis_negstrictprec_valro   ro   rr   parenthesize   s   
zLatexPrinter.parenthesizec                 C  s*   d|v r| j d r| |S d|S |S )z
        Protect superscripts in s

        If the parenthesize_super option is set, protect with parentheses, else
        wrap in braces.
        r   r   z{{{}}})r   r   r   r   ro   ro   rr   r      s
   


zLatexPrinter.parenthesize_superc                 C  s^   t | |}| jd dkr|S | jd dkrd| S | jd r#d| S | jd }d|||f S )Nr   r   r   z$%s$r   z$$%s$$z\begin{%s}%s\end{%s})r   doprintr   )r   exprtexenv_strro   ro   rr   r   	  s   

zLatexPrinter.doprintboolc                 C  s(   |j r|jp|jo|tjuo|jdu  S )z
        Returns True if the expression needs to be wrapped in brackets when
        printed, False otherwise. For example: a + b => True; a => False;
        10 => False; -10 => True.
        F)
is_Integeris_nonnegativeis_Atomr   NegativeOneis_Rationalr   r   ro   ro   rr   _needs_brackets  s   zLatexPrinter._needs_bracketsc                 C  sJ   |  |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   ro   ro   rr   _needs_function_brackets   s   
z%LatexPrinter._needs_function_bracketsc                   s   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r2dS t fddtfD r@dS |sRt fd	d|||fD rRd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      | ]}  |V  qd S r   has.0xr   ro   rr   	<genexpr>N      z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>c                 3  r  r   r  r  r  ro   rr   r  Q  r  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  ro   r  rr   _needs_mul_brackets7  s(   
z LatexPrinter._needs_mul_bracketsc                   s4    j rdS t fddtfD rdS  j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  r  r   r  r  r  ro   rr   r  ^  r  z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>F)r  r  r   r   r   ro   r  rr   _needs_add_bracketsV  s   z LatexPrinter._needs_add_bracketsc                 C  s   |j D ]}|jr dS qdS )NFT)argsr   )r   r   r;   ro   ro   rr   r   d  s
   
zLatexPrinter._mul_is_cleanc                 C  s   |  |j S r   )r   baser   ro   ro   rr   r   j     zLatexPrinter._pow_is_cleanr   c                 C  s   |d ur
d||f S |S )N\left(%s\right)^{%s}ro   r   r   expro   ro   rr   _do_exponentm  s   zLatexPrinter._do_exponentc                   sH     |jj}|jr fdd|jD }d}||d|S d|S )Nc                      g | ]}  |qS ro   r   )r	  rL   r   ro   rr   
<listcomp>v      z-LatexPrinter._print_Basic.<locals>.<listcomp>z"\operatorname{{{}}}\left({}\right), z\text{{{}}})_deal_with_super_sub	__class____name__r  r   join)r   r   namelsrq   ro   r"  rr   _print_Basics  s   
zLatexPrinter._print_Basice!bool | BooleanTrue | BooleanFalsec                 C     d| S N	\text{%s}ro   r   r-  ro   ro   rr   _print_bool|     zLatexPrinter._print_boolc                 C  r/  r0  ro   r2  ro   ro   rr   _print_NoneType  r4  zLatexPrinter._print_NoneTypec                 C  sv   | j ||d}d}t|D ]+\}}|dkrn| r"|d7 }| }n|d7 }| |}| |r4d| }||7 }q|S )N)r   r   r    -  + \left(%s\right))_as_ordered_terms	enumerater  r   r  )r   r   r   termsr   r   termterm_texro   ro   rr   
_print_Add  s   


zLatexPrinter._print_Addc                 C  s   ddl m} |jdkrdS ||}|j}|j}|jd |d kr(||d gg }d}|D ]}|t|dd7 }q,|d	d
}|dd}|S )Nr   Permutation\left( \right)   r   ,r   r   z\left( r   \right)) sympy.combinatorics.permutationsr@  sizecyclic_form
array_formr   r   )r   r   r@  	expr_permsizr=  r   ro   ro   rr   _print_Cycle  s   
zLatexPrinter._print_Cyclec           
        s   ddl m} ddlm} |j}|d ur |d| ddddd	 n jd
d}|r. |S |jdkr5dS  fdd|j	D } fddt
t|D }d|}d|}d||f}	d|	 S )Nr   r?  )sympy_deprecation_warningzw
                Setting Permutation.print_cyclic is deprecated. Instead use
                init_printing(perm_cyclic=z).
                z1.6z#deprecated-permutation-print_cyclic   )deprecated_since_versionactive_deprecations_target
stacklevelr   TrA  c                   r   ro   r!  r	  r;   r"  ro   rr   r#    r$  z3LatexPrinter._print_Permutation.<locals>.<listcomp>c                   r   ro   r!  rR  r"  ro   rr   r#    r$   & z \\ z \begin{pmatrix} %s \end{pmatrix})rF  r@  sympy.utilities.exceptionsrM  print_cyclicr   r   rL  rG  rI  rangelenr)  )
r   r   r@  rM  r   lowerupperrow1row2matro   r"  rr   _print_Permutation  s.   




zLatexPrinter._print_Permutationc                 C  s"   |j \}}d| || |f S )Nz\sigma_{%s}(%s))r  r   )r   r   permvarro   ro   rr   _print_AppliedPermutation  s   
z&LatexPrinter._print_AppliedPermutationc           
      C  s   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||||d}| jd }d|v r`|d\}}	|	d	 d
krL|	dd  }	| jd dkrY|dd}d|||	f S |dkrfdS |dkrldS | jd dkry|dd}|S )Nr   FTr   r   )strip_zeros	min_fixed	max_fixedr   r-  r   +rC  r   comma.z{,}z%s%s10^{%s}z+infz\inftyz-infz- \infty)r!   _precr   mlib_to_str_mpf_splitr   )
r   r   dpsr   lowhighstr_real	separatormantr  ro   ro   rr   _print_Float  s(   

zLatexPrinter._print_Floatc                 C  0   |j }|j}d| |td | |td f S )Nz%s \times %sr	   _expr1_expr2r   r    r   r   vec1vec2ro   ro   rr   _print_Cross  
   zLatexPrinter._print_Crossc                 C     |j }d| |td  S )Nz\nabla\times %sr	   _exprr   r    r   r   r   ro   ro   rr   _print_Curl     zLatexPrinter._print_Curlc                 C  r{  )Nz\nabla\cdot %sr	   r|  r~  ro   ro   rr   _print_Divergence  r  zLatexPrinter._print_Divergencec                 C  rr  )Nz%s \cdot %sr	   rs  rv  ro   ro   rr   
_print_Dot  rz  zLatexPrinter._print_Dotc                 C  r{  )Nz	\nabla %sr	   r|  r   r   funcro   ro   rr   _print_Gradient  r  zLatexPrinter._print_Gradientc                 C  r{  )Nz	\Delta %sr	   r|  r  ro   ro   rr   _print_Laplacian  r  zLatexPrinter._print_Laplacianr   c                   s  ddl m} jd jd d# fdd}d#fd	d
 t|trA|j}|d tju s=tdd |dd  D rA |S d}|	 rV| }d}|j
rU|d7 }d}nd}||dd\}}|tju rvtdddd|jvrv|||7 }n||}	||}
t|
 }jd }jd r|dkrd|
vrj|ddr|d|	|
f 7 }n|d|	|
f 7 }n|d ur@t|	 || kr@j|ddr|d|
|	f 7 }nx|jr6tj}tj}|jD ]2}j|ddst|||  || ks|j|j  u rdu rn n||9 }q||9 }q݈j|ddr'|d|||
||f 7 }n!|d|||
||f 7 }n|d |
|	f 7 }n|d!|	|
f 7 }|rO|d"7 }|S )$Nr   )fractionr   r   r   r   c                   sn   | j s
t| S jdvr|  }nt| j}t|dd dd\}}t|dd dd\}} || | S )N)oldnonec                 S  s*   t | dpt | dpt| tot | jdS )N_scale_factoris_physical_constant)hasattr
isinstancer   r  r
  ro   ro   rr   rs     s    
z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>T)binaryc                 S  s
   t | dS )Nr  )r  r  ro   ro   rr   rs     s   
 )r   r   r   r   as_ordered_factorslistr  r$   )r   r  unitsnonunitsprefixes)convert_argsr   ro   rr   convert  s   




z(LatexPrinter._print_Mul.<locals>.convertc                   s   d }}t | D ]M\}}|}t|dsIt|dsIj||dk|t| d kdr/d| }td |rBtd |rB| 7 }n|rH|7 }n|rO|7 }||7 }|}q|S )Nr   r  r  r   rC  )r  r  r8  )r:  r   r  r  rW  _between_two_numbers_psearchmatch)r  _texlast_term_texr   r<  r=  )	numbersepr   ro  ro   rr   r    s(   

z-LatexPrinter._print_Mul.<locals>.convert_argsc                 s  s    | ]}t |tV  qd S r   )r  r
   rR  ro   ro   rr   r  :  r  z*LatexPrinter._print_Mul.<locals>.<genexpr>rC  F- r   Tr   )exactrB  )evaluater   r      r   )r  z\left(%s\right) / %sz%s / %sz\frac{1}{%s}%s\left(%s\right)z\frac{%s}{%s}%s\left(%s\right)z\frac{%s}{%s}%s%sz\frac{1}{%s}%s%s\frac{%s}{%s}r   r   r   )sympy.simplifyr  r   r  r	   r  r   Oner  r  r   r   rW  rj  r  r   is_commutative)r   r   r  r  r  include_parensr   numerdenomsnumersdenomldenomratioabr
  ro   )r  r  r   ro  rr   
_print_Mul  sr   


(


 

zLatexPrinter._print_Mulc                 C  s&   |j r| |  S | | S r   )
is_aliasedr   as_polyas_exprr   ro   ro   rr   _print_AlgebraicNumberz  s   z#LatexPrinter._print_AlgebraicNumberc                 C  s@   |  |j}|jrd| dS |  |j }d| d| dS )N\left(rE  r%  )r   pis_inertalphar  )r   r   r  r  ro   ro   rr   _print_PrimeIdeal  s
   zLatexPrinter._print_PrimeIdealr   c                 C  s  |j jr|j j}|j j}t|dkrF|dkrF| jd rF| |j}|dkr*d| }n| jd r6d||f }nd||f }|j jrDd| S |S | jd	 rx|dkrx| 	|jt
d
 }|jjra| |}|jjrq| j|jd||f dS d|||f S |j jr|jjr|jdkrd|j|j f S |jjr|jj}|jj}|| t|kr|j dkrd||f S d||t|j f S | |S |jjr| j|j| |j dS d}| ||S )NrC  r   r  z	\sqrt{%s}r   z\root{%d}{%s}z\sqrt[%d]{%s}z\frac{1}{%s}r   r   z%s/%sr  z
%s^{%s/%s}%s^{%s}rB  z\frac{1}{\frac{%s}{%s}}z\frac{1}{(\frac{%s}{%s})^{%s}})r  r   r  qr   r   r   r  is_negativer   r    	is_Symbolr   r   r  r  _helper_print_standard_power)r   r   r  r  r  r   base_pbase_qro   ro   rr   
_print_Pow  sF   





zLatexPrinter._print_Powtemplatec                 C  s   |  |j}| |jtd }|jjr| |}n%|jjr"d| }nt|jt	r>|
dr>td|r>|dr>|dd }|||f S )Nr   z{%s}r  z\\left\(\\d?d?dotrE     i)r   r  r   r  r    r  r   is_Floatr  r   
startswithr7   r  endswith)r   r   r  r  r  ro   ro   rr   r    s   

z)LatexPrinter._helper_print_standard_powerc                 C  s   |  |jd S Nr   r   r  r   ro   ro   rr   _print_UnevaluatedExpr     z#LatexPrinter._print_UnevaluatedExprc                      t |jdkrdtfdd|jd D  }nfdd dtd	 fd
d|jD  }t|jtr@|d|j 7 }|S ||j7 }|S )NrC  z\sum_{%s=%s}^{%s} c                   r   ro   r!  r	  r   r"  ro   rr   r#    r$  z+LatexPrinter._print_Sum.<locals>.<listcomp>r   c                   ,   dt  fdd| d | d | d fD  S )N%s \leq %s \leq %sc                   r   ro   r!  r	  rq   r"  ro   rr   r#    r$  zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>rC  r   r  tuplelr"  ro   rr   _format_ineq     &z-LatexPrinter._print_Sum.<locals>._format_ineqz\sum_{\substack{%s}} \\c                      g | ]} |qS ro   ro   r	  r  r  ro   rr   r#        r8  	rW  limitsr  r   r)  r  functionr   r   r   r   r   ro   r  r   rr   
_print_Sum     zLatexPrinter._print_Sumc                   r  )NrC  z\prod_{%s=%s}^{%s} c                   r   ro   r!  r  r"  ro   rr   r#    r$  z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                   r  )Nr  c                   r   ro   r!  r  r"  ro   rr   r#    r$  zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>rC  r   r  r  r  r"  ro   rr   r    r  z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} r  c                   r  ro   ro   r  r  ro   rr   r#    r  r8  r  r  ro   r  rr   _print_Product  r  zLatexPrinter._print_Product'BasisDependent'c                 C  s  ddl m} g }||jkr|jjS t||r|  }nd|fg}|D ]G\}}t|j }|j	dd d |D ]1\}}	|	dkrJ|
d|j  q9|	dkrW|
d	|j  q9d
| |	 d }
|
d|
 |j  q9q$d|}|d dkr|dd  }|S |dd  }|S )Nr   )Vectorc                 S  s   | d   S r  )__str__r  ro   ro   rr   rs     rt   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>keyrC  r7  rB  r6  r  rE  r   -   )sympy.vectorr  zero_latex_formr  separateitemsr  
componentssortappendr   r)  )r   r   r  o1r  systemvect
inneritemskvarg_stroutstrro   ro   rr   _print_BasisDependent  s0   



	z"LatexPrinter._print_BasisDependentc                 C  s4   |  |j}d| d ddt| j |j  }|S )Nr   rn   _{%s}rD  )r   r  r)  mapindices)r   r   tex_baser   ro   ro   rr   _print_Indexed  s
   zLatexPrinter._print_Indexedc                 C     |  |jS r   )r   labelr   ro   ro   rr   _print_IndexedBase     zLatexPrinter._print_IndexedBasec                 C  sf   |  |j}|jd ur1|  |j}|jd ur|  |j}n|  tj}dj||d}dj||dS |S )Nz%{lower}\mathrel{{..}}\nobreak {upper})rX  rY  z{{{label}}}_{{{interval}}})r  interval)r   r  rY  rX  r   Zeror   )r   r   r  rY  rX  r  ro   ro   rr   
_print_Idx  s   

zLatexPrinter._print_Idxc              	   C  s   t |jrd}n| jd }d}d}t|jD ]*\}}||7 }|dkr.|d|| |f 7 }q|d|| | || |f 7 }q|dkrLd||f }n
d	|| ||f }td
d |jD rpd|| j	|jt
d dddf S d|| j	|jt
d dddf S )Nz\partialr   r   r   rC  %s %sz
%s %s^{%s}r  z\frac{%s^{%s}}{%s}c                 s      | ]}|  V  qd S r   r  r  ro   ro   rr   r  :      z1LatexPrinter._print_Derivative.<locals>.<genexpr>r	   Tr   r   F)r   r   r   reversedvariable_countr   r   r  r  r   r    )r   r   diff_symbolr   dimr
  numro   ro   rr   _print_Derivative$  s6   




zLatexPrinter._print_Derivativec           	        s`   |j \}}} |} fdd|D } fdd|D }ddd t||D }d||f S )Nc                 3  r  r   r!  r	  r-  r"  ro   rr   r  H  r  z+LatexPrinter._print_Subs.<locals>.<genexpr>c                 3  r  r   r!  r  r"  ro   rr   r  I  r  z\\ c                 s  s$    | ]}|d  d |d  V  qdS )r   =rC  Nro   r  ro   ro   rr   r  J  s    
z#\left. %s \right|_{\substack{ %s }})r  r   r)  zip)	r   subsr   r  new
latex_expr	latex_old	latex_new
latex_subsro   r"  rr   _print_SubsE  s   

zLatexPrinter._print_Subsc              	     sX  dg }}j d  t|jdkr4tdd |jD r4ddt|jd   d	 } fd
d|jD }n\t|jD ]V}|d }|d7 }t|dkrj d dkrYj d sY|d7 }t|dkrq|d|d |d f 7 }t|dkr|d|d  7 }|dd |f  q9d|j|jt	d t
dd |jD ddd|f S )Nr   r      c                 s  s    | ]	}t |d kV  qdS )rC  N)rW  )r	  limro   ro   rr   r  T  s    z/LatexPrinter._print_Integral.<locals>.<genexpr>z\ir   rC  ntc                   s"   g | ]}d   |d f qS )\, %s%sr   r!  r	  symbolr  r   ro   rr   r#  X  s    z0LatexPrinter._print_Integral.<locals>.<listcomp>r   z\intr   r   r   z\limitsr  z
_{%s}^{%s}r  ^{%s}r  z%s %s%sr	   c                 s  r  r   r	  r  ro   ro   rr   r  o  r
  Tr  )r   rW  r  allr  r   insertr   r  r    r  r  r)  )r   r   r   symbolsr  r!  ro   r"  rr   _print_IntegralO  s:   

"zLatexPrinter._print_Integralc                 C  s   |j \}}}}d| | }t|dks|tjtjfv r&|d| | 7 }n|d| || |f 7 }t|trBd|| |f S d|| |f S )Nz\lim_{%s \to z+-z%s}z%s^%s}%s\left(%s\right)r  )r  r   r   r   InfinityNegativeInfinityr  r   )r   r   r-  zz0dirr   ro   ro   rr   _print_Limits  s   
zLatexPrinter._print_Limitr  c                 C  s   |  |}|d}|d}|tv rd| }|S t|dks,|ds,|dks,|dkr0|}|S |dkrN|dkrNd|dt|| |t||d f }|S |dkrbd|d| ||d f }|S |dkrvd|d| ||d f }|S d	| }|S )
ak  
        Logic to decide how to render a function to latex
          - if it is a recognized latex name, use the appropriate latex command
          - if it is a single letter, excluding sub- and superscripts, just use that letter
          - if it is a longer name, then put \operatorname{} around it and be
            mindful of undercores in the name
        r   _z\%srC  r   r   z\operatorname{%s}%sNz\operatorname{%s})r&  findaccepted_latex_functionsrW  r  r   )r   r  superscriptidxsubscriptidxr*  ro   ro   rr   _hprint_Function  s:   


&

	

zLatexPrinter._hprint_Functionr   c                   s  |j j}t d| rt|tst d| ||S  fdd|jD } jd }d} jd o>t|dko> 	|jd  }g d	}||v rs|d
krLn'|dkra|d dkrXdnd|dd  }n|dkrs|dd }d}|dursd}|r|t
v r~d| }	nd| }	n|dur |}
 |
}
d|
|f }	n |}	|r|t
v r|	d7 }	n	|	d7 }	n|	d7 }	|r|dur|	d| 7 }	|	d| S )a#  
        Render functions to LaTeX, handling functions that LaTeX knows about
        e.g., sin, cos, ... by using the proper LaTeX command (\sin, \cos, ...).
        For single-letter function names, render them as regular LaTeX math
        symbols. For multi-letter function names that LaTeX does not know
        about, (e.g., Li, sech) use \operatorname{} so that the function name
        is rendered in Roman font and LaTeX handles spacing properly.

        expr is the expression involving the function
        exp is an exponent
        _print_c                   s   g | ]	}t  |qS ro   )r   r   rR  r"  ro   rr   r#        z0LatexPrinter._print_Function.<locals>.<listcomp>r   Fr   rC  r   )asinacosatanacscasecacotasinhacoshatanhacschasechacothr   fullrB  hararcNpowerTz\%s^{-1}z\operatorname{%s}^{-1}r  z {%s}%s{\left(%s \right)}r#  rD  )r  r(  r  r  r   getattrr  r   rW  r  r1  r4  r   r)  )r   r   r  r  r  r   inv_trig_power_casecan_fold_bracketsinv_trig_tabler*  func_texro   r"  rr   _print_Function  sR   


"






zLatexPrinter._print_Functionc                 C     |  t|S r   )r4  r   r   ro   ro   rr   _print_UndefinedFunction  r  z%LatexPrinter._print_UndefinedFunctionc                 C     d|  |j|  |jf S )Nz{%s}_{\circ}\left({%s}\right))r   r  r   r   ro   ro   rr   _print_ElementwiseApplyFunction  s   

z,LatexPrinter._print_ElementwiseApplyFunctionc                 C  s\   ddl m} ddlm}m} ddlm} ddlm} ddl	m
} |d|d|d	|d
|d|diS )Nr   )KroneckerDelta)gamma
lowergamma)beta)
DiracDelta)rT   z\deltar?   z\gammaz\operatorname{B}z\operatorname{Chi})(sympy.functions.special.tensor_functionsrT  'sympy.functions.special.gamma_functionsrU  rV  &sympy.functions.special.beta_functionsrW  'sympy.functions.special.delta_functionsrX  'sympy.functions.special.error_functionsrT   )r   rT  rU  rV  rW  rX  rT   ro   ro   rr   _special_function_classes  s   z&LatexPrinter._special_function_classesc                 C  s>   | j D ]}t||r|j|jkr| j |   S q| t|S r   )r^  
issubclassr(  r4  r   )r   r   clsro   ro   rr   _print_FunctionClass  s
   
z!LatexPrinter._print_FunctionClassc                 C  sJ   |j \}}t|dkr| |d }n| t|}d|| |f }|S )NrC  r   z\left( %s \mapsto %s \right))r  rW  r   r  )r   r   r&  r   ro   ro   rr   _print_Lambda
  s   
zLatexPrinter._print_Lambdac                 C     dS )Nz\left( x \mapsto x \right)ro   r   ro   ro   rr   _print_IdentityFunction     z$LatexPrinter._print_IdentityFunctionc                   sT   t |jtd} fdd|D }dt|j d|f }|d ur(d||f S |S )Nr  c                      g | ]	}d   | qS )rH  r!  r   r"  ro   rr   r#    r6  z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)r%  r  )sortedr  r   r   r  rX  r)  )r   r   r  r  texargsr   ro   r"  rr   _hprint_variadic_function  s   z&LatexPrinter._hprint_variadic_functionc                 C  ,   d|  |jd  }|d urd||f S |S )Nz\left\lfloor{%s}\right\rfloorr   r  r  r   r   r  r   ro   ro   rr   _print_floor%     zLatexPrinter._print_floorc                 C  rj  )Nz\left\lceil{%s}\right\rceilr   r  r  rk  ro   ro   rr   _print_ceiling-  rm  zLatexPrinter._print_ceilingc                 C  sL   | j d sd| |jd  }n
d| |jd  }|d ur$d||f S |S )Nr   z\log{\left(%s \right)}r   z\ln{\left(%s \right)}r  )r   r   r  rk  ro   ro   rr   
_print_log5  s   
zLatexPrinter._print_logc                 C  rj  )N\left|{%s}\right|r   r  r  rk  ro   ro   rr   
_print_Abs@  rm  zLatexPrinter._print_Absc                 C  N   | j d rd| |jd td  }nd| |jd td }| ||S )Nr   z\Re{%s}r   Atomz\operatorname{{re}}{{{}}}r   r   r  r    r   r  rk  ro   ro   rr   	_print_reH     
zLatexPrinter._print_rec                 C  rr  )Nr   z\Im{%s}r   rs  z\operatorname{{im}}{{{}}}rt  rk  ro   ro   rr   	_print_imP  rv  zLatexPrinter._print_imc                 C  s   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  S d| |jd  S )Nr   )
EquivalentImpliesz\not\Leftrightarrowz\not\Rightarrowz\neg \left(%s\right)z\neg %s)	sympy.logic.boolalgrx  ry  r  r  _print_Equivalent_print_Implies
is_Booleanr   )r   r-  rx  ry  ro   ro   rr   
_print_NotX  s   zLatexPrinter._print_Notc                 C  s   |d }|j r|jsd| | }nd| | }|dd  D ]}|j r3|js3|d|| |f 7 }q|d|| |f 7 }q|S )Nr   r8  rH  rC  z %s \left(%s\right)z %s %s)r}  is_Notr   )r   r  charr;   r   ro   ro   rr   _print_LogOpc  s   zLatexPrinter._print_LogOpc                 C     t |jtd}| |dS )Nr  z\wedgerg  r  r   r  r   r-  r  ro   ro   rr   
_print_Andr     zLatexPrinter._print_Andc                 C  r  )Nr  z\veer  r  ro   ro   rr   	_print_Orv  r  zLatexPrinter._print_Orc                 C  r  )Nr  z\veebarr  r  ro   ro   rr   
_print_Xorz  r  zLatexPrinter._print_Xorc                 C  s   |  |j|pdS )Nz\Rightarrow)r  r  )r   r-  altcharro   ro   rr   r|  ~     zLatexPrinter._print_Impliesc                 C  s   t |jtd}| ||pdS )Nr  z\Leftrightarrowr  )r   r-  r  r  ro   ro   rr   r{    s   zLatexPrinter._print_Equivalentc                 C  rj  )Nz\overline{%s}r   r  r  rk  ro   ro   rr   _print_conjugate  rm  zLatexPrinter._print_conjugatec                 C  s:   d}d|  |jd  }|d urd|||f S d||f S )Nz\operatorname{polar\_lift}rI  r   	%s^{%s}%s%s%sr  )r   r   r  r  r;   ro   ro   rr   _print_polar_lift  s
   zLatexPrinter._print_polar_liftc                 C  s    d|  |jd  }| ||S )Nze^{%s}r   )r   r  r  rk  ro   ro   rr   _print_ExpBase  s   zLatexPrinter._print_ExpBasec                 C  rc  )Nr-  ro   r  ro   ro   rr   _print_Exp1  re  zLatexPrinter._print_Exp1c                 C  0   d|  |jd  }|d urd||f S d| S )Nr8  r   zK^{%s}%szK%sr  rk  ro   ro   rr   _print_elliptic_k  s   zLatexPrinter._print_elliptic_kc                 C  @   d|  |jd |  |jd f }|d urd||f S d| S )N\left(%s\middle| %s\right)r   rC  zF^{%s}%szF%sr  rk  ro   ro   rr   _print_elliptic_f  s   zLatexPrinter._print_elliptic_fc                 C  sd   t |jdkrd| |jd | |jd f }n
d| |jd  }|d ur.d||f S d| S )Nr  r  r   rC  r8  zE^{%s}%szE%srW  r  r   rk  ro   ro   rr   _print_elliptic_e  s   zLatexPrinter._print_elliptic_ec                 C  s   t |jdkr!d| |jd | |jd | |jd f }nd| |jd | |jd f }|d ur=d||f S d| S )	Nr  z\left(%s; %s\middle| %s\right)r   rC  r  r  z
\Pi^{%s}%sz\Pi%sr  rk  ro   ro   rr   _print_elliptic_pi  s   zLatexPrinter._print_elliptic_pic                 C  sZ   |j d }t|j dkr|j d n|j d }d| d| d}|d ur)d||f S d| S )Nr   rC  r  r%  rE  z\operatorname{B}^{%s}%sz\operatorname{B}%s)r  rW  )r   r   r  r
  yr   ro   ro   rr   _print_beta  s   
"zLatexPrinter._print_betaBc                   sb    fdd|j D }d|d |d f }|d ur%d||d |d ||f S d	||d |d |f S )
Nc                   r   ro   r!  rR  r"  ro   rr   r#    r$  z/LatexPrinter._print_betainc.<locals>.<listcomp>\left(%s, %s\right)r   rC  z#\operatorname{%s}_{(%s, %s)}^{%s}%sr  r  z\operatorname{%s}_{(%s, %s)}%s)r  )r   r   r  operatorlargsr   ro   r"  rr   _print_betainc  s
   zLatexPrinter._print_betaincc                 C  s   | j ||ddS )NI)r  )r  r  ro   ro   rr   _print_betainc_regularized  r  z'LatexPrinter._print_betainc_regularizedc                 C  r  )Nr  r   rC  z\Gamma^{%s}%sz\Gamma%sr  rk  ro   ro   rr   _print_uppergamma     zLatexPrinter._print_uppergammac                 C  r  )Nr  r   rC  z\gamma^{%s}%s\gamma%sr  rk  ro   ro   rr   _print_lowergamma  r  zLatexPrinter._print_lowergammac                 C  sF   d|  |jd  }|d urd|  |j||f S d|  |j|f S Nr8  r   r  r  )r   r  r  rk  ro   ro   rr   _hprint_one_arg_func  s   z!LatexPrinter._hprint_one_arg_funcc                 C  r  )Nr8  r   z\operatorname{Chi}^{%s}%sz\operatorname{Chi}%sr  rk  ro   ro   rr   
_print_Chi     zLatexPrinter._print_Chic                 C  sF   d|  |jd  }|  |jd }|d urd|||f S d||f S )Nr8  rC  r   z\operatorname{E}_{%s}^{%s}%sz\operatorname{E}_{%s}%sr  )r   r   r  r   nuro   ro   rr   _print_expint  s
   zLatexPrinter._print_expintc                 C  r  )Nr8  r   zS^{%s}%szS%sr  rk  ro   ro   rr   _print_fresnels
  r  zLatexPrinter._print_fresnelsc                 C  r  )Nr8  r   zC^{%s}%szC%sr  rk  ro   ro   rr   _print_fresnelc  r  zLatexPrinter._print_fresnelcc                 C  2   d|  |jd td  }|d urd||f S |S )Nz!%sr   Funcr  r   r  r    rk  ro   ro   rr   _print_subfactorial     z LatexPrinter._print_subfactorialc                 C  r  )Nz%s!r   r  r  r  rk  ro   ro   rr   _print_factorial"  r  zLatexPrinter._print_factorialc                 C  r  )Nz%s!!r   r  r  r  rk  ro   ro   rr   _print_factorial2*  r  zLatexPrinter._print_factorial2c                 C  s<   d|  |jd |  |jd f }|d urd||f S |S )Nz{\binom{%s}{%s}}r   rC  r  r  rk  ro   ro   rr   _print_binomial2  s   zLatexPrinter._print_binomialc                 C  s<   |j \}}d| |td  }d|| |f }| ||S )NrH  r  z{%s}^{\left(%s\right)}r  r   r    r   r  )r   r   r  nr  r  r   ro   ro   rr   _print_RisingFactorial;     
z#LatexPrinter._print_RisingFactorialc                 C  s<   |j \}}d| |td  }d| ||f }| ||S )NrH  r  z{\left(%s\right)}_{%s}r  )r   r   r  r  r  subr   ro   ro   rr   _print_FallingFactorialC  r  z$LatexPrinter._print_FallingFactorialsymc                 C  sf   d| }d}|d ur| ddkrd||f }nd}d|| |j| |jf }|r1| ||}|S )NrH  Fr   rB  r  T%s_{%s}\left(%s\right))r0  r   r   argumentr  )r   r   r  r  r   need_expro   ro   rr   _hprint_BesselBaseK  s   
zLatexPrinter._hprint_BesselBasec                 C  sF   |sdS d}|d d D ]}|d|  | 7 }q||  |d 7 }|S )Nr   rB  z%s, r!  )r   r   rq   r   ro   ro   rr   _hprint_vec\  s   zLatexPrinter._hprint_vecc                 C     |  ||dS )NJr  r  ro   ro   rr   _print_besselje  r  zLatexPrinter._print_besseljc                 C  r  )Nr  r  r  ro   ro   rr   _print_besselih  r  zLatexPrinter._print_besselic                 C  r  )NKr  r  ro   ro   rr   _print_besselkk  r  zLatexPrinter._print_besselkc                 C  r  )NYr  r  ro   ro   rr   _print_besselyn  r  zLatexPrinter._print_besselyc                 C  r  )Nr  r  r  ro   ro   rr   	_print_ynq  r  zLatexPrinter._print_ync                 C  r  )Nr   r  r  ro   ro   rr   	_print_jnt  r  zLatexPrinter._print_jnc                 C  r  )NzH^{(1)}r  r  ro   ro   rr   _print_hankel1w  r  zLatexPrinter._print_hankel1c                 C  r  )NzH^{(2)}r  r  ro   ro   rr   _print_hankel2z  r  zLatexPrinter._print_hankel2c                 C  r  )Nzh^{(1)}r  r  ro   ro   rr   
_print_hn1}  r  zLatexPrinter._print_hn1c                 C  r  )Nzh^{(2)}r  r  ro   ro   rr   
_print_hn2  r  zLatexPrinter._print_hn2r   c                 C  6   d|  |jd  }|d urd|||f S d||f S r  r  r   r   r  notationr   ro   ro   rr   _hprint_airy     zLatexPrinter._hprint_airyc                 C  r  )Nr8  r   z{%s^\prime}^{%s}%sz%s^\prime%sr  r  ro   ro   rr   _hprint_airy_prime  r  zLatexPrinter._hprint_airy_primec                 C  r  NAir  r  ro   ro   rr   _print_airyai  r  zLatexPrinter._print_airyaic                 C  r  NBir  r  ro   ro   rr   _print_airybi  r  zLatexPrinter._print_airybic                 C  r  r  r  r  ro   ro   rr   _print_airyaiprime  r  zLatexPrinter._print_airyaiprimec                 C  r  r  r  r  ro   ro   rr   _print_airybiprime  r  zLatexPrinter._print_airybiprimec                 C  sZ   d|  t|j|  t|j| |j| |j|  |jf }|d ur+d||f }|S )NzN{{}_{%s}F_{%s}\left(\begin{matrix} %s \\ %s \end{matrix}\middle| {%s} \right)}	{%s}^{%s})r   rW  apbqr  r  rk  ro   ro   rr   _print_hyper  s   
zLatexPrinter._print_hyperc                 C  s   d|  t|j|  t|j|  t|j|  t|j| |j| |j| |j| |j|  |j	f	 }|d urCd||f }|S )Nz^{G_{%s, %s}^{%s, %s}\left(\begin{matrix} %s & %s \\%s & %s \end{matrix} \middle| {%s} \right)}r  )
r   rW  r  r  r   anr  aotherbotherr  rk  ro   ro   rr   _print_meijerg  s   
zLatexPrinter._print_meijergc                 C  r  )Nr8  r   z\eta^{%s}%sz\eta%sr  rk  ro   ro   rr   _print_dirichlet_eta  s   z!LatexPrinter._print_dirichlet_etac                 C  sV   t |jdkrdtt| j|j }n
d| |jd  }|d ur'd||f S d| S )Nr  r  r8  r   z\zeta^{%s}%sz\zeta%srW  r  r  r  r   rk  ro   ro   rr   _print_zeta     zLatexPrinter._print_zetac                 C  sV   t |jdkrdtt| j|j }n
d| |jd  }|d ur'd||f S d| S )Nr  z_{%s}\left(%s\right)r  r   z\gamma%s^{%s}r  r  rk  ro   ro   rr   _print_stieltjes  r  zLatexPrinter._print_stieltjesc                 C  s2   dt t| j|j }|d u rd| S d||f S )Nz\left(%s, %s, %s\right)z\Phi%sz\Phi^{%s}%s)r  r  r   r  rk  ro   ro   rr   _print_lerchphi  s   zLatexPrinter._print_lerchphic                 C  s<   t | j|j\}}d| }|d u rd||f S d|||f S )Nr8  z\operatorname{Li}_{%s}%sz\operatorname{Li}_{%s}^{%s}%sr  r   r  )r   r   r  rq   r+  r   ro   ro   rr   _print_polylog  s
   zLatexPrinter._print_polylogc                 C  B   t | j|j\}}}}d||||f }|d urd| d|  }|S )Nz*P_{%s}^{\left(%s,%s\right)}\left(%s\right)r  \right)^{%s}r  )r   r   r  r  r  r  r
  r   ro   ro   rr   _print_jacobi  
   zLatexPrinter._print_jacobic                 C  >   t | j|j\}}}d|||f }|d urd| d|  }|S )Nz'C_{%s}^{\left(%s\right)}\left(%s\right)r  r  r  r   r   r  r  r  r
  r   ro   ro   rr   _print_gegenbauer  
   zLatexPrinter._print_gegenbauerc                 C  :   t | j|j\}}d||f }|d urd| d|  }|S )NzT_{%s}\left(%s\right)r  r  r  r   r   r  r  r
  r   ro   ro   rr   _print_chebyshevt  
   zLatexPrinter._print_chebyshevtc                 C  r  )NzU_{%s}\left(%s\right)r  r  r  r  ro   ro   rr   _print_chebyshevu  r  zLatexPrinter._print_chebyshevuc                 C  r  )NzP_{%s}\left(%s\right)r  r  r  r  ro   ro   rr   _print_legendre  r  zLatexPrinter._print_legendrec                 C  r  )Nz'P_{%s}^{\left(%s\right)}\left(%s\right)r  r  r  r  ro   ro   rr   _print_assoc_legendre  r  z"LatexPrinter._print_assoc_legendrec                 C  r  )NzH_{%s}\left(%s\right)r  r  r  r  ro   ro   rr   _print_hermite  r  zLatexPrinter._print_hermitec                 C  r  )NzL_{%s}\left(%s\right)r  r  r  r  ro   ro   rr   _print_laguerre  r  zLatexPrinter._print_laguerrec                 C  r  )Nz'L_{%s}^{\left(%s\right)}\left(%s\right)r  r  r  r  ro   ro   rr   _print_assoc_laguerre  r  z"LatexPrinter._print_assoc_laguerrec                 C  r  )NzY_{%s}^{%s}\left(%s,%s\right)r  r  r  r   r   r  r  mthetaphir   ro   ro   rr   
_print_Ynm  r  zLatexPrinter._print_Ynmc                 C  r  )NzZ_{%s}^{%s}\left(%s,%s\right)r  r  r  r  ro   ro   rr   
_print_Znm"  r  zLatexPrinter._print_Znmc           	      C  sB   t | j|\}}}|rdnd}|sdnd| }d||||||f S )Nz	^{\prime}r   r#  z%s%s\left(%s, %s, %s\right)%s)r  r   )	r   	characterr  r   r  r  r  r+  supro   ro   rr   __print_mathieu_functions)  s   z&LatexPrinter.__print_mathieu_functionsc                 C     | j d|j|dS )NCr  &_LatexPrinter__print_mathieu_functionsr  r  ro   ro   rr   _print_mathieuc/  r  zLatexPrinter._print_mathieucc                 C  r  )Nr   r  r  r  ro   ro   rr   _print_mathieus2  r  zLatexPrinter._print_mathieusc                 C     | j d|jd|dS )Nr  Tr   r  r  r  ro   ro   rr   _print_mathieucprime5     z!LatexPrinter._print_mathieucprimec                 C  r  )Nr   Tr  r  r  ro   ro   rr   _print_mathieusprime8  r  z!LatexPrinter._print_mathieusprimec                 C  s^   |j dkr)d}|j}|jdk rd}| }| jd r!d|||j f S d|||j f S | |jS )NrC  r   r   r  r   z	%s%d / %dz%s\frac{%d}{%d})r  r  r   r   )r   r   signr  ro   ro   rr   _print_Rational;  s   


zLatexPrinter._print_Rationalc                 C  s   |  |j}|jrtdd |jD st|jdkr\|d7 }t|jdkr.||  |j7 }n|jr;||  |jd 7 }|d7 }t|jdkrR||  |j7 }d| S ||  |jd 7 }d| S )Nc                 s  s    | ]}|t jkV  qd S r   )r   r  )r	  r  ro   ro   rr   r  J  r  z,LatexPrinter._print_Order.<locals>.<genexpr>rC  ; r   z\rightarrow zO\left(%s\right))r   r   pointr  rW  	variablesr   r   rq   ro   ro   rr   _print_OrderH  s   zLatexPrinter._print_Orderr   c                 C  s,   | j d |}|d ur|S | j|j|dS )Nr   style)r   r   r&  r*  )r   r   r  r*  ro   ro   rr   _print_SymbolX  s   zLatexPrinter._print_Symbolstringc                 C  s   d|v r|g g }}}nt |\}}}t|}dd |D }dd |D }|dkr/d|}|r:|dd| 7 }|rE|d	d| 7 }|S )
Nr   c                 S     g | ]}t |qS ro   	translater	  r
  ro   ro   rr   r#  h  r  z5LatexPrinter._deal_with_super_sub.<locals>.<listcomp>c                 S  r"  ro   r#  r	  r  ro   ro   rr   r#  i  r  r   \mathbf{{{}}}r#  r   r  )r   r$  r   r)  )r   r!  r  r*  supersr  ro   ro   rr   r&  a  s   
z!LatexPrinter._deal_with_super_subc                 C  sR   | j d r
d}d}nd}d}d||ddd	d
}d| |j||j | |jf S )Nr   z\gtz\lt><r  z\geqz\leqz\neq)z==r)  r*  z>=z<=z!=z%s %s %s)r   r   lhsrel_oprhs)r   r   gtltcharmapro   ro   rr   _print_Relationalw  s   
	zLatexPrinter._print_Relationalc                   s    fdd|j d d D }|j d jtkr%|d |j d j  n|d |j d j |j d jf  d}|d| S )Nc                   s(   g | ]\}}d   |  |f qS )%s & \text{for}\: %sr!  )r	  r-  r   r"  ro   rr   r#    s    z1LatexPrinter._print_Piecewise.<locals>.<listcomp>rB  z%s & \text{otherwise}r2  z\begin{cases} %s \end{cases}z \\)r  condr   r  r   r   r)  )r   r   ecpairsr   ro   r"  rr   _print_Piecewise  s   
zLatexPrinter._print_Piecewisec              
     s   g }t |jD ]}|d fdd||d d f D  q jd }|d u r> jd dkr2d}n|jdkd	u r<d
}nd}d}|d|}|dkrW|ddd|j  d }|d| S )NrS  c                   r   ro   r!  r  r"  ro   rr   r#    r$  z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>r   r   r   smallmatrix
   Tmatrixarray \begin{%MATSTR%}%s\end{%MATSTR%}%MATSTR%rH  r   r   }%sr  )rV  rowsr  r)  r   colsr   )r   r   linesliner   out_strro   r"  rr   _print_matrix_contents  s   ,
z#LatexPrinter._print_matrix_contentsc                 C  s@   |  |}| jd r| jd }| j| }d| | d | }|S )Nr   \left\right)rB  r   r   )r   r   rA  
left_delimright_delimro   ro   rr   _print_MatrixBase  s   




zLatexPrinter._print_MatrixBasec                 C  sF   | j |jtd dd}| |j d| |j }d| d| dS )Nrs  Tr   rD  r   z}_{rn   )r   parentr    r   r   r   )r   r   matrix_part
index_partro   ro   rr   _print_MatrixElement  s   z!LatexPrinter._print_MatrixElementc                   sN    fdd} j |jtd ddd ||j|jj d ||j|jj d S )	Nc                   sZ   t | } | d dkr| d= | d dkrd | d< | d |kr!d | d< d fdd| D S )Nr  rC  r   :c                 3  s&    | ]}|d ur  |ndV  qd S Nr   r!  )r	  xir"  ro   rr   r       $ zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>)r  r)  )r
  r  r"  ro   rr   
latexslice  s   z3LatexPrinter._print_MatrixSlice.<locals>.latexslicers  TrH  \left[r%  \right])r   rI  r    rowslicer=  colslicer>  )r   r   rQ  ro   r"  rr   _print_MatrixSlice  s   	zLatexPrinter._print_MatrixSlicec                 C  r   r   )r   blocksr   ro   ro   rr   _print_BlockMatrix  r  zLatexPrinter._print_BlockMatrixc                 C  sh   |j }ddlm}m} t||st||s|jrd| | S | |t|d}d|v r0d| S d| S )Nr   MatrixSymbolBlockMatrixz\left(%s\right)^{T}Tr   z%s^{T})	r;   sympy.matricesrZ  r[  r  is_MatrixExprr   r   r   )r   r   r\  rZ  r[  rq   ro   ro   rr   _print_Transpose  s   
zLatexPrinter._print_Transposec                 C  s   |j }d| | S )Nz!\operatorname{tr}\left(%s \right))r;   r   r   r   r\  ro   ro   rr   _print_Trace  s   zLatexPrinter._print_Tracec                 C  s   dddd}| | jd d}|j}ddlm}m} t||s0t||s0|jr0d| ||f S | 	|t
|d	}d
|v rCd||f S d||f S )Nz\daggerz\astz
\mathsf{H})r   star	hermitianr   r   rY  r  Tr   r  )r   r   r;   r\  rZ  r[  r  r]  r   r   r   )r   r   style_to_latexr   r\  rZ  r[  rq   ro   ro   rr   _print_Adjoint  s"   
zLatexPrinter._print_Adjointc                   sz   ddl m   fdd}tj} r5|d dkr$|dd  }n|d  |d< ddt|| S dt||S )	Nr   )MatMulc                   s0   t | trt |  s| S | tdS NF)r  r	   r   r   r   r  re  r   r   ro   rr   rs     s    z,LatexPrinter._print_MatMul.<locals>.<lambda>rB  rC  r  r   )sympyre  r  r  r  r)  r  )r   r   parensr  ro   rg  rr   _print_MatMul  s   
zLatexPrinter._print_MatMulc                 C  sN   |j }|jr ddlm} t||rd| |j S d| | S d| | S )Nr   )r[  rp  )r;   r]  &sympy.matrices.expressions.blockmatrixr[  r  rB  rW  r   )r   r   r\  r[  ro   ro   rr   _print_Determinant  s   
zLatexPrinter._print_Determinantc                 C  sz   |d ur!d| j |jd td dd| j |jd td dd|f S d| j |jd td dd| j |jd td ddf S )Nz\left(%s \bmod %s\right)^{%s}r   r	   TrH  rC  z%s \bmod %sr  r  ro   ro   rr   
_print_Mod  s(   zLatexPrinter._print_Modc                   .   |j }td | j d fdd|D S )Nr   z \circ c                 3      | ]
} |d dV  qdS TrH  Nro   rR  ri  precro   rr   r  !      z6LatexPrinter._print_HadamardProduct.<locals>.<genexpr>r  r    r   r)  r   r   r  ro   rq  rr   _print_HadamardProduct     z#LatexPrinter._print_HadamardProductc                 C  s(   t |jtd k rd}nd}| ||S )Nr	   z%s^{\circ \left({%s}\right)}z%s^{\circ {%s}})r   r  r    r  )r   r   r  ro   ro   rr   _print_HadamardPower#  s   z!LatexPrinter._print_HadamardPowerc                   rn  )Nr   	 \otimes c                 3  ro  rp  ro   rR  rq  ro   rr   r  0  rs  z7LatexPrinter._print_KroneckerProduct.<locals>.<genexpr>rt  ru  ro   rq  rr   _print_KroneckerProduct*  rw  z$LatexPrinter._print_KroneckerProductc                 C  sx   |j |j}}ddlm} t||s!|jr!d| || |f S | |}d|v r3d|| |f S d|| |f S )Nr   )rZ  r  r   r  )r  r  r\  rZ  r  r]  r   )r   r   r  r  rZ  base_strro   ro   rr   _print_MatPow2  s   

zLatexPrinter._print_MatPowc                 C  s   | j || jd dS )Nr   r  )r   r   r   ro   ro   rr   _print_MatrixSymbol?  s   
z LatexPrinter._print_MatrixSymbolc                 C     | j d dkr	dS dS )Nr   r   0z
\mathbf{0}r   )r   Zro   ro   rr   _print_ZeroMatrixC     zLatexPrinter._print_ZeroMatrixc                 C  r~  )Nr   r   1z
\mathbf{1}r  )r   Oro   ro   rr   _print_OneMatrixG  r  zLatexPrinter._print_OneMatrixc                 C  r~  )Nr   r   z
\mathbb{I}z
\mathbf{I}r  )r   r  ro   ro   rr   _print_IdentityK  r  zLatexPrinter._print_Identityc                 C  s   |  |jd }d| S )Nr   zP_{%s}r  )r   Pperm_strro   ro   rr   _print_PermutationMatrixO  s   z%LatexPrinter._print_PermutationMatrixr%   c              
   C  s  |  dkr| |d S | jd }|d u r2| jd dkr d}n|  dks-|jd dkr0d	}nd
}d}|d|}|d
krM|ddd|jd   d }| jd rf| jd }| j| }d| | d | }|  dkrp|d S dd t|  d D }dd |jD }tj| D ]n}|d 	| ||  d}	t|  d ddD ]S}
t
||
d  |j|
 k r nC|	r||
 	d||
d   n(||
 	|d||
d    t
||
d  dkrd||
 d  d ||
 d< |	 }	g ||
d < qq|d d }|  d dkr|| }|S )Nr   ro   r   r   r   r6  rB  r7  r8  r9  r:  r;  rH  r   r   r<  r   rC  rD  r   c                 S  s   g | ]}g qS ro   ro   r  ro   ro   rr   r#  o  s    z1LatexPrinter._print_NDimArray.<locals>.<listcomp>rC  c                 S  s   g | ]}t t|qS ro   )r  rV  r  ro   ro   rr   r#  p      TrS  r  rR  rS  r  )rankr   r   shaper   r   rV  	itertoolsproductr  rW  r)  )r   r   r   	block_strrE  rF  	level_strshape_rangesouter_ievenback_outer_irA  ro   ro   rr   _print_NDimArrayS  sf   





zLatexPrinter._print_NDimArray	index_mapdictc           	      C  s   |  |}d }d }|D ]M}|j}||v s|r||kr|d7 }||kr6|d ur*|d7 }|jr2|d7 }n|d7 }||  |jd 7 }||v rT|d7 }||  || 7 }d}nd}|}q|d ura|d7 }|S )	NrD  rn   z{}^{z{}_{r   r  TF)r   is_upr  )	r   r*  r  r  rA  last_valenceprev_mapindexnew_valencero   ro   rr   _printer_tensor_indices  s0   

z$LatexPrinter._printer_tensor_indicesc                 C  s&   |j d j d }| }| ||i S r  )r  get_indicesr  )r   r   r*  r  ro   ro   rr   _print_Tensor  s   zLatexPrinter._print_Tensorc                 C  s0   |j jd jd }|j  }|j}| |||S r  )r   r  r  r  r  )r   r   r*  r  r  ro   ro   rr   _print_TensorElement  s   
z!LatexPrinter._print_TensorElementc                   s*      \}}|d fdd|D  S )Nr   c                   s   g | ]
} |t qS ro   )r   r   rR  r   r   ro   rr   r#        z/LatexPrinter._print_TensMul.<locals>.<listcomp>)!_get_args_for_traditional_printerr)  )r   r   r  r  ro   r  rr   _print_TensMul  s   zLatexPrinter._print_TensMulc                 C  sL   g }|j }|D ]}|| |t| q|  d|}|dd}|S )Nr7  z+ -r  )r  r  r   r   r  r)  r   )r   r   r  r  r
  rq   ro   ro   rr   _print_TensAdd  s   
zLatexPrinter._print_TensAddc                 C  s"   d|j rdnd| |jd f S )Nz{}%s{%s}r   r/  r   )r  r   r  r   ro   ro   rr   _print_TensorIndex  s   zLatexPrinter._print_TensorIndexc                   sp   t |jdkrd |jd  |jtd df S dt |jd fdd	|jD  |jtd df S )
NrC  z"\frac{\partial}{\partial {%s}}{%s}r   r	   Fz\frac{\partial^{%s}}{%s}{%s}r   c                   rf  )z\partial {%s}r!  r  r"  ro   rr   r#    r6  z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>)rW  r  r   r   r   r    r)  r   ro   r"  rr   _print_PartialDerivative  s   z%LatexPrinter._print_PartialDerivativec                 C  r   r   )r   r*  r   ro   ro   rr   _print_ArraySymbol  r  zLatexPrinter._print_ArraySymbolc                   s2   d  |jtd dd fdd|jD f S )Nz{{%s}_{%s}}r  Tr%  c                   s   g | ]}  | qS ro   r!  r  r"  ro   rr   r#    r  z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>)r   r*  r    r)  r  r   ro   r"  rr   _print_ArrayElement  s   z LatexPrinter._print_ArrayElementc                 C  rc  )Nz
\mathbb{U}ro   r   ro   ro   rr   _print_UniversalSet  re  z LatexPrinter._print_UniversalSetc                 C  s4   |d u rd|  |jd  S d|  |jd |f S )Nz$\operatorname{frac}{\left(%s\right)}r   z)\operatorname{frac}{\left(%s\right)}^{%s}r  r  ro   ro   rr   _print_frac  s
   zLatexPrinter._print_fracc                   sv    j d dkr
d}n j d dkrd}ntdt|dkr*  |d | S  |d	  fd
d|D S )Nr   re  ;r   rD  Unknown Decimal SeparatorrC  r   z \  c                   r   ro   r!  r  r"  ro   rr   r#    r$  z-LatexPrinter._print_tuple.<locals>.<listcomp>)r   r   rW  r   r   r)  )r   r   sepro   r"  rr   _print_tuple  s   zLatexPrinter._print_tuplec                       fdd|j D }d|S )Nc                   r   ro   r!  r	  r  r"  ro   rr   r#    r$  z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>ry  r  r)  r   r   elementsro   r"  rr   _print_TensorProduct     
z!LatexPrinter._print_TensorProductc                   r  )Nc                   r   ro   r!  r  r"  ro   rr   r#    r$  z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>z \wedge r  r  ro   r"  rr   _print_WedgeProduct  r  z LatexPrinter._print_WedgeProductc                 C  
   |  |S r   )r  r   ro   ro   rr   _print_Tuple  r   zLatexPrinter._print_Tuplec                   s\    j d dkrdd fdd|D  S  j d dkr*dd fd	d|D  S td
)Nr   re  z\left[ %s\right]z; \  c                   r   ro   r!  r  r"  ro   rr   r#    r$  z,LatexPrinter._print_list.<locals>.<listcomp>r   , \  c                   r   ro   r!  r  r"  ro   rr   r#    r$  r  )r   r)  r   r   ro   r"  rr   _print_list  s   zLatexPrinter._print_listc                 C  sR   t | td}g }|D ]}|| }|d| || |f  qdd| S )Nr  z%s : %sz\left\{ %s\right\}r  )rg  keysr   r  r   r)  )r   r   r  r  r  valro   ro   rr   _print_dict  s    zLatexPrinter._print_dictc                 C  r  r   )r  r   ro   ro   rr   _print_Dict  r   zLatexPrinter._print_Dictc                 C  sj   t |jdks|jd dkrd| |jd  }nd| |jd | |jd f }|r3d||f }|S )NrC  r   z\delta\left(%s\right)z+\delta^{\left( %s \right)}\left( %s \right)r  r  rk  ro   ro   rr   _print_DiracDelta  s   zLatexPrinter._print_DiracDeltac                 C  sP   |  |jd |jd  }|  |jd }d||f }|d ur&d|||f }|S )Nr   rC  r  z${\left\langle %s \right\rangle}^{%s}z-{\left({\langle %s \rangle}^{%s}\right)}^{%s}r  )r   r   r  shiftrG  r   ro   ro   rr   _print_SingularityFunction#  s   z'LatexPrinter._print_SingularityFunctionc                   s6   d  fdd|jD }d| }|rd||f }|S )Nr%  c                 3  r  r   r!  rR  r"  ro   rr   r  ,  r  z0LatexPrinter._print_Heaviside.<locals>.<genexpr>z\theta\left(%s\right)r  )r)  pargs)r   r   r  r  r   ro   r"  rr   _print_Heaviside+  s
   zLatexPrinter._print_Heavisidec                 C  sj   |  |jd }|  |jd }|jd jr#|jd jr#d||f }nd||f }|d ur3d||f }|S )Nr   rC  z\delta_{%s %s}z\delta_{%s, %s}r  )r   r  r   )r   r   r  r   r   r   ro   ro   rr   _print_KroneckerDelta2  s   z"LatexPrinter._print_KroneckerDeltac                 C  sT   t | j|j}tdd |jD rdd| }ndd| }|r(d||f }|S )Nc                 s  s    | ]}|j V  qd S r   )r   r  ro   ro   rr   r  ?  s    z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}r   r%  r  )r  r   r  r$  r)  )r   r   r  r  r   ro   ro   rr   _print_LeviCivita=  s   zLatexPrinter._print_LeviCivitac                 C  sj   t |drd| |  S t |dr#d| |j d | |j S t |dr0d| |j S | d S )N
as_booleanz\text{Domain: }setz \in r&  z\text{Domain on })r  r   r  r&  r  )r   r   ro   ro   rr   _print_RandomDomainG  s   




z LatexPrinter._print_RandomDomainc                 C  s   t |jtd}| |S )Nr  )rg  r  r   
_print_setr   rq   r  ro   ro   rr   _print_FiniteSetR  s   
zLatexPrinter._print_FiniteSetc                 C  sd   t |td}| jd dkrdt| j|}d| S | jd dkr.dt| j|}d| S td)	Nr  r   re  r  r   r%  r  \left\{%s\right\})rg  r   r   r)  r  r   r   r  ro   ro   rr   r  V  s   zLatexPrinter._print_setc                   s
  fdd}t   jjr&jjr&jjr ddd f}nV ddd f}nNjjr7 d j d f}n=jjrIt}t|t| f}n+jd urqj	dk dkrZt
}njrnt}t|t| d f}n| S | S dd	 fd
d|D  d S )Nc                    s    j d dkr% j d dkr j d } n4dfdd j D } n& j d dkr>dfdd j d d D } ndfdd j D } d	|  d
S )Nr   r  rC  r%  c                 3  r  r   r!  rR  r"  ro   rr   r  j  r  zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>c                 3  r  r   r!  rR  r"  ro   rr   r  m  r  c                 3  r  r   r!  rR  r"  ro   rr   r  o  r  z\text{Range}\left(rE  )r  r   r)  )cont)rq   r   ro   rr   _print_symbolic_ranged  s   $z8LatexPrinter._print_Range.<locals>._print_symbolic_rangerB  r   rC  r  Tz\left\{r%  c                 3  &    | ]}| ur |nd V  qdS z\ldotsNr!  r	  eldotsr   ro   rr   r    rP  z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})objectstartis_infinitestopstepis_positiveiternextis_emptyrG  r  is_iterabler)  )r   rq   r  printsetitro   )r  rq   r   rr   _print_Rangec  s0   

zLatexPrinter._print_Rangec                 C  s   t |jdkr2|d urd|| |jd || |jd f S d|| |jd | |jd f S d|| |jd f }|d urHd||f }|S )Nr  z%s_{%s}^{%s}\left(%s\right)r   rC  r  z%s_{%s}r  r  )r   r   letterr  r   ro   ro   rr   __print_number_polynomial  s   z&LatexPrinter.__print_number_polynomialc                 C     |  |d|S Nr  &_LatexPrinter__print_number_polynomialr  ro   ro   rr   _print_bernoulli  r  zLatexPrinter._print_bernoullic                 C  r  )NGr  r  ro   ro   rr   _print_genocchi  r  zLatexPrinter._print_genocchic                   s   t |jdkr=d |jd  |jd f }dd fdd|jd	 D  }|d ur7d
|||f }|S || }|S  |d|S )Nr  z
B_{%s, %s}r   rC  r8  r%  c                 3  r  r   r!  r  r"  ro   rr   r    s    z+LatexPrinter._print_bell.<locals>.<genexpr>r  r  r  )rW  r  r   r)  r  )r   r   r  tex1tex2r   ro   r"  rr   _print_bell  s   
zLatexPrinter._print_bellc                 C  r  NFr  r  ro   ro   rr   _print_fibonacci  r  zLatexPrinter._print_fibonaccic                 C  ,   d|  |jd  }|d urd||f }|S )NzL_{%s}r   r  r  rk  ro   ro   rr   _print_lucas     zLatexPrinter._print_lucasc                 C  r  )NTr  r  ro   ro   rr   _print_tribonacci  r  zLatexPrinter._print_tribonaccic                 C  s4   |d u rd|  |jd  S d||  |jd f S )Nz\mu\left(%s\right)r   z\mu^{%s}\left(%s\right)r  r  ro   ro   rr   _print_mobius  s   zLatexPrinter._print_mobiusc                   s   t   t|jjdkst|jjdkr-d|j|jd |j|jf S |jtj	u rP|j} |
|d |
|d |
|d |
|f}n|jtju s[|jdkrg|d d }|  nt|}dd fd	d
|D  d S )Nr   z\left\{%s\right\}_{%s=%s}^{%s}r  r  rC  r  rR  r%  c                 3  r  r  r!  r  r  ro   rr   r    rP  z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>rS  )r  rW  r  free_symbolsr  r   formular  r   r*  coeffr)  lengthr  r  r)  )r   rq   r  r  ro   r  rr   _print_SeqFormula  s,    


zLatexPrinter._print_SeqFormulac                 C  s\   |j |jkrd| |j  S |jrd}nd}|jrd}nd}d|| |j | |j|f S )Nr  r   r   r   r   z\left%s%s, %s\right%s)r  endr   	left_open
right_open)r   r   leftrightro   ro   rr   _print_Interval  s   zLatexPrinter._print_Intervalc                 C  rR  )Nz \left\langle %s, %s\right\rangle)r   r   r   r   r   ro   ro   rr   _print_AccumulationBounds  s   z&LatexPrinter._print_AccumulationBoundsc                   (   t |  fdd|jD }d|S )Nc                      g | ]} | qS ro   r   r  rr  r   ro   rr   r#    r  z-LatexPrinter._print_Union.<locals>.<listcomp>z \cup r   r  r)  r   uargs_strro   r	  rr   _print_Union     
zLatexPrinter._print_Unionc                   r  )Nc                   r  ro   r  r  r	  ro   rr   r#    r  z2LatexPrinter._print_Complement.<locals>.<listcomp>z \setminus r
  r  ro   r	  rr   _print_Complement  r  zLatexPrinter._print_Complementc                   r  )Nc                   r  ro   r  r  r	  ro   rr   r#    r  z4LatexPrinter._print_Intersection.<locals>.<listcomp>z \cap r
  r  ro   r	  rr   _print_Intersection  r  z LatexPrinter._print_Intersectionc                   r  )Nc                   r  ro   r  r  r	  ro   rr   r#  	  r  z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>z \triangle r
  r  ro   r	  rr   _print_SymmetricDifference  r  z'LatexPrinter._print_SymmetricDifferencec                   s\   t | t|jdkr t|js |jd  dt|j  S d fdd|jD S )NrC  r   z^{%d}r   c                 3  s    | ]	} | V  qd S r   r  )r	  r  r	  ro   rr   r  	  s    
z1LatexPrinter._print_ProductSet.<locals>.<genexpr>)r   rW  setsr#   r   r)  r   r  ro   r	  rr   _print_ProductSet	  s    zLatexPrinter._print_ProductSetc                 C  rc  )Nz	\emptysetro   r2  ro   ro   rr   _print_EmptySet	  re  zLatexPrinter._print_EmptySetc                 C  rc  )Nz
\mathbb{N}ro   r   r  ro   ro   rr   _print_Naturals	  re  zLatexPrinter._print_Naturalsc                 C  rc  )Nz\mathbb{N}_0ro   r  ro   ro   rr   _print_Naturals0	  re  zLatexPrinter._print_Naturals0c                 C  rc  Nz
\mathbb{Z}ro   r  ro   ro   rr   _print_Integers	  re  zLatexPrinter._print_Integersc                 C  rc  Nz
\mathbb{Q}ro   r  ro   ro   rr   _print_Rationals	  re  zLatexPrinter._print_Rationalsc                 C  rc  Nz
\mathbb{R}ro   r  ro   ro   rr   _print_Reals	  re  zLatexPrinter._print_Realsc                 C  rc  Nz
\mathbb{C}ro   r  ro   ro   rr   _print_Complexes	  re  zLatexPrinter._print_Complexesc                   sP   |j j}|j j} fddt||jD }ddd |D }d ||f S )Nc                 3  s(    | ]\}}  |  |fV  qd S r   r!  )r	  r
  r  r"  ro   rr   r  #	  s   & z/LatexPrinter._print_ImageSet.<locals>.<genexpr>r%  c                 s  s    | ]}d | V  qdS )	%s \in %sNro   )r	  xyro   ro   rr   r  $	  r
  z!\left\{%s\; \middle|\; %s\right\})rW   r   	signaturer  	base_setsr)  r   )r   rq   r   sigxysxinysro   r"  rr   _print_ImageSet 	  s
   zLatexPrinter._print_ImageSetc                   s^   d  fddt|jD }|jtju rd| |jf S d|| |j |jf S )Nr%  c                   r   ro   r!  r	  r_  r"  ro   rr   r#  (	  r$  z4LatexPrinter._print_ConditionSet.<locals>.<listcomp>z"\left\{%s\; \middle|\; %s \right\}z3\left\{%s\; \middle|\; %s \in %s \wedge %s \right\})r)  r   r  base_setr   UniversalSetr   	conditionr   rq   
vars_printro   r"  rr   _print_ConditionSet'	  s   

z LatexPrinter._print_ConditionSetc                 C     |  |jd }d|S )Nr   z\mathcal{{P}}\left({}\right)r   r  r   )r   r   	arg_printro   ro   rr   _print_PowerSet3	  s   
zLatexPrinter._print_PowerSetc                   s8   d  fdd|jD }d |j| |jf S )Nr%  c                   r   ro   r!  r*  r"  ro   rr   r#  8	  r$  z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z)\left\{%s\; \middle|\; %s \in %s \right\})r)  r  r   r   r  r.  ro   r"  rr   _print_ComplexRegion7	  s   

z!LatexPrinter._print_ComplexRegionc                   s   dt  fdd|jD  S )Nr"  c                 3  r  r   r!  r  r"  ro   rr   r  ?	  r  z/LatexPrinter._print_Contains.<locals>.<genexpr>)r  r  r2  ro   r"  rr   _print_Contains>	     zLatexPrinter._print_Containsc                 C  s:   |j jtju r|jjtju r| |jS | | d S )Nz	 + \ldots)	r  r  r   r  bnr   a0r>  truncater   ro   ro   rr   _print_FourierSeriesA	  s   z!LatexPrinter._print_FourierSeriesc                 C  r   r   )r>  infiniter   ro   ro   rr   _print_FormalPowerSeriesF	  r  z%LatexPrinter._print_FormalPowerSeriesc                 C  s
   d|j  S )Nz\mathbb{F}_{%s})modr   ro   ro   rr   _print_FiniteFieldI	  r   zLatexPrinter._print_FiniteFieldc                 C  rc  r  ro   r   ro   ro   rr   _print_IntegerRingL	  re  zLatexPrinter._print_IntegerRingc                 C  rc  r  ro   r   ro   ro   rr   _print_RationalFieldO	  re  z!LatexPrinter._print_RationalFieldc                 C  rc  r  ro   r   ro   ro   rr   _print_RealFieldR	  re  zLatexPrinter._print_RealFieldc                 C  rc  r   ro   r   ro   ro   rr   _print_ComplexFieldU	  re  z LatexPrinter._print_ComplexFieldc                 C  ,   |  |j}dt| j |j}d||f S )Nr%  z%s\left[%s\right]r   domainr)  r  r&  r   r   rF  r&  ro   ro   rr   _print_PolynomialRingX	     z"LatexPrinter._print_PolynomialRingc                 C  rD  )Nr%  r(  rE  rG  ro   ro   rr   _print_FractionField]	  rI  z!LatexPrinter._print_FractionFieldc                 C  s<   |  |j}dt| j |j}d}|jsd}d|||f S )Nr%  r   zS_<^{-1}z%s%s\left[%s\right])r   rF  r)  r  r&  is_Poly)r   r   rF  r&  invro   ro   rr   _print_PolynomialRingBaseb	  s   z&LatexPrinter._print_PolynomialRingBasec                 C  s  |j j}g }| D ]\}}d}t|D ]$\}}|dkr8|dkr+|| |j| 7 }q|| t|j| |7 }q|jrL|rFd| | }	n'| |}	n!|rh|tj	u r[|
d|g q
|tju rh|
d|g q
| |}	|sr|	}
n|	d | }
|
dr|
d|
dd  g q
|
d|
g q
|d dv r|d}|dkrd|d  |d< d|}tt| j|j}d	| |  }d
|g| |g }|tv rd||f }|S d||f }|S )Nr   r   rC  r8  rd  r  r   )r  rd  z	domain=%sr%  z\%s {\left(%s \right)}z$\operatorname{%s}{\left( %s \right)})r'  r(  r;  r:  r   genspowr   r   r  extendr   r  popr)  r  r  
get_domainr1  )r   polyr`  r;  monomr  s_monomr   r  s_coeffs_termmodifierr   rN  rF  r  r   ro   ro   rr   _print_Polyj	  sR   





zLatexPrinter._print_Polyc                 C  sJ   |j j}|dkr
d}| |j}|j}|tv rd|||f S d|||f S )NComplexRootOfCRootOfz\%s {\left(%s, %d\right)}z'\operatorname{%s} {\left(%s, %d\right)})r'  r(  r   r   r  r1  )r   r:   r`  r   r  ro   ro   rr   _print_ComplexRootOf	  s   z!LatexPrinter._print_ComplexRootOfc                 C  s`   |j j}| |jg}|jtjur|| |j |tv r'd|d	|f S d|d	|f S )Nz\%s {\left(%s\right)}r%  z#\operatorname{%s} {\left(%s\right)})
r'  r(  r   r   funr   IdentityFunctionr  r1  r)  )r   r   r`  r  ro   ro   rr   _print_RootSum	  s   zLatexPrinter._print_RootSumc                 C  rc  )N\omegaro   r   ro   ro   rr   _print_OrdinalOmega	  re  z LatexPrinter._print_OrdinalOmegac                 C  sF   |j \}}|dkr|dkrd||S d|S |dkr!d|S dS )NrC  z{} \omega^{{{}}}z	{} \omegaz\omega^{{{}}}r`  )r  r   )r   r   r  mulro   ro   rr   _print_OmegaPower	  s   


zLatexPrinter._print_OmegaPowerc                   s   d  fdd|jD S )Nr7  c                   r   ro   r!  rR  r"  ro   rr   r#  	  r$  z/LatexPrinter._print_Ordinal.<locals>.<listcomp>)r)  r  r   ro   r"  rr   _print_Ordinal	  s   zLatexPrinter._print_Ordinalc                 C  s   | j d }|| td|S )Nr   z	{%s}^{%d})r   r   r    )r   rS  r   ro   ro   rr   _print_PolyElement	  s   
zLatexPrinter._print_PolyElementc                 C  s:   |j dkr| |jS | |j}| |j }d||f S )NrC  r  )r  r   r  )r   r9   r  r  ro   ro   rr   _print_FracElement	  s
   
zLatexPrinter._print_FracElementc                 C  sf   t |jdkr|jd d fn|j\}}d| | }|d ur$d||f }|d ur1d|| |f }|S )NrC  r   zE_{%s}r  r(  r  )r   r   r  r  r
  r   ro   ro   rr   _print_euler	  s   &zLatexPrinter._print_eulerc                 C  r  )NzC_{%s}r   r  r  rk  ro   ro   rr   _print_catalan	  r  zLatexPrinter._print_catalanc              
   C  s>   d ||rdnd| |jd | |jd | |jd S )Nz5\mathcal{{{}}}{}_{{{}}}\left[{}\right]\left({}\right)z^{-1}r   rC  r   r  r   r   r  )r   r   rq   inversero   ro   rr   _print_UnifiedTransform	  s   >z$LatexPrinter._print_UnifiedTransformc                 C     |  |dS )NMrk  r   ro   ro   rr   _print_MellinTransform	  r  z#LatexPrinter._print_MellinTransformc                 C     |  |ddS )Nrm  Trn  r   ro   ro   rr   _print_InverseMellinTransform	  r  z*LatexPrinter._print_InverseMellinTransformc                 C  rl  )NLrn  r   ro   ro   rr   _print_LaplaceTransform	  r  z$LatexPrinter._print_LaplaceTransformc                 C  rp  )Nrr  Trn  r   ro   ro   rr   _print_InverseLaplaceTransform	  r  z+LatexPrinter._print_InverseLaplaceTransformc                 C  rl  r  rn  r   ro   ro   rr   _print_FourierTransform	  r  z$LatexPrinter._print_FourierTransformc                 C  rp  )Nr  Trn  r   ro   ro   rr   _print_InverseFourierTransform	  r  z+LatexPrinter._print_InverseFourierTransformc                 C  rl  )NSINrn  r   ro   ro   rr   _print_SineTransform	  r  z!LatexPrinter._print_SineTransformc                 C  rp  )Nrw  Trn  r   ro   ro   rr   _print_InverseSineTransform
  r  z(LatexPrinter._print_InverseSineTransformc                 C  rl  )NCOSrn  r   ro   ro   rr   _print_CosineTransform
  r  z#LatexPrinter._print_CosineTransformc                 C  rp  )Nrz  Trn  r   ro   ro   rr   _print_InverseCosineTransform
  r  z*LatexPrinter._print_InverseCosineTransformc                 C  sD   z|j d ur| |j |W S W n	 ty   Y nw | t|S r   )ringr   to_sympyr   reprr  ro   ro   rr   
_print_DMP
  s   
zLatexPrinter._print_DMPc                 C  r  r   )r  r  ro   ro   rr   
_print_DMF
  r   zLatexPrinter._print_DMFc                 C  s   |  t|jS r   r   r   r*  )r   r  ro   ro   rr   _print_Object
  r  zLatexPrinter._print_Objectc                 C  sf   |  |jd }|d urd|f nd}t|jdkr"d||f }|S |  |jd }d|||}|S )Nr   r#  r   rC  zW%s\left(%s\right)zW{0}_{{{1}}}\left({2}\right))r   r  rW  r   )r   r   r  arg0resultarg1ro   ro   rr   _print_LambertW
  s   zLatexPrinter._print_LambertWc                 C     d | |jd S )Nz!\operatorname{{E}}\left[{}\right]r   ri  r   ro   ro   rr   _print_Expectation$
     zLatexPrinter._print_Expectationc                 C  r  )Nz#\operatorname{{Var}}\left({}\right)r   ri  r   ro   ro   rr   _print_Variance'
  r  zLatexPrinter._print_Variancec                   s    d d fdd|jD S )Nz#\operatorname{{Cov}}\left({}\right)r%  c                 3  r  r   r!  rR  r"  ro   rr   r  +
  r  z1LatexPrinter._print_Covariance.<locals>.<genexpr>)r   r)  r  r   ro   r"  rr   _print_Covariance*
  s    zLatexPrinter._print_Covariancec                 C  r  )Nz!\operatorname{{P}}\left({}\right)r   ri  r   ro   ro   rr   _print_Probability-
  r  zLatexPrinter._print_Probabilityc                 C  s$   |  |j}|  |j}d||f S )Nz%s\rightarrow %s)r   rF  codomain)r   morphismrF  r  ro   ro   rr   _print_Morphism0
  s   zLatexPrinter._print_Morphismc                 C  s&   |  |j|  |j}}d||f S )Nr  )r   r  den)r   r   r  r  ro   ro   rr   _print_TransferFunction5
  s   z$LatexPrinter._print_TransferFunctionc                   s(   t  j} fdd}dt||S )Nc                   s    | t dS rf  )r   r   r  r  ro   rr   rs   ;
  s    z,LatexPrinter._print_Series.<locals>.<lambda>r   )r  r  r)  r  r   r   r  ri  ro   r  rr   _print_Series9
  s   
zLatexPrinter._print_Seriesc                   s@   ddl m  tjd d d } fdd}dt||S )Nr   )MIMOParallelrB  c                   s&   t |  r| tdS | S rf  )r  r   r   r   r  r  r   r   ro   rr   rs   B
  s
   
z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>z\cdot)sympy.physics.control.ltir  r  r  r)  r  r  ro   r  rr   _print_MIMOSeries?
  s   zLatexPrinter._print_MIMOSeriesc                 C     d t| j|jS Nr7  r)  r  r   r  r   ro   ro   rr   _print_ParallelF
  r  zLatexPrinter._print_Parallelc                 C  r  r  r  r   ro   ro   rr   _print_MIMOParallelI
  r  z LatexPrinter._print_MIMOParallelc                 C  s  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||rGt|j|rG|g ||R  }	n[t||rit|j|ri|j|kr\|| }	nF||g ||jR  f}	n9t||rt|j|r||kr}|| }	n%||g|R  }	n||kr|| }	n|j|kr|| }	n	|g ||R  }	| 	|}
| 	|}| 	|	}|j
dkrdnd}d|
|||f S )Nr   )TransferFunctionSeriesrC  rB  rd  r  z\frac{%s}{%s %s %s})sympy.physics.controlr  r  sys1r_  r  r  r  sys2r   r  )r   r   r  r  r  tfnum_arg_listden_arg_list
den_term_1
den_term_2r  denom_1denom_2_signro   ro   rr   _print_FeedbackL
  s8   









zLatexPrinter._print_Feedbackc                 C  sL   ddl m} | ||j|j}| |j}|jdkrdnd}d|||f S )Nr   )
MIMOSeriesrB  rd  r  z)\left(I_{\tau} %s %s\right)^{-1} \cdot %s)r  r  r   r  r  r  )r   r   r  inv_matr  r  ro   ro   rr   _print_MIMOFeedbackp
  s
   z LatexPrinter._print_MIMOFeedbackc                 C  s   |  |j}d| S )Nz%s_\tau)r   	_expr_matr_  ro   ro   rr   _print_TransferFunctionMatrixw
  s   z*LatexPrinter._print_TransferFunctionMatrixc                 C  s   d |jj|jS )Nz\text{{{}}}_{{{}}})r   r'  r(  r  r   ro   ro   rr   
_print_DFT{
  r  zLatexPrinter._print_DFTc                 C  s&   |  t|j}| |}d||f S )Nz%s:%s)r   r   r*  r  )r   r  pretty_namepretty_morphismro   ro   rr   _print_NamedMorphism
  s   
z!LatexPrinter._print_NamedMorphismc                 C  s"   ddl m} | ||j|jdS )Nr   )NamedMorphismid)sympy.categoriesr  r  rF  r  )r   r  r  ro   ro   rr   _print_IdentityMorphism
  s   
z$LatexPrinter._print_IdentityMorphismc                   s<    fdd|j D }|  d|d } |}|| S )Nc                   s   g | ]
}  t|jqS ro   r  )r	  	componentr"  ro   rr   r#  
  s    z9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z\circ rM  )r  reverser)  r  )r   r  component_names_listcomponent_namesr  ro   r"  rr   _print_CompositeMorphism
  s   

z%LatexPrinter._print_CompositeMorphismc                 C  s   d | t|jS Nr'  )r   r   r   r*  )r   r  ro   ro   rr   _print_Category
  r  zLatexPrinter._print_Categoryc                 C  s<   |j s	| tjS | |j }|jr|d| |j 7 }|S )Nz\Longrightarrow %s)premisesr   r   EmptySetconclusions)r   diagramlatex_resultro   ro   rr   _print_Diagram
  s   
zLatexPrinter._print_Diagramc                 C  s   dd|j   }t|jD ]8}t|j D ]!}|||f r%|t|||f 7 }|d7 }||j d kr4|d7 }q||jd kr@|d7 }|d7 }q|d7 }|S )	Nz\begin{array}{%s}
r   r   rC  & r  
z\end{array}
)widthrV  heightlatex)r   gridr  r   r   ro   ro   rr   _print_DiagramGrid
  s   
zLatexPrinter._print_DiagramGridc                 C     d | |j| |jS )Nz{{{}}}^{{{}}})r   r   r}  r  r   rm  ro   ro   rr   _print_FreeModule
  r7  zLatexPrinter._print_FreeModulec                   s   d d fdd|D S )N\left[ {} \right]rD  c                 3  "    | ]}d   | d V  qdS r   rn   Nr!  r  r"  ro   rr   r  
      
z8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>)r   r)  )r   r  ro   r"  rr   _print_FreeModuleElement
  s   
z%LatexPrinter._print_FreeModuleElementc                   sJ   fddj D }dd  dd d fdd|D }d	|S )
Nc                   s    g | ]} fd d|D qS )c                   s   g | ]}  j|qS ro   )r   r}  r~  r  r  r   ro   rr   r#  
      z<LatexPrinter._print_SubModule.<locals>.<listcomp>.<listcomp>ro   r	  gr  ro   rr   r#  
  s     z1LatexPrinter._print_SubModule.<locals>.<listcomp>c                 S  rm   )Nr   rn   ro   rL   ro   ro   rr   rs   
  rt   z/LatexPrinter._print_SubModule.<locals>.<lambda>c                 S  rm   )Nz\left[ z \right]ro   r  ro   ro   rr   rs   
  rt   rD  c                 3  s0    | ]} d   fdd|D V  qdS )rD  c                 3  s    | ]} |V  qd S r   ro   r  )curlyro   rr   r  
  r
  z:LatexPrinter._print_SubModule.<locals>.<genexpr>.<genexpr>N)r)  r  )r  squarero   rr   r  
  s   . z0LatexPrinter._print_SubModule.<locals>.<genexpr>\left\langle {} \right\rangle)rN  r)  r   r   r  rN  
gens_latexro   )r  r  r   r  rr   _print_SubModule
  s
   
zLatexPrinter._print_SubModulec                   s$   d  fdd|jD }d|S )NrD  c                   s   g | ]}d   | d qS )r   rn   r!  r  r"  ro   rr   r#  
  r  z9LatexPrinter._print_SubQuotientModule.<locals>.<listcomp>r  )r)  rN  r   )r   r  r  ro   r"  rr   _print_SubQuotientModule
  s   
z%LatexPrinter._print_SubQuotientModulec                   s8    fdd j jD }dfdd|D }d|S )Nc                   s   g | ]	\} j |qS ro   )r}  r~  r  r  ro   rr   r#  
  r6  z>LatexPrinter._print_ModuleImplementedIdeal.<locals>.<listcomp>rD  c                 3  r  r  r!  r  r"  ro   rr   r  
  s     z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>r  )_modulerN  r)  r   r  ro   r  rr   _print_ModuleImplementedIdeal
  s   
z*LatexPrinter._print_ModuleImplementedIdealc                   sD    fdd|j D }|d gdd t|dd  dD  }d|S )Nc                   s    g | ]} j |td  ddqS )r	   TrH  )r   r    r  r"  ro   rr   r#  
  s    z2LatexPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]
\}}|d  | qS )r   ro   )r	  r   r   ro   ro   rr   r#  
  r  rC  ijkr7  )r  r  r)  )r   r   rq   r  ro   r"  rr   _print_Quaternion
  s
   
&
zLatexPrinter._print_Quaternionc                 C  r  Nz\frac{{{}}}{{{}}})r   r   r}  
base_ideal)r   Rro   ro   rr   _print_QuotientRing
     
z LatexPrinter._print_QuotientRingc                 C  s(   |  |j|}d||  |jjS )N{{{}}} + {{{}}})r   r}  r~  r   r  )r   r
  x_latexro   ro   rr   _print_QuotientRingElement
  s   z'LatexPrinter._print_QuotientRingElementc                   sH    fdd j D }ddfdd|D }d| jjS )Nc                   s   g | ]	} j j|qS ro   )moduler}  r~  r  r  ro   rr   r#  
  r6  z=LatexPrinter._print_QuotientModuleElement.<locals>.<listcomp>r  rD  c                 3  r  r  r!  r  r"  ro   rr   r  
  r  z<LatexPrinter._print_QuotientModuleElement.<locals>.<genexpr>r  )datar   r)  r   r  killed_module)r   r  r  
data_latexro   r  rr   _print_QuotientModuleElement
  s   
z)LatexPrinter._print_QuotientModuleElementc                 C  r  r  )r   r   r  r  r  ro   ro   rr   _print_QuotientModule
  r  z"LatexPrinter._print_QuotientModulec                 C  s(   d | | | |j| |jS )Nz{{{}}} : {{{}}} \to {{{}}})r   r   _sympy_matrixrF  r  )r   rD  ro   ro   rr   _print_MatrixHomomorphism
  s   z&LatexPrinter._print_MatrixHomomorphismc                 C  s   |j j }d|v r|g g }}}nt|\}}}t|}dd |D }dd |D }d| }|r9|dd| 7 }|rD|dd| 7 }|S )	Nr   c                 S  r"  ro   r#  r%  ro   ro   rr   r#  
  r  z0LatexPrinter._print_Manifold.<locals>.<listcomp>c                 S  r"  ro   r#  r&  ro   ro   rr   r#  
  r  r1  r#  r   r  )r*  r   r$  r)  )r   manifoldr!  r*  r(  r  ro   ro   rr   _print_Manifold
  s   zLatexPrinter._print_Manifoldc                 C  rR  )Nz\text{%s}_{%s})r   r*  r  )r   patchro   ro   rr   _print_Patch  r7  zLatexPrinter._print_Patchc                 C  s(   d|  |j|  |jj|  |jf S )Nz\text{%s}^{\text{%s}}_{%s})r   r*  r  r  )r   coordsysro   ro   rr   _print_CoordSystem  s    zLatexPrinter._print_CoordSystemc                 C  s   d|  |j S )Nz\mathbb{\nabla}_{%s})r   _wrt)r   cvdro   ro   rr   _print_CovarDerivativeOp
  r  z%LatexPrinter._print_CovarDerivativeOpc                 C  $   |j j|j j}d| t|S r  
_coord_sysr&  _indexr*  r   r   r   r   fieldr!  ro   ro   rr   _print_BaseScalarField     z#LatexPrinter._print_BaseScalarFieldc                 C  r  )Nz\partial_{{{}}}r   r  ro   ro   rr   _print_BaseVectorField  r  z#LatexPrinter._print_BaseVectorFieldc                 C  sH   |j }t|dr|jj|j j}d| t|S | |}d|S )Nr  z\operatorname{{d}}{}z!\operatorname{{d}}\left({}\right))	_form_fieldr  r  r&  r  r*  r   r   r   )r   diffr  r!  ro   ro   rr   _print_Differential  s   


z LatexPrinter._print_Differentialc                 C  r1  )Nr   z"\operatorname{{tr}}\left({}\right)r2  )r   r  contentsro   ro   rr   	_print_Tr  s   
zLatexPrinter._print_Trc                 C  4   |d urd|  |jd |f S d|  |jd  S )Nz%\left(\phi\left(%s\right)\right)^{%s}r   z\phi\left(%s\right)r  r  ro   ro   rr   _print_totient#  
   zLatexPrinter._print_totientc                 C  r  )Nz(\left(\lambda\left(%s\right)\right)^{%s}r   z\lambda\left(%s\right)r  r  ro   ro   rr   _print_reduced_totient)  r  z#LatexPrinter._print_reduced_totientc                 C  d   t |jdkrdtt| j|jd |jd f }n
d| |jd  }|d ur.d||f S d| S )Nr  _%s\left(%s\right)rC  r   r8  z\sigma^{%s}%sz\sigma%sr  rk  ro   ro   rr   _print_divisor_sigma/     

z!LatexPrinter._print_divisor_sigmac                 C  r  )Nr  r  rC  r   r8  z\sigma^*^{%s}%sz
\sigma^*%sr  rk  ro   ro   rr   _print_udivisor_sigma9  r  z"LatexPrinter._print_udivisor_sigmac                 C  r  )Nz$\left(\nu\left(%s\right)\right)^{%s}r   z\nu\left(%s\right)r  r  ro   ro   rr   _print_primenuC  r  zLatexPrinter._print_primenuc                 C  r  )Nz'\left(\Omega\left(%s\right)\right)^{%s}r   z\Omega\left(%s\right)r  r  ro   ro   rr   _print_primeomegaI  r  zLatexPrinter._print_primeomegac                 C  s
   t |jS r   )r   r*  r   ro   ro   rr   
_print_StrO  r   zLatexPrinter._print_Strc                 C  rP  r   )r   r   r   ro   ro   rr   _print_floatR  r  zLatexPrinter._print_floatc                 C     t |S r   r   r   ro   ro   rr   
_print_intU  r4  zLatexPrinter._print_intc                 C  r  r   r  r   ro   ro   rr   
_print_mpzX  r4  zLatexPrinter._print_mpzc                 C  r  r   r  r   ro   ro   rr   
_print_mpq[  r4  zLatexPrinter._print_mpqc                 C  r  r   r  r   ro   ro   rr   _print_fmpz^  r4  zLatexPrinter._print_fmpzc                 C  r  r   r  r   ro   ro   rr   _print_fmpqa  r4  zLatexPrinter._print_fmpqc                 C  s   d tt|jS )Nz"\operatorname{{Q}}_{{\text{{{}}}}})r   r   r   r*  r   ro   ro   rr   _print_Predicated  r  zLatexPrinter._print_Predicatec                   s:   |j }|j} |}d fdd|D }d||f S )Nr%  c                   r   ro   r!  r  r"  ro   rr   r#  k  r$  z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>z%s(%s))r  	argumentsr   r)  )r   r   predr  
pred_latex
args_latexro   r"  rr   _print_AppliedPredicateg  s
   
z$LatexPrinter._print_AppliedPredicatec                   s   t  |}dt| S )Nz\mathtt{\text{%s}})superemptyPrinterr   r  r'  ro   rr   r(  n  s   zLatexPrinter.emptyPrinterr   r  )FF)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   rN  )FN)r   )r   r   )r!  r   r   r   )r   r%   )r  r  )F(A  r(  
__module____qualname__printmethodr   __annotations__r   r   r   r   r   r   r   r  r  r  r   r   r  r,  r3  _print_BooleanTrue_print_BooleanFalser5  r>  rL  r]  r`  rq  ry  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r'  r.  r4  rO  rQ  rS  propertyr^  ra  rb  rd  ri  
_print_Min
_print_Maxrl  rn  ro  rq  ru  rw  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  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r   _print_RandomSymbolr&  r1  r5  rB  rG  rL  rV  rX  r^  r`  rd  rj  rl  rm  rv  rx  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  _print_frozensetr  r  r  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)  r0  r4  r5  r6  r;  r=  r?  r@  rA  rB  rC  rH  rJ  rM  rY  r\  r_  ra  rc  rd  re  rf  rg  rh  rk  ro  rq  rs  rt  ru  rv  rx  ry  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  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r&  r(  __classcell__ro   ro   r)  rr   r      s  
 	
=

	!s-!
$ L

										
7



*9		
$	

r   c                 C  s   t | }|r	|S |  tv rd|   S | tv rd|  S tt tddD ]"}|  	|rHt| t|krHt| t
| dt|    S q&| 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   rX  greek_letters_setother_symbolsrg  r   r  rW  r  r$  )rq   r   r  ro   ro   rr   r$  u  s   
"r$  c                 K  s   t || S )a%  Convert the given expression to LaTeX string representation.

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

    Notes
    =====

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

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

    Examples
    ========

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

    Basic usage:

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

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

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

    Fraction options:

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

    Multiplication options:

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

    Trig options:

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

    Matrix options:

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

    Custom printing of symbols:

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

    Logarithms:

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

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

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

    Unsupported types are rendered as monospaced plaintext:

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

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

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

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

    Parameters
    ==========

    lhs : Expr
        Left-hand side of equation

    rhs : Expr
        Right-hand side of equation

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

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

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

    Examples
    ========

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

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

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

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

    Notes
    =====

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

    eqnarrayz\begin{eqnarray}
z& = &z	\nonumberz
\end{eqnarray}TIEEEeqnarrayz\begin{IEEEeqnarray}{rCl}
z
\end{IEEEeqnarray}rA  z\begin{align*}
z= &r   z
\end{align*}FzUnknown environment: {}z\dotsrC  rd  z& & r  r  r  r   rB  r  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s}Nro   )r   r   r   as_ordered_termsrW  rV  r  r   )r+  r-  terms_per_lineenvironmentuse_dotsr   r  r  
first_termnonumberend_termdoubleetr  r;  n_terms
term_countr   r<  
term_startterm_endr  ro   ro   rr   multiline_latexu  sn   C


rP  )rq   r   r   r   )rC  rA  F)J__doc__
__future__r   typingr   r   r   r  
sympy.corer   r   r   r	   r
   r   r   r   sympy.core.alphabetsr   sympy.core.containersr   sympy.core.functionr   r   r   sympy.core.operationsr   sympy.core.powerr   sympy.core.sortingr   sympy.core.sympifyr   rz  r   r   r   sympy.printing.precedencer   sympy.printing.printerr   r   sympy.printing.conventionsr   r   r   r    mpmath.libmp.libmpfr!   r"   rh  sympy.utilities.iterablesr#   r$   r7   sympy.tensor.arrayr%   sympy.vector.basisdependentr&   r1  r;  r=  r   r-  	frozensetr<  compiler  r   r   r$  r  r@  rP  ro   ro   ro   rr   <module>   sZ   (	
 !"#'	

                     
|
 Z