B
    ™‘[¸T ã            %   @   st  d Z ddlmZmZ ddlZddlmZ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 dd
l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 ddl m Z m!Z! ddl"m#Z$ ddl"m%Z% ddl&m'Z'm(Z( ddl)m*Z* ddl+Z+dddddddddddddd d!d"d#d$d%d&d'gZ,d(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAd2dBd>dCdDdEdFdGdHdIdJœ$Z-e.dKdLdMdNdOdPdQdRdSdTg
ƒZ/dUdV„ dWdV„ dXdV„ dYdV„ dZdV„ d[dV„ d\dV„ d]dV„ d^dV„ d_dV„ d`dV„ dadV„ dbdV„ dcdV„ dddV„ dedV„ dfdV„ dgdV„ dhdV„ didV„ djdV„ dkdV„ dldV„ dmdV„ dnœZ0e1eƒZ2e+ 3do¡e+ 3dp¡fZ4G dqdr„ dreƒZ5dsdt„ Z6d}dydz„Z7d{d|„ Z8dS )~zC
A Printer which converts an expression into its LaTeX equivalent.
é    )Úprint_functionÚdivisionN)ÚSÚAddÚSymbolÚMod)ÚSympifyError)Úgreeks)ÚAssocOp)ÚTuple)Útrue)Ú_coeff_isnegÚUndefinedFunctionÚAppliedUndefÚ
Derivative)Úprecedence_traditionalé   )ÚPrinter)Úsplit_super_subÚrequires_partial)Ú
precedenceÚ
PRECEDENCE)Úprec_to_dps)Údefault_sort_keyÚrange)Úhas_varietyZarcsinZarccosZarctanZsinZcosZtanZsinhZcoshZtanhZsqrtZlnÚlogZsecZcscZcotZcothÚreZimÚfracÚrootÚargÚAÚBz\Gammaz\DeltaÚEÚZÚHz\ThetaÚIÚKz\LambdaÚMÚNz\XiÚoÚOz\PiÚPz\SigmaÚTz\Upsilonz\PhiÚXz\Psiz\Omegaz\lambdaz\chiz\varepsilonz	\varkappaz\varphiz\varpiz\varrhoz	\varsigmaz	\vartheta)$ZAlphaZBetaZGammaZDeltaZEpsilonZZetaZEtaZThetaZIotaZKappaZLambdaZMuZNuZXiZomicronZOmicronZPiZRhoZSigmaZTauZUpsilonZPhiÚChiZPsiZOmegaÚlamdaZLamdaZkhiZKhiZ
varepsilonZvarkappaZvarphiZvarpiZvarrhoZvarsigmaZvarthetaZalephZbethZdalethZgimelZellZethZhbarZhslashZmhoZwpc             C   s   d|  d S )Nz
\mathring{Ú}© )Úsr2   r2   ú3lib/python3.7/site-packages/sympy/printing/latex.pyÚ<lambda>U   s    r5   c             C   s   d|  d S )Nz\ddddot{r1   r2   )r3   r2   r2   r4   r5   V   s    c             C   s   d|  d S )Nz\dddot{r1   r2   )r3   r2   r2   r4   r5   W   s    c             C   s   d|  d S )Nz\ddot{r1   r2   )r3   r2   r2   r4   r5   X   s    c             C   s   d|  d S )Nz\dot{r1   r2   )r3   r2   r2   r4   r5   Y   s    c             C   s   d|  d S )Nz\check{r1   r2   )r3   r2   r2   r4   r5   Z   s    c             C   s   d|  d S )Nz\breve{r1   r2   )r3   r2   r2   r4   r5   [   s    c             C   s   d|  d S )Nz\acute{r1   r2   )r3   r2   r2   r4   r5   \   s    c             C   s   d|  d S )Nz\grave{r1   r2   )r3   r2   r2   r4   r5   ]   s    c             C   s   d|  d S )Nz\tilde{r1   r2   )r3   r2   r2   r4   r5   ^   s    c             C   s   d|  d S )Nz\hat{r1   r2   )r3   r2   r2   r4   r5   _   s    c             C   s   d|  d S )Nz\bar{r1   r2   )r3   r2   r2   r4   r5   `   s    c             C   s   d|  d S )Nz\vec{r1   r2   )r3   r2   r2   r4   r5   a   s    c             C   s   d|  d S )NÚ{z}'r2   )r3   r2   r2   r4   r5   b   s    c             C   s   d|  d S )Nr6   z}'r2   )r3   r2   r2   r4   r5   c   s    c             C   s   d|  d S )Nz\boldsymbol{r1   r2   )r3   r2   r2   r4   r5   e   s    c             C   s   d|  d S )Nz\boldsymbol{r1   r2   )r3   r2   r2   r4   r5   f   s    c             C   s   d|  d S )Nz	\mathcal{r1   r2   )r3   r2   r2   r4   r5   g   s    c             C   s   d|  d S )Nz	\mathscr{r1   r2   )r3   r2   r2   r4   r5   h   s    c             C   s   d|  d S )Nz
\mathfrak{r1   r2   )r3   r2   r2   r4   r5   i   s    c             C   s   d|  d S )Nz\left\|{z	}\right\|r2   )r3   r2   r2   r4   r5   k   s    c             C   s   d|  d S )Nz\left\langle{z}\right\rangler2   )r3   r2   r2   r4   r5   l   s    c             C   s   d|  d S )Nz\left|{z}\right|r2   )r3   r2   r2   r4   r5   m   s    c             C   s   d|  d S )Nz\left|{z}\right|r2   )r3   r2   r2   r4   r5   n   s    )ZmathringZddddotZdddotZddotÚdotZcheckZbreveZacuteZgraveÚtildeZhatZbarÚvecZprimeZprmZboldÚbmZcalZscrZfrakZnormZavgÚabsZmagz[0-9][} ]*$z[{ ]*[-+0-9]c               @   s*
  e Zd ZdZdddddddddddi ddœZdÁdd	„ZdÂ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eZeZdd„ ZdÄd d!„Zd"d#„ ZeZd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Z d:d;„ Z!d<d=„ Z"d>d?„ Z#d@dA„ Z$dBdC„ Z%dDdE„ Z&dFdG„ Z'dHdI„ Z(dÅdJdK„Z)dLdM„ Z*e+dNdO„ ƒZ,dPdQ„ Z-dRdS„ Z.dÆdTdU„Z/e/ Z0Z1dÇdVdW„Z2dÈdXdY„Z3dÉdZd[„Z4dÊd\d]„Z5e5Z6dËd^d_„Z7dÌd`da„Z8dbdc„ Z9ddde„ Z:dfdg„ Z;dhdi„ Z<djdk„ Z=dÍdldm„Z>dÎdndo„Z?dÏdpdq„Z@dÐdrds„ZAdÑdtdu„ZBdÒdvdw„ZCdÓdxdy„ZDdÔdzd{„ZEdÕd|d}„ZFdÖd~d„ZGd×d€d„ZHdØd‚dƒ„ZIdÙd„d…„ZJeJZKdÚd†d‡„ZLdÛdˆd‰„ZMdÜdŠd‹„ZNdÝdŒd„ZOdÞdŽd„ZPdßdd‘„ZQdàd’d“„ZRdád”d•„ZSdâd–d—„ZTdãd˜d™„ZUdšd›„ ZVdœ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±„Zadîd³d´„Zbdïdµd¶„Zcdðd·d¸„Zddñd¹dº„Zedòd»d¼„Zfdód½d¾„Zgdôd¿dÀ„ZhdõdÁdÂ„ZidödÃdÄ„Zjd÷dÅdÆ„ZkdødÇdÈ„ZldùdÉdÊ„ZmdúdËdÌ„ZndûdÍdÎ„ZodüdÏdÐ„ZpdýdÑdÒ„ZqdþdÓdÔ„ZrdÿdÕdÖ„Zsd d×dØ„ZtddÙdÚ„ZuddÛdÜ„ZvddÝdÞ„Zwddßdà„Zxdádâ„ Zydãdä„ Zzdådæ„ Z{e{Z|e{Z}dçdè„ Z~dédê„ Zdëdì„ Z€dídî„ Ze Z‚ Zƒ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’e’Z“e’Z”e’Z•e’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d„Z ddd „Z¡d	d!d"„Z¢d#d$„ Z£d%d&„ Z¤d'd(„ Z¥d)d*„ Z¦e¦Z§d+d,„ Z¨d-d.„ Z©e©Zªe©Z«e©Z¬d/d0„ Z­d1d2„ Z®d3d4„ Z¯d5d6„ Z°d7d8„ Z±d9d:„ Z²d;d<„ Z³d=d>„ Z´d?d@„ ZµdAdB„ Z¶dCdD„ Z·dEdF„ Z¸dGdH„ Z¹dIdJ„ ZºdKdL„ Z»dMdN„ Z¼dOdP„ Z½dQdR„ Z¾dSdT„ Z¿dUdV„ ZÀdWdX„ ZÁdYdZ„ ZÂd[d\„ ZÃd]d^„ ZÄd_d`„ ZÅdadb„ ZÆdcdd„ ZÇdedf„ ZÈdgdh„ ZÉdidj„ ZÊdkdl„ ZËd
dmdn„ZÌddodp„ZÍdqdr„ ZÎdsdt„ ZÏdudv„ ZÐdwdx„ ZÑdydz„ ZÒd{d|„ ZÓd}d~„ ZÔdd€„ 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»d¼„Zódd½d¾„Zôdd¿dÀ„ZõdS (  ÚLatexPrinterZ_latexNÚplainFÚabbreviatedú[)ÚorderÚmodeÚitexÚfold_frac_powersÚfold_func_bracketsÚfold_short_fracÚlong_frac_ratioÚ
mul_symbolÚinv_trig_styleÚmat_strÚ	mat_delimÚsymbol_namesÚln_notationc             C   s   t  | |¡ d| jkr8ddddg}| jd |kr8tdƒ‚| jd d kr^| jd dkr^d| jd< d	d
dddœ}y|| jd  | jd< W n$ tk
r¨   | jd | jd< Y nX y|| jd pºd | jd< W nH tk
r   | jd  ¡ dkrú|d | jd< n| jd | jd< Y nX dddœ| _d S )NrA   Úinliner=   Úequationz	equation*zB'mode' must be one of 'inline', 'plain', 'equation' or 'equation*'rE   Tú z \,.\, z \cdot z \times )NZldotr7   ÚtimesrG   Úmul_symbol_latexr7   Úmul_symbol_latex_numbers)Ú rO   ú\z\,z\:z\;z\quadú)ú])ú(r?   )r   Ú__init__Ú	_settingsÚ
ValueErrorÚKeyErrorÚstripÚ_delim_dict)ÚselfÚsettingsZvalid_modesZmul_symbol_tabler2   r2   r4   rX   Œ   s2    

zLatexPrinter.__init__c             C   s8   t |ƒ}||k s|s*||kr*d|  |¡ S |  |¡S d S )Nz\left(%s\right))r   Ú_print)r^   ÚitemÚlevelÚstrictZprec_valr2   r2   r4   Úparenthesize´   s    zLatexPrinter.parenthesizec             C   sb   t  | |¡}| jd dkr|S | jd dkr4d| S | jd rFd| S | jd }d|||f S d S )NrA   r=   rM   z$%s$rB   z$$%s$$z\begin{%s}%s\end{%s})r   ÚdoprintrY   )r^   ÚexprÚtexZenv_strr2   r2   r4   re   »   s    

zLatexPrinter.doprintc             C   s(   |j r|jp$|jo$|tjk	o$|jdk S )zÁ
        Returns True if the expression needs to be wrapped in brackets when
        printed, False otherwise. For example: a + b => True; a => False;
        10 => False; -10 => True.
        F)Z
is_IntegerZis_nonnegativeÚis_Atomr   ÚNegativeOneÚis_Rational)r^   rf   r2   r2   r4   Ú_needs_bracketsÈ   s    zLatexPrinter._needs_bracketsc             C   sN   |   |¡sdS |jr"|  |¡s"dS |jr6|  |¡s6dS |jsB|jrFdS dS dS )aˆ  
        Returns True if the expression needs to be wrapped in brackets when
        passed as an argument to a function, False otherwise. This is a more
        liberal version of _needs_brackets, in that many expressions which need
        to be wrapped in brackets when added/subtracted/raised to a power do
        not need them when passed to a function. Such an example is a*b.
        FTN)rk   Úis_MulÚ_mul_is_cleanZis_PowÚ_pow_is_cleanÚis_AddÚis_Function)r^   rf   r2   r2   r4   Ú_needs_function_bracketsÒ   s    
