o
     ôjã ã                	   @  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r£d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_„ “d€d_„ d�d_„ d‚d_„ dƒd_„ d„d_„ d…d_„ d†d_„ d‡œ¥Z>dˆe?d‰< e@eƒZAe6 BdŠ¡e6 Bd‹¡fZCdžd�d�„ZDG d‘d’„ d’e(ƒZEdžd“d”„ZFe)eEƒd•d–„ ƒZGd—d˜„ ZHdŸdœd�„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ú\GammaZDeltaz\DeltaZEpsilonz
\mathrm{E}ZZetaz
\mathrm{Z}ZEtaz
\mathrm{H}ZThetaz\ThetaZIotaz
\mathrm{I}ZKappaz
\mathrm{K}ÚLambdaz\LambdaZMuz
\mathrm{M}ZNuz
\mathrm{N}ZXiz\XiÚomicronÚoZOmicronz
\mathrm{O}ÚPiz\PiZRhoz
\mathrm{P}ZSigmaz\SigmaZTauz
\mathrm{T}ZUpsilonz\UpsilonÚPhiz\PhiÚChiz
\mathrm{X}ZPsiz\PsiÚOmegaz\OmegaÚlamdaz\lambdaZLamdaZkhiz\chiZKhiZ
varepsilonz\varepsilonZvarkappaz	\varkappaZvarphiz\varphiZvarpiz\varpiZvarrhoz\varrhoz	\varsigmaz	\vartheta)ÚvarsigmaZvartheta>
   ÚwpZmhoZethÚellZgimelZbethZalephZhslashZhbarZdalethÚmathringc                 C  ó   d|  d S )Nz
\mathring{Ú}© ©ÚsrN   rN   úg/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/sympy/printing/latex.pyÚ<lambda>[   ó    rR   Úddddotc                 C  rL   )Nz\ddddot{rM   rN   rO   rN   rN   rQ   rR   \   rS   Údddotc                 C  rL   )Nz\dddot{rM   rN   rO   rN   rN   rQ   rR   ]   rS   Úddotc                 C  rL   )Nz\ddot{rM   rN   rO   rN   rN   rQ   rR   ^   rS   Údotc                 C  rL   )Nz\dot{rM   rN   rO   rN   rN   rQ   rR   _   rS   Úcheckc                 C  rL   )Nz\check{rM   rN   rO   rN   rN   rQ   rR   `   rS   Úbrevec                 C  rL   )Nz\breve{rM   rN   rO   rN   rN   rQ   rR   a   rS   Úacutec                 C  rL   )Nz\acute{rM   rN   rO   rN   rN   rQ   rR   b   rS   Úgravec                 C  rL   )Nz\grave{rM   rN   rO   rN   rN   rQ   rR   c   rS   Útildec                 C  rL   )Nz\tilde{rM   rN   rO   rN   rN   rQ   rR   d   rS   Úhatc                 C  rL   )Nz\hat{rM   rN   rO   rN   rN   rQ   rR   e   rS   Úbarc                 C  rL   )Nz\bar{rM   rN   rO   rN   rN   rQ   rR   f   rS   Úvecc                 C  rL   )Nz\vec{rM   rN   rO   rN   rN   rQ   rR   g   rS   Úprimec                 C  rL   ©NÚ{z}'rN   rO   rN   rN   rQ   rR   h   rS   Úprmc                 C  rL   ra   rN   rO   rN   rN   rQ   rR   i   rS   Úboldc                 C  rL   ©Nz\boldsymbol{rM   rN   rO   rN   rN   rQ   rR   k   rS   Úbmc                 C  rL   re   rN   rO   rN   rN   rQ   rR   l   rS   c                 C  rL   )Nz	\mathcal{rM   rN   rO   rN   rN   rQ   rR   m   rS   c                 C  rL   )Nz	\mathscr{rM   rN   rO   rN   rN   rQ   rR   n   rS   c                 C  rL   )Nz
\mathfrak{rM   rN   rO   rN   rN   rQ   rR   o   rS   c                 C  rL   )Nz\left\|{z	}\right\|rN   rO   rN   rN   rQ   rR   q   rS   c                 C  rL   )Nz\left\langle{z}\right\ranglerN   rO   rN   rN   rQ   rR   r   rS   c                 C  rL   ©Nz\left|{z}\right|rN   rO   rN   rN   rQ   rR   s   rS   c                 C  rL   rg   rN   rO   rN   rN   rQ   rR   t   rS   )ÚcalZscrZfrakÚnormÚavgÚabsÚmagzdict[str, Callable[[str], str]]Úmodifier_dictz[0-9][} ]*$z(\d|\\frac{\d+}{\d+})rP   Ú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)rP   ÚcrN   rN   rQ   Úlatex_escape   s   ru   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dœ	¥Zded< �d–d d!„Z�d—d$d%„Z�d—d&d'„Z�d˜�d—d(d)„Z	d*d+„ Z
�d—d,d-„Z�d™d/d0„Z�d™d1d2„Z�d˜�d™d3d4„Z�d™d5d6„Z�d™d7d8„Z�d™d9d:„Z�dšd<d=„Zd>d?„ Z�d›dBdC„ZeZeZdDdE„ Z�d–dFdG„ZdHdI„ ZdJdK„ ZdLdM„ ZdNdO„ ZdPdQ„ ZdRdS„ ZdTdU„ ZdVdW„ Z dXdY„ Z!dZd[„ Z"�dœd]d^„Z#d_d`„ Z$dadb„ Z%�d�ddde„Z&�dždgdh„Z'didj„ Z(dkdl„ Z)dmdn„ Z*�dŸdpdq„Z+drds„ Z,dtdu„ Z-dvdw„ Z.dxdy„ Z/dzd{„ Z0d|d}„ Z1d~d„ Z2�d d�d‚„Z3�d–�d¡d„d…„Z4d†d‡„ Z5dˆd‰„ Z6e7dŠd‹„ ƒZ8dŒd�„ Z9dŽd�„ Z:d�d‘„ Z;�d–�d—d’d“„Z<e< Z=Z>�d–d”d•„Z?�d–d–d—„Z@�d–d˜d™„ZA�d–dšd›„ZB�d–dœd�„ZC�d–dždŸ„ZDd d¡„ ZEd¢d£„ ZFd¤d¥„ ZGd¦d§„ ZHd¨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È„ZX�d–�d—dÉdÊ„ZYeYZZ�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ùdú„Zq�d¤�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„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„Z�e�Z‘�d¨�d<�d=„Z’�d¦�d©�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[�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ª�dª�dp�dq„Z«�d«�dt�du„Z¬�dv�dw„ Z­�dx�dy„ Z®�dz�d{„ Z¯�d|�d}„ Z°�d~�d„ Z±�d€�d�„ Z²�d‚�dƒ„ Z³�d„�d…„ Z´�d†�d‡„ Zµ�d–�dˆ�d‰„Z¶�dŠ�d‹„ 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§„ ZÅeÅ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–�d¶�d·„ZÎ�d–�d¸�d¹„ZÏ�dº�d»„ 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Ë„ 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�d0�d1„ �Z�d2�d3„ �Z�d4�d5„ �Z�d6�d7„ �Z�d8�d9„ �Z�d:�d;„ �Z�d<�d=„ �Z�d>�d?„ �Z�d@�dA„ �Z�dB�dC„ �Z�e�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.�dp�dq„ �Z/�dr�ds„ �Z0�dt�du„ �Z1�d–�dv�dw„�Z2�d–�dx�dy„�Z3�d–�dz�d{„�Z4�d–�d|�d}„�Z5�d–�d~�d„�Z6�d–�d€�d�„�Z7�d‚�dƒ„ �Z8�d„�d…„ �Z9�d†�d‡„ �Z:�dˆ�d‰„ �Z;�dŠ�d‹„ �Z<�dŒ�d�„ �Z=�dŽ�d�„ �Z>�d��d‘„ �Z?�d’�d“„ �Z@‡ f�d”�d•„�ZA‡  �ZBS (­  Ú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_styleÚdisable_split_super_subz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 \,.\, ú \cdot ú \times )NZldotrW   Útimesr†   Úmul_symbol_latexrW   Úmul_symbol_latex_numbers)Ú rœ   rp   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_modesZmul_symbol_tableZimaginary_unit_tableÚ	imag_unitZdiff_operator_tabler–   rN   rN   rQ   r°   ®   sf   

üÿÿÿÿÿ
ÿÿ€ú	ù
	ü
zLatexPrinter.__init__ro   rn   c                 C  ó
   d  |¡S )Nz\left({}\right)©Úformat©r·   rP   rN   rN   rQ   Ú_add_parensë   ó   
zLatexPrinter._add_parensc                 C  r»   )Nz\left( {}\right)r¼   r¾   rN   rN   rQ   Ú_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ÚstrictZprec_valrN   rN   rQ   Ú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.
        rr   r“   z{{{}}})r±   r¿   r½   r¾   rN   rN   rQ   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ÚtexZenv_strrN   rN   rQ   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Ê   rN   rN   rQ   Ú_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Ò   rN   rN   rQ   Ú_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Ê   rN   rQ   Ú	<genexpr>O  ó   € z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>c                 3  rÞ   rÂ   rß   rá   rä   rN   rQ   rå   R  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Ý   rN   rä   rQ   Ú_needs_mul_brackets8  s(   
€ÿz LatexPrinter._needs_mul_bracketsc                   s4   ˆ j rdS t‡ fdd„tfD ƒƒrdS ˆ j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ä   rN   rQ   rå   _  ræ   z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>F)rë   rí   r   rØ   rÒ   rN   rä   rQ   Ú_needs_add_bracketsW  s   z LatexPrinter._needs_add_bracketsc                 C  s   |j D ]}|jr dS qdS )NFT)ÚargsrÙ   )r·   rÊ   r;   rN   rN   rQ   rÕ   e  s
   
ÿzLatexPrinter._mul_is_cleanc                 C  s   |   |j¡ S rÂ   )rÓ   ÚbaserÒ   rN   rN   rQ   r×   k  ó   zLatexPrinter._pow_is_cleanrÊ   c                 C  s   |d ur
d||f S |S )Nú\left(%s\right)^{%s}rN   ©r·   rÊ   ÚexprN   rN   rQ   Ú_do_exponentn  s   zLatexPrinter._do_exponentc                   sH   ˆ   |jj¡}|jr‡ fdd„|jD ƒ}d}| |d |¡¡S d |¡S )Nc                   ó   g | ]}ˆ   |¡‘qS rN   ©rÃ   )râ   rB   ©r·   rN   rQ   Ú
<listcomp>w  ó    z-LatexPrinter._print_Basic.<locals>.<listcomp>z"\operatorname{{{}}}\left({}\right)ú, z\text{{{}}})Ú_deal_with_super_subÚ	__class__Ú__name__rò   r½   Újoin)r·   rÊ   ÚnameÚlsrP   rN   rû   rQ   Ú_print_Basict  s   
zLatexPrinter._print_BasicÚeú!bool | BooleanTrue | BooleanFalsec                 C  ó   d| S ©Nú	\text{%s}rN   ©r·   r  rN   rN   rQ   Ú_print_bool}  ó   zLatexPrinter._print_boolc                 C  r  r	  rN   r  rN   rN   rQ   Ú_print_NoneTypeƒ  r  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_texrN   rN   rQ   Ú
_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_formrn   rs   )r·   rÊ   r  Z	expr_permÚsizr  rŒ   rN   rN   rQ   Ú_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’   Tr  c                   rù   rN   rú   ©râ   r;   rû   rN   rQ   rü   Á  rý   z3LatexPrinter._print_Permutation.<locals>.<listcomp>c                   rù   rN   rú   r*  rû   rN   rQ   rü   Â  rý   ú & z \\ z \begin{pmatrix} %s \end{pmatrix})r  r  Úsympy.utilities.exceptionsr%  Úprint_cyclicr±   r¶   r$  r   r"  ÚrangeÚlenr  )
r·   rÊ   r  r%  r’   ÚlowerÚupperZrow1Úrow2ÚmatrN   rû   rQ   Ú_print_Permutation©  s.   þù