z%LatexPrinter._needs_function_bracketsc                sœ   ddl m}m}m}m} ˆ jr0|sNtˆ ƒrNdS ntˆ ƒtd k rDdS ˆ j	rNdS ˆ j
rXdS t‡ fdd„tfD ƒƒrtdS |s˜t‡ fdd„|||fD ƒƒr˜dS dS )	a¿  
        Returns True if the expression needs to be wrapped in brackets when
        printed as part of a Mul, False otherwise. This is True for Add,
        but also for some container objects that would not need brackets
        when appearing last in a Mul, e.g. an Integral. ``last=True``
        specifies that this expr is the last to appear in a Mul.
        ``first=True`` specifies that this expr is the first to appear in a Mul.
        r   )ÚIntegralÚ	PiecewiseÚProductÚSumTÚMulc                s   g | ]}ˆ   |¡‘qS r2   )Úhas)Ú.0Úx)rf   r2   r4   ú
<listcomp>ý   s    z4LatexPrinter._needs_mul_brackets.<locals>.<listcomp>c                s   g | ]}ˆ   |¡‘qS r2   )rw   )rx   ry   )rf   r2   r4   rz      s    F)Úsympyrr   rs   rt   ru   rl   r   r   r   Úis_RelationalZis_PiecewiseÚanyr   )r^   rf   ÚfirstÚlastrr   rs   rt   ru   r2   )rf   r4   Ú_needs_mul_bracketsé   s     	z LatexPrinter._needs_mul_bracketsc                s4   ˆ j r
dS t‡ fdd„tfD ƒƒr&dS ˆ jr0dS dS )z±
        Returns True if the expression needs to be wrapped in brackets when
        printed as part of an Add, False otherwise.  This is False for most
        things.
        Tc                s   g | ]}ˆ   |¡‘qS r2   )rw   )rx   ry   )rf   r2   r4   rz     s    z4LatexPrinter._needs_add_brackets.<locals>.<listcomp>F)r|   r}   r   ro   )r^   rf   r2   )rf   r4   Ú_needs_add_brackets  s    z LatexPrinter._needs_add_bracketsc             C   s   x|j D ]}|jrdS qW dS )NFT)Úargsrp   )r^   rf   r    r2   r2   r4   rm     s    zLatexPrinter._mul_is_cleanc             C   s   |   |j¡ S )N)rk   Úbase)r^   rf   r2   r2   r4   rn     s    zLatexPrinter._pow_is_cleanc             C   s   |d k	rd||f S |S d S )Nz\left(%s\right)^{%s}r2   )r^   rf   Úexpr2   r2   r4   Ú_do_exponent  s    zLatexPrinter._do_exponentc             C   s   d| S )Nz\mathrm{%s}r2   )r^   Úer2   r2   r4   Ú_print_bool$  s    zLatexPrinter._print_boolc             C   s   d| S )Nz\mathrm{%s}r2   )r^   r†   r2   r2   r4   Ú_print_NoneType*  s    zLatexPrinter._print_NoneTypec             C   s   | j dkrt|jƒ}n| j||d}d}xbt|ƒD ]V\}}|dkrDn t|ƒr\|d7 }| }n|d7 }|  |¡}|  |¡r€d| }||7 }q2W |S )NÚnone)r@   rS   r   z - z + z\left(%s\right))r@   Úlistr‚   Z_as_ordered_termsÚ	enumerater   r`   r   )r^   rf   r@   Útermsrg   ÚiÚtermÚterm_texr2   r2   r4   Ú
_print_Add.  s     


zLatexPrinter._print_Addc             C   s’   ddl m} |jdkrdS ||ƒ}|j}|j}|jd |d krP||d gg }d}x |D ]}|t|ƒ dd¡7 }qZW | d	d
¡}| dd¡}|S )Nr   )ÚPermutationz\left( \right)éÿÿÿÿr   rS   ú,z\;r?   z\left( rV   z\right))Z sympy.combinatorics.permutationsr‘   ÚsizeZcyclic_formZ
array_formÚstrÚreplace)r^   rf   r‘   Z	expr_permZsizr   r   r2   r2   r4   Ú_print_CycleD  s    

zLatexPrinter._print_Cyclec             C   s‚   t |jƒ}tj|j|dd}| jd }d|krb| d¡\}}|d dkrT|dd … }d|||f S |d	krnd
S |dkrzdS |S d S )NT)Zstrip_zerosrR   r†   r   ú+r   z%s%s10^{%s}z+infz\inftyz-infz- \infty)r   Z_precÚmlibZto_strZ_mpf_rY   Úsplit)r^   rf   ZdpsZstr_realÚ	separatorZmantr„   r2   r2   r4   Ú_print_FloatV  s    

zLatexPrinter._print_Floatc             C   s0   |j }|j}d|  |td ¡|  |td ¡f S )Nz%s \times %srv   )Ú_expr1Ú_expr2rd   r   )r^   rf   Úvec1Úvec2r2   r2   r4   Ú_print_Crossm  s    zLatexPrinter._print_Crossc             C   s   |j }d|  |td ¡ S )Nz\nabla\times %srv   )Ú_exprrd   r   )r^   rf   r9   r2   r2   r4   Ú_print_Curls  s    zLatexPrinter._print_Curlc             C   s   |j }d|  |td ¡ S )Nz\nabla\cdot %srv   )r¢   rd   r   )r^   rf   r9   r2   r2   r4   Ú_print_Divergencew  s    zLatexPrinter._print_Divergencec             C   s0   |j }|j}d|  |td ¡|  |td ¡f S )Nz%s \cdot %srv   )r   rž   rd   r   )r^   rf   rŸ   r    r2   r2   r4   Ú
_print_Dot{  s    zLatexPrinter._print_Dotc             C   s   |j }d|  |td ¡ S )Nz\nabla\cdot %srv   )r¢   rd   r   )r^   rf   Úfuncr2   r2   r4   Ú_print_Gradient  s    zLatexPrinter._print_Gradientc                s€  ddl m‰  ddlm‰ d}t|ƒrB| }d}|jrF|d7 }d}nd}dd	lm} ||dd
\}}ˆjd ‰ˆjd ‰‡ ‡‡‡‡fdd„}|t	j
kr¸ˆ dddd|jkr¸|||ƒ7 }n¶||ƒ}||ƒ}	t|	 ¡ ƒ}
ˆjd }ˆjd r4|
dkr4d|	kr4ˆj|ddr |d||	f 7 }n|d||	f 7 }n:|d k	r^t| ¡ ƒ||
 kr^ˆj|ddrx|d|	ˆ|f 7 }nä|jrJt	j
}t	j
}xp|jD ]f}ˆj|ddsæt||| ƒ ¡ ƒ||
 ksæ|j|j  krâdkrðn n
||9 }n||9 }q”W ˆj|ddr,|d||ƒ|	ˆ||ƒf 7 }n|d||ƒ|	ˆ||ƒf 7 }n|d|	ˆ|f 7 }n|d||	f 7 }|r||d7 }|S )Nr   )ÚPow)ÚQuantityFz- rW   TrS   )Úfraction)ÚexactrQ   rR   c                sÞ   | j stˆ | ¡ƒS d }}ˆjdkr0|  ¡ }n
t| jƒ}t|‡ ‡fdd„d}x„t|ƒD ]x\}}ˆ |¡}ˆj	||dk|t
|ƒd kdr”d	| }td  |¡rºtd  |¡rº|ˆ7 }n|rÆ|ˆ7 }||7 }|}qZW |S d S )
NrS   )Úoldr‰   c                s    t | ˆƒpt | ˆ ƒot | jˆƒS )N)Ú
isinstancerƒ   )ry   )r¨   r©   r2   r4   r5   £  s   
z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>)Úkeyr   r   )r~   r   z\left(%s\right))rl   r•   r`   r@   Zas_ordered_factorsrŠ   r‚   Úsortedr‹   r€   ÚlenÚ_between_two_numbers_pÚsearchÚmatch)rf   Z_texZlast_term_texr‚   r   rŽ   r   )r¨   r©   Ú	numbersepr^   r›   r2   r4   Úconvert—  s(    




z(LatexPrinter._print_Mul.<locals>.convertr   r’   )ZevaluaterF   rE   é   ú^)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%sz\frac{%s}{%s}rU   )Zsympy.core.powerr¨   Zsympy.physics.unitsr©   r   ro   Zsympy.simplifyrª   rY   r   ÚOner‚   r°   rš   r€   rl   Úis_commutative)r^   rf   Zinclude_parensrg   rª   ÚnumerÚdenomrµ   ZsnumerZsdenomZldenomZratioÚaÚbry   r2   )r¨   r©   r´   r^   r›   r4   Ú
_print_Mul…  sd    

!

 
zLatexPrinter._print_Mulc             C   s  |j jr†t|j jƒdkr†|j jdkr†|  |j¡}|j j}|dkrJd| }n$| jd rbd||f }nd||f }|j jr~d| S |S n„| jd r|j jr|j jdkr|  	|jt
d	 ¡|j j|j j  }}}d
|krè|jjrèd| }|jjr
| j|jd||f dS d|||f S |j jr\|j jr\|jjr\|jdkrRd|j|j f S |  |¡S |jjr~| j|j|  |j ¡dS d}|  |j ¡}|  	|jt
d	 ¡}d
|kr¾|jjr¾d| }n@t|jtƒrþ| d¡rþt d|¡rþ| d¡rþ|dd… }|||f S d S )Nr   r¶   z	\sqrt{%s}rB   z\root{%d}{%s}z\sqrt[%d]{%s}z\frac{1}{%s}rC   r¨   r·   z\left(%s\right)z%s/%s)r„   z
%s^{%s/%s}z%s^{%s}z\left(z\\left\(\\d?d?dotz\right)é   iùÿÿÿ)r„   rj   r;   ÚpÚqr`   rƒ   rY   Zis_negativerd   r   Z	is_Symbolrp   r¹   r¾   r­   r   Ú
startswithr   r³   Úendswith)r^   rf   rƒ   Zexpqrg   rÀ   rÁ   r„   r2   r2   r4   Ú
_print_Powé  sJ    $


&



zLatexPrinter._print_Powc             C   s   |   |jd ¡S )Nr   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_UnevaluatedExpr  s    z#LatexPrinter._print_UnevaluatedExprc                s’   t |jƒdkr0dt‡fdd„|jd D ƒƒ }n,‡fdd„‰ dt d	‡ fd
d„|jD ƒ¡ }t|jtƒr~|dˆ |j¡ 7 }n|ˆ |j¡7 }|S )Nr   z\sum_{%s=%s}^{%s} c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   #  s    z+LatexPrinter._print_Sum.<locals>.<listcomp>r   c                s,   dt ‡ fdd„| d | d | d fD ƒƒ S )Nz%s \leq %s \leq %sc                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r3   )r^   r2   r4   rz   '  s    zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>r   r   r¶   )Útuple)Úl)r^   r2   r4   Ú_format_ineq%  s    z-LatexPrinter._print_Sum.<locals>._format_ineqz\sum_{\substack{%s}} z\\c                s   g | ]}ˆ |ƒ‘qS r2   r2   )rx   rÇ   )rÈ   r2   r4   rz   *  s    z\left(%s\right))	r°   ÚlimitsrÆ   r•   Újoinr­   Úfunctionr   r`   )r^   rf   rg   r2   )rÈ   r^   r4   Ú
_print_Sum   s     zLatexPrinter._print_Sumc                s’   t |jƒdkr0dt‡fdd„|jd D ƒƒ }n,‡fdd„‰ dt d	‡ fd
d„|jD ƒ¡ }t|jtƒr~|dˆ |j¡ 7 }n|ˆ |j¡7 }|S )Nr   z\prod_{%s=%s}^{%s} c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   6  s    z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                s,   dt ‡ fdd„| d | d | d fD ƒƒ S )Nz%s \leq %s \leq %sc                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r3   )r^   r2   r4   rz   :  s    zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>r   r   r¶   )rÆ   )rÇ   )r^   r2   r4   rÈ   8  s    z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} z\\c                s   g | ]}ˆ |ƒ‘qS r2   r2   )rx   rÇ   )rÈ   r2   r4   rz   =  s    z\left(%s\right))	r°   rÉ   rÆ   r•   rÊ   r­   rË   r   r`   )r^   rf   rg   r2   )rÈ   r^   r4   Ú_print_Product3  s     zLatexPrinter._print_Productc             C   s  ddl m} g }||jkr"|jjS t||ƒr:| ¡  ¡ }n
d|fg}xœ|D ]”\}}t|j ¡ ƒ}|j	dd„ d xl|D ]d\}}	|	dkr˜| 
d|j ¡ qv|	dkr²| 
d	|j ¡ qvd
tƒ  |	¡ d }
| 
d|
 |j ¡ qvW qJW d |¡}|d dkr|dd … }n|dd … }|S )Nr   )ÚVectorc             S   s   | d   ¡ S )Nr   )Ú__str__)ry   r2   r2   r4   r5   S  s    z4LatexPrinter._print_BasisDependent.<locals>.<lambda>)r®   r   z + r’   z - rW   rU   rS   ú-é   )Zsympy.vectorrÎ   ZzeroZ_latex_formr­   ZseparateÚitemsrŠ   Ú
componentsÚsortÚappendr<   re   rÊ   )r^   rf   rÎ   Zo1rÒ   ÚsystemZvectZ
inneritemsÚkÚvZarg_strZoutstrr2   r2   r4   Ú_print_BasisDependentF  s,    



z"LatexPrinter._print_BasisDependentc             C   s4   |   |j¡}d| d dd t| j |jƒ¡  }|S )Nr6   r1   z_{%s}r“   )r`   rƒ   rÊ   ÚmapÚindices)r^   rf   Ztex_baserg   r2   r2   r4   Ú_print_Indexedd  s    zLatexPrinter._print_Indexedc             C   s   |   |j¡S )N)r`   Zlabel)r^   rf   r2   r2   r4   Ú_print_IndexedBasej  s    zLatexPrinter._print_IndexedBasec             C   s´   t |ƒrd}nd}d}d}xVt|jƒD ]H\}}||7 }|dkrV|d||  |¡f 7 }q&|d||  |¡|f 7 }q&W |dkrˆd||f }nd	|||f }d|| j|jtd
 ddf S )Nz\partialÚdrS   r   r   z%s %sz
%s %s^{%s}z\frac{%s}{%s}z\frac{%s^{%s}}{%s}rv   T)rc   )r   ÚreversedZvariable_countr`   rd   rf   r   )r^   rf   Zdiff_symbolrg   Zdimry   Znumr2   r2   r4   Ú_print_Derivativem  s    zLatexPrinter._print_Derivativec       	         s`   |j \}}}ˆ  |¡}‡ fdd„|D ƒ}‡ fdd„|D ƒ}d dd„ t||ƒD ƒ¡}d||f S )Nc             3   s   | ]}ˆ   |¡V  qd S )N)r`   )rx   r†   )r^   r2   r4   ú	<genexpr>†  s    z+LatexPrinter._print_Subs.<locals>.<genexpr>c             3   s   | ]}ˆ   |¡V  qd S )N)r`   )rx   r†   )r^   r2   r4   rá   ‡  s    z\\ c             s   s"   | ]}|d  d |d  V  qdS )r   ú=r   Nr2   )rx   r†   r2   r2   r4   rá   ‰  s    z#\left. %s \right|_{\substack{ %s }})r‚   r`   rÊ   Úzip)	r^   Úsubsrf   r¬   ÚnewZ
latex_exprZ	latex_oldZ	latex_newZ
latex_subsr2   )r^   r4   Ú_print_Subsƒ  s    
zLatexPrinter._print_Subsc                s:  dg  }}t |jƒdkr\tdd„ |jD ƒƒr\ddt |jƒd   d }‡ fd	d
„|jD ƒ}n¸x¶t|jƒD ]¨}|d }|d7 }t |ƒdkrúˆ jd dkr¨ˆ jd s¨|d7 }t |ƒdkrØ|dˆ  |d ¡ˆ  |d ¡f 7 }t |ƒdkrú|dˆ  |d ¡ 7 }| ddˆ  |¡ ¡ qhW d|ˆ j|jt	d ddd 
|¡f S )NrS   é   c             s   s   | ]}t |ƒd kV  qdS )r   N)r°   )rx   Úlimr2   r2   r4   rá     s    z/LatexPrinter._print_Integral.<locals>.<genexpr>z\ir   r   Úntc                s   g | ]}d ˆ   |d ¡ ‘qS )z\, d%sr   )r`   )rx   Úsymbol)r^   r2   r4   rz   ”  s   z0LatexPrinter._print_Integral.<locals>.<listcomp>r   z\intrA   )rN   z	equation*rB   z\limitsrÑ   z
_{%s}^{%s}r¶   z^{%s}z\, d%sz%s %s%srv   T)rc   )r°   rÉ   Úallrß   rY   r`   Úinsertrd   rË   r   rÊ   )r^   rf   rg   Úsymbolsrè   rê   r2   )r^   r4   Ú_print_IntegralŒ  s(    
"

zLatexPrinter._print_Integralc             C   sš   |j \}}}}d|  |¡ }t|ƒdks8|tjtjfkrL|d|  |¡ 7 }n|d|  |¡|  |¡f 7 }t|tƒr„d||  |¡f S d||  |¡f S d S )Nz\lim_{%s \to z+-z%s}z%s^%s}z%s\left(%s\right)z%s %s)r‚   r`   r•   r   ÚInfinityÚNegativeInfinityr­   r
   )r^   rf   r†   ÚzZz0Údirrg   r2   r2   r4   Ú_print_Limit¬  s    
zLatexPrinter._print_Limitc             C   sD   |   |¡}|tkrd| }n$t|ƒdks2| d¡r8|}nd| }|S )aJ  
        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, just use that letter
          - if it is a longer name, then put \operatorname{} around it and be
            mindful of undercores in the name
        z\%sr   rT   z\operatorname{%s})Ú_deal_with_super_subÚaccepted_latex_functionsr°   rÂ   )r^   r¦   Únamer2   r2   r4   Ú_hprint_Functionº  s    

zLatexPrinter._hprint_Functionc       
         sŠ  |j j}tˆ d| ƒr6t|j tƒs6tˆ d| ƒ||ƒS ‡ fdd„|jD ƒ}ˆ jd }d}ˆ jd o~t|ƒdko~ˆ  	|jd ¡ }d	d
ddddg}||krä|dkr¦|}n>|dkrÀd|dd…  }n$|dkrä|dd… }d}|dk	räd}|r|t
k rþd| }	nd| }	n(|dk	r&dˆ  |¡|f }	n
ˆ  |¡}	|rT|t
krJ|	d7 }	n|	d7 }	n|	d7 }	|rx|dk	rx|	d| 7 }	|	d |¡ S dS )a#  
        Render functions to LaTeX, handling functions that LaTeX knows about
        e.g., sin, cos, ... by using the proper LaTeX command (\sin, \cos, ...).
        For single-letter function names, render them as regular LaTeX math
        symbols. For multi-letter function names that LaTeX does not know
        about, (e.g., Li, sech) use \operatorname{} so that the function name
        is rendered in Roman font and LaTeX handles spacing properly.

        expr is the expression involving the function
        exp is an exponent
        Z_print_c                s   g | ]}t ˆ  |¡ƒ‘qS r2   )r•   r`   )rx   r    )r^   r2   r4   rz   Ü  s    z0LatexPrinter._print_Function.<locals>.<listcomp>rH   FrD   r   r   ZasinZacosZatanZacscZasecZacotr>   ZfullZarcNÚpowerTz\%s^{-1}z\operatorname{%s}^{-1}z%s^{%s}z {%s}z%sz{\left (%s \right )}z^{%s}r“   )r¦   Ú__name__Úhasattrr­   r   Úgetattrr‚   rY   r°   rq   rõ   r÷   rÊ   )
r^   rf   r„   r¦   r‚   rH   Zinv_trig_power_caseZcan_fold_bracketsZinv_trig_tablerö   r2   )r^   r4   Ú_print_FunctionË  sH    









zLatexPrinter._print_Functionc             C   s   |   t|ƒ¡S )N)r÷   r•   )r^   rf   r2   r2   r4   Ú_print_UndefinedFunction  s    z%LatexPrinter._print_UndefinedFunctionc             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)r/   z\deltaz\Gammaz\gammaz\operatorname{B}z\operatorname{Chi})Z(sympy.functions.special.tensor_functionsrþ   Z'sympy.functions.special.gamma_functionsrÿ   r   Z&sympy.functions.special.beta_functionsr  Z'sympy.functions.special.delta_functionsr  Z'sympy.functions.special.error_functionsr/   )r^   rþ   rÿ   r   r  r  r/   r2   r2   r4   Ú_special_function_classes  s    z&LatexPrinter._special_function_classesc             C   s>   x.| j D ]$}t||ƒr|j|jkr| j | S qW |  t|ƒ¡S )N)r  Ú
issubclassrù   r÷   r•   )r^   rf   Úclsr2   r2   r4   Ú_print_FunctionClass!  s    z!LatexPrinter._print_FunctionClassc             C   sX   |j \}}t|ƒdkr&|  |d ¡}n|  t|ƒ¡}||  |¡f}d||  |¡f }|S )Nr   r   z\left( %s \mapsto %s \right))r‚   r°   r`   rÆ   )r^   rf   rí   r‚   rg   r2   r2   r4   Ú_print_Lambda'  s    
zLatexPrinter._print_Lambdac                s^   t |jtd}‡ fdd„|D ƒ}dˆ  t|jƒ ¡ ¡d |¡f }|d k	rVd||f S |S d S )N)r®   c                s   g | ]}d ˆ   |¡ ‘qS )z%s)r`   )rx   rê   )r^   r2   r4   rz   6  s    z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)z, z%s^{%s})r¯   r‚   r   r`   r•   r¦   ÚlowerrÊ   )r^   rf   r„   r‚   Ztexargsrg   r2   )r^   r4   Ú_hprint_variadic_function4  s    "z&LatexPrinter._hprint_variadic_functionc             C   s0   d|   |jd ¡ }|d k	r(d||f S |S d S )Nz\lfloor{%s}\rfloorr   z%s^{%s})r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_floor?  s    zLatexPrinter._print_floorc             C   s0   d|   |jd ¡ }|d k	r(d||f S |S d S )Nz\lceil{%s}\rceilr   z%s^{%s})r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_ceilingG  s    zLatexPrinter._print_ceilingc             C   sP   | j d s d|  |jd ¡ }nd|  |jd ¡ }|d k	rHd||f S |S d S )NrL   z\log{\left (%s \right )}r   z\ln{\left (%s \right )}z%s^{%s})rY   r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú
_print_logO  s    
zLatexPrinter._print_logc             C   s0   d|   |jd ¡ }|d k	r(d||f S |S d S )Nz\left|{%s}\right|r   z%s^{%s})r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú
_print_AbsZ  s    zLatexPrinter._print_Absc             C   s&   d|   |jd td ¡ }|  ||¡S )Nz\Re{%s}r   ÚAtom)rd   r‚   r   r…   )r^   rf   r„   rg   r2   r2   r4   Ú	_print_rec  s    zLatexPrinter._print_rec             C   s&   d|   |jd td ¡ }|  ||¡S )Nz\Im{%s}r   ÚFunc)rd   r‚   r   r…   )r^   rf   r„   rg   r2   r2   r4   Ú	_print_imh  s    zLatexPrinter._print_imc             C   sŒ   ddl m}m} t|jd |ƒr2|  |jd d¡S t|jd |ƒrT|  |jd d¡S |jd jrtd|  |jd ¡ S d|  |jd ¡ S d S )Nr   )Ú
EquivalentÚImpliesz\not\Leftrightarrowz\not\Rightarrowz	\neg (%s)z\neg %s)	r{   r  r  r­   r‚   Ú_print_EquivalentÚ_print_ImpliesÚ
is_Booleanr`   )r^   r†   r  r  r2   r2   r4   Ú
_print_Notm  s    zLatexPrinter._print_Notc             C   s†   |d }|j r$|js$d|  |¡ }nd|  |¡ }xN|dd … D ]>}|j rh|jsh|d||  |¡f 7 }q@|d||  |¡f 7 }q@W |S )Nr   z\left(%s\right)z%sr   z %s \left(%s\right)z %s %s)r  Zis_Notr`   )r^   r‚   Úcharr    rg   r2   r2   r4   Ú_print_LogOpx  s    zLatexPrinter._print_LogOpc             C   s   t |jtd}|  |d¡S )N)r®   z\wedge)r¯   r‚   r   r  )r^   r†   r‚   r2   r2   r4   Ú
_print_And‡  s    zLatexPrinter._print_Andc             C   s   t |jtd}|  |d¡S )N)r®   z\vee)r¯   r‚   r   r  )r^   r†   r‚   r2   r2   r4   Ú	_print_Or‹  s    zLatexPrinter._print_Orc             C   s   t |jtd}|  |d¡S )N)r®   z\veebar)r¯   r‚   r   r  )r^   r†   r‚   r2   r2   r4   Ú
_print_Xor  s    zLatexPrinter._print_Xorc             C   s   |   |j|pd¡S )Nz\Rightarrow)r  r‚   )r^   r†   Úaltcharr2   r2   r4   r  “  s    zLatexPrinter._print_Impliesc             C   s   t |jtd}|  ||pd¡S )N)r®   z\Leftrightarrow)r¯   r‚   r   r  )r^   r†   r  r‚   r2   r2   r4   r  –  s    zLatexPrinter._print_Equivalentc             C   s0   d|   |jd ¡ }|d k	r(d||f S |S d S )Nz\overline{%s}r   z%s^{%s})r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_conjugateš  s    zLatexPrinter._print_conjugatec             C   s>   d}d|   |jd ¡ }|d k	r.d|||f S d||f S d S )Nz\operatorname{polar\_lift}z{\left (%s \right )}r   z	%s^{%s}%sz%s%s)r`   r‚   )r^   rf   r„   r¦   r    r2   r2   r4   Ú_print_polar_lift¢  s
    zLatexPrinter._print_polar_liftc             C   s    d|   |jd ¡ }|  ||¡S )Nze^{%s}r   )r`   r‚   r…   )r^   rf   r„   rg   r2   r2   r4   Ú_print_ExpBase«  s    zLatexPrinter._print_ExpBasec             C   s4   d|   |jd ¡ }|d k	r(d||f S d| S d S )Nz\left(%s\right)r   zK^{%s}%szK%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_elliptic_k±  s    zLatexPrinter._print_elliptic_kc             C   sD   d|   |jd ¡|   |jd ¡f }|d k	r8d||f S d| S d S )Nz\left(%s\middle| %s\right)r   r   zF^{%s}%szF%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_elliptic_f¸  s
    "zLatexPrinter._print_elliptic_fc             C   sh   t |jƒdkr4d|  |jd ¡|  |jd ¡f }nd|  |jd ¡ }|d k	r\d||f S d| S d S )Nr¶   z\left(%s\middle| %s\right)r   r   z\left(%s\right)zE^{%s}%szE%s)r°   r‚   r`   )r^   rf   r„   rg   r2   r2   r4   Ú_print_elliptic_eÀ  s    $zLatexPrinter._print_elliptic_ec             C   s†   t |jƒdkrBd|  |jd ¡|  |jd ¡|  |jd ¡f }n$d|  |jd ¡|  |jd ¡f }|d k	rzd||f S d| S d S )	NrÑ   z\left(%s; %s\middle| %s\right)r   r   r¶   z\left(%s\middle| %s\right)z