zLatexPrinter._print_Permutationc                 C  s"   |j \}}d|  |¡|  |¡f S )Nz\sigma_{%s}(%s))rò   rÃ   )r·   rÊ   ÚpermÚvarrN   rN   rQ   Ú_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 )Nrx   FTr”   r•   )Ústrip_zerosÚ	min_fixedÚ	max_fixedr¡   r  r   ú+r  r‘   ÚcommaÚ.z{,}z%s%s10^{%s}z+infz\inftyz-infz- \infty)r!   Ú_precr±   Úmlib_to_strÚ_mpf_Úsplitrs   )
r·   rÊ   Údpsr´   ÚlowÚhighZstr_realÚ	separatorZmantr÷   rN   rN   rQ   Ú_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Úvec2rN   rN   rQ   Ú_print_Crossì  ó
   ÿzLatexPrinter._print_Crossc                 C  ó   |j }d|  |td ¡ S )Nz\nabla\times %sr	   ©Ú_exprrÈ   r    ©r·   rÊ   r_   rN   rN   rQ   Ú_print_Curlò  ó   zLatexPrinter._print_Curlc                 C  rP  )Nz\nabla\cdot %sr	   rQ  rS  rN   rN   rQ   Ú_print_Divergenceö  rU  zLatexPrinter._print_Divergencec                 C  rG  )Nz%s \cdot %sr	   rH  rK  rN   rN   rQ   Ú
_print_Dotú  rO  zLatexPrinter._print_Dotc                 C  rP  )Nz	\nabla %sr	   rQ  ©r·   rÊ   ÚfuncrN   rN   rQ   Ú_print_Gradient   rU  zLatexPrinter._print_Gradientc                 C  rP  )Nz	\Delta %sr	   rQ  rX  rN   rN   rQ   Ú_print_Laplacian  rU  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r¯d|
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¡   ro   rn   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ã   rN   rN   rQ   rR     s    
z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>T)Úbinaryc                 S  s
   t | dƒS )Nr_  )ra  rc  rN   rN   rQ   rR     s   
 )rÔ   rn   rÃ   r‡   Úas_ordered_factorsÚlistrò   r$   )rÊ   rò   ÚunitsZnonunitsÚprefixes)Úconvert_argsr·   rN   rQ   Ú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   r  )rî   rï   r  )r  rÃ   ra  rð   r/  Ú_between_two_numbers_pÚsearchÚmatch)rò   Z_texZlast_term_texrŒ   r  r  )Ú	numbersepr·   rE  rN   rQ   ri    s(   
ÿÿ
€z-LatexPrinter._print_Mul.<locals>.convert_argsc                 s  s   � | ]}t |tƒV  qd S rÂ   )rb  r
   r*  rN   rN   rQ   rå   ;  ræ   z*LatexPrinter._print_Mul.<locals>.<genexpr>r  Fú- r¦   Tr¢   )Úexactr  )Úevaluater€   r{   é   rr   )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¤   ©ro   rn   )Zsympy.simplifyr\  r±   rb  r	   rò   r   ÚOnerí   rê   rØ   r   r/  rA  rð   rÔ   Úis_commutative)r·   rÊ   r\  rj  rò   Zinclude_parensrË   ÚnumerÚdenomZsnumerZsdenomZldenomÚratioÚaÚbrã   rN   )ri  rn  r·   rE  rQ   Ú
_print_Mul  sr   


(€

ÿ
 

ÿÿzLatexPrinter._print_Mulc                 C  s&   |j r|  | ¡  ¡ ¡S |  | ¡ ¡S rÂ   )Ú
is_aliasedrÃ   Úas_polyÚas_exprrÒ   rN   rN   rQ   Ú_print_AlgebraicNumber{  s   z#LatexPrinter._print_AlgebraicNumberc                 C  s@   |   |j¡}|jrd|› d�S |   |j ¡ ¡}d|› d|› d�S )Nú\left(r  rþ   )rÃ   ÚpZis_inertÚalphar  )r·   rÊ   r‚  rƒ  rN   rN   rQ   Ú_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r�d|j|j f S |jjr¶|jj}|jj}|| t|ƒkr¶|j dkr¬d||f S d||t|j ƒf S |  |¡S |jjrË| j|j|  |j ¡d�S d}|  ||¡S )Nr  r‰   rr  z	\sqrt{%s}r~   z\root{%d}{%s}z\sqrt[%d]{%s}z\frac{1}{%s}ry   r   z%s/%s©r÷   z
%s^{%s/%s}ú%s^{%s}r  z\frac{1}{\frac{%s}{%s}}z\frac{1}{(\frac{%s}{%s})^{%s}})r÷   rÑ   r‚  Úqrk   r±   rÃ   ró   Úis_negativerÈ   r    Ú	is_Symbolr“   rÙ   rv  r|  Ú_helper_print_standard_power)r·   rÊ   r‚  r‡  ró   rË   Zbase_pZbase_qrN   rN   rQ   Ú
_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?dotr  é   iùÿÿÿ)rÃ   r÷   rÈ   ró   r    r‰  r“   Úis_Floatrb  r   Ú
startswithr7   rm  Úendswith)r·   rÊ   rŒ  r÷   ró   rN   rN   rQ   rŠ  µ  s   
ÿ
þýz)LatexPrinter._helper_print_standard_powerc                 C  s   |   |jd ¡S ©Nr   ©rÃ   rò   rÒ   rN   rN   rQ   Ú_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 )Nr  z\sum_{%s=%s}^{%s} c                   rù   rN   rú   ©râ   rŒ   rû   rN   rQ   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ù   rN   rú   ©râ   rP   rû   rN   rQ   rü   Ð  rý   zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>r  r   rr  ©Útuple©Úlrû   rN   rQ   Ú_format_ineqÎ  ó   &ÿz-LatexPrinter._print_Sum.<locals>._format_ineqz\sum_{\substack{%s}} ú\\c                   ó   g | ]}ˆ |ƒ‘qS rN   rN   ©râ   r�  ©rž  rN   rQ   rü   Ó  ó    r  ©	r/  Úlimitsr›  rn   r  rb  Úfunctionr   rÃ   ©r·   rÊ   rË   rN   ©rž  r·   rQ   Ú
_print_SumÉ  ó   ÿÿþzLatexPrinter._print_Sumc                   r•  )Nr  z\prod_{%s=%s}^{%s} c                   rù   rN   rú   r–  rû   rN   rQ   rü   ß  rý   z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                   r—  )Nr˜  c                   rù   rN   rú   r™  rû   rN   rQ   rü   ã  rý   zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>r  r   rr  rš  rœ  rû   rN   rQ   rž  á  rŸ  z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} r   c                   r¡  rN   rN   r¢  r£  rN   rQ   rü   æ  r¤  r  r¥  r¨  rN   r©  rQ   Ú_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__rc  rN   rN   rQ   rR   ü  rS   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>©Úkeyr  r  r  r  r�  r  r¢   ú-é   )Úsympy.vectorr®  ÚzeroZ_latex_formrb  ÚseparateÚitemsrf  Ú
componentsÚsortÚappendrÃ   r  )r·   rÊ   r®  Úo1r·  ÚsystemÚvectÚ
inneritemsÚkÚvÚarg_strZoutstrrN   rN   rQ   Ú_print_BasisDependentï  s0   


ù
	ÿz"LatexPrinter._print_BasisDependentc                 C  s4   |   |j¡}d| d dd t| j |jƒ¡  }|S )Nrb   rM   ú_{%s}r  )rÃ   ró   r  ÚmapÚindices)r·   rÊ   Ztex_baserË   rN   rN   rQ   Ú_print_Indexed  s
   ÿzLatexPrinter._print_Indexedc                 C  ó   |   |j¡S rÂ   )rÃ   ÚlabelrÒ   rN   rN   rQ   Ú_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})r0  r1  z{{{label}}}_{{{interval}}})rÈ  Úinterval)rÃ   rÈ  r1  r0  r   ÚZeror½   )r·   rÊ   rÈ  r1  r0  rË  rN   rN   rQ   Ú
_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   r  ú%s %sz
%s %s^{%s}rs  z\frac{%s^{%s}}{%s}c                 s  ó   � | ]}|  ¡ V  qd S rÂ   ©rê   r–  rN   rN   rQ   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ã   ÚnumrN   rN   rQ   Ú_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û   rN   rQ   rå   I  ræ   z+LatexPrinter._print_Subs.<locals>.<genexpr>c                 3  rÞ   rÂ   rú   rÙ  rû   rN   rQ   rå   J  ræ   z\\ c                 s  s$   � | ]}|d  d |d  V  qdS )r   ú=r  NrN   rÙ  rN   rN   rQ   rå   K  s   € 
ÿz#\left. %s \right|_{\substack{ %s }})rò   rÃ   r  Úzip)	r·   ÚsubsrÊ   r]  ÚnewZ
latex_exprZ	latex_oldZ	latex_newZ
latex_subsrN   rû   rQ   Ú_print_SubsF  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 )r  N)r/  )râ   ÚlimrN   rN   rQ   rå   U  s   € z/LatexPrinter._print_Integral.<locals>.<genexpr>z\irŒ   r  Úntc                   s"   g | ]}d ˆ ˆ  |d ¡f ‘qS )ú\, %s%sr   rú   ©râ   Úsymbol©rÕ  r·   rN   rQ   rü   Y  s    ÿz0LatexPrinter._print_Integral.<locals>.<listcomp>r   z\intr„   rš   r~   z\limitsr³  z
_{%s}^{%s}rr  ú^{%s}râ  z%s %s%sr	   c                 s  rÏ  rÂ   rÐ  r–  rN   rN   rQ   rå   p  rÑ  TrÒ  )r±   r/  r¦  ÚallrÓ  rÃ   ÚinsertrÈ   r§  r    rí   rò   r  )r·   rÊ   rË   Úsymbolsrà  rä  rN   rå  rQ   Ú_print_IntegralP  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Ã   rn   r   ÚInfinityÚNegativeInfinityrb  r   )r·   rÊ   r  ÚzÚz0ÚdirrË   rN   rN   rQ   Ú_print_Limitt  s   
zLatexPrinter._print_LimitrY  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
        rr   Ú_z\%sr  rp   r   z\operatorname{%s}%sNz\operatorname{%s})rÿ   ÚfindÚaccepted_latex_functionsr/  r�  r”   )r·   rY  ZsuperscriptidxZsubscriptidxr  rN   rN   rQ   Ú_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 rN   )rn   rÃ   r*  rû   rN   rQ   rü   ³  ó    z0LatexPrinter._print_Function.<locals>.<listcomp>r|   Frz   r  r   )ÚasinÚacosÚatanÚacscÚasecÚacotÚasinhÚacoshÚatanhÚacschÚasechÚacothr}   Úfullr  ÚhÚarZarcNÚpowerTz\%s^{-1}z\operatorname{%s}^{-1}r†  z {%s}ú%sú{\left(%s \right)}ræ  r  )rY  r  ra  rb  r   Úgetattrrò   r±   r/  rÚ   rô  rõ  r“   r  )r·   rÊ   r÷   rY  rò   r|   Zinv_trig_power_caseZcan_fold_bracketsZinv_trig_tabler  Zfunc_texrN   rû   rQ   Ú_print_Function¢  sR   ÿ


ÿþ"