\Pi^{%s}%sz\Pi%s)r°   r‚   r`   )r^   rf   r„   rg   r2   r2   r4   Ú_print_elliptic_piË  s    "zLatexPrinter._print_elliptic_pic             C   sD   d|   |jd ¡|   |jd ¡f }|d k	r8d||f S d| S d S )Nz\left(%s, %s\right)r   r   z\operatorname{B}^{%s}%sz\operatorname{B}%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_betaØ  s
    zLatexPrinter._print_betac             C   sD   d|   |jd ¡|   |jd ¡f }|d k	r8d||f S d| S d S )Nz\left(%s, %s\right)r   r   z\Gamma^{%s}%sz\Gamma%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_uppergammaá  s
    zLatexPrinter._print_uppergammac             C   sD   d|   |jd ¡|   |jd ¡f }|d k	r8d||f S d| S d S )Nz\left(%s, %s\right)r   r   z\gamma^{%s}%sz\gamma%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_lowergammaê  s
    zLatexPrinter._print_lowergammac             C   sJ   d|   |jd ¡ }|d k	r2d|   |j¡||f S d|   |j¡|f S d S )Nz\left(%s\right)r   z	%s^{%s}%sz%s%s)r`   r‚   r¦   )r^   rf   r„   rg   r2   r2   r4   Ú_hprint_one_arg_funcó  s    z!LatexPrinter._hprint_one_arg_funcc             C   s4   d|   |jd ¡ }|d k	r(d||f S d| S d S )Nz\left(%s\right)r   z\operatorname{Chi}^{%s}%sz\operatorname{Chi}%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú
_print_Chiý  s    zLatexPrinter._print_Chic             C   sJ   d|   |jd ¡ }|   |jd ¡}|d k	r:d|||f S d||f S d S )Nz\left(%s\right)r   r   z\operatorname{E}_{%s}^{%s}%sz\operatorname{E}_{%s}%s)r`   r‚   )r^   rf   r„   rg   Znur2   r2   r4   Ú_print_expint  s
    zLatexPrinter._print_expintc             C   s4   d|   |jd ¡ }|d k	r(d||f S d| S d S )Nz\left(%s\right)r   zS^{%s}%szS%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_fresnels  s    zLatexPrinter._print_fresnelsc             C   s4   d|   |jd ¡ }|d k	r(d||f S d| S d S )Nz\left(%s\right)r   zC^{%s}%szC%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_fresnelc  s    zLatexPrinter._print_fresnelcc             C   s6   d|   |jd td ¡ }|d k	r.d||f S |S d S )Nz!%sr   r  z%s^{%s})rd   r‚   r   )r^   rf   r„   rg   r2   r2   r4   Ú_print_subfactorial  s    z LatexPrinter._print_subfactorialc             C   s6   d|   |jd td ¡ }|d k	r.d||f S |S d S )Nz%s!r   r  z%s^{%s})rd   r‚   r   )r^   rf   r„   rg   r2   r2   r4   Ú_print_factorial&  s    zLatexPrinter._print_factorialc             C   s6   d|   |jd td ¡ }|d k	r.d||f S |S d S )Nz%s!!r   r  z%s^{%s})rd   r‚   r   )r^   rf   r„   rg   r2   r2   r4   Ú_print_factorial2.  s    zLatexPrinter._print_factorial2c             C   s@   d|   |jd ¡|   |jd ¡f }|d k	r8d||f S |S d S )Nz{\binom{%s}{%s}}r   r   z%s^{%s})r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_binomial6  s
    zLatexPrinter._print_binomialc             C   s<   |j \}}d|  |td ¡ }d||  |¡f }|  ||¡S )Nz%sr  z{%s}^{\left(%s\right)})r‚   rd   r   r`   r…   )r^   rf   r„   Únr×   rƒ   rg   r2   r2   r4   Ú_print_RisingFactorial?  s    
z#LatexPrinter._print_RisingFactorialc             C   s<   |j \}}d|  |td ¡ }d|  |¡|f }|  ||¡S )Nz%sr  z{\left(%s\right)}_{%s})r‚   rd   r   r`   r…   )r^   rf   r„   r1  r×   Úsubrg   r2   r2   r4   Ú_print_FallingFactorialG  s    
z$LatexPrinter._print_FallingFactorialc             C   sl   d| }d}|d k	r:|  d¡dkr6d||  |¡f }nd}d||  |j¡|  |j¡f }|rh|  ||¡}|S )Nz%sFr·   r’   z%s^{%s}Tz%s_{%s}\left(%s\right))Úfindr`   r@   Úargumentr…   )r^   rf   r„   Úsymrg   Zneed_expr2   r2   r4   Ú_hprint_BesselBaseO  s    zLatexPrinter._hprint_BesselBasec             C   sR   t |ƒdkrdS d}x&|d d… D ]}|d|  |¡ 7 }q"W ||  |d ¡7 }|S )Nr   rS   r’   z%s, )r°   r`   )r^   r9   r3   r   r2   r2   r4   Ú_hprint_vec`  s    zLatexPrinter._hprint_vecc             C   s   |   ||d¡S )NÚJ)r8  )r^   rf   r„   r2   r2   r4   Ú_print_besselji  s    zLatexPrinter._print_besseljc             C   s   |   ||d¡S )Nr&   )r8  )r^   rf   r„   r2   r2   r4   Ú_print_besselil  s    zLatexPrinter._print_besselic             C   s   |   ||d¡S )Nr'   )r8  )r^   rf   r„   r2   r2   r4   Ú_print_besselko  s    zLatexPrinter._print_besselkc             C   s   |   ||d¡S )NÚY)r8  )r^   rf   r„   r2   r2   r4   Ú_print_besselyr  s    zLatexPrinter._print_besselyc             C   s   |   ||d¡S )NÚy)r8  )r^   rf   r„   r2   r2   r4   Ú	_print_ynu  s    zLatexPrinter._print_ync             C   s   |   ||d¡S )NÚj)r8  )r^   rf   r„   r2   r2   r4   Ú	_print_jnx  s    zLatexPrinter._print_jnc             C   s   |   ||d¡S )NzH^{(1)})r8  )r^   rf   r„   r2   r2   r4   Ú_print_hankel1{  s    zLatexPrinter._print_hankel1c             C   s   |   ||d¡S )NzH^{(2)})r8  )r^   rf   r„   r2   r2   r4   Ú_print_hankel2~  s    zLatexPrinter._print_hankel2c             C   s   |   ||d¡S )Nzh^{(1)})r8  )r^   rf   r„   r2   r2   r4   Ú
_print_hn1  s    zLatexPrinter._print_hn1c             C   s   |   ||d¡S )Nzh^{(2)})r8  )r^   rf   r„   r2   r2   r4   Ú
_print_hn2„  s    zLatexPrinter._print_hn2rS   c             C   s:   d|   |jd ¡ }|d k	r*d|||f S d||f S d S )Nz\left(%s\right)r   z	%s^{%s}%sz%s%s)r`   r‚   )r^   rf   r„   Únotationrg   r2   r2   r4   Ú_hprint_airy‡  s    zLatexPrinter._hprint_airyc             C   s:   d|   |jd ¡ }|d k	r*d|||f S d||f S d S )Nz\left(%s\right)r   z{%s^\prime}^{%s}%sz%s^\prime%s)r`   r‚   )r^   rf   r„   rH  rg   r2   r2   r4   Ú_hprint_airy_prime  s    zLatexPrinter._hprint_airy_primec             C   s   |   ||d¡S )NÚAi)rI  )r^   rf   r„   r2   r2   r4   Ú_print_airyai—  s    zLatexPrinter._print_airyaic             C   s   |   ||d¡S )NÚBi)rI  )r^   rf   r„   r2   r2   r4   Ú_print_airybiš  s    zLatexPrinter._print_airybic             C   s   |   ||d¡S )NrK  )rJ  )r^   rf   r„   r2   r2   r4   Ú_print_airyaiprime  s    zLatexPrinter._print_airyaiprimec             C   s   |   ||d¡S )NrM  )rJ  )r^   rf   r„   r2   r2   r4   Ú_print_airybiprime   s    zLatexPrinter._print_airybiprimec             C   s`   d|   t|jƒ¡|   t|jƒ¡|  |j¡|  |j¡|   |j¡f }|d k	r\d||   |¡f }|S )NzN{{}_{%s}F_{%s}\left(\begin{matrix} %s \\ %s \end{matrix}\middle| {%s} \right)}z	{%s}^{%s})r`   r°   ÚapÚbqr9  r6  )r^   rf   r„   rg   r2   r2   r4   Ú_print_hyper£  s    zLatexPrinter._print_hyperc             C   s   d|   t|jƒ¡|   t|jƒ¡|   t|jƒ¡|   t|jƒ¡|  |j¡|  |j¡|  |j¡|  |j¡|   |j	¡f	 }|d k	rŒd||   |¡f }|S )Nz^{G_{%s, %s}^{%s, %s}\left(\begin{matrix} %s & %s \\%s & %s \end{matrix} \middle| {%s} \right)}z	{%s}^{%s})
r`   r°   rQ  rR  r:   Zanr9  ZaotherZbotherr6  )r^   rf   r„   rg   r2   r2   r4   Ú_print_meijerg®  s    zLatexPrinter._print_meijergc             C   s6   d|   |jd ¡ }|d k	r.d|   |¡|f S d| S )Nz\left(%s\right)r   z\eta^{%s}%sz\eta%s)r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_dirichlet_eta»  s    z!LatexPrinter._print_dirichlet_etac             C   s\   t |jƒdkr&dtt| j|jƒƒ }nd|  |jd ¡ }|d k	rTd|  |¡|f S d| S )Nr¶   z\left(%s, %s\right)z\left(%s\right)r   z\zeta^{%s}%sz\zeta%s)r°   r‚   rÆ   rÚ   r`   )r^   rf   r„   rg   r2   r2   r4   Ú_print_zetaÁ  s    zLatexPrinter._print_zetac             C   s8   dt t| j|jƒƒ }|d kr&d| S d|  |¡|f S )Nz\left(%s, %s, %s\right)z\Phi%sz\Phi^{%s}%s)rÆ   rÚ   r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_lerchphiÊ  s    zLatexPrinter._print_lerchphic             C   sB   t | j|jƒ\}}d| }|d kr.d||f S d||  |¡|f S )Nz\left(%s\right)z\operatorname{Li}_{%s}%sz\operatorname{Li}_{%s}^{%s}%s)rÚ   r`   r‚   )r^   rf   r„   r3   rñ   rg   r2   r2   r4   Ú_print_polylogÐ  s
    zLatexPrinter._print_polylogc             C   sH   t | j|jƒ\}}}}d||||f }|d k	rDd| d|  |¡  }|S )Nz*P_{%s}^{\left(%s,%s\right)}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  r¼   r½   ry   rg   r2   r2   r4   Ú_print_jacobi×  s
    zLatexPrinter._print_jacobic             C   sD   t | j|jƒ\}}}d|||f }|d k	r@d| d|  |¡  }|S )Nz'C_{%s}^{\left(%s\right)}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  r¼   ry   rg   r2   r2   r4   Ú_print_gegenbauerÞ  s
    zLatexPrinter._print_gegenbauerc             C   s@   t | j|jƒ\}}d||f }|d k	r<d| d|  |¡  }|S )NzT_{%s}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  ry   rg   r2   r2   r4   Ú_print_chebyshevtå  s
    zLatexPrinter._print_chebyshevtc             C   s@   t | j|jƒ\}}d||f }|d k	r<d| d|  |¡  }|S )NzU_{%s}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  ry   rg   r2   r2   r4   Ú_print_chebyshevuì  s
    zLatexPrinter._print_chebyshevuc             C   s@   t | j|jƒ\}}d||f }|d k	r<d| d|  |¡  }|S )NzP_{%s}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  ry   rg   r2   r2   r4   Ú_print_legendreó  s
    zLatexPrinter._print_legendrec             C   sD   t | j|jƒ\}}}d|||f }|d k	r@d| d|  |¡  }|S )Nz'P_{%s}^{\left(%s\right)}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  r¼   ry   rg   r2   r2   r4   Ú_print_assoc_legendreú  s
    z"LatexPrinter._print_assoc_legendrec             C   s@   t | j|jƒ\}}d||f }|d k	r<d| d|  |¡  }|S )NzH_{%s}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  ry   rg   r2   r2   r4   Ú_print_hermite  s
    zLatexPrinter._print_hermitec             C   s@   t | j|jƒ\}}d||f }|d k	r<d| d|  |¡  }|S )NzL_{%s}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  ry   rg   r2   r2   r4   Ú_print_laguerre  s
    zLatexPrinter._print_laguerrec             C   sD   t | j|jƒ\}}}d|||f }|d k	r@d| d|  |¡  }|S )Nz'L_{%s}^{\left(%s\right)}\left(%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  r¼   ry   rg   r2   r2   r4   Ú_print_assoc_laguerre  s
    z"LatexPrinter._print_assoc_laguerrec             C   sH   t | j|jƒ\}}}}d||||f }|d k	rDd| d|  |¡  }|S )NzY_{%s}^{%s}\left(%s,%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  ÚmÚthetaÚphirg   r2   r2   r4   Ú
_print_Ynm  s
    zLatexPrinter._print_Ynmc             C   sH   t | j|jƒ\}}}}d||||f }|d k	rDd| d|  |¡  }|S )NzZ_{%s}^{%s}\left(%s,%s\right)z\left(z\right)^{%s})rÚ   r`   r‚   )r^   rf   r„   r1  rb  rc  rd  rg   r2   r2   r4   Ú
_print_Znm  s
    zLatexPrinter._print_Znmc             C   sb   |j dkrRd}|j}|jdk r(d}| }| jd rBd|||j f S d|||j f S |  |j¡S d S )Nr   rS   r   z- rE   z	%s%d / %dz%s\frac{%d}{%d})rÁ   rÀ   rY   r`   )r^   rf   ÚsignrÀ   r2   r2   r4   Ú_print_Rational$  s    


zLatexPrinter._print_Rationalc             C   s¾   |   |j¡}|jr&tdd„ |jD ƒƒs4t|jƒdkr¶|d7 }t|jƒdkr\||   |j¡7 }nt|jƒrz||   |jd ¡7 }|d7 }t|jƒdkr¢||   |j¡7 }n||   |jd ¡7 }d| S )Nc             s   s   | ]}|t jkV  qd S )N)r   ZZero)rx   rÀ   r2   r2   r4   rá   3  s    z,LatexPrinter._print_Order.<locals>.<genexpr>r   z; r   z\rightarrow zO\left(%s\right))r`   rf   Zpointr}   r°   Ú	variables)r^   rf   r3   r2   r2   r4   Ú_print_Order1  s    
zLatexPrinter._print_Orderc             C   s8   || j d kr| j d | S d|jkr2|  |j¡S |jS )NrK   rT   )rY   rö   rô   )r^   rf   r2   r2   r4   Ú_print_SymbolA  s    zLatexPrinter._print_Symbolc             C   s~   d|kr|S t |ƒ\}}}t|ƒ}dd„ |D ƒ}dd„ |D ƒ}t|ƒdkr\|dd |¡ 7 }t|ƒdkrz|dd |¡ 7 }|S )	Nr6   c             S   s   g | ]}t |ƒ‘qS r2   )Ú	translate)rx   Zsupr2   r2   r4   rz   R  s    z5LatexPrinter._deal_with_super_sub.<locals>.<listcomp>c             S   s   g | ]}t |ƒ‘qS r2   )rl  )rx   r3  r2   r2   r4   rz   S  s    r   z^{%s}rO   z_{%s})r   rl  r°   rÊ   )r^   Ústringrö   Zsupersrä   r2   r2   r4   rô   K  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 )NrB   z\gtz\ltú>ú<râ   z\geqz\leqz\neq)z==rn  ro  z>=z<=z!=z%s %s %s)rY   r`   ZlhsZrel_opZrhs)r^   rf   ÚgtÚltÚcharmapr2   r2   r4   Ú_print_Relational]  s    
zLatexPrinter._print_Relationalc                sŠ   ‡ fdd„|j d d… D ƒ}|j d jtkrJ| dˆ  |j d j¡ ¡ n.| dˆ  |j d j¡ˆ  |j d j¡f ¡ d}|d |¡ S )Nc                s(   g | ] \}}d ˆ   |¡ˆ   |¡f ‘qS )z%s & \text{for}\: %s)r`   )rx   r†   Úc)r^   r2   r4   rz   r  s   z1LatexPrinter._print_Piecewise.<locals>.<listcomp>r’   z%s & \text{otherwise}z%s & \text{for}\: %sz\begin{cases} %s \end{cases}z \\)r‚   Zcondr   rÕ   r`   rf   rÊ   )r^   rf   Zecpairsrg   r2   )r^   r4   Ú_print_Piecewiseq  s    
zLatexPrinter._print_Piecewisec          
      sò   g }x<t |jƒD ].}| d ‡ fdd„||d d …f D ƒ¡¡ qW ˆ jd }|d kr€ˆ jd dkrhd}n|jdkd	kr|d
}nd}d}| d|¡}|dkr²| ddd|j  d ¡}ˆ jd räˆ jd }ˆ j| }d| | d | }|d |¡ S )Nz & c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   ‚  s    z2LatexPrinter._print_MatrixBase.<locals>.<listcomp>rI   rA   rM   Úsmallmatrixé
   TÚmatrixÚarrayz \begin{%MATSTR%}%s\end{%MATSTR%}z%MATSTR%z%sr6   rt  z}%srJ   z\leftz\rightz\\)r   ZrowsrÕ   rÊ   rY   Zcolsr–   r]   )r^   rf   ÚlinesÚlinerI   Úout_strÚ
left_delimÚright_delimr2   )r^   r4   Ú_print_MatrixBase~  s&    .



zLatexPrinter._print_MatrixBasec             C   s&   | j |jtd ddd|j|jf  S )Nr  T)rc   z	_{%s, %s})rd   Úparentr   r   rB  )r^   rf   r2   r2   r4   Ú_print_MatrixElementœ  s    z!LatexPrinter._print_MatrixElementc                s8   ‡ fdd„}ˆ   |j¡d ||jƒ d ||jƒ d S )Nc                sZ   t | ƒ} | d dkr| d= | d | d d kr4| d= | d dkrHd| d< d tˆ j| ƒ¡S )Nr¶   r   r   rS   ú:)rŠ   rÊ   rÚ   r`   )ry   )r^   r2   r4   Ú
latexslice¡  s    z3LatexPrinter._print_MatrixSlice.<locals>.latexslicez\left[z, z\right])r`   r€  ZrowsliceZcolslice)r^   rf   rƒ  r2   )r^   r4   Ú_print_MatrixSlice   s    zLatexPrinter._print_MatrixSlicec             C   s   |   |j¡S )N)r`   Zblocks)r^   rf   r2   r2   r4   Ú_print_BlockMatrix®  s    zLatexPrinter._print_BlockMatrixc             C   s<   |j }ddlm} t||ƒs*d|  |¡ S d|  |¡ S d S )Nr   )ÚMatrixSymbolz\left(%s\right)^Tz%s^T)r    Úsympy.matricesr†  r­   r`   )r^   rf   Úmatr†  r2   r2   r4   Ú_print_Transpose±  s
    
zLatexPrinter._print_Transposec             C   s<   |j }ddlm} t||ƒs*d|  |¡ S d|  |¡ S d S )Nr   )r†  z\left(%s\right)^\daggerz
%s^\dagger)r    r‡  r†  r­   r`   )r^   rf   rˆ  r†  r2   r2   r4   Ú_print_Adjoint¹  s
    
zLatexPrinter._print_Adjointc                sx   ‡ fdd„|j D ƒ}g }x:|D ]2}| d¡r>d}|dd … }nd}| ||g¡ qW | d¡}|dkrjd}|d |¡ S )	Nc                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   Út)r^   r2   r4   rz   Â  s    z.LatexPrinter._print_MatAdd.<locals>.<listcomp>rÐ   r   r˜   r   rS   rO   )r‚   rÂ   ÚextendÚpoprÊ   )r^   rf   rŒ   rÇ   r‹  rg  r2   )r^   r4   Ú_print_MatAddÁ  s    


zLatexPrinter._print_MatAddc                s    ddl m‰ m‰m‰m}m} ‡ ‡‡‡fdd„}t||ƒrŠ|jd jrŠ|jd dk rŠ|d|jd  ||jdd … Ž ƒ}dd 	t
||jƒ¡ S d 	t
||jƒ¡S d S )	Nr   )r   ÚMatAddÚHadamardProductÚMatMulrv   c                s(   t | ˆ ˆˆfƒrdˆ | ¡ S ˆ | ¡S )Nz\left(%s\right))r­   r`   )ry   )r   r  r  r^   r2   r4   ÚparensÓ  s    z*LatexPrinter._print_MatMul.<locals>.parensr’   r   rÐ   rO   )r{   r   r  r  r‘  rv   r­   r‚   Z	is_NumberrÊ   rÚ   )r^   rf   r‘  rv   r’  r2   )r   r  r  r^   r4   Ú_print_MatMulÐ  s    $"zLatexPrinter._print_MatMulc             C   sl   |d k	r>d| j |jd td dd|  |jd ¡|  |¡f S d| j |jd td dd|  |jd ¡f S )Nz\left(%s\bmod{%s}\right)^{%s}r   rv   T)rc   r   z%s\bmod{%s})rd   r‚   r   r`   )r^   rf   r„   r2   r2   r4   Ú
_print_ModÞ  s
    (zLatexPrinter._print_Modc                s8   ddl m‰ m‰m‰ ‡ ‡‡‡fdd„}d t||jƒ¡S )Nr   )r   r  r‘  c                s(   t | ˆ ˆˆfƒrdˆ | ¡ S ˆ | ¡S )Nz\left(%s\right))r­   r`   )ry   )r   r  r‘  r^   r2   r4   r’  è  s    z3LatexPrinter._print_HadamardProduct.<locals>.parensz \circ )r{   r   r  r‘  rÊ   rÚ   r‚   )r^   rf   r’  r2   )r   r  r‘  r^   r4   Ú_print_HadamardProductå  s    z#LatexPrinter._print_HadamardProductc                s8   ddl m‰ m‰m‰ ‡ ‡‡‡fdd„}d t||jƒ¡S )Nr   )r   r  r‘  c                s(   t | ˆ ˆˆfƒrdˆ | ¡ S ˆ | ¡S )Nz\left(%s\right))r­   r`   )ry   )r   r  r‘  r^   r2   r4   r’  ñ  s    z4LatexPrinter._print_KroneckerProduct.<locals>.parensz	 \otimes )r{   r   r  r‘  rÊ   rÚ   r‚   )r^   rf   r’  r2   )r   r  r‘  r^   r4   Ú_print_KroneckerProductî  s    z$LatexPrinter._print_KroneckerProductc             C   sX   |j |j }}ddlm} t||ƒs<d|  |¡|  |¡f S d|  |¡|  |¡f S d S )Nr   )r†  z\left(%s\right)^{%s}z%s^{%s})rƒ   r„   r‡  r†  r­   r`   )r^   rf   rƒ   r„   r†  r2   r2   r4   Ú_print_MatPow÷  s
    
zLatexPrinter._print_MatPowc             C   s   dS )Nz
\mathbb{0}r2   )r^   r$   r2   r2   r4   Ú_print_ZeroMatrixÿ  s    zLatexPrinter._print_ZeroMatrixc             C   s   dS )Nz
\mathbb{I}r2   )r^   r&   r2   r2   r4   Ú_print_Identity  s    zLatexPrinter._print_Identityc          
   C   s  |  ¡ dkr|  |d ¡S | jd }|d krd| jd dkr@d}n$|  ¡ dksZ|jd dkr`d	}nd
}d}| d|¡}| jd r¦| jd }| j| }d| | d | }|  ¡ dkrº|d S g gdd„ t|  ¡ ƒD ƒ }dd„ |jD ƒ}xôtj|Ž D ]æ}|d  	|  || ¡¡ d}	xÄt|  ¡ d ddƒD ]¬}
t
||
d  ƒ|j|
 k rJP |	rn||
  	d ||