zLatexPrinter._print_Functionc                 C  ó   |   t|ƒ¡S rÂ   )rõ  rn   rÒ   rN   rN   rQ   Ú_print_UndefinedFunctionî  rô   z%LatexPrinter._print_UndefinedFunctionc                 C  ó   d|   |j¡|   |j¡f S )Nz{%s}_{\circ}\left({%s}\right))rÃ   r§  rÊ   rÒ   rN   rN   rQ   Ú_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)rE   z\deltar?   z\gammaz\operatorname{B}z\operatorname{Chi})Ú(sympy.functions.special.tensor_functionsr  Ú'sympy.functions.special.gamma_functionsr  r  Ú&sympy.functions.special.beta_functionsr  Ú'sympy.functions.special.delta_functionsr  Ú'sympy.functions.special.error_functionsrE   )r·   r  r  r  r  r  rE   rN   rN   rQ   Ú_special_function_classes÷  s   ûz&LatexPrinter._special_function_classesc                 C  s>   | j D ]}t||ƒr|j|jkr| j |   S q|  t|ƒ¡S rÂ   )r  Ú
issubclassr  rõ  rn   )r·   rÊ   ÚclsrN   rN   rQ   Ú_print_FunctionClass  s
   
€z!LatexPrinter._print_FunctionClassc                 C  sJ   |j \}}t|ƒdkr|  |d ¡}n|  t|ƒ¡}d||  |¡f }|S )Nr  r   z\left( %s \mapsto %s \right))rò   r/  rÃ   r›  )r·   rÊ   ré  rË   rN   rN   rQ   Ú_print_Lambda  s   
zLatexPrinter._print_Lambdac                 C  ó   dS )Nz\left( x \mapsto x \right)rN   rÒ   rN   rN   rQ   Ú_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 )r  rú   rã  rû   rN   rQ   rü     r÷  z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)rþ   r†  )Úsortedrò   r   rn   rY  r0  r  )r·   rÊ   r÷   rò   ZtexargsrË   rN   rû   rQ   Ú_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Ë   rN   rN   rQ   Ú_print_floor&  ó   zLatexPrinter._print_floorc                 C  r%  )Nz\left\lceil{%s}\right\rceilr   r†  r’  r&  rN   rN   rQ   Ú_print_ceiling.  r(  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ò   r&  rN   rN   rQ   Ú
_print_log6  s   
zLatexPrinter._print_logc                 C  r%  )Nú\left|{%s}\right|r   r†  r’  r&  rN   rN   rQ   Ú
_print_AbsA  r(  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ø   r&  rN   rN   rQ   Ú	_print_reI  ó   
zLatexPrinter._print_rec                 C  r-  )Nr�   z\Im{%s}r   r.  z\operatorname{{im}}{{{}}}r/  r&  rN   rN   rQ   Ú	_print_imQ  r1  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.boolalgr3  r4  rb  rò   Ú_print_EquivalentÚ_print_ImpliesÚ
is_BooleanrÃ   )r·   r  r3  r4  rN   rN   rQ   Ú
_print_NotY  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   r  r  r  z %s \left(%s\right)z %s %s)r8  Úis_NotrÃ   )r·   rò   Úcharr;   rË   rN   rN   rQ   Ú_print_LogOpd  s   zLatexPrinter._print_LogOpc                 C  ó   t |jtd�}|  |d¡S )Nr°  z\wedge©r#  rò   r   r<  ©r·   r  rò   rN   rN   rQ   Ú
_print_Ands  ó   zLatexPrinter._print_Andc                 C  r=  )Nr°  z\veer>  r?  rN   rN   rQ   Ú	_print_Orw  rA  zLatexPrinter._print_Orc                 C  r=  )Nr°  z\veebarr>  r?  rN   rN   rQ   Ú
_print_Xor{  rA  zLatexPrinter._print_Xorc                 C  s   |   |j|pd¡S )Nz\Rightarrow)r<  rò   )r·   r  ÚaltcharrN   rN   rQ   r7    ó   zLatexPrinter._print_Impliesc                 C  s   t |jtd�}|  ||pd¡S )Nr°  z\Leftrightarrowr>  )r·   r  rD  rò   rN   rN   rQ   r6  ‚  s   zLatexPrinter._print_Equivalentc                 C  r%  )Nz\overline{%s}r   r†  r’  r&  rN   rN   rQ   Ú_print_conjugate†  r(  zLatexPrinter._print_conjugatec                 C  s:   d}d|   |jd ¡ }|d urd|||f S d||f S )Nz\operatorname{polar\_lift}r	  r   ú	%s^{%s}%sú%s%sr’  )r·   rÊ   r÷   rY  r;   rN   rN   rQ   Ú_print_polar_liftŽ  s
   zLatexPrinter._print_polar_liftc                 C  s    d|   |jd ¡ }|  ||¡S )Nze^{%s}r   )rÃ   rò   rø   r&  rN   rN   rQ   Ú_print_ExpBase—  s   zLatexPrinter._print_ExpBasec                 C  r  )Nr  rN   rö   rN   rN   rQ   Ú_print_Exp1�  r!  zLatexPrinter._print_Exp1c                 C  ó0   d|   |jd ¡ }|d urd||f S d| S )Nr  r   zK^{%s}%szK%sr’  r&  rN   rN   rQ   Ú_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   r  zF^{%s}%szF%sr’  r&  rN   rN   rQ   Ú_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 )Nrr  rO  r   r  r  zE^{%s}%szE%s©r/  rò   rÃ   r&  rN   rN   rQ   Ú_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   r  rr  rO  z
\Pi^{%s}%sz\Pi%srQ  r&  rN   rN   rQ   Ú_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   r  r�  rþ   r  z\operatorname{B}^{%s}%sz\operatorname{B}%s)rò   r/  )r·   rÊ   r÷   rã   ÚyrË   rN   rN   rQ   Ú_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ù   rN   rú   r*  rû   rN   rQ   rü   Ó  rý   z/LatexPrinter._print_betainc.<locals>.<listcomp>ú\left(%s, %s\right)r   r  z#\operatorname{%s}_{(%s, %s)}^{%s}%srr  r³  z\operatorname{%s}_{(%s, %s)}%s)rò   )r·   rÊ   r÷   ÚoperatorZlargsrË   rN   rû   rQ   Ú_print_betaincÒ  s
   zLatexPrinter._print_betaincc                 C  s   | j ||dd�S )NÚI)rX  )rY  rö   rN   rN   rQ   Ú_print_betainc_regularizedÛ  r”  z'LatexPrinter._print_betainc_regularizedc                 C  rN  )NrW  r   r  z\Gamma^{%s}%sz\Gamma%sr’  r&  rN   rN   rQ   Ú_print_uppergammaÞ  ó   ÿzLatexPrinter._print_uppergammac                 C  rN  )NrW  r   r  z\gamma^{%s}%sú\gamma%sr’  r&  rN   rN   rQ   Ú_print_lowergammaç  r]  zLatexPrinter._print_lowergammac                 C  sF   d|   |jd ¡ }|d urd|   |j¡||f S d|   |j¡|f S ©Nr  r   rG  rH  )rÃ   rò   rY  r&  rN   rN   rQ   Ú_hprint_one_arg_funcð  s   z!LatexPrinter._hprint_one_arg_funcc                 C  rL  )Nr  r   z\operatorname{Chi}^{%s}%sz\operatorname{Chi}%sr’  r&  rN   rN   rQ   Ú
_print_Chiú  ó   zLatexPrinter._print_Chic                 C  sF   d|   |jd ¡ }|   |jd ¡}|d urd|||f S d||f S )Nr  r  r   z\operatorname{E}_{%s}^{%s}%sz\operatorname{E}_{%s}%sr’  )r·   rÊ   r÷   rË   ÚnurN   rN   rQ   Ú_print_expint  s
   zLatexPrinter._print_expintc                 C  rL  )Nr  r   zS^{%s}%szS%sr’  r&  rN   rN   rQ   Ú_print_fresnels  rc  zLatexPrinter._print_fresnelsc                 C  rL  )Nr  r   zC^{%s}%szC%sr’  r&  rN   rN   rQ   Ú_print_fresnelc  rc  zLatexPrinter._print_fresnelcc                 C  ó2   d|   |jd td ¡ }|d urd||f S |S )Nz!%sr   ÚFuncrõ   ©rÈ   rò   r    r&  rN   rN   rQ   Ú_print_subfactorial  ó   z LatexPrinter._print_subfactorialc                 C  rh  )Nz%s!r   ri  r†  rj  r&  rN   rN   rQ   Ú_print_factorial#  rl  zLatexPrinter._print_factorialc                 C  rh  )Nz%s!!r   ri  r†  rj  r&  rN   rN   rQ   Ú_print_factorial2+  rl  zLatexPrinter._print_factorial2c                 C  s<   d|   |jd ¡|   |jd ¡f }|d urd||f S |S )Nz{\binom{%s}{%s}}r   r  r†  r’  r&  rN   rN   rQ   Ú_print_binomial3  s   ÿzLatexPrinter._print_binomialc                 C  s<   |j \}}d|  |td ¡ }d||  |¡f }|  ||¡S )Nr  ri  z{%s}^{\left(%s\right)}©rò   rÈ   r    rÃ   rø   )r·   rÊ   r÷   Únr¿  ró   rË   rN   rN   rQ   Ú_print_RisingFactorial<  ó   
z#LatexPrinter._print_RisingFactorialc                 C  s<   |j \}}d|  |td ¡ }d|  |¡|f }|  ||¡S )Nr  ri  z{\left(%s\right)}_{%s}rp  )r·   rÊ   r÷   rq  r¿  ÚsubrË   rN   rN   rQ   Ú_print_FallingFactorialD  rs  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 )Nr  Frr   r  r†  Tú%s_{%s}\left(%s\right))ró  rÃ   r‡   Úargumentrø   )r·   rÊ   r÷   rv  rË   Zneed_exprN   rN   rQ   Ú_hprint_BesselBaseL  s   
ÿzLatexPrinter._hprint_BesselBasec                 C  sF   |sdS d}|d d… D ]}|d|   |¡ 7 }q||   |d ¡7 }|S )Nr¢   r  z%s, rú   )r·   r_   rP   rŒ   rN   rN   rQ   Ú_hprint_vec]  s   zLatexPrinter._hprint_vecc                 C  ó   |   ||d¡S )NÚJ©ry  rö   rN   rN   rQ   Ú_print_besseljf  rô   zLatexPrinter._print_besseljc                 C  r{  )NrZ  r}  rö   rN   rN   rQ   Ú_print_besselii  rô   zLatexPrinter._print_besselic                 C  r{  )NÚKr}  rö   rN   rN   rQ   Ú_print_besselkl  rô   zLatexPrinter._print_besselkc                 C  r{  )NÚYr}  rö   rN   rN   rQ   Ú_print_besselyo  rô   zLatexPrinter._print_besselyc                 C  r{  )NrT  r}  rö   rN   rN   rQ   Ú	_print_ynr  rô   zLatexPrinter._print_ync                 C  r{  )Nr§   r}  rö   rN   rN   rQ   Ú	_print_jnu  rô   zLatexPrinter._print_jnc                 C  r{  )NzH^{(1)}r}  rö   rN   rN   rQ   Ú_print_hankel1x  rô   zLatexPrinter._print_hankel1c                 C  r{  )NzH^{(2)}r}  rö   rN   rN   rQ   Ú_print_hankel2{  rô   zLatexPrinter._print_hankel2c                 C  r{  )Nzh^{(1)}r}  rö   rN   rN   rQ   Ú
_print_hn1~  rô   zLatexPrinter._print_hn1c                 C  r{  )Nzh^{(2)}r}  rö   rN   rN   rQ   Ú
_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÷   ZnotationrË   rN   rN   rQ   Ú_hprint_airy„  ó   zLatexPrinter._hprint_airyc                 C  rŠ  )Nr  r   z{%s^\prime}^{%s}%sz%s^\prime%sr’  r‹  rN   rN   rQ   Ú_hprint_airy_primeŒ  r�  zLatexPrinter._hprint_airy_primec                 C  r{  ©NÚAi©rŒ  rö   rN   rN   rQ   Ú_print_airyai”  rô   zLatexPrinter._print_airyaic                 C  r{  ©NÚBir‘  rö   rN   rN   rQ   Ú_print_airybi—  rô   zLatexPrinter._print_airybic                 C  r{  r�  ©rŽ  rö   rN   rN   rQ   Ú_print_airyaiprimeš  rô   zLatexPrinter._print_airyaiprimec                 C  r{  r“  r–  rö   rN   rN   rQ   Ú_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Ã   r/  ÚapÚbqrz  rx  r&  rN   rN   rQ   Ú_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Ã   r/  rš  r›  rf   Úanrz  ÚaotherÚbotherrx  r&  rN   rN   rQ   Ú_print_meijerg«  s   
üþzLatexPrinter._print_meijergc                 C  rL  )Nr  r   z\eta^{%s}%sz\eta%sr’  r&  rN   rN   rQ   Ú_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 )Nrr  rW  r  r   z\zeta^{%s}%sz\zeta%s©r/  rò   r›  rÄ  rÃ   r&  rN   rN   rQ   Ú_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 )Nrr  z_{%s}\left(%s\right)rÃ  r   z\gamma%s^{%s}r^  r¢  r&  rN   rN   rQ   Ú_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ò   r&  rN   rN   rQ   Ú_print_lerchphiÐ  s   zLatexPrinter._print_lerchphic                 C  s<   t | j|jƒ\}}d| }|d u rd||f S d|||f S )Nr  z\operatorname{Li}_{%s}%sz\operatorname{Li}_{%s}^{%s}%s©rÄ  rÃ   rò   )r·   rÊ   r÷   rP   rî  rË   rN   rN   rQ   Ú_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÷   rq  rz  r{  rã   rË   rN   rN   rQ   Ú_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÷   rq  rz  rã   rË   rN   rN   rQ   Ú_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÷   rq  rã   rË   rN   rN   rQ   Ú_print_chebyshevtë  ó
   zLatexPrinter._print_chebyshevtc                 C  r±  )NzU_{%s}\left(%s\right)r�  rª  r§  r²  rN   rN   rQ   Ú_print_chebyshevuò  r´  zLatexPrinter._print_chebyshevuc                 C  r±  )NzP_{%s}\left(%s\right)r�  rª  r§  r²  rN   rN   rQ   Ú_print_legendreù  r´  zLatexPrinter._print_legendrec                 C  r­  )Nz'P_{%s}^{\left(%s\right)}\left(%s\right)r�  rª  r§  r®  rN   rN   rQ   Ú_print_assoc_legendre   r°  z"LatexPrinter._print_assoc_legendrec                 C  r±  )NzH_{%s}\left(%s\right)r�  rª  r§  r²  rN   rN   rQ   Ú_print_hermite  r´  zLatexPrinter._print_hermitec                 C  r±  )NzL_{%s}\left(%s\right)r�  rª  r§  r²  rN   rN   rQ   Ú_print_laguerre  r´  zLatexPrinter._print_laguerrec                 C  r­  )Nz'L_{%s}^{\left(%s\right)}\left(%s\right)r�  rª  r§  r®  rN   rN   rQ   Ú_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÷   rq  ÚmÚthetaÚphirË   rN   rN   rQ   Ú