d  ¡¡ nR||
  	|d ||
d  ¡ ¡ t
||
d  ƒdkrÀd||
 d  d ||
 d< |	 }	g ||
d < q(W qòW |d d }|  ¡ d dkr|| }|S )Nr   r2   rI   rA   rM   rv  r’   rw  rx  ry  z \begin{%MATSTR%}%s\end{%MATSTR%}z%MATSTR%rJ   z\leftz\rightrS   c             S   s   g | ]}g ‘qS r2   r2   )rx   r   r2   r2   r4   rz     s    z1LatexPrinter._print_NDimArray.<locals>.<listcomp>c             S   s   g | ]}t t|ƒƒ‘qS r2   )rŠ   r   )rx   r   r2   r2   r4   rz     s    Tr   z & z\\z\left[z\right]r¶   )Úrankr`   rY   Úshaper–   r]   r   Ú	itertoolsÚproductrÕ   r°   rÊ   )r^   rf   rI   Z	block_strr}  r~  Z	level_strZshape_rangesZouter_iZevenZback_outer_ir|  r2   r2   r4   Ú_print_NDimArray  sH    



 zLatexPrinter._print_NDimArrayc                s   dd  ‡ fdd„|D ƒ¡ S )Nz\left ( %s\right )z, \quad c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   =  s    z-LatexPrinter._print_tuple.<locals>.<listcomp>)rÊ   )r^   rf   r2   )r^   r4   Ú_print_tuple;  s    zLatexPrinter._print_tuplec                s   ‡ fdd„|j D ƒ}d |¡S )Nc                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r¼   )r^   r2   r4   rz   @  s    z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>z	 \otimes )r‚   rÊ   )r^   rf   Úelementsr2   )r^   r4   Ú_print_TensorProduct?  s    z!LatexPrinter._print_TensorProductc                s   ‡ fdd„|j D ƒ}d |¡S )Nc                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r¼   )r^   r2   r4   rz   D  s    z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>z \wedge )r‚   rÊ   )r^   rf   r   r2   )r^   r4   Ú_print_WedgeProductC  s    z LatexPrinter._print_WedgeProductc             C   s
   |   |¡S )N)rŸ  )r^   rf   r2   r2   r4   Ú_print_TupleG  s    zLatexPrinter._print_Tuplec                s   dd  ‡ fdd„|D ƒ¡ S )Nz\left [ %s\right ]z, \quad c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   L  s    z,LatexPrinter._print_list.<locals>.<listcomp>)rÊ   )r^   rf   r2   )r^   r4   Ú_print_listJ  s    zLatexPrinter._print_listc             C   sV   t | ¡ td}g }x2|D ]*}|| }| d|  |¡|  |¡f ¡ qW dd |¡ S )N)r®   z%s : %sz\left \{ %s\right \}z, \quad )r¯   Úkeysr   rÕ   r`   rÊ   )r^   rÞ   r¥  rÒ   r®   Úvalr2   r2   r4   Ú_print_dictN  s    
"zLatexPrinter._print_dictc             C   s
   |   |¡S )N)r§  )r^   rf   r2   r2   r4   Ú_print_DictX  s    zLatexPrinter._print_Dictc             C   sj   t |jƒdks|jd dkr2d|  |jd ¡ }n$d|  |jd ¡|  |jd ¡f }|rfd||f }|S )Nr   r   z\delta\left(%s\right)z+\delta^{\left( %s \right)}\left( %s \right)z\left(%s\right)^{%s})r°   r‚   r`   )r^   rf   r„   rg   r2   r2   r4   Ú_print_DiracDelta[  s    "zLatexPrinter._print_DiracDeltac             C   s:   |   |jd |jd  ¡}|   |jd ¡}d||f }|S )Nr   r   r¶   z{\langle %s \rangle}^{%s})r`   r‚   )r^   rf   Úshiftrø   rg   r2   r2   r4   Ú_print_SingularityFunctione  s    z'LatexPrinter._print_SingularityFunctionc             C   s(   d|   |jd ¡ }|r$d||f }|S )Nz\theta\left(%s\right)r   z\left(%s\right)^{%s})r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_Heavisidek  s    zLatexPrinter._print_Heavisidec             C   sf   |   |jd ¡}|   |jd ¡}|jd jrF|jd jrFd||f }nd||f }|rbd||f }|S )Nr   r   z\delta_{%s %s}z\delta_{%s, %s}z\left(%s\right)^{%s})r`   r‚   rh   )r^   rf   r„   r   rB  rg   r2   r2   r4   Ú_print_KroneckerDeltaq  s    z"LatexPrinter._print_KroneckerDeltac             C   sT   t | j|jƒ}tdd„ |jD ƒƒr2dd |¡ }ndd |¡ }|rPd||f }|S )Nc             s   s   | ]}|j V  qd S )N)rh   )rx   ry   r2   r2   r4   rá   ~  s    z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}rO   z, z\left(%s\right)^{%s})rÚ   r`   r‚   rë   rÊ   )r^   rf   r„   rÛ   rg   r2   r2   r4   Ú_print_LeviCivita|  s    zLatexPrinter._print_LeviCivitac                sT   t |jƒdkr6t|jƒs6ˆ  |jd ¡dt |jƒ  S d ‡ fdd„|jD ƒ¡S d S )Nr   r   z^%dz \times c             3   s   | ]}ˆ   |¡V  qd S )N)r`   )rx   Úset)r^   r2   r4   rá   Š  s    z1LatexPrinter._print_ProductSet.<locals>.<genexpr>)r°   Úsetsr   r`   rÊ   )r^   rÀ   r2   )r^   r4   Ú_print_ProductSet†  s    zLatexPrinter._print_ProductSetc             C   sn   t |dƒrd|  | ¡ ¡ S t |dƒrFd|  |j¡ d |  |j¡ S t |dƒr`d|  |j¡ S |  d ¡S d S )NÚ
as_booleanzDomain: r¯  z in rí   z
Domain on )rú   r`   r²  rí   r¯  )r^   rÞ   r2   r2   r4   Ú_print_RandomDomainŒ  s    


z LatexPrinter._print_RandomDomainc             C   s   t |jtd}|  |¡S )N)r®   )r¯   r‚   r   Ú
_print_set)r^   r3   rÒ   r2   r2   r4   Ú_print_FiniteSet—  s    zLatexPrinter._print_FiniteSetc             C   s&   t |td}d t| j|ƒ¡}d| S )N)r®   z, z\left\{%s\right\})r¯   r   rÊ   rÚ   r`   )r^   r3   rÒ   r2   r2   r4   r´  ›  s    zLatexPrinter._print_setc                sˆ   d}|j jr*|j ||d |j |d f}n>|jjs>t|ƒdkr`t|ƒ}t|ƒt|ƒ||d f}nt|ƒ}dd ‡ fdd„|D ƒ¡ d S )	Nz\ldotsr’   rç   z\left\{z, c             3   s   | ]}ˆ   |¡V  qd S )N)r`   )rx   Úel)r^   r2   r4   rá   ®  s    z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})	ÚstartZis_infiniteÚstepÚstopr°   ÚiterÚnextrÆ   rÊ   )r^   r3   ZdotsÚprintsetÚitr2   )r^   r4   Ú_print_Range¢  s    zLatexPrinter._print_Rangec                sœ   |j tjkrF|j}d| |d ¡| |d ¡| |d ¡| |¡f}n6|jtjks\|jdkrt|d d… }| d¡ nt|ƒ}dd 	‡ fdd	„|D ƒ¡ d
 S )Nz\ldotsrÑ   r¶   r   rç   z\left[z, c             3   s   | ]}ˆ   |¡V  qd S )N)r`   )rx   r¶  )r^   r2   r4   rá   ½  s    z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>z\right])
r·  r   rð   r¹  Úcoeffrï   ÚlengthrÕ   rÆ   rÊ   )r^   r3   r¹  r¼  r2   )r^   r4   Ú_print_SeqFormula±  s    zLatexPrinter._print_SeqFormulac             C   s`   |j |jkrd|  |j ¡ S |jr(d}nd}|jr8d}nd}d||  |j ¡|  |j¡|f S d S )Nz\left\{%s\right\}rW   r?   rU   rV   z\left%s%s, %s\right%s)r·  Úendr`   Z	left_openZ
right_open)r^   r   ÚleftÚrightr2   r2   r4   Ú_print_IntervalÄ  s    zLatexPrinter._print_Intervalc             C   s   d|   |j¡|   |j¡f S )Nz\langle %s, %s\rangle)r`   ÚminÚmax)r^   r   r2   r2   r4   Ú_print_AccumulationBoundsÖ  s    z&LatexPrinter._print_AccumulationBoundsc                s   d  ‡ fdd„|jD ƒ¡S )Nz \cup c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   Û  s    z-LatexPrinter._print_Union.<locals>.<listcomp>)rÊ   r‚   )r^   Úur2   )r^   r4   Ú_print_UnionÚ  s    zLatexPrinter._print_Unionc                s   d  ‡ fdd„|jD ƒ¡S )Nz \setminus c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   Þ  s    z2LatexPrinter._print_Complement.<locals>.<listcomp>)rÊ   r‚   )r^   rÉ  r2   )r^   r4   Ú_print_ComplementÝ  s    zLatexPrinter._print_Complementc                s   d  ‡ fdd„|jD ƒ¡S )Nz \cap c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   á  s    z4LatexPrinter._print_Intersection.<locals>.<listcomp>)rÊ   r‚   )r^   rÉ  r2   )r^   r4   Ú_print_Intersectionà  s    z LatexPrinter._print_Intersectionc                s   d  ‡ fdd„|jD ƒ¡S )Nz \triangle c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   r   )r^   r2   r4   rz   ä  s    z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>)rÊ   r‚   )r^   rÉ  r2   )r^   r4   Ú_print_SymmetricDifferenceã  s    z'LatexPrinter._print_SymmetricDifferencec             C   s   dS )Nz	\emptysetr2   )r^   r†   r2   r2   r4   Ú_print_EmptySetæ  s    zLatexPrinter._print_EmptySetc             C   s   dS )Nz
\mathbb{N}r2   )r^   r1  r2   r2   r4   Ú_print_Naturalsé  s    zLatexPrinter._print_Naturalsc             C   s   dS )Nz\mathbb{N}_0r2   )r^   r1  r2   r2   r4   Ú_print_Naturals0ì  s    zLatexPrinter._print_Naturals0c             C   s   dS )Nz
\mathbb{Z}r2   )r^   r   r2   r2   r4   Ú_print_Integersï  s    zLatexPrinter._print_Integersc             C   s   dS )Nz
\mathbb{R}r2   )r^   r   r2   r2   r4   Ú_print_Realsò  s    zLatexPrinter._print_Realsc             C   s   dS )Nz
\mathbb{C}r2   )r^   r   r2   r2   r4   Ú_print_Complexesõ  s    zLatexPrinter._print_Complexesc                sF   |j dd … }‡ fdd„t|jj|ƒD ƒ}dˆ  |jj¡d |¡f S )Nr   c                s(   g | ] \}}d ˆ   |¡ˆ   |¡f ‘qS )z	%s \in %s)r`   )rx   ÚvarZsetv)r^   r2   r4   rz   ú  s   z0LatexPrinter._print_ImageSet.<locals>.<listcomp>z\left\{%s\; |\; %s\right\}z, )r‚   rã   r0   ri  r`   rf   rÊ   )r^   r3   r°  Zvarsetsr2   )r^   r4   Ú_print_ImageSetø  s    
zLatexPrinter._print_ImageSetc                sf   d  ‡ fdd„t|jƒD ƒ¡}|jtjkrBd|ˆ  |j ¡ ¡f S d||ˆ  |j¡ˆ  |j ¡ ¡f S )Nz, c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   rÔ  )r^   r2   r4   rz     s    z4LatexPrinter._print_ConditionSet.<locals>.<listcomp>z\left\{%s \mid %s \right\}z+\left\{%s \mid %s \in %s \wedge %s \right\})	rÊ   r   r7  Zbase_setr   ZUniversalSetr`   Z	conditionZas_expr)r^   r3   Ú
vars_printr2   )r^   r4   Ú_print_ConditionSet   s    
z LatexPrinter._print_ConditionSetc                s8   d  ‡ fdd„|jD ƒ¡}dˆ  |j¡|ˆ  |j¡f S )Nz, c                s   g | ]}ˆ   |¡‘qS r2   )r`   )rx   rÔ  )r^   r2   r4   rz     s    z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z"\left\{%s\; |\; %s \in %s \right\})rÊ   ri  r`   rf   r°  )r^   r3   rÖ  r2   )r^   r4   Ú_print_ComplexRegion  s
    