_print_Ynm  r¬  zLatexPrinter._print_Ynmc                 C  r©  )NzZ_{%s}^{%s}\left(%s,%s\right)r�  rª  r§  r»  rN   rN   rQ   Ú
_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÷   rz  r‡  rî  ÚsuprN   rN   rQ   Z__print_mathieu_functions*  s   z&LatexPrinter.__print_mathieu_functionsc                 C  ó   | j d|j|d�S )NÚCr…  ©Ú&_LatexPrinter__print_mathieu_functionsrò   rö   rN   rN   rQ   Ú_print_mathieuc0  rE  zLatexPrinter._print_mathieucc                 C  rÃ  )Nr   r…  rÅ  rö   rN   rN   rQ   Ú_print_mathieus3  rE  zLatexPrinter._print_mathieusc                 C  ó   | j d|jd|d�S )NrÄ  T©r`   r÷   rÅ  rö   rN   rN   rQ   Ú_print_mathieucprime6  ó   z!LatexPrinter._print_mathieucprimec                 C  rÉ  )Nr   TrÊ  rÅ  rö   rN   rN   rQ   Ú_print_mathieusprime9  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 )Nr  r¢   r   ro  r{   z	%s%d / %dz%s\frac{%d}{%d})r‡  r‚  r±   rÃ   )r·   rÊ   Úsignr‚  rN   rN   rQ   Ú_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‚  rN   rN   rQ   rå   K  ræ   z,LatexPrinter._print_Order.<locals>.<genexpr>r  ú; r   z\rightarrow zO\left(%s\right))rÃ   rÊ   Úpointrí   r/  Ú	variables©r·   rÊ   rP   rN   rN   rQ   Ú_print_OrderI  s   ÿzLatexPrinter._print_Orderr   c                 C  s,   | j d  |¡}|d ur|S | j|j|d�S )Nrˆ   ©Ústyle)r±   r¶   rÿ   r  )r·   rÊ   rÖ  r  rN   rN   rQ   Ú_print_SymbolY  s   zLatexPrinter._print_Symbolr  ú tuple[str, list[str], list[str]]c                 C  s‚   |d u sd|v r|g g fS | j d r#| dd¡ dd¡g g }}}nt|ƒ\}}}t|ƒ}dd„ |D ƒ}d	d„ |D ƒ}|||fS )
Nrb   r˜   rò  z\_rr   z\^c                 S  ó   g | ]}t |ƒ‘qS rN   ©Ú	translate)râ   rÂ  rN   rN   rQ   rü   j  r¤  z1LatexPrinter._split_super_sub.<locals>.<listcomp>c                 S  rÙ  rN   rÚ  )râ   rt  rN   rN   rQ   rü   k  r¤  )r±   rs   r   rÛ  )r·   r  ÚsupersrÜ  rN   rN   rQ   Ú_split_super_subb  s   

"
zLatexPrinter._split_super_subÚstringc                 C  sR   |   |¡\}}}|dkrd |¡}|r|dd |¡ 7 }|r'|dd |¡ 7 }|S )Nrd   ú\mathbf{{{}}}ræ  rœ   rÃ  )rÝ  r½   r  )r·   rÞ  rÖ  r  rÜ  rÜ  rN   rN   rQ   rÿ   n  s   
z!LatexPrinter._deal_with_super_subc                 C  sR   | j d r
d}d}nd}d}d||ddd	d
œ}d|  |j¡||j |  |j¡f S )Nr~   z\gtz\ltú>ú<rÚ  z\geqz\leqz\neq)z==rà  rá  z>=z<=z!=z%s %s %s)r±   rÃ   ÚlhsÚrel_opÚrhs)r·   rÊ   ÚgtÚltÚcharmaprN   rN   rQ   Ú_print_Relational}  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  rt   rû   rN   rQ   rü   ’  s    ÿz1LatexPrinter._print_Piecewise.<locals>.<listcomp>r  z%s & \text{otherwise}ré  z\begin{cases} %s \end{cases}z \\)rò   Úcondr   rº  rÃ   rÊ   r  )r·   rÊ   ZecpairsrË   rN   rû   rQ   Ú_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 )Nr+  c                   rù   rN   rú   r–  rû   rN   rQ   rü   ¢  rý   z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>rƒ   r„   rš   Úsmallmatrixé
   TÚmatrixÚarrayú \begin{%MATSTR%}%s\end{%MATSTR%}ú%MATSTR%r  rb   rt   ú}%sr   )r.  Úrowsrº  r  r±   Úcolsrs   )r·   rÊ   ÚlinesÚlinerƒ   Úout_strrN   rû   rQ   Ú_print_matrix_contentsž  s   ,
z#LatexPrinter._print_matrix_contentsc                 C  s@   |   |¡}| jd r| jd }| j| }d| | d | }|S )Nr�   ú\leftú\right)rø  r±   rµ   )r·   rÊ   r÷  Ú
left_delimÚright_delimrN   rN   rQ   Ú_print_MatrixBase´  s   




ÿÿzLatexPrinter._print_MatrixBasec                 C  sF   | j |jtd dd�}|  |j¡› d|  |j¡› �}d|› d|› d�S )Nr.  T©rÇ   r  rb   z}_{rM   )rÈ   Úparentr    rÃ   rŒ   r§   )r·   rÊ   Zmatrix_partZ
index_partrN   rN   rQ   Ú_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 )Nrr  r  r   ú:c                 3  s&   � | ]}|d urˆ   |¡ndV  qd S ©Nr¢   rú   )râ   Úxirû   rN   rQ   rå   Ë  ó   €$ zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>)rf  r  )rã   rÖ  rû   rN   rQ   Ú
latexsliceÃ  s   z3LatexPrinter._print_MatrixSlice.<locals>.latexslicer.  Trþ  ú\left[rþ   ú\right])rÈ   rÿ  r    Úrowsliceró  Úcolslicerô  )r·   rÊ   r  rN   rû   rQ   Ú_print_MatrixSliceÂ  s   	ÿÿþþzLatexPrinter._print_MatrixSlicec                 C  rÇ  rÂ   )rÃ   ÚblocksrÒ   rN   rN   rQ   Ú_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}Trr   z%s^{T})	r;   Úsympy.matricesr  r  rb  Úis_MatrixExprrÃ   rÈ   r   )r·   rÊ   r3  r  r  rP   rN   rN   rQ   Ú_print_TransposeÓ  s   
ÿÿzLatexPrinter._print_Transposec                 C  s   |j }d|  |¡ S )Nz!\operatorname{tr}\left(%s \right))r;   rÃ   ©r·   rÊ   r3  rN   rN   rQ   Ú_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   r  rõ   Trr   r†  )r¶   r±   r;   r  r  r  rb  r  rÃ   rÈ   r   )r·   rÊ   Zstyle_to_latexr—   r3  r  r  rP   rN   rN   rQ   Ú_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)rb  r	   rÃ   rÈ   r   rc  ©r  rÊ   r·   rN   rQ   rR   û  s    z,LatexPrinter._print_MatMul.<locals>.<lambda>r  r  ro  rœ   )Úsympyr  rf  rò   rê   r  rÄ  )r·   rÊ   Úparensrò   rN   r  rQ   Ú_print_MatMul÷  s   
zLatexPrinter._print_MatMulc                 C  s0   t |ƒ}|j\}}|  ||¡› d|  ||¡› �S )Nr�   )r   rò   rÈ   )r·   rÊ   rÅ   ÚleftÚrightrN   rN   rQ   Ú_print_DotProduct  s   
zLatexPrinter._print_DotProductc                 C  sN   |j }|jr ddlm} t||ƒrd|  |j¡ S d|  |¡ S d|  |¡ S )Nr   )r  r+  )r;   r  Ú&sympy.matrices.expressions.blockmatrixr  rb  rø  r  rÃ   )r·   rÊ   r3  r  rN   rN   rQ   Ú_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	   Trþ  r  z%s \bmod %srj  rö   rN   rN   rQ   Ú
_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 ©Trþ  NrN   r*  ©r  ÚprecrN   rQ   rå   ,  ó   € z6LatexPrinter._print_HadamardProduct.<locals>.<genexpr>©rò   r    rÈ   r  ©r·   rÊ   rò   rN   r'  rQ   Ú_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Œ  rN   rN   rQ   Ú_print_HadamardPower.  s   z!LatexPrinter._print_HadamardPowerc                   r$  )Nr   ú	 \otimes c                 3  r%  r&  rN   r*  r'  rN   rQ   rå   ;  r)  z7LatexPrinter._print_KroneckerProduct.<locals>.<genexpr>r*  r+  rN   r'  rQ   Ú_print_KroneckerProduct5  r-  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   )r  rõ   rr   r†  )ró   r÷   r  r  rb  r  rÃ   )r·   rÊ   ró   r÷   r  Zbase_strrN   rN   rQ   Ú_print_MatPow=  s   
ÿ
zLatexPrinter._print_MatPowc                 C  s   | j || jd d�S )NrŠ   rÕ  )r×  r±   rÒ   rN   rN   rQ   Ú_print_MatrixSymbolJ  s   
ÿz LatexPrinter._print_MatrixSymbolc                 C  ó   | j d dkr	dS dS )NrŠ   r…   Ú0z
\mathbf{0}©r±   )r·   ÚZrN   rN   rQ   Ú_print_ZeroMatrixN  ó   ÿÿÿzLatexPrinter._print_ZeroMatrixc                 C  r3  )NrŠ   r…   Ú1z
\mathbf{1}r5  )r·   ÚOrN   rN   rQ   Ú_print_OneMatrixR  r8  zLatexPrinter._print_OneMatrixc                 C  r3  )NrŠ   r…   z
\mathbb{I}z
\mathbf{I}r5  )r·   rZ  rN   rN   rQ   Ú_print_IdentityV  r8  zLatexPrinter._print_Identityc                 C  s   |   |jd ¡}d| S )Nr   zP_{%s}r’  )r·   ÚPZperm_strrN   rN   rQ   Ú_print_PermutationMatrixZ  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rîd||
 d  d ||
 d< |	 }	g ||
d < q¤qŠ|d d }|  ¡ d dk�r|| }|S )Nr   rN   rƒ   r„   rš   rì  r  rí  rî  rï  rð  rñ  r  rb   rt   rò  r�   rù  rú  r¢   c                 S  s   g | ]}g ‘qS rN   rN   r–  rN   rN   rQ   rü   z  s    z1LatexPrinter._print_NDimArray.<locals>.<listcomp>r  c                 S  s   g | ]}t t|ƒƒ‘qS rN   )rf  r.  r–  rN   rN   rQ   rü   {  ó    Tr+  r   r  r  rr  )ÚrankrÃ   r±   Úshapers   rµ   r.  Ú	itertoolsÚproductrº  r/  r  )r·   rÊ   rƒ   Z	block_strrû  rü  Ú	level_strÚshape_rangesÚouter_iÚevenÚback_outer_ir÷  rN   rN   rQ   Ú_print_NDimArray^  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 )	Nr  rM   z{}^{z{}_{r   rÚ  TF)rÃ   Úis_uprò   )	r·   r  rÅ  rJ  r÷  Úlast_valenceÚprev_mapÚindexZnew_valencerN   rN   rQ   Ú_printer_tensor_indices•  s0   

z$LatexPrinter._printer_tensor_indicesc                 C  s&   |j d j d }| ¡ }|  ||i ¡S r‘  )rò   Úget_indicesrP  )r·   rÊ   r  rÅ  rN   rN   rQ   Ú_print_Tensor±  s   zLatexPrinter._print_Tensorc                 C  s0   |j jd jd }|j  ¡ }|j}|  |||¡S r‘  )rÊ   rò   rQ  rJ  rP  )r·   rÊ   r  rÅ  rJ  rN   rN   rQ   Ú_print_TensorElement¶  s   
z!LatexPrinter._print_TensorElementc                   s*   ˆ   ¡ \}}|d ‡ ‡fdd„|D ƒ¡ S )Nr¢   c                   s   g | ]
}ˆ  |tˆ ƒ¡‘qS rN   )rÈ   r   r*  ©rÊ   r·   rN   rQ   rü   À  ó    z/LatexPrinter._print_TensMul.<locals>.<listcomp>)Ú!_get_args_for_traditional_printerr  )r·   rÊ   rÎ  rò   rN   rT  rQ   Ú_print_TensMul¼  s   ÿzLatexPrinter._print_TensMulc                 C  sL   g }|j }|D ]}| |  |t|ƒ¡¡ q| ¡  d |¡}| dd¡}|S )Nr  z+ -ro  )rò   rº  rÈ   r   r¹  r  rs   )r·   rÊ   rz  rò   rã   rP   rN   rN   rQ   Ú_print_TensAddÃ  s   
zLatexPrinter._print_TensAddc                 C  s"   d|j rdnd|  |jd ¡f S )Nz{}%s{%s}rr   rò  r   )rL  rÃ   rò   rÒ   rN   rN   rQ   Ú_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 )
Nr  z"\frac{\partial}{\partial {%s}}{%s}r   r	   Fz\frac{\partial^{%s}}{%s}{%s}rœ   c                   r"  )z\partial {%s}rú   r–  rû   rN   rQ   rü   Ü  r÷  z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>)r/  rÒ  rÃ   rÈ   rÊ   r    r  rÒ   rN   rû   rQ   Ú_print_PartialDerivativeÓ  s   þýz%LatexPrinter._print_PartialDerivativec                 C  rÇ  rÂ   )rÃ   r  rÒ   rN   rN   rQ   Ú_print_ArraySymbolà  rÊ  zLatexPrinter._print_ArraySymbolc                   s2   dˆ   |jtd d¡d ‡ fdd„|jD ƒ¡f S )Nz{{%s}_{%s}}ri  Trþ   c                   s   g | ]}ˆ   |¡› ‘qS rN   rú   r–  rû   rN   rQ   rü   æ  r?  z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>)rÈ   r  r    r  rÅ  rÒ   rN   rû   rQ   Ú_print_ArrayElementã  s   þz LatexPrinter._print_ArrayElementc                 C  r  )Nz
\mathbb{U}rN   rÒ   rN   rN   rQ   Ú_print_UniversalSetè  r!  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ö   rN   rN   rQ   Ú_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‘   r<  ú;r�   r  úUnknown Decimal Separatorr  r   z \  c                   rù   rN   rú   r–  rû   rN   rQ   rü   ÿ  rý   z-LatexPrinter._print_tuple.<locals>.<listcomp>)r±   r²   r/  rÁ   rÃ   r  )r·   rÊ   ÚseprN   rû   rQ   Ú_print_tupleò  s   ÿzLatexPrinter._print_tuplec                   ó   ‡ fdd„|j D ƒ}d |¡S )Nc                   rù   rN   rú   ©râ   rz  rû   rN   rQ   rü     rý   z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>r/  ©rò   r  ©r·   rÊ   ÚelementsrN   rû   rQ   Ú_print_TensorProduct  ó   
z!LatexPrinter._print_TensorProductc                   rc  )Nc                   rù   rN   rú   rd  rû   rN   rQ   rü     rý   z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>z \wedge re  rf  rN   rû   rQ   Ú_print_WedgeProduct  ri  z LatexPrinter._print_WedgeProductc                 C  ó
   |   |¡S rÂ   )rb  rÒ   rN   rN   rQ   Ú_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‘   r<  z\left[ %s\right]z; \  c                   rù   rN   rú   r–  rû   rN   rQ   rü     rý   z,LatexPrinter._print_list.<locals>.<listcomp>r�   ú, \  c                   rù   rN   rú   r–  rû   rN   rQ   rü     rý   r`  )r±   r  r²   rÒ   rN   rû   rQ   Ú_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\}rm  )r#  Úkeysr   rº  rÃ   r  )r·   rŽ   ro  r·  r±  ÚvalrN   rN   rQ   Ú_print_dict  s    zLatexPrinter._print_dictc                 C  rk  rÂ   )rq  rÒ   rN   rN   rQ   Ú_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 )Nr  r   z\delta\left(%s\right)z+\delta^{\left( %s \right)}\left( %s \right)rõ   rQ  r&  rN   rN   rQ   Ú_print_DiracDelta$  s   ÿzLatexPrinter._print_DiracDeltac                 C  sP   |   |jd |jd  ¡}|   |jd ¡}d||f }|d ur&d|||f }|S )Nr   r  rr  z${\left\langle %s \right\rangle}^{%s}z-{\left({\langle %s \rangle}^{%s}\right)}^{%s}r’  )r·   rÊ   r÷   Úshiftr  rË   rN   rN   rQ   Ú_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ú   r*  rû   rN   rQ   rå   7  ræ   z0LatexPrinter._print_Heaviside.<locals>.<genexpr>z\theta\left(%s\right)rõ   )r  Úpargs)r·   rÊ   r÷   rv  rË   rN   rû   rQ   Ú_print_Heaviside6  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   r  z\delta_{%s %s}z\delta_{%s, %s}rõ   )rÃ   rò   rÏ   )r·   rÊ   r÷   rŒ   r§   rË   rN   rN   rQ   Ú_print_KroneckerDelta=  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á   rN   rN   rQ   rå   J  s   € z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}rœ   rþ   rõ   )rÄ  rÃ   rò   rç  r  )r·   rÊ   r÷   rÅ  rË   rN   rN   rQ   Ú_print_LeviCivitaH  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 })ra  rÃ   rz  ré  r{  )r·   rŽ   rN   rN   rQ   Ú_print_RandomDomainR  s   


ÿ

z LatexPrinter._print_RandomDomainc                 C  s   t |jtd�}|  |¡S )Nr°  )r#  rò   r   Ú
_print_set©r·   rP   r·  rN   rN   rQ   Ú_print_FiniteSet]  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‘   r<  rÐ  r�   rþ   r`  ú\left\{%s\right\})r#  r   r±   r  rÄ  rÃ   r²   r~  rN   rN   rQ   r}  a  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   rr  r  rþ   c                 3  rÞ   rÂ   rú   r*  rû   rN   rQ   rå   u  ræ   zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>c                 3  rÞ   rÂ   rú   r*  rû   rN   rQ   rå   x  ræ   c                 3  rÞ   rÂ   rú   r*  rû   rN   rQ   rå   z  ræ   z\text{Range}\left(r  )rò   rÃ   r  )Úcont)rP   r·   rN   rQ   Ú_print_symbolic_rangeo  s   $z8LatexPrinter._print_Range.<locals>._print_symbolic_ranger  r   r  rß  Tz\left\{rþ   c                 3  ó&   � | ]}|ˆ urˆ  |¡nd V  qdS ©z\ldotsNrú   ©râ   Úel©Údotsr·   rN   rQ   rå   •  r  z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})ÚobjectÚstartÚis_infiniteÚstopÚstepÚis_positiveÚiterÚnextZis_emptyr   r›  Úis_iterabler  )r·   rP   r‚  ÚprintsetÚitrN   )rˆ  rP   r·   rQ   Ú_print_Rangen  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 )Nrr  z%s_{%s}^{%s}\left(%s\right)r   r  rw  z%s_{%s}r†  rQ  )r·   rÊ   Úletterr÷   rË   rN   rN   rQ   Z__print_number_polynomial˜  s   þÿz&LatexPrinter.__print_number_polynomialc                 C  ó   |   |d|¡S ©NrV  ©Ú&_LatexPrinter__print_number_polynomialrö   rN   rN   rQ   Ú_print_bernoulli¦  rô   zLatexPrinter._print_bernoullic                 C  r–  )NÚGr˜  rö   rN   rN   rQ   Ú_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   r  r  rþ   c                 3  rÞ   rÂ   rú   r…  rû   rN   rQ   rå   °  s   € ÿz+LatexPrinter._print_bell.<locals>.<genexpr>rr  rG  rV  )r/  rò   rÃ   r  r™  )r·   rÊ   r÷   Ztex1Ztex2rË   rN   rû   rQ   Ú_print_bell¬  s   ÿ
ÿÿzLatexPrinter._print_bellc                 C  r–  ©NÚFr˜  rö   rN   rN   rQ   Ú_print_fibonacci¹  rô   zLatexPrinter._print_fibonaccic                 C  ó,   d|   |jd ¡ }|d urd||f }|S )NzL_{%s}r   r†  r’  r&  rN   rN   rQ   Ú_print_lucas¼  ó   zLatexPrinter._print_lucasc                 C  r–  )NÚTr˜  rö   rN   rN   rQ   Ú_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ö   rN   rN   rQ   Ú_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³  rr  r  rß  r  rþ   c                 3  rƒ  r„  rú   r…  r‡  rN   rQ   rå   Þ  r  z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>r  )r‰  r/  rŠ  Úfree_symbolsrŒ  rÃ   ÚformularÒ  r   rí  Úcoeffrì  Úlengthrº  r›  r  )r·   rP   rŒ  r’  rN   r‡  rQ   Ú_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Œ   r  r  rN   rN   rQ   Ú_print_Intervalå  s   ÿzLatexPrinter._print_Intervalc                 C  r  )Nz \left\langle %s, %s\right\rangle)rÃ   r”   r•   ©r·   rŒ   rN   rN   rQ   Ú_print_AccumulationBounds÷  s   ÿz&LatexPrinter._print_AccumulationBoundsc                   ó(   t |ƒ‰ ‡ ‡fdd„|jD ƒ}d |¡S )Nc                   ó   g | ]}ˆ  |ˆ ¡‘qS rN   ©rÈ   r–  ©r(  r·   rN   rQ   rü   ý  r?  z-LatexPrinter._print_Union.<locals>.<listcomp>z \cup ©r   rò   r  ©r·   ÚuÚargs_strrN   rµ  rQ   Ú_print_Unionû  ó   
zLatexPrinter._print_Unionc                   r²  )Nc                   r³  rN   r´  r–  rµ  rN   rQ   rü   	  r?  z2LatexPrinter._print_Complement.<locals>.<listcomp>z \setminus r¶  r·  rN   rµ  rQ   Ú_print_Complement 	  r»  zLatexPrinter._print_Complementc                   r²  )Nc                   r³  rN   r´  r–  rµ  rN   rQ   rü   	  r?  z4LatexPrinter._print_Intersection.<locals>.<listcomp>z \cap r¶  r·  rN   rµ  rQ   Ú_print_Intersection	  r»  z LatexPrinter._print_Intersectionc                   r²  )Nc                   r³  rN   r´  r–  rµ  rN   rQ   rü   	  r?  z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>z \triangle r¶  r·  rN   rµ  rQ   Ú_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 )Nr  r   z^{%d}rž   c                 3  s   � | ]	}ˆ  |ˆ ¡V  qd S rÂ   r´  )râ   r{  rµ  rN   rQ   rå   	  s   € 
ÿz1LatexPrinter._print_ProductSet.<locals>.<genexpr>)r   r/  Úsetsr#   rÈ   r  ©r·   r‚  rN   rµ  rQ   Ú_print_ProductSet	  s    ÿzLatexPrinter._print_ProductSetc                 C  r  )Nz	\emptysetrN   r  rN   rN   rQ   Ú_print_EmptySet	  r!  zLatexPrinter._print_EmptySetc                 C  r  )Nz
\mathbb{N}rN   ©r·   rq  rN   rN   rQ   Ú_print_Naturals	  r!  zLatexPrinter._print_Naturalsc                 C  r  )Nz\mathbb{N}_0rN   rÃ  rN   rN   rQ   Ú_print_Naturals0	  r!  zLatexPrinter._print_Naturals0c                 C  r  ©Nz
\mathbb{Z}rN   r°  rN   rN   rQ   Ú_print_Integers	  r!  zLatexPrinter._print_Integersc                 C  r  ©Nz
\mathbb{Q}rN   r°  rN   rN   rQ   Ú_print_Rationals"	  r!  zLatexPrinter._print_Rationalsc                 C  r  ©Nz
\mathbb{R}rN   r°  rN   rN   rQ   Ú_print_Reals%	  r!  zLatexPrinter._print_Realsc                 C  r  ©Nz
\mathbb{C}rN   r°  rN   rN   rQ   Ú_print_Complexes(	  r!  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ã   rT  rû   rN   rQ   rå   .	  s   €& z/LatexPrinter._print_ImageSet.<locals>.<genexpr>rþ   c                 s  s   � | ]}d | V  qdS )ú	%s \in %sNrN   )râ   ÚxyrN   rN   rQ   rå   /	  rÑ  z!\left\{%s\; \middle|\; %s\right\})rG   rÊ   Ú	signaturerÛ  Ú	base_setsr  rÃ   )r·   rP   rÊ   ÚsigZxysZxinysrN   rû   rQ   Ú_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ù   rN   rú   ©râ   r6  rû   rN   rQ   rü   3	  rý   z4LatexPrinter._print_ConditionSet.<locals>.<listcomp>z"\left\{%s\; \middle|\; %s \right\}z3\left\{%s\; \middle|\; %s \in %s \wedge %s \right\})r  r   rv  Úbase_setr   ÚUniversalSetrÃ   Ú	condition©r·   rP   Z
vars_printrN   rû   rQ   Ú_print_ConditionSet2	  s   ÿ

üz LatexPrinter._print_ConditionSetc                 C  ó   |   |jd ¡}d |¡S )Nr   z\mathcal{{P}}\left({}\right)©rÃ   rò   r½   )r·   rÊ   Z	arg_printrN   rN   rQ   Ú_print_PowerSet>	  s   
zLatexPrinter._print_PowerSetc                   s8   d  ‡ fdd„|jD ƒ¡}dˆ  |j¡|ˆ  |j¡f S )Nrþ   c                   rù   rN   rú   rÔ  rû   rN   rQ   rü   C	  rý   z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z)\left\{%s\; \middle|\; %s \in %s \right\})r  rÒ  rÃ   rÊ   r¿  rØ  rN   rû   rQ   Ú_print_ComplexRegionB	  s   

ýz!LatexPrinter._print_ComplexRegionc                   s   dt ‡ fdd„|jD ƒƒ S )NrÎ  c                 3  rÞ   rÂ   rú   rd  rû   rN   rQ   rå   J	  ræ   z/LatexPrinter._print_Contains.<locals>.<genexpr>)r›  rò   r  rN   rû   rQ   Ú_print_ContainsI	  ó   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¾   rN   rN   rQ   Ú_print_FourierSeriesL	  s   z!LatexPrinter._print_FourierSeriesc                 C  rÇ  rÂ   )r  Úinfiniter¾   rN   rN   rQ   Ú_print_FormalPowerSeriesQ	  rÊ  z%LatexPrinter._print_FormalPowerSeriesc                 C  s
   d|j  S )Nz\mathbb{F}_{%s})ÚmodrÒ   rN   rN   rQ   Ú_print_FiniteFieldT	  rÀ   zLatexPrinter._print_FiniteFieldc                 C  r  rÆ  rN   rÒ   rN   rN   rQ   Ú_print_IntegerRingW	  r!  zLatexPrinter._print_IntegerRingc                 C  r  rÈ  rN   rÒ   rN   rN   rQ   Ú_print_RationalFieldZ	  r!  z!LatexPrinter._print_RationalFieldc                 C  r  rÊ  rN   rÒ   rN   rN   rQ   Ú_print_RealField]	  r!  zLatexPrinter._print_RealFieldc                 C  r  rÌ  rN   rÒ   rN   rN   rQ   Ú_print_ComplexField`	  r!  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Ê   rî  ré  rN   rN   rQ   Ú_print_PolynomialRingc	  ó   z"LatexPrinter._print_PolynomialRingc                 C  rì  )Nrþ   rë  rí  rï  rN   rN   rQ   Ú_print_FractionFieldh	  rñ  z!LatexPrinter._print_FractionFieldc                 C  s<   |   |j¡}d t| j |jƒ¡}d}|jsd}d|||f S )Nrþ   r¢   zS_<^{-1}z%s%s\left[%s\right])rÃ   rî  r  rÄ  ré  Úis_Poly)r·   rÊ   rî  ré  ÚinvrN   rN   rQ   Ú_print_PolynomialRingBasem	  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r¨d|d  |d< d |¡}tt| j|jƒƒ}d	|  | ¡ ¡ }d
 |g| |g ¡}|tv rÖd||f }|S d||f }|S )Nr¢   r   r  r  r;  r²  rœ   )r²  r;  z	domain=%srþ   z\%s {\left(%s \right)}z$\operatorname{%s}{\left( %s \right)})r   r  r  r  rÃ   ÚgensÚpowrØ   r   ru  ÚextendrÐ   r�  Úpopr  rf  rÄ  Ú
get_domainrô  )r·   Úpolyr  r  Úmonomr©  Ús_monomrŒ   r÷   Ús_coeffÚs_termÚmodifierrÊ   rö  rî  rò   rË   rN   rN   rQ   Ú_print_Polyu	  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Ê   rO  rô  )r·   r:   r  rÊ   rO  rN   rN   rQ   Ú_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º  rô  r  )r·   rÊ   r  rò   rN   rN   rQ   Ú_print_RootSumº	  s   ÿzLatexPrinter._print_RootSumc                 C  r  )Nú\omegarN   rÒ   rN   rN   rQ   Ú_print_OrdinalOmegaÇ	  r!  z LatexPrinter._print_OrdinalOmegac                 C  sF   |j \}}|dkr|dkrd ||¡S d |¡S |dkr!d |¡S dS )Nr  z{} \omega^{{{}}}z	{} \omegaz\omega^{{{}}}r  )rò   r½   )r·   rÊ   r÷   ÚmulrN   rN   rQ   Ú_print_OmegaPowerÊ	  s   


zLatexPrinter._print_OmegaPowerc                   s   d  ‡ fdd„|jD ƒ¡S )Nr  c                   rù   rN   rú   r*  rû   rN   rQ   rü   Ø	  rý   z/LatexPrinter._print_Ordinal.<locals>.<listcomp>)r  rò   rÒ   rN   rû   rQ   Ú_print_Ordinal×	  s   zLatexPrinter._print_Ordinalc                 C  s   | j d }| | td|¡S )Nr    z	{%s}^{%d})r±   rn   r    )r·   rû  r†   rN   rN   rQ   Ú_print_PolyElementÚ	  s   
zLatexPrinter._print_PolyElementc                 C  s:   |j dkr|  |j¡S |  |j¡}|  |j ¡}d||f S )Nr  rs  )rx  rÃ   rw  )r·   r9   rw  rx  rN   rN   rQ   Ú_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 )Nr  r   zE_{%s}r†  rë  rQ  )r·   rÊ   r÷   r¼  rã   rË   rN   rN   rQ   Ú_print_euleræ	  s   &zLatexPrinter._print_eulerc                 C  r¡  )NzC_{%s}r   r†  r’  r&  rN   rN   rQ   Ú_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¢   r  r   rr  ©r½   rÃ   rò   )r·   rÊ   rP   ÚinverserN   rN   rQ   Ú_print_UnifiedTransformõ	  s   >z$LatexPrinter._print_UnifiedTransformc                 C  ó   |   |d¡S )NÚM©r  rÒ   rN   rN   rQ   Ú_print_MellinTransformø	  rÊ  z#LatexPrinter._print_MellinTransformc                 C  ó   |   |dd¡S )Nr  Tr  rÒ   rN   rN   rQ   Ú_print_InverseMellinTransformû	  rô   z*LatexPrinter._print_InverseMellinTransformc                 C  r  )NÚLr  rÒ   rN   rN   rQ   Ú_print_LaplaceTransformþ	  rÊ  z$LatexPrinter._print_LaplaceTransformc                 C  r  )Nr  Tr  rÒ   rN   rN   rQ   Ú_print_InverseLaplaceTransform
  rô   z+LatexPrinter._print_InverseLaplaceTransformc                 C  r  rž  r  rÒ   rN   rN   rQ   Ú_print_FourierTransform
  rÊ  z$LatexPrinter._print_FourierTransformc                 C  r  )NrŸ  Tr  rÒ   rN   rN   rQ   Ú_print_InverseFourierTransform
  rô   z+LatexPrinter._print_InverseFourierTransformc                 C  r  )NÚSINr  rÒ   rN   rN   rQ   Ú_print_SineTransform

  rÊ  z!LatexPrinter._print_SineTransformc                 C  r  )Nr  Tr  rÒ   rN   rN   rQ   Ú_print_InverseSineTransform
  rô   z(LatexPrinter._print_InverseSineTransformc                 C  r  )NÚCOSr  rÒ   rN   rN   rQ   Ú_print_CosineTransform
  rÊ  z#LatexPrinter._print_CosineTransformc                 C  r  )Nr"  Tr  rÒ   rN   rN   rQ   Ú_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À  rN   rN   rQ   Ú