z!LatexPrinter._print_ComplexRegionc                s   dt ‡ fdd„|jD ƒƒ S )Nz	%s \in %sc             3   s   | ]}ˆ   |¡V  qd S )N)r`   )rx   r¼   )r^   r2   r4   rá     s    z/LatexPrinter._print_Contains.<locals>.<genexpr>)rÆ   r‚   )r^   r†   r2   )r^   r4   Ú_print_Contains  s    zLatexPrinter._print_Containsc             C   s   |   | ¡ ¡|  d¡ S )Nz	 + \ldots)r   Útruncater`   )r^   r3   r2   r2   r4   Ú_print_FourierSeries  s    z!LatexPrinter._print_FourierSeriesc             C   s   |   |j¡S )N)r   Zinfinite)r^   r3   r2   r2   r4   Ú_print_FormalPowerSeries  s    z%LatexPrinter._print_FormalPowerSeriesc             C   s
   d|j  S )Nz\mathbb{F}_{%s})Úmod)r^   rf   r2   r2   r4   Ú_print_FiniteField  s    zLatexPrinter._print_FiniteFieldc             C   s   dS )Nz
\mathbb{Z}r2   )r^   rf   r2   r2   r4   Ú_print_IntegerRing   s    zLatexPrinter._print_IntegerRingc             C   s   dS )Nz
\mathbb{Q}r2   )r^   rf   r2   r2   r4   Ú_print_RationalField#  s    z!LatexPrinter._print_RationalFieldc             C   s   dS )Nz
\mathbb{R}r2   )r^   rf   r2   r2   r4   Ú_print_RealField&  s    zLatexPrinter._print_RealFieldc             C   s   dS )Nz
\mathbb{C}r2   )r^   rf   r2   r2   r4   Ú_print_ComplexField)  s    z LatexPrinter._print_ComplexFieldc             C   s,   |   |j¡}d t| j |jƒ¡}d||f S )Nz, z%s\left[%s\right])r`   ÚdomainrÊ   rÚ   rí   )r^   rf   rã  rí   r2   r2   r4   Ú_print_PolynomialRing,  s    z"LatexPrinter._print_PolynomialRingc             C   s,   |   |j¡}d t| j |jƒ¡}d||f S )Nz, z%s\left(%s\right))r`   rã  rÊ   rÚ   rí   )r^   rf   rã  rí   r2   r2   r4   Ú_print_FractionField1  s    z!LatexPrinter._print_FractionFieldc             C   s<   |   |j¡}d t| j |jƒ¡}d}|js.d}d|||f S )Nz, rS   zS_<^{-1}z%s%s\left[%s\right])r`   rã  rÊ   rÚ   rí   Zis_Poly)r^   rf   rã  rí   Úinvr2   r2   r4   Ú_print_PolynomialRingBase6  s    z&LatexPrinter._print_PolynomialRingBasec             C   sÎ  |j j}g }x | ¡ D ]\}}d}xTt|ƒD ]H\}}|dkr0|dkr^||  |j| ¡7 }q0||  t|j| |ƒ¡7 }q0W |jr¢|r–d|  |¡ }	qä|  |¡}	nB|rÚ|tj	krÀ| 
d|g¡ q|tjkrÚ| 
d|g¡ q|  |¡}	|sî|	}
n|	d | }
|
 d¡r| 
d|
dd … g¡ q| 
d|
g¡ qW |d dkrb| d¡}|dkrbd|d  |d< d |¡}tt| j|jƒƒ}d	|  | ¡ ¡ }d
 |g| |g ¡}|tkr¾d||f }nd||f }|S )NrS   r   r   z\left(%s\right)r˜   rÐ   rO   )rÐ   r˜   z	domain=%sz, z\%s {\left (%s \right )}z$\operatorname{%s}{\left( %s \right)})Ú	__class__rù   rŒ   r‹   r`   ÚgensÚpowro   r   r¸   rŒ  ri   rÂ   r  rÊ   rŠ   rÚ   Z
get_domainrõ   )r^   Úpolyr  rŒ   Zmonomr¿  Zs_monomr   r„   Zs_coeffZs_termZmodifierrf   ré  rã  r‚   rg   r2   r2   r4   Ú_print_Poly>  sN    






zLatexPrinter._print_Polyc             C   sN   |j j}|dkrd}|  |j¡}|j}|tkr<d|||f S d|||f S d S )NZComplexRootOfZCRootOfz\%s {\left(%s, %d\right)}z'\operatorname{%s} {\left(%s, %d\right)})rè  rù   r`   rf   Úindexrõ   )r^   r   r  rf   rí  r2   r2   r4   Ú_print_ComplexRootOfw  s    z!LatexPrinter._print_ComplexRootOfc             C   sd   |j j}|  |j¡g}|jtjk	r4| |  |j¡¡ |tkrNd|d 	|¡f S d|d 	|¡f S d S )Nz\%s {\left(%s\right)}z, z#\operatorname{%s} {\left(%s\right)})
rè  rù   r`   rf   Zfunr   ZIdentityFunctionrÕ   rõ   rÊ   )r^   rf   r  r‚   r2   r2   r4   Ú_print_RootSum‚  s    zLatexPrinter._print_RootSumc             C   s   | j d }| | td|¡S )NrQ   z	{%s}^{%d})rY   r•   r   )r^   rë  rG   r2   r2   r4   Ú_print_PolyElementŽ  s    
zLatexPrinter._print_PolyElementc             C   s>   |j dkr|  |j¡S |  |j¡}|  |j ¡}d||f S d S )Nr   z\frac{%s}{%s})r»   r`   rº   )r^   r   rº   r»   r2   r2   r4   Ú_print_FracElement’  s
    
zLatexPrinter._print_FracElementc             C   sl   t |jƒdkr|jd d fn|j\}}d|  |¡ }|d k	rNd||  |¡f }|d k	rhd||  |¡f }|S )Nr   r   zE_{%s}z%s^{%s}z%s\left(%s\right))r°   r‚   r`   )r^   rf   r„   rb  ry   rg   r2   r2   r4   Ú_print_eulerš  s    &zLatexPrinter._print_eulerc             C   s2   d|   |jd ¡ }|d k	r.d||   |¡f }|S )NzC_{%s}r   z%s^{%s})r`   r‚   )r^   rf   r„   rg   r2   r2   r4   Ú_print_catalan£  s    zLatexPrinter._print_catalanc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz.\mathcal{M}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_MellinTransform©  s    z#LatexPrinter._print_MellinTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz3\mathcal{M}^{-1}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_InverseMellinTransform¬  s    z*LatexPrinter._print_InverseMellinTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz.\mathcal{L}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_LaplaceTransform¯  s    z$LatexPrinter._print_LaplaceTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz3\mathcal{L}^{-1}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_InverseLaplaceTransform²  s    z+LatexPrinter._print_InverseLaplaceTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz.\mathcal{F}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_FourierTransformµ  s    z$LatexPrinter._print_FourierTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz3\mathcal{F}^{-1}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_InverseFourierTransform¸  s    z+LatexPrinter._print_InverseFourierTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz0\mathcal{SIN}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_SineTransform»  s    z!LatexPrinter._print_SineTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz5\mathcal{SIN}^{-1}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_InverseSineTransform¾  s    z(LatexPrinter._print_InverseSineTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz0\mathcal{COS}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_CosineTransformÁ  s    z#LatexPrinter._print_CosineTransformc             C   s2   d|   |jd ¡|   |jd ¡|   |jd ¡f S )Nz5\mathcal{COS}^{-1}_{%s}\left[%s\right]\left(%s\right)r   r   r¶   )r`   r‚   )r^   rf   r2   r2   r4   Ú_print_InverseCosineTransformÄ  s    z*LatexPrinter._print_InverseCosineTransformc             C   sD   y |j d k	r|  |j  |¡¡S W n tk
r4   Y nX |  t|ƒ¡S )N)Úringr`   Zto_sympyr   Úrepr)r^   rÀ   r2   r2   r4   Ú
_print_DMPÇ  s    
zLatexPrinter._print_DMPc             C   s
   |   |¡S )N)r   )r^   rÀ   r2   r2   r4   Ú
_print_DMFÐ  s    zLatexPrinter._print_DMFc             C   s   |   t|jƒ¡S )N)r`   r   rö   )r^   Úobjectr2   r2   r4   Ú_print_ObjectÓ  s    zLatexPrinter._print_Objectc             C   s$   |   |j¡}|   |j¡}d||f S )Nz%s\rightarrow %s)r`   rã  Úcodomain)r^   Úmorphismrã  r  r2   r2   r4   Ú_print_MorphismÖ  s    zLatexPrinter._print_Morphismc             C   s&   |   t|jƒ¡}|  |¡}d||f S )Nz%s:%s)r`   r   rö   r  )r^   r  Zpretty_nameÚpretty_morphismr2   r2   r4   Ú_print_NamedMorphismÛ  s    
z!LatexPrinter._print_NamedMorphismc             C   s"   ddl m} |  ||j|jdƒ¡S )Nr   )ÚNamedMorphismÚid)Zsympy.categoriesr	  r  rã  r  )r^   r  r	  r2   r2   r4   Ú_print_IdentityMorphismà  s    z$LatexPrinter._print_IdentityMorphismc                s<   ‡ fdd„|j D ƒ}| ¡  d |¡d }ˆ  |¡}|| S )Nc                s   g | ]}ˆ   t|jƒ¡‘qS r2   )r`   r   rö   )rx   Z	component)r^   r2   r4   rz   è  s   z9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z\circ r‚  )rÓ   ÚreverserÊ   r  )r^   r  Zcomponent_names_listZcomponent_namesr  r2   )r^   r4   Ú_print_CompositeMorphismå  s    