_print_DMP
  s   
þÿzLatexPrinter._print_DMPc                 C  rk  rÂ   )r(  rÀ  rN   rN   rQ   Ú
_print_DMF
  rÀ   zLatexPrinter._print_DMFc                 C  s   |   t|jƒ¡S rÂ   ©rÃ   r   r  )r·   r‰  rN   rN   rQ   Ú_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¢   r  zW%s\left(%s\right)zW{0}_{{{1}}}\left({2}\right))rÃ   rò   r/  r½   )r·   rÊ   r÷   Úarg0ÚresultÚarg1rN   rN   rQ   Ú_print_LambertW%
  s   þzLatexPrinter._print_LambertWc                 C  ó   d  |  |jd ¡¡S )Nz!\operatorname{{E}}\left[{}\right]r   r  rÒ   rN   rN   rQ   Ú_print_Expectation/
  ó   zLatexPrinter._print_Expectationc                 C  r0  )Nz#\operatorname{{Var}}\left({}\right)r   r  rÒ   rN   rN   rQ   Ú_print_Variance2
  r2  zLatexPrinter._print_Variancec                   s    d  d ‡ fdd„|jD ƒ¡¡S )Nz#\operatorname{{Cov}}\left({}\right)rþ   c                 3  rÞ   rÂ   rú   r*  rû   rN   rQ   rå   6
  ræ   z1LatexPrinter._print_Covariance.<locals>.<genexpr>)r½   r  rò   rÒ   rN   rû   rQ   Ú_print_Covariance5
  s    zLatexPrinter._print_Covariancec                 C  r0  )Nz!\operatorname{{P}}\left({}\right)r   r  rÒ   rN   rN   rQ   Ú_print_Probability8
  r2  zLatexPrinter._print_Probabilityc                 C  s$   |   |j¡}|   |j¡}d||f S )Nz%s\rightarrow %s)rÃ   rî  Úcodomain)r·   Úmorphismrî  r6  rN   rN   rQ   Ú_print_Morphism;
  s   zLatexPrinter._print_Morphismc                 C  s&   |   |j¡|   |j¡}}d||f S )Nrs  )rÃ   r×  Úden)r·   rÊ   r×  r9  rN   rN   rQ   Ú_print_TransferFunction@
  s   z$LatexPrinter._print_TransferFunctionc                   s(   t ˆ jƒ}‡ ‡fdd„}d t||ƒ¡S )Nc                   s   ˆ  | tˆ ƒd¡S r  )rÈ   r   rc  rT  rN   rQ   rR   F
  s    ÿz,LatexPrinter._print_Series.<locals>.<lambda>rœ   )rf  rò   r  rÄ  ©r·   rÊ   rò   r  rN   rT  rQ   Ú_print_SeriesD
  s   
zLatexPrinter._print_Seriesc                   s@   ddl m‰  tˆjƒd d d… }‡ ‡‡fdd„}d t||ƒ¡S )Nr   )ÚMIMOParallelr  c                   s&   t | ˆ ƒrˆ | tˆƒd¡S ˆ | ¡S r  )rb  rÈ   r   rÃ   rc  ©r=  rÊ   r·   rN   rQ   rR   M
  s
   ÿÿ
z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>z\cdot)Úsympy.physics.control.ltir=  rf  rò   r  rÄ  r;  rN   r>  rQ   Ú_print_MIMOSeriesJ
  s   zLatexPrinter._print_MIMOSeriesc                 C  ó   d  t| j|jƒ¡S ©Nr  ©r  rÄ  rÃ   rò   rÒ   rN   rN   rQ   Ú_print_ParallelQ
  rÌ  zLatexPrinter._print_Parallelc                 C  rA  rB  rC  rÒ   rN   rN   rQ   Ú_print_MIMOParallelT
  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||ƒr†t|j|ƒr†||kr}||Ž }	n%||g|¢R Ž }	n||kr�||Ž }	n|j|kr™||Ž }	n	|g |¢|¢R Ž }	|  	|¡}
|  	|¡}|  	|	¡}|j
dkr¸dnd}d|
|||f S )Nr   )ÚTransferFunctionÚSeriesr  r  r;  r²  z\frac{%s}{%s %s %s})Úsympy.physics.controlrF  rG  Úsys1r6  rb  rf  rò   Úsys2rÃ   rÎ  )r·   rÊ   rF  rG  r×  ÚtfÚnum_arg_listÚden_arg_listZ
den_term_1Z
den_term_2rw  Zdenom_1Zdenom_2Ú_signrN   rN   rQ   Ú_print_FeedbackW
  s8   
ÿÿ








zLatexPrinter._print_Feedbackc                 C  sL   ddl m} |  ||j|jƒ¡}|  |j¡}|jdkrdnd}d|||f S )Nr   )Ú
MIMOSeriesr  r;  r²  z)\left(I_{\tau} %s %s\right)^{-1} \cdot %s)rH  rP  rÃ   rJ  rI  rÎ  )r·   rÊ   rP  Úinv_matrI  rN  rN   rN   rQ   Ú_print_MIMOFeedback{
  s
   z LatexPrinter._print_MIMOFeedbackc                 C  s   |   |j¡}d| S )Nz%s_\tau)rÃ   Ú	_expr_matr  rN   rN   rQ   Ú_print_TransferFunctionMatrix‚
  s   z*LatexPrinter._print_TransferFunctionMatrixc                 C  s   d  |jj|j¡S )Nz\text{{{}}}_{{{}}})r½   r   r  rq  rÒ   rN   rN   rQ   Ú
_print_DFT†
  rE  zLatexPrinter._print_DFTc                 C  s&   |   t|jƒ¡}|  |¡}d||f S )Nz%s:%s)rÃ   r   r  r8  )r·   r7  Úpretty_nameÚpretty_morphismrN   rN   rQ   Ú_print_NamedMorphismŠ
  s   
z!LatexPrinter._print_NamedMorphismc                 C  s"   ddl m} |  ||j|jdƒ¡S )Nr   )ÚNamedMorphismÚid)Úsympy.categoriesrY  rX  rî  r6  )r·   r7  rY  rN   rN   rQ   Ú_print_IdentityMorphism�
  s   
ÿz$LatexPrinter._print_IdentityMorphismc                   s<   ‡ fdd„|j D ƒ}| ¡  d |¡d }ˆ  |¡}|| S )Nc                   s   g | ]
}ˆ   t|jƒ¡‘qS rN   r*  )râ   Ú	componentrû   rN   rQ   rü   —
  s    ÿz9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z\circ r  )r¸  Úreverser  r8  )r·   r7  Úcomponent_names_listÚcomponent_namesrW  rN   rû   rQ   Ú_print_CompositeMorphism”
  s   
ÿ
z%LatexPrinter._print_CompositeMorphismc                 C  s   d  |  t|jƒ¡¡S ©Nrß  )r½   rÃ   r   r  )r·   r7  rN   rN   rQ   Ú_print_CategoryŸ
  r2  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_resultrN   rN   rQ   Ú_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}
rt   rœ   r  ú& r   Ú
z\end{array}
)Úwidthr.  ÚheightÚlatex)r·   Úgridrh  rŒ   r§   rN   rN   rQ   Ú_print_DiagramGrid®
  s   €
zLatexPrinter._print_DiagramGridc                 C  ó   d  |  |j¡|  |j¡¡S )Nz{{{}}}^{{{}}})r½   rÃ   r%  r@  ©r·   r  rN   rN   rQ   Ú_print_FreeModuleÀ
  rß  zLatexPrinter._print_FreeModulec                   s   d  d ‡ fdd„|D ƒ¡¡S )Nú\left[ {} \right]r  c                 3  ó"   � | ]}d ˆ   |¡ d V  qdS ©rb   rM   Nrú   rá   rû   rN   rQ   rå   Å
  ó   € 
ÿz8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>)r½   r  )r·   r¼  rN   rû   rQ   Ú_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 rN   )rÃ   r%  r&  rá   ©r¼  r·   rN   rQ   rü   É
  ó    z<LatexPrinter._print_SubModule.<locals>.<listcomp>.<listcomp>rN   ©râ   Úgry  rN   rQ   rü   É
  s     z1LatexPrinter._print_SubModule.<locals>.<listcomp>c                 S  rL   )Nrb   rM   rN   ©rB   rN   rN   rQ   rR   Ê
  rS   z/LatexPrinter._print_SubModule.<locals>.<lambda>c                 S  rL   )Nz\left[ z \right]rN   r}  rN   rN   rQ   rR   Ë
  rS   r  c                 3  s0   � | ]}ˆ ˆd   ‡ fdd„|D ƒ¡ƒƒV  qdS )r  c                 3  s   � | ]}ˆ |ƒV  qd S rÂ   rN   rá   )ÚcurlyrN   rQ   rå   Ì
  rÑ  z:LatexPrinter._print_SubModule.<locals>.<genexpr>.<genexpr>N)r  r{  )r~  ÚsquarerN   rQ   rå   Ì
  s   €. z0LatexPrinter._print_SubModule.<locals>.<genexpr>ú\left\langle {} \right\rangle)rö  r  r½   ©r·   r¼  rö  Ú
gens_latexrN   )r~  r¼  r·   r  rQ   Ú_print_SubModuleÈ
  s
   
zLatexPrinter._print_SubModulec                   s$   d  ‡ fdd„|jD ƒ¡}d |¡S )Nr  c                   s   g | ]}d ˆ   |¡ d ‘qS )rb   rM   rú   r{  rû   rN   rQ   rü   Ð
  rz  z9LatexPrinter._print_SubQuotientModule.<locals>.<listcomp>r€  )r  rö  r½   )r·   r¼  r‚  rN   rû   rQ   Ú_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 rN   )r%  r&  rá   ©r¼  rN   rQ   rü   Ô
  r÷  z>LatexPrinter._print_ModuleImplementedIdeal.<locals>.<listcomp>r  c                 3  ru  rv  rú   rá   rû   rN   rQ   rå   Õ
  s   €  z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>r€  )Ú_modulerö  r  r½   r�  rN   ry  rQ   Ú_print_ModuleImplementedIdealÓ
  s   
z*LatexPrinter._print_ModuleImplementedIdealc                   sD   ‡ fdd„|j D ƒ}|d gdd„ t|dd … dƒD ƒ }d |¡S )Nc                   s    g | ]}ˆ j |td  dd�‘qS )r	   Trþ  )rÈ   r    r–  rû   rN   rQ   rü   Û
  s    ÿz2LatexPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]
\}}|d  | ‘qS )rœ   rN   )râ   rŒ   r§   rN   rN   rQ   rü   Ý
  rU  r  Úijkr  )rò   rÛ  r  )r·   rÊ   rP   rz  rN   rû   rQ   Ú_print_QuaternionØ
  s
   
ÿ&
zLatexPrinter._print_Quaternionc                 C  rq  ©Nz\frac{{{}}}{{{}}})r½   rÃ   r%  Ú
base_ideal)r·   ÚRrN   rN   rQ   Ú_print_QuotientRingà
  ó   
ÿz LatexPrinter._print_QuotientRingc                 C  s(   |   |j |¡¡}d ||   |jj¡¡S )Nú{{{}}} + {{{}}})rÃ   r%  r&  r½   r‹  )r·   rã   Zx_latexrN   rN   rQ   Ú_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 rN   )Úmoduler%  r&  rá   r…  rN   rQ   rü   ë
  r÷  z=LatexPrinter._print_QuotientModuleElement.<locals>.<listcomp>rt  r  c                 3  ru  rv  rú   rá   rû   rN   rQ   rå   ì
  rw  z<LatexPrinter._print_QuotientModuleElement.<locals>.<genexpr>r�  )Údatar½   r  rÃ   r‘  Úkilled_module)r·   r¼  r’  Z
data_latexrN   ry  rQ   Ú_print_QuotientModuleElementê
  s   
ÿÿz)LatexPrinter._print_QuotientModuleElementc                 C  rq  rŠ  )r½   rÃ   ró   r“  rr  rN   rN   rQ   Ú_print_QuotientModuleñ
  rŽ  z"LatexPrinter._print_QuotientModulec                 C  s(   d  |  | ¡ ¡|  |j¡|  |j¡¡S )Nz{{{}}} : {{{}}} \to {{{}}})r½   rÃ   Ú_sympy_matrixrî  r6  )r·   r  rN   rN   rQ   Ú_print_MatrixHomomorphismö
  s   ÿz&LatexPrinter._print_MatrixHomomorphismc                 C  sL   |   |jj¡\}}}d| }|r|dd |¡ 7 }|r$|dd |¡ 7 }|S )Nr
  ræ  rœ   rÃ  )rÝ  r  r  )r·   Úmanifoldr  rÜ  rÜ  rN   rN   rQ   Ú_print_Manifoldú
  s   zLatexPrinter._print_Manifoldc                 C  r  )Nz\text{%s}_{%s})rÃ   r  r˜  )r·   ÚpatchrN   rN   rQ   Ú_print_Patch  rß  zLatexPrinter._print_Patchc                 C  s(   d|   |j¡|   |jj¡|   |j¡f S )Nz\text{%s}^{\text{%s}}_{%s})rÃ   r  rš  r˜  )r·   ZcoordsysrN   rN   rQ   Ú_print_CoordSystem  s    ÿzLatexPrinter._print_CoordSystemc                 C  s   d|   |j¡ S )Nz\mathbb{\nabla}_{%s})rÃ   Z_wrt)r·   ZcvdrN   rN   rQ   Ú_print_CovarDerivativeOp  r”  z%LatexPrinter._print_CovarDerivativeOpc                 C  ó$   |j j|j j}d |  t|ƒ¡¡S rb  ©Ú
_coord_sysré  Ú_indexr  r½   rÃ   r   ©r·   ÚfieldrÞ  rN   rN   rQ   Ú_print_BaseScalarField  ó   z#LatexPrinter._print_BaseScalarFieldc                 C  rž  )Nz\partial_{{{}}}rŸ  r¢  rN   rN   rQ   Ú_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_fieldra  r   ré  r¡  r  r½   rÃ   r   )r·   Údiffr£  rÞ  rN   rN   rQ   Ú_print_Differential  s   


z LatexPrinter._print_Differentialc                 C  rÚ  )Nr   z"\operatorname{{tr}}\left({}\right)rÛ  )r·   r‚  ÚcontentsrN   rN   rQ   Ú	_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ö   rN   rN   rQ   Ú_print_totient&  ó
   ÿzLatexPrinter._print_totientc                 C  r¬  )Nz(\left(\lambda\left(%s\right)\right)^{%s}r   z\lambda\left(%s\right)r’  rö   rN   rN   rQ   Ú_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 )Nrr  ú_%s\left(%s\right)r  r   r  z\sigma^{%s}%sz\sigma%sr¢  r&  rN   rN   rQ   Ú_print_divisor_sigma2  ó   

ÿz!LatexPrinter._print_divisor_sigmac                 C  r°  )Nrr  r±  r  r   r  z\sigma^*^{%s}%sz
\sigma^*%sr¢  r&  rN   rN   rQ   Ú_print_udivisor_sigma<  r³  z"LatexPrinter._print_udivisor_sigmac                 C  r¬  )Nz$\left(\nu\left(%s\right)\right)^{%s}r   z\nu\left(%s\right)r’  rö   rN   rN   rQ   Ú_print_primenuF  r®  zLatexPrinter._print_primenuc                 C  r¬  )Nz'\left(\Omega\left(%s\right)\right)^{%s}r   z\Omega\left(%s\right)r’  rö   rN   rN   rQ   Ú_print_primeomegaL  r®  zLatexPrinter._print_primeomegac                 C  s
   t |jƒS rÂ   )rn   r  r¾   rN   rN   rQ   Ú
_print_StrR  rÀ   zLatexPrinter._print_Strc                 C  r  rÂ   )rÃ   r   rÒ   rN   rN   rQ   Ú_print_floatU  rô   zLatexPrinter._print_floatc                 C  ó   t |ƒS rÂ   ©rn   rÒ   rN   rN   rQ   Ú
_print_intX  r  zLatexPrinter._print_intc                 C  r¹  rÂ   rº  rÒ   rN   rN   rQ   Ú
_print_mpz[  r  zLatexPrinter._print_mpzc                 C  r¹  rÂ   rº  rÒ   rN   rN   rQ   Ú
_print_mpq^  r  zLatexPrinter._print_mpqc                 C  r¹  rÂ   rº  rÒ   rN   rN   rQ   Ú_print_fmpza  r  zLatexPrinter._print_fmpzc                 C  r¹  rÂ   rº  rÒ   rN   rN   rQ   Ú_print_fmpqd  r  zLatexPrinter._print_fmpqc                 C  s   d  tt|jƒƒ¡S )Nz"\operatorname{{Q}}_{{\text{{{}}}}})r½   ru   rn   r  rÒ   rN   rN   rQ   Ú_print_Predicateg  rÌ  zLatexPrinter._print_Predicatec                   s:   |j }|j}ˆ  |¡}d ‡ fdd„|D ƒ¡}d||f S )Nrþ   c                   rù   rN   rú   rd  rû   rN   rQ   rü   n  rý   z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>z%s(%s))r§  Ú	argumentsrÃ   r  )r·   rÊ   Úpredrò   Z
pred_latexZ
args_latexrN   rû   rQ   Ú_print_AppliedPredicatej  s
   
z$LatexPrinter._print_AppliedPredicatec                   s   t ƒ  |¡}dt|ƒ S )Nz\mathtt{\text{%s}})ÚsuperÚemptyPrinterru   rÓ  ©r   rN   rQ   rÅ  q  s   zLatexPrinter.emptyPrinterrÂ   rt  )FF)ro   rÌ   )rÊ   rn   )r  r  )rÊ   r   )rÊ   r   )rŒ  rn   ro   rn   )rÊ   r­  )rY  rn   ro   rn   )rÊ   r   ro   rn   r—  )rv  rn   ro   rn   r  )FN)r…   )rÊ   r   )r  rn   ro   rØ  )rÞ  rn   ro   rn   )rÊ   r%   )rJ  rK  )F(C  r  Ú
__module__Ú__qualname__Úprintmethodr™   Ú__annotations__r°   r¿   rÁ   rÈ   r“   rÉ   rÓ   rÚ   rð   rñ   rÕ   r×   rø   r  r  Ú_print_BooleanTrueÚ_print_BooleanFalser  r  r$  r4  r7  rF  rN  rT  rV  rW  rZ  r[  r|  r€  r„  r‹  rŠ  r“  rª  r¬  rÂ  rÆ  rÉ  rÍ  rØ  rÞ  rê  rñ  rõ  r  r  r  Úpropertyr  r  r  r   r$  Z
_print_MinZ
_print_Maxr'  r)  r*  r,  r0  r2  r9  r<  r@  rB  rC  r7  r6  rF  rI  rJ  rK  rM  rP  rR  rS  rU  rY  r[  r\  r_  ra  Ú_print_gammarb  re  rf  rg  rk  rm  rn  ro  rr  ru  ry  rz  r~  r  r�  rƒ  r„  r…  r†  r‡  rˆ  r‰  rŒ  rŽ  r’  r•  r—  r˜  rœ  r   r¡  r£  r¥  r¦  r¨  r«  r¯  r³  rµ  r¶  r·  r¸  r¹  rº  r¿  rÀ  rÆ  rÇ  rÈ  rË  rÍ  rÏ  rÔ  r×  Ú_print_RandomSymbolrÝ  rÿ   rè  rë  rø  rý  r   r
  r  r  r  r  r  r   r"  r#  r,  r.  r0  r1  r2  r7  r;  r<  r>  rI  rP  rR  rS  rW  rX  rY  rZ  r[  r\  r]  r^  rb  rh  rj  rl  rn  rq  rr  rs  ru  rw  rx  ry  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Ó  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/  r1  r3  r4  r5  r8  r:  r<  r@  rD  rE  rO  rR  rT  rU  Z_print_IDFTrX  r\  ra  rc  ri  rp  rs  rx  rƒ  r„  r‡  r‰  r�  r�  r”  r•  r—  r™  r›  rœ  r�  r¤  r¦  r©  r«  r­  r¯  r²  r´  rµ  r¶  r·  r¸  r»  r¼  r½  r¾  r¿  rÀ  rÃ  rÅ  Ú__classcell__rN   rN   rÆ  rQ   rv   Ž   sÔ  
 ÿþýüûúùø	÷
öõôóòñðïæ=

	!s-!
$ L

										
7



*9		
$	

rv   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}}}'"
    rp   T)r±  r^  N)Útex_greek_dictionaryr¶   r0  Úgreek_letters_setÚother_symbolsr#  rm   ro  r/  r�  rÛ  )rP   rË   r±  rN   rN   rQ   rÛ  x  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.

    )rv   rÉ   ©rÊ   r¸   rN   rN   rQ   rn  —  s    Xrn  c                 K  s   t t| fi |¤Žƒ dS )z`Prints LaTeX representation of the given expression. Takes the same
    settings as ``latex()``.N)Úprintrn  rØ  rN   rN   rQ   Úprint_latexq  s   rÚ  r  ú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r‹d| }d}|dkr§|dkr•d}|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.

    Zeqnarrayz\begin{eqnarray}
z& = &z	\nonumberz
\end{eqnarray}TZIEEEeqnarrayz\begin{IEEEeqnarray}{rCl}
z
\end{IEEEeqnarray}rÛ  z\begin{align*}
z= &r¢   z
\end{align*}FzUnknown environment: {}z\dotsr  r;  z& & rj  r   rk  r   r  r²  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s}NrN   )rv   r²   r½   Úas_ordered_termsr/  r.  re  rÉ   )râ  rä  Zterms_per_lineÚenvironmentZuse_dotsr¸   r�  r-  Z
first_termZnonumberZend_termZdoubleetrˆ  r  Zn_termsZ
term_countrŒ   r  Z
term_startZterm_endrÎ  rN   rN   rQ   Úmultiline_latexx  sn   Cÿ

ÿ
rÞ  )rP   rn   ro   rn   )r  rÛ  F)JÚ__doc__Ú
__future__r   Útypingr   r   r   rB  Ú
sympy.corer   r   r   r	   r
   r   r   r   Úsympy.core.alphabetsr   Úsympy.core.containersr   Úsympy.core.functionr   r   r   Zsympy.core.operationsr   Úsympy.core.powerr   Úsympy.core.sortingr   Úsympy.core.sympifyr   r5  r   r   r   Úsympy.printing.precedencer   Úsympy.printing.printerr   r   Úsympy.printing.conventionsr   r   r   r    Zmpmath.libmp.libmpfr!   r"   r?  Úsympy.utilities.iterablesr#   r$   r7   Úsympy.tensor.arrayr%   Zsympy.vector.basisdependentr&   rô  rÕ  r×  rm   rÊ  Ú	frozensetrÖ  Úcompilerk  ru   rv   rÛ  rn  rÚ  rÞ  rN   rN   rN   rQ   Ú<module>   sZ   (ÿþýüûúùø	÷
öõôóòñðïîíìëêéèçæåäãâá à!ß"Þ#Ü'þýüûúùø	÷
öõôóòñðîíåþ
                     

 Z