z%LatexPrinter._print_CompositeMorphismc             C   s   d|   t|jƒ¡ S )Nz\mathbf{%s})r`   r   rö   )r^   r  r2   r2   r4   Ú_print_Categoryð  s    zLatexPrinter._print_Categoryc             C   s<   |j s|  tj¡S |  |j ¡}|jr8|d|  |j¡ 7 }|S )Nz\Longrightarrow %s)Zpremisesr`   r   ZEmptySetZconclusions)r^   ZdiagramÚlatex_resultr2   r2   r4   Ú_print_Diagramó  s    zLatexPrinter._print_Diagramc             C   sž   dd|j   }x‚t|jƒD ]t}xPt|j ƒD ]B}|||f rN|t|||f ƒ7 }|d7 }||j d kr*|d7 }q*W ||jd kr†|d7 }|d7 }qW |d7 }|S )	Nz\begin{array}{%s}
rt  rO   r   z& z\\Ú
z\end{array}
)Úwidthr   ZheightÚlatex)r^   Zgridr  r   rB  r2   r2   r4   Ú_print_DiagramGridÿ  s    zLatexPrinter._print_DiagramGridc             C   s   d|   |j¡|   |j¡f S )Nz	{%s}^{%s})r`   rþ  rš  )r^   r(   r2   r2   r4   Ú_print_FreeModule  s    zLatexPrinter._print_FreeModulec                s   dd  ‡ fdd„|D ƒ¡ S )Nz\left[ %s \right]r“   c             3   s    | ]}d ˆ   |¡ d V  qdS )r6   r1   N)r`   )rx   ry   )r^   r2   r4   rá     s    z8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>)rÊ   )r^   rb  r2   )r^   r4   Ú_print_FreeModuleElement  s    z%LatexPrinter._print_FreeModuleElementc                s   dd  ‡ fdd„|jD ƒ¡ S )Nz\left< %s \right>r“   c             3   s    | ]}d ˆ   |¡ d V  qdS )r6   r1   N)r`   )rx   ry   )r^   r2   r4   rá     s    z0LatexPrinter._print_SubModule.<locals>.<genexpr>)rÊ   ré  )r^   rb  r2   )r^   r4   Ú_print_SubModule  s    zLatexPrinter._print_SubModulec                s    dd  ‡ fdd„|jjD ƒ¡ S )Nz\left< %s \right>r“   c             3   s"   | ]\}d ˆ   |¡ d V  qdS )r6   r1   N)r`   )rx   ry   )r^   r2   r4   rá     s    z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>)rÊ   Ú_moduleré  )r^   rb  r2   )r^   r4   Ú_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 )rv   T)rc   )rd   r   )rx   r   )r^   r2   r4   rz   $  s    z2LatexPrinter._print_Quaternion.<locals>.<listcomp>r   c             S   s   g | ]\}}|d  | ‘qS )rO   r2   )rx   r   rB  r2   r2   r4   rz   %  s    r   Zijkz + )r‚   rã   rÊ   )r^   rf   r3   r¼   r2   )r^   r4   Ú_print_Quaternion!  s    &zLatexPrinter._print_Quaternionc             C   s   d|   |j¡|   |j¡f S )Nz\frac{%s}{%s})r`   rþ  Ú
base_ideal)r^   ÚRr2   r2   r4   Ú_print_QuotientRing(  s    z LatexPrinter._print_QuotientRingc             C   s   d|   |j¡|   |jj¡f S )Nz{%s} + {%s})r`   Údatarþ  r  )r^   ry   r2   r2   r4   Ú_print_QuotientRingElement,  s    z'LatexPrinter._print_QuotientRingElementc             C   s   d|   |j¡|   |jj¡f S )Nz{%s} + {%s})r`   r  ÚmoduleÚkilled_module)r^   rb  r2   r2   r4   Ú_print_QuotientModuleElement/  s    z)LatexPrinter._print_QuotientModuleElementc             C   s   d|   |j¡|   |j¡f S )Nz\frac{%s}{%s})r`   rƒ   r!  )r^   r(   r2   r2   r4   Ú_print_QuotientModule3  s    z"LatexPrinter._print_QuotientModulec             C   s(   d|   | ¡ ¡|   |j¡|   |j¡f S )Nz{%s} : {%s} \to {%s})r`   Z_sympy_matrixrã  r  )r^   Úhr2   r2   r4   Ú_print_MatrixHomomorphism8  s    z&LatexPrinter._print_MatrixHomomorphismc             C   s    |j j|j }d|  t|ƒ¡ S )Nz\boldsymbol{\mathrm{%s}})Ú
_coord_sysÚ_namesÚ_indexr`   r   )r^   Úfieldrm  r2   r2   r4   Ú_print_BaseScalarField<  s    z#LatexPrinter._print_BaseScalarFieldc             C   s    |j j|j }d|  t|ƒ¡ S )Nz\partial_{%s})r&  r'  r(  r`   r   )r^   r)  rm  r2   r2   r4   Ú_print_BaseVectorField@  s    z#LatexPrinter._print_BaseVectorFieldc             C   sB   |j }t|dƒr0|jj|j }d|  t|ƒ¡ S d|  |¡ S d S )Nr&  z\mathrm{d}%szd(%s)z\mathrm{d}\left(%s\right))Z_form_fieldrú   r&  r'  r(  r`   r   )r^   Zdiffr)  rm  r2   r2   r4   Ú_print_DifferentialD  s    
 z LatexPrinter._print_Differentialc             C   s   |   |jd ¡}d| S )Nr   z\mbox{Tr}\left(%s\right))r`   r‚   )r^   rÀ   Úcontentsr2   r2   r4   Ú	_print_TrN  s    zLatexPrinter._print_Trc             C   s:   |d k	r&d|   |jd ¡|   |¡f S d|   |jd ¡ S )Nz%\left(\phi\left(%s\right)\right)^{%s}r   z\phi\left(%s\right))r`   r‚   )r^   rf   r„   r2   r2   r4   Ú_print_totientS  s    zLatexPrinter._print_totientc             C   s:   |d k	r&d|   |jd ¡|   |¡f S d|   |jd ¡ S )Nz(\left(\lambda\left(%s\right)\right)^{%s}r   z\lambda\left(%s\right))r`   r‚   )r^   rf   r„   r2   r2   r4   Ú_print_reduced_totientY  s    z#LatexPrinter._print_reduced_totientc             C   sj   t |jƒdkr4dtt| j|jd |jd fƒƒ }nd|  |jd ¡ }|d k	rbd|  |¡|f S d| S )Nr¶   z_%s\left(%s\right)r   r   z\left(%s\right)z\sigma^{%s}%sz\sigma%s)r°   r‚   rÆ   rÚ   r`   )r^   rf   r„   rg   r2   r2   r4   Ú_print_divisor_sigma_  s    
z!LatexPrinter._print_divisor_sigmac             C   sj   t |jƒdkr4dtt| j|jd |jd fƒƒ }nd|  |jd ¡ }|d k	rbd|  |¡|f S d| S )Nr¶   z_%s\left(%s\right)r   r   z\left(%s\right)z\sigma^*^{%s}%sz
\sigma^*%s)r°   r‚   rÆ   rÚ   r`   )r^   rf   r„   rg   r2   r2   r4   Ú_print_udivisor_sigmai  s    
z"LatexPrinter._print_udivisor_sigmac             C   s:   |d k	r&d|   |jd ¡|   |¡f S d|   |jd ¡ S )Nz$\left(\nu\left(%s\right)\right)^{%s}r   z\nu\left(%s\right))r`   r‚   )r^   rf   r„   r2   r2   r4   Ú_print_primenus  s    zLatexPrinter._print_primenuc             C   s:   |d k	r&d|   |jd ¡|   |¡f S d|   |jd ¡ S )Nz'\left(\Omega\left(%s\right)\right)^{%s}r   z\Omega\left(%s\right))r`   r‚   )r^   rf   r„   r2   r2   r4   Ú_print_primeomegay  s    zLatexPrinter._print_primeomega)N)F)FF)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)NrS   )NrS   )N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)örù   Ú
__module__Ú__qualname__ZprintmethodZ_default_settingsrX   rd   re   rk   rq   r€   r   rm   rn   r…   r‡   Z_print_BooleanTrueZ_print_BooleanFalserˆ   r   r—   Z_print_Permutationrœ   r¡   r£   r¤   r¥   r§   r¾   rÄ   rÅ   rÌ   rÍ   rÙ   rÜ   rÝ   rà   ræ   rî   ró   r÷   rü   rý   Úpropertyr  r  r  r	  Z
_print_MinZ
_print_Maxr
  r  r  r  Z_print_Determinantr  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r#  r$  r%  r&  r'  r(  Z_print_gammar)  r*  r+  r,  r-  r.  r/  r0  r2  r4  r8  r9  r;  r<  r=  r?  rA  rC  rD  rE  rF  rG  rI  rJ  rL  rN  rO  rP  rS  rT  rU  rV  rW  rX  rY  rZ  r[  r\  r]  r^  r_  r`  ra  re  rf  rh  rj  rk  Z_print_RandomSymbolZ_print_MatrixSymbolrô   rs  ru  r  Z_print_ImmutableMatrixZ_print_ImmutableDenseMatrixZ_print_Matrixr  r„  r…  r‰  rŠ  rŽ  r“  r”  r•  r–  r—  r˜  r™  rž  Z_print_ImmutableDenseNDimArrayZ_print_ImmutableSparseNDimArrayZ_print_MutableDenseNDimArrayZ_print_MutableSparseNDimArrayrŸ  r¡  r¢  r£  r¤  r§  r¨  r©  r«  r¬  r­  r®  r±  r³  rµ  r´  Z_print_frozensetr¾  rÁ  Z_print_SeqPerZ_print_SeqAddZ_print_SeqMulrÅ  rÈ  rÊ  rË  rÌ  rÍ  rÎ  rÏ  rÐ  rÑ  rÒ  rÓ  rÕ  r×  rØ  rÙ  rÛ  rÜ  rÞ  rß  rà  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/  r0  r1  r2  r3  r4  r2   r2   r2   r4   r<   y   sö  (
d4	 E									
		1


9		


r<   c             C   sž   t  | ¡}|r|S |  ¡ tkr*d|  ¡  S | tkr:d|  S xZtt ¡ dd„ ddD ]@}|  ¡  |¡rRt	| ƒt	|ƒkrRt| t
| dt	|ƒ … ƒƒS qRW | S dS )aŽ  
    Check for a modifier ending the string.  If present, convert the
    modifier to latex and translate the rest recursively.

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

    Let everything else pass as given.

    >>> from sympy.printing.latex import translate
    >>> translate('alphahatdotprime')
    "{\\dot{\\hat{\\alpha}}}'"
    rT   c             S   s   t | ƒS )N)r°   )r×   r2   r2   r4   r5   ˜  s    ztranslate.<locals>.<lambda>T)r®   r  N)Útex_greek_dictionaryÚgetr  Úgreek_letters_setÚother_symbolsr¯   Úmodifier_dictr¥  rÃ   r°   rl  )r3   rg   r®   r2   r2   r4   rl  €  s    
"rl  Fr>   r?   r=   c             C   s:   |dkri }|||||||||	|
|||dœ}t |ƒ | ¡S )aO  Convert the given expression to LaTeX string representation.

    Parameters
    ==========
    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.

    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 list, tuple, and
    dictionary.

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

    N)rC   rD   rE   rH   rB   rL   rF   rJ   rI   rA   rG   r@   rK   )r<   re   )rf   rC   rD   rE   rH   rB   rL   rF   rJ   rI   rA   rG   r@   rK   r_   r2   r2   r4   r  ž  s"     %r  c             K   s   t t| f|Žƒ dS )z`Prints LaTeX representation of the given expression. Takes the same
    settings as ``latex()``.N)Úprintr  )rf   r_   r2   r2   r4   Úprint_latexX	  s    r>  )FFNr>   FFNr?   Nr=   NNN)9Ú__doc__Z
__future__r   r   rœ  Z
sympy.corer   r   r   r   Zsympy.core.sympifyr   Zsympy.core.alphabetsr	   Zsympy.core.operationsr
   Zsympy.core.containersr   Zsympy.logic.boolalgr   Zsympy.core.functionr   r   r   r   Zsympy.printing.precedencer   Zprinterr   Zconventionsr   r   r   r   Zmpmath.libmpZlibmpr™   r   Zsympy.core.compatibilityr   r   Zsympy.utilities.iterablesr   r   rõ   r8  r¯  r;  r<  Ú	frozensetr:  Úcompiler±   r<   rl  r  r>  r2   r2   r2   r4   Ú<module>   sÞ                       
 7