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ú\GammaÚDeltaz\DeltaÚEpsilonz
\mathrm{E}ÚZetaz
\mathrm{Z}ÚEtaz
\mathrm{H}ÚThetaz\ThetaÚIotaz
\mathrm{I}ÚKappaz
\mathrm{K}ÚLambdaz\LambdaÚMuz
\mathrm{M}ÚNuz
\mathrm{N}ÚXiz\XiÚomicronÚoÚOmicronz
\mathrm{O}ÚPiz\PiÚRhoz
\mathrm{P}ÚSigmaz\SigmaÚTauz
\mathrm{T}ÚUpsilonz\UpsilonÚPhiz\PhiÚChiz
\mathrm{X}ÚPsiz\PsiÚOmegaz\OmegaÚlamdaz\lambdaZLamdaZkhiz\chiZKhiZ
varepsilonz\varepsilonZvarkappaz	\varkappaZvarphiz\varphiZvarpiz\varpiZvarrhoz\varrhoz	\varsigmaz	\vartheta)ÚvarsigmaZvartheta>
   ÚellZbethÚethZalephZhslashZgimelZhbarZdalethZmhoÚwpÚmathringc                 C  ó   d|  d S )Nz
\mathring{Ú}© ©Úsr_   r_   úe/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/sympy/printing/latex.pyÚ<lambda>[   ó    rc   Úddddotc                 C  r]   )Nz\ddddot{r^   r_   r`   r_   r_   rb   rc   \   rd   Údddotc                 C  r]   )Nz\dddot{r^   r_   r`   r_   r_   rb   rc   ]   rd   Úddotc                 C  r]   )Nz\ddot{r^   r_   r`   r_   r_   rb   rc   ^   rd   Údotc                 C  r]   )Nz\dot{r^   r_   r`   r_   r_   rb   rc   _   rd   Úcheckc                 C  r]   )Nz\check{r^   r_   r`   r_   r_   rb   rc   `   rd   Úbrevec                 C  r]   )Nz\breve{r^   r_   r`   r_   r_   rb   rc   a   rd   Úacutec                 C  r]   )Nz\acute{r^   r_   r`   r_   r_   rb   rc   b   rd   Úgravec                 C  r]   )Nz\grave{r^   r_   r`   r_   r_   rb   rc   c   rd   Útildec                 C  r]   )Nz\tilde{r^   r_   r`   r_   r_   rb   rc   d   rd   Úhatc                 C  r]   )Nz\hat{r^   r_   r`   r_   r_   rb   rc   e   rd   Úbarc                 C  r]   )Nz\bar{r^   r_   r`   r_   r_   rb   rc   f   rd   Úvecc                 C  r]   )Nz\vec{r^   r_   r`   r_   r_   rb   rc   g   rd   Úprimec                 C  r]   ©NÚ{z}'r_   r`   r_   r_   rb   rc   h   rd   Úprmc                 C  r]   rr   r_   r`   r_   r_   rb   rc   i   rd   Úboldc                 C  r]   ©Nz\boldsymbol{r^   r_   r`   r_   r_   rb   rc   k   rd   Úbmc                 C  r]   rv   r_   r`   r_   r_   rb   rc   l   rd   c                 C  r]   )Nz	\mathcal{r^   r_   r`   r_   r_   rb   rc   m   rd   c                 C  r]   )Nz	\mathscr{r^   r_   r`   r_   r_   rb   rc   n   rd   c                 C  r]   )Nz
\mathfrak{r^   r_   r`   r_   r_   rb   rc   o   rd   c                 C  r]   )Nz\left\|{z	}\right\|r_   r`   r_   r_   rb   rc   q   rd   c                 C  r]   )Nz\left\langle{z}\right\rangler_   r`   r_   r_   rb   rc   r   rd   c                 C  r]   ©Nz\left|{z}\right|r_   r`   r_   r_   rb   rc   s   rd   c                 C  r]   rx   r_   r`   r_   r_   rb   rc   t   rd   )ÚcalZscrZfrakÚnormÚavgÚabsÚmagzdict[str, Callable[[str], str]]Úmodifier_dictz[0-9][} ]*$z(\d|\\frac{\d+}{\d+})ra   Ú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)ra   Úcr_   r_   rb   Úlatex_escape   s   r†   c                      s  e Zd ZU dZi dd“dd“dd“dd“dd	“d
d“dd“dd“dd“dd“dd“dd“dd“di “dd“dd“dd“ddddddddd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ldotrh   Útimesr—   Úmul_symbol_latexrh   Úmul_symbol_latex_numbers)Ú r­   r�   z\,z\:ú\;z\quadú)Ú])ú(r“   r�   z
\mathrm{i}z\text{i}Újz
\mathrm{j}z\text{j})Nr�   ÚriÚtir¸   ÚrjÚtjrœ   Úimaginary_unit_latexrŸ   z
\mathrm{d}z\text{d})NrŸ   ÚrdÚtdr§   Údiff_operator_latex)r   Ú__init__Ú	_settingsÚ
ValueErrorÚKeyErrorÚstripÚ_delim_dictÚget)ÚselfÚsettingsÚvalid_modesZmul_symbol_tableZimaginary_unit_tableÚ	imag_unitZdiff_operator_tabler§   r_   r_   rb   rÁ   ®   sf   

üÿÿÿÿÿ
ÿÿ€ú	ù
	ü
zLatexPrinter.__init__r€   r   c                 C  ó
   d  |¡S )Nz\left({}\right)©Úformat©rÈ   ra   r_   r_   rb   Ú_add_parensë   ó   
zLatexPrinter._add_parensc                 C  rÌ   )Nz\left( {}\right)rÍ   rÏ   r_   r_   rb   Ú_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_valr_   r_   rb   Úparenthesizeò   s   
zLatexPrinter.parenthesizec                 C  s*   d|v r| j d r|  |¡S d |¡S |S )z”
        Protect superscripts in s

        If the parenthesize_super option is set, protect with parentheses, else
        wrap in braces.
        rƒ   r¤   z{{{}}})rÂ   rÐ   rÎ   rÏ   r_   r_   rb   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_strr_   r_   rb   rÚ   
  s   

zLatexPrinter.doprintÚboolc                 C  s(   |j r|jp|jo|tjuo|jdu  S )zÁ
        Returns True if the expression needs to be wrapped in brackets when
        printed, False otherwise. For example: a + b => True; a => False;
        10 => False; -10 => True.
        F)Ú
is_IntegerÚis_nonnegativeÚis_Atomr   ÚNegativeOneÚis_Rational©rÈ   rÛ   r_   r_   rb   Ú_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ã   r_   r_   rb   Ú_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Û   r_   rb   Ú	<genexpr>O  ó   € z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>c                 3  rï   rÓ   rð   rò   rõ   r_   rb   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î   r_   rõ   rb   Ú_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õ   r_   rb   rö   _  r÷   z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>F)rü   rþ   r   ré   rã   r_   rõ   rb   Ú_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;   r_   r_   rb   ræ   e  s
   
ÿzLatexPrinter._mul_is_cleanc                 C  s   |   |j¡ S rÓ   )rä   Úbaserã   r_   r_   rb   rè   k  ó   zLatexPrinter._pow_is_cleanrÛ   c                 C  s   |d ur
d||f S |S )Nú\left(%s\right)^{%s}r_   ©rÈ   rÛ   Úexpr_   r_   rb   Ú_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 r_   ©rÔ   )ró   rL   ©rÈ   r_   rb   Ú
<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Úlsra   r_   r  rb   Ú_print_Basict  s   
zLatexPrinter._print_BasicÚeú!bool | BooleanTrue | BooleanFalsec                 C  ó   d| S ©Nú	\text{%s}r_   ©rÈ   r  r_   r_   rb   Ú_print_bool}  ó   zLatexPrinter._print_boolc                 C  r  r  r_   r  r_   r_   rb   Ú_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_texr_   r_   rb   Ú
_print_Add†  s   


zLatexPrinter._print_Addc                 C  sŽ   ddl m} |jdkrdS ||ƒ}|j}|j}|jd |d kr(||d gg }d}|D ]}|t|ƒ dd¡7 }q,| d	d
¡}| dd¡}|S )Nr   ©ÚPermutationú\left( \right)éÿÿÿÿé   r³   ú,r´   r“   z\left( r¶   ú\right))Ú sympy.combinatorics.permutationsr*  ÚsizeÚcyclic_formÚ
array_formr   r„   )rÈ   rÛ   r*  Z	expr_permÚsizr'  r�   r_   r_   rb   Ú_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
  r_   r  ©ró   r;   r  r_   rb   r  Á  r  z3LatexPrinter._print_Permutation.<locals>.<listcomp>c                   r
  r_   r  r;  r  r_   rb   r  Â  r  ú & z \\ z \begin{pmatrix} %s \end{pmatrix})r0  r*  Úsympy.utilities.exceptionsr6  Úprint_cyclicrÂ   rÇ   r5  r1  r3  ÚrangeÚlenr  )
rÈ   rÛ   r*  r6  r£   ÚlowerÚupperZrow1Úrow2Úmatr_   r  rb   Ú_print_Permutation©  s.   þù




zLatexPrinter._print_Permutationc                 C  s"   |j \}}d|  |¡|  |¡f S )Nz\sigma_{%s}(%s))r  rÔ   )rÈ   rÛ   ÚpermÚvarr_   r_   rb   Ú_print_AppliedPermutationÊ  s   
z&LatexPrinter._print_AppliedPermutationc           
      C  sö   t |jƒ}| jd rdnd}d| jv r| jd nd }d| jv r$| jd nd }t|j||||d�}| jd }d|v r`| d¡\}}	|	d	 d
krL|	dd … }	| jd dkrY| dd¡}d|||	f S |dkrfdS |dkrldS | jd dkry| dd¡}|S )Nr‰   FTr¥   r¦   )Ústrip_zerosÚ	min_fixedÚ	max_fixedr²   r  r   ú+r-  r¢   ÚcommaÚ.z{,}z%s%s10^{%s}z+infz\inftyz-infz- \infty)r!   Ú_precrÂ   Úmlib_to_strÚ_mpf_Úsplitr„   )
rÈ   rÛ   ÚdpsrÅ   ÚlowÚhighZstr_realÚ	separatorZmantr  r_   r_   rb   Ú_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Úvec2r_   r_   rb   Ú_print_Crossì  ó
   ÿzLatexPrinter._print_Crossc                 C  ó   |j }d|  |td ¡ S )Nz\nabla\times %sr	   ©Ú_exprrÙ   r    ©rÈ   rÛ   rp   r_   r_   rb   Ú_print_Curlò  ó   zLatexPrinter._print_Curlc                 C  ra  )Nz\nabla\cdot %sr	   rb  rd  r_   r_   rb   Ú_print_Divergenceö  rf  zLatexPrinter._print_Divergencec                 C  rX  )Nz%s \cdot %sr	   rY  r\  r_   r_   rb   Ú
_print_Dotú  r`  zLatexPrinter._print_Dotc                 C  ra  )Nz	\nabla %sr	   rb  ©rÈ   rÛ   Úfuncr_   r_   rb   Ú_print_Gradient   rf  zLatexPrinter._print_Gradientc                 C  ra  )Nz	\Delta %sr	   rb  ri  r_   r_   rb   Ú_print_Laplacian  rf  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²   r€   r   c                   sn   | j s
tˆ | ¡ƒS ˆjdvr|  ¡ }nt| jƒ}t|dd„ dd�\}}t|dd„ dd�\}}ˆ || | ƒS )N)ÚoldÚnonec                 S  s*   t | dƒpt | dƒpt| tƒot | jdƒS )NÚ_scale_factorÚis_physical_constant)ÚhasattrÚ
isinstancer   r  ©rô   r_   r_   rb   rc     s    
z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>T)Úbinaryc                 S  s
   t | dƒS )Nrp  )rr  rt  r_   r_   rb   rc     s   
 )rå   r   rÔ   r˜   Úas_ordered_factorsÚlistr  r$   )rÛ   r  ÚunitsZnonunitsÚprefixes)Úconvert_argsrÈ   r_   rb   Ú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³   rp  rq  r   r-  )rÿ   r   r"  )r$  rÔ   rr  r  r@  Ú_between_two_numbers_pÚsearchÚmatch)r  Z_texZlast_term_texr�   r&  r'  )Ú	numberseprÈ   rV  r_   rb   rz    s(   
ÿÿ
€z-LatexPrinter._print_Mul.<locals>.convert_argsc                 s  s   � | ]}t |tƒV  qd S rÓ   )rs  r
   r;  r_   r_   rb   rö   ;  r÷   z*LatexPrinter._print_Mul.<locals>.<genexpr>r-  Fú- r·   Tr³   )Úexactr,  )Úevaluater‘   rŒ   é   rƒ   )r   z\left(%s\right) / %sz%s / %sz\frac{1}{%s}%s\left(%s\right)z\frac{%s}{%s}%s\left(%s\right)z\frac{%s}{%s}%s%sz\frac{1}{%s}%s%sú\frac{%s}{%s}rµ   ©r€   r   )Zsympy.simplifyrm  rÂ   rs  r	   r  r   ÚOnerþ   rû   ré   r   r@  rR  r  rå   Úis_commutative)rÈ   rÛ   rm  r{  r  Zinclude_parensrÜ   ÚnumerÚdenomZsnumerZsdenomZldenomÚratioÚaÚbrô   r_   )rz  r  rÈ   rV  rb   Ú
_print_Mul  sr   


(€

ÿ
 

ÿÿzLatexPrinter._print_Mulc                 C  s&   |j r|  | ¡  ¡ ¡S |  | ¡ ¡S rÓ   )Ú
is_aliasedrÔ   Úas_polyÚas_exprrã   r_   r_   rb   Ú_print_AlgebraicNumber{  s   z#LatexPrinter._print_AlgebraicNumberc                 C  s@   |   |j¡}|jrd|› d�S |   |j ¡ ¡}d|› d|› d�S )Nú\left(r/  r  )rÔ   ÚpZis_inertÚalphar�  )rÈ   rÛ   r“  r”  r_   r_   rb   Ú_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š   rƒ  z	\sqrt{%s}r�   z\root{%d}{%s}z\sqrt[%d]{%s}z\frac{1}{%s}rŠ   r   z%s/%s©r  z
%s^{%s/%s}ú%s^{%s}r,  z\frac{1}{\frac{%s}{%s}}z\frac{1}{(\frac{%s}{%s})^{%s}})r  râ   r“  Úqr|   rÂ   rÔ   r  Úis_negativerÙ   r    Ú	is_Symbolr¤   rê   r‡  r�  Ú_helper_print_standard_power)rÈ   rÛ   r“  r˜  r  rÜ   Zbase_pZbase_qr_   r_   rb   Ú
_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_Floatrs  r   Ú
startswithr7   r~  Úendswith)rÈ   rÛ   r�  r  r  r_   r_   rb   r›  µ  s   
ÿ
þýz)LatexPrinter._helper_print_standard_powerc                 C  s   |   |jd ¡S ©Nr   ©rÔ   r  rã   r_   r_   rb   Ú_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
  r_   r  ©ró   r�   r  r_   rb   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
  r_   r  ©ró   ra   r  r_   rb   r  Ð  r  zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>r-  r   rƒ  ©Útuple©Úlr  r_   rb   Ú_format_ineqÎ  ó   &ÿz-LatexPrinter._print_Sum.<locals>._format_ineqz\sum_{\substack{%s}} ú\\c                   ó   g | ]}ˆ |ƒ‘qS r_   r_   ©ró   r®  ©r¯  r_   rb   r  Ó  ó    r"  ©	r@  Úlimitsr¬  r   r  rs  Úfunctionr   rÔ   ©rÈ   rÛ   rÜ   r_   ©r¯  rÈ   rb   Ú
_print_SumÉ  ó   ÿÿþzLatexPrinter._print_Sumc                   r¦  )Nr-  z\prod_{%s=%s}^{%s} c                   r
  r_   r  r§  r  r_   rb   r  ß  r  z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                   r¨  )Nr©  c                   r
  r_   r  rª  r  r_   rb   r  ã  r  zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>r-  r   rƒ  r«  r­  r  r_   rb   r¯  á  r°  z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} r±  c                   r²  r_   r_   r³  r´  r_   rb   r  æ  rµ  r"  r¶  r¹  r_   rº  rb   Ú_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__rt  r_   r_   rb   rc   ü  rd   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>©Úkeyr-  r!  r,  r   r’  r/  r³   ú-é   )Úsympy.vectorr¿  ÚzeroZ_latex_formrs  ÚseparateÚitemsrw  Ú
componentsÚsortÚappendrÔ   r  )rÈ   rÛ   r¿  Úo1rÈ  ÚsystemÚvectÚ
inneritemsÚkÚvÚarg_strZoutstrr_   r_   rb   Ú_print_BasisDependentï  s0   


ù
	ÿz"LatexPrinter._print_BasisDependentc                 C  s4   |   |j¡}d| d dd t| j |jƒ¡  }|S )Nrs   r^   ú_{%s}r.  )rÔ   r  r  ÚmapÚindices)rÈ   rÛ   Ztex_baserÜ   r_   r_   rb   Ú_print_Indexed  s
   ÿzLatexPrinter._print_Indexedc                 C  ó   |   |j¡S rÓ   )rÔ   Úlabelrã   r_   r_   rb   Ú_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})rA  rB  z{{{label}}}_{{{interval}}})rÙ  Úinterval)rÔ   rÙ  rB  rA  r   ÚZerorÎ   )rÈ   rÛ   rÙ  rB  rA  rÜ  r_   r_   rb   Ú
_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}r„  z\frac{%s^{%s}}{%s}c                 s  ó   � | ]}|  ¡ V  qd S rÓ   ©rû   r§  r_   r_   rb   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ô   Únumr_   r_   rb   Ú_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  r_   rb   rö   I  r÷   z+LatexPrinter._print_Subs.<locals>.<genexpr>c                 3  rï   rÓ   r  rê  r  r_   rb   rö   J  r÷   z\\ c                 s  s$   � | ]}|d  d |d  V  qdS )r   ú=r-  Nr_   rê  r_   r_   rb   rö   K  s   € 
ÿz#\left. %s \right|_{\substack{ %s }})r  rÔ   r  Úzip)	rÈ   ÚsubsrÛ   rn  ÚnewZ
latex_exprZ	latex_oldZ	latex_newZ
latex_subsr_   r  rb   Ú_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ó   Úlimr_   r_   rb   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È   r_   rb   r  Y  s    ÿz0LatexPrinter._print_Integral.<locals>.<listcomp>r   z\intr•   r«   r�   z\limitsrÄ  z
_{%s}^{%s}rƒ  ú^{%s}ró  z%s %s%sr	   c                 s  rà  rÓ   rá  r§  r_   r_   rb   rö   p  râ  Trã  )rÂ   r@  r·  Úallrä  rÔ   ÚinsertrÙ   r¸  r    rþ   r  r  )rÈ   rÛ   rÜ   Úsymbolsrñ  rõ  r_   rö  rb   Ú_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Ô   r   r   ÚInfinityÚNegativeInfinityrs  r   )rÈ   rÛ   r  ÚzÚz0ÚdirrÜ   r_   r_   rb   Ú_print_Limitt  s   
zLatexPrinter._print_Limitrj  c                 C  sø   |   |¡}| d¡}| d¡}|tv rd| }|S t|ƒdks,| d¡s,|dks,|dkr0|}|S |dkrN|dkrNd|dt||ƒ… |t||ƒd… f }|S |dkrbd|d|… ||d… f }|S |dkrvd|d|… ||d… f }|S d	| }|S )
ak  
        Logic to decide how to render a function to latex
          - if it is a recognized latex name, use the appropriate latex command
          - if it is a single letter, excluding sub- and superscripts, just use that letter
          - if it is a longer name, then put \operatorname{} around it and be
            mindful of undercores in the name
        rƒ   Ú_z\%sr-  r�   r   z\operatorname{%s}%sNz\operatorname{%s})r  ÚfindÚaccepted_latex_functionsr@  r   r¥   )rÈ   rj  ZsuperscriptidxZsubscriptidxr  r_   r_   rb   Ú_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 r_   )r   rÔ   r;  r  r_   rb   r  ³  ó    z0LatexPrinter._print_Function.<locals>.<listcomp>r�   Fr‹   r-  r   )ÚasinÚacosÚatanÚacscÚasecÚacotÚasinhÚacoshÚatanhÚacschÚasechÚacothrŽ   Úfullr,  ÚhÚarÚarcNÚpowerTz\%s^{-1}z\operatorname{%s}^{-1}r—  z {%s}ú%sú{\left(%s \right)}r÷  r.  )rj  r  rr  rs  r   Úgetattrr  rÂ   r@  rë   r  r  r¤   r  )rÈ   rÛ   r  rj  r  r�   Zinv_trig_power_caseZcan_fold_bracketsZinv_trig_tabler  Zfunc_texr_   r  rb   Ú_print_Function¢  sR   ÿ


ÿþ"






zLatexPrinter._print_Functionc                 C  ó   |   t|ƒ¡S rÓ   )r  r   rã   r_   r_   rb   Ú_print_UndefinedFunctionî  r  z%LatexPrinter._print_UndefinedFunctionc                 C  ó   d|   |j¡|   |j¡f S )Nz{%s}_{\circ}\left({%s}\right))rÔ   r¸  rÛ   rã   r_   r_   rb   Ú_print_ElementwiseApplyFunctionñ  s   

þz,LatexPrinter._print_ElementwiseApplyFunctionc                 C  s\   ddl m} ddlm}m} ddlm} ddlm} ddl	m
} |d|d|d	|d
|d|diS )Nr   )ÚKroneckerDelta)ÚgammaÚ
lowergamma)Úbeta)Ú
DiracDelta)rT   z\deltar?   z\gammaz\operatorname{B}z\operatorname{Chi})Ú(sympy.functions.special.tensor_functionsr"  Ú'sympy.functions.special.gamma_functionsr#  r$  Ú&sympy.functions.special.beta_functionsr%  Ú'sympy.functions.special.delta_functionsr&  Ú'sympy.functions.special.error_functionsrT   )rÈ   r"  r#  r$  r%  r&  rT   r_   r_   rb   Ú_special_function_classes÷  s   ûz&LatexPrinter._special_function_classesc                 C  s>   | j D ]}t||ƒr|j|jkr| j |   S q|  t|ƒ¡S rÓ   )r,  Ú
issubclassr  r  r   )rÈ   rÛ   Úclsr_   r_   rb   Ú_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Ü   r_   r_   rb   Ú_print_Lambda  s   
zLatexPrinter._print_Lambdac                 C  ó   dS )Nz\left( x \mapsto x \right)r_   rã   r_   r_   rb   Ú_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  r_   rb   r    r  z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)r  r—  )Úsortedr  r   r   rj  rA  r  )rÈ   rÛ   r  r  ZtexargsrÜ   r_   r  rb   Ú_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Ü   r_   r_   rb   Ú_print_floor&  ó   zLatexPrinter._print_floorc                 C  r7  )Nz\left\lceil{%s}\right\rceilr   r—  r£  r8  r_   r_   rb   Ú_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  r8  r_   r_   rb   Ú
_print_log6  s   
zLatexPrinter._print_logc                 C  r7  )Nú\left|{%s}\right|r   r—  r£  r8  r_   r_   rb   Ú
_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	  r8  r_   r_   rb   Ú	_print_reI  ó   
zLatexPrinter._print_rec                 C  r?  )Nr¡   z\Im{%s}r   r@  z\operatorname{{im}}{{{}}}rA  r8  r_   r_   rb   Ú	_print_imQ  rC  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.boolalgrE  rF  rs  r  Ú_print_EquivalentÚ_print_ImpliesÚ
is_BooleanrÔ   )rÈ   r  rE  rF  r_   r_   rb   Ú
_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)rJ  Úis_NotrÔ   )rÈ   r  Úcharr;   rÜ   r_   r_   rb   Ú_print_LogOpd  s   zLatexPrinter._print_LogOpc                 C  ó   t |jtd�}|  |d¡S )NrÁ  z\wedge©r5  r  r   rN  ©rÈ   r  r  r_   r_   rb   Ú
_print_Ands  ó   zLatexPrinter._print_Andc                 C  rO  )NrÁ  z\veerP  rQ  r_   r_   rb   Ú	_print_Orw  rS  zLatexPrinter._print_Orc                 C  rO  )NrÁ  z\veebarrP  rQ  r_   r_   rb   Ú
_print_Xor{  rS  zLatexPrinter._print_Xorc                 C  s   |   |j|pd¡S )Nz\Rightarrow)rN  r  )rÈ   r  Úaltcharr_   r_   rb   rI    ó   zLatexPrinter._print_Impliesc                 C  s   t |jtd�}|  ||pd¡S )NrÁ  z\LeftrightarrowrP  )rÈ   r  rV  r  r_   r_   rb   rH  ‚  s   zLatexPrinter._print_Equivalentc                 C  r7  )Nz\overline{%s}r   r—  r£  r8  r_   r_   rb   Ú_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  rj  r;   r_   r_   rb   Ú_print_polar_liftŽ  s
   zLatexPrinter._print_polar_liftc                 C  s    d|   |jd ¡ }|  ||¡S )Nze^{%s}r   )rÔ   r  r	  r8  r_   r_   rb   Ú_print_ExpBase—  s   zLatexPrinter._print_ExpBasec                 C  r1  )Nr  r_   r  r_   r_   rb   Ú_print_Exp1�  r3  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£  r8  r_   r_   rb   Ú_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£  r8  r_   r_   rb   Ú_print_elliptic_f§  s   ÿzLatexPrinter._print_elliptic_fc                 C  sd   t |jƒdkrd|  |jd ¡|  |jd ¡f }n
d|  |jd ¡ }|d ur.d||f S d| S )Nrƒ  ra  r   r-  r"  zE^{%s}%szE%s©r@  r  rÔ   r8  r_   r_   rb   Ú_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-  rƒ  ra  z
\Pi^{%s}%sz\Pi%src  r8  r_   r_   rb   Ú_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Ü   r_   r_   rb   Ú_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
  r_   r  r;  r  r_   rb   r  Ó  r  z/LatexPrinter._print_betainc.<locals>.<listcomp>ú\left(%s, %s\right)r   r-  z#\operatorname{%s}_{(%s, %s)}^{%s}%srƒ  rÄ  z\operatorname{%s}_{(%s, %s)}%s)r  )rÈ   rÛ   r  ÚoperatorZlargsrÜ   r_   r  rb   Ú_print_betaincÒ  s
   zLatexPrinter._print_betaincc                 C  s   | j ||dd�S )NÚI)rj  )rk  r  r_   r_   rb   Ú_print_betainc_regularizedÛ  r¥  z'LatexPrinter._print_betainc_regularizedc                 C  r`  )Nri  r   r-  z\Gamma^{%s}%sz\Gamma%sr£  r8  r_   r_   rb   Ú_print_uppergammaÞ  ó   ÿzLatexPrinter._print_uppergammac                 C  r`  )Nri  r   r-  z\gamma^{%s}%sú\gamma%sr£  r8  r_   r_   rb   Ú_print_lowergammaç  ro  zLatexPrinter._print_lowergammac                 C  sF   d|   |jd ¡ }|d urd|   |j¡||f S d|   |j¡|f S ©Nr"  r   rY  rZ  )rÔ   r  rj  r8  r_   r_   rb   Ú_hprint_one_arg_funcð  s   z!LatexPrinter._hprint_one_arg_funcc                 C  r^  )Nr"  r   z\operatorname{Chi}^{%s}%sz\operatorname{Chi}%sr£  r8  r_   r_   rb   Ú
_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Ü   Únur_   r_   rb   Ú_print_expint  s
   zLatexPrinter._print_expintc                 C  r^  )Nr"  r   zS^{%s}%szS%sr£  r8  r_   r_   rb   Ú_print_fresnels  ru  zLatexPrinter._print_fresnelsc                 C  r^  )Nr"  r   zC^{%s}%szC%sr£  r8  r_   r_   rb   Ú_print_fresnelc  ru  zLatexPrinter._print_fresnelcc                 C  ó2   d|   |jd td ¡ }|d urd||f S |S )Nz!%sr   ÚFuncr  ©rÙ   r  r    r8  r_   r_   rb   Ú_print_subfactorial  ó   z LatexPrinter._print_subfactorialc                 C  rz  )Nz%s!r   r{  r—  r|  r8  r_   r_   rb   Ú_print_factorial#  r~  zLatexPrinter._print_factorialc                 C  rz  )Nz%s!!r   r{  r—  r|  r8  r_   r_   rb   Ú_print_factorial2+  r~  zLatexPrinter._print_factorial2c                 C  s<   d|   |jd ¡|   |jd ¡f }|d urd||f S |S )Nz{\binom{%s}{%s}}r   r-  r—  r£  r8  r_   r_   rb   Ú_print_binomial3  s   ÿzLatexPrinter._print_binomialc                 C  s<   |j \}}d|  |td ¡ }d||  |¡f }|  ||¡S )Nr  r{  z{%s}^{\left(%s\right)}©r  rÙ   r    rÔ   r	  )rÈ   rÛ   r  ÚnrÐ  r  rÜ   r_   r_   rb   Ú_print_RisingFactorial<  ó   
z#LatexPrinter._print_RisingFactorialc                 C  s<   |j \}}d|  |td ¡ }d|  |¡|f }|  ||¡S )Nr  r{  z{\left(%s\right)}_{%s}r‚  )rÈ   rÛ   r  rƒ  rÐ  ÚsubrÜ   r_   r_   rb   Ú_print_FallingFactorialD  r…  z$LatexPrinter._print_FallingFactorialÚsymc                 C  sf   d| }d}|d ur|  d¡dkrd||f }nd}d||  |j¡|  |j¡f }|r1|  ||¡}|S )Nr  Frƒ   r,  r—  Tú%s_{%s}\left(%s\right))r  rÔ   r˜   Úargumentr	  )rÈ   rÛ   r  rˆ  rÜ   Zneed_expr_   r_   rb   Ú_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È   rp   ra   r�   r_   r_   rb   Ú_hprint_vec]  s   zLatexPrinter._hprint_vecc                 C  ó   |   ||d¡S )NÚJ©r‹  r  r_   r_   rb   Ú_print_besseljf  r  zLatexPrinter._print_besseljc                 C  r�  )Nrl  r�  r  r_   r_   rb   Ú_print_besselii  r  zLatexPrinter._print_besselic                 C  r�  )NÚKr�  r  r_   r_   rb   Ú_print_besselkl  r  zLatexPrinter._print_besselkc                 C  r�  )NÚYr�  r  r_   r_   rb   Ú_print_besselyo  r  zLatexPrinter._print_besselyc                 C  r�  )Nrf  r�  r  r_   r_   rb   Ú	_print_ynr  r  zLatexPrinter._print_ync                 C  r�  )Nr¸   r�  r  r_   r_   rb   Ú	_print_jnu  r  zLatexPrinter._print_jnc                 C  r�  )NzH^{(1)}r�  r  r_   r_   rb   Ú_print_hankel1x  r  zLatexPrinter._print_hankel1c                 C  r�  )NzH^{(2)}r�  r  r_   r_   rb   Ú_print_hankel2{  r  zLatexPrinter._print_hankel2c                 C  r�  )Nzh^{(1)}r�  r  r_   r_   rb   Ú
_print_hn1~  r  zLatexPrinter._print_hn1c                 C  r�  )Nzh^{(2)}r�  r  r_   r_   rb   Ú
_print_hn2�  r  zLatexPrinter._print_hn2r³   c                 C  ó6   d|   |jd ¡ }|d urd|||f S d||f S rr  r£  ©rÈ   rÛ   r  ÚnotationrÜ   r_   r_   rb   Ú_hprint_airy„  ó   zLatexPrinter._hprint_airyc                 C  rœ  )Nr"  r   z{%s^\prime}^{%s}%sz%s^\prime%sr£  r�  r_   r_   rb   Ú_hprint_airy_primeŒ  r   zLatexPrinter._hprint_airy_primec                 C  r�  ©NÚAi©rŸ  r  r_   r_   rb   Ú_print_airyai”  r  zLatexPrinter._print_airyaic                 C  r�  ©NÚBir¤  r  r_   r_   rb   Ú_print_airybi—  r  zLatexPrinter._print_airybic                 C  r�  r¢  ©r¡  r  r_   r_   rb   Ú_print_airyaiprimeš  r  zLatexPrinter._print_airyaiprimec                 C  r�  r¦  r©  r  r_   r_   rb   Ú_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ÚbqrŒ  rŠ  r8  r_   r_   rb   Ú_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®  rw   ÚanrŒ  ÚaotherÚbotherrŠ  r8  r_   r_   rb   Ú_print_meijerg«  s   
üþzLatexPrinter._print_meijergc                 C  r^  )Nr"  r   z\eta^{%s}%sz\eta%sr£  r8  r_   r_   rb   Ú_print_dirichlet_eta¸  s   z!LatexPrinter._print_dirichlet_etac                 C  sV   t |jƒdkrdtt| j|jƒƒ }n
d|  |jd ¡ }|d ur'd||f S d| S )Nrƒ  ri  r"  r   z\zeta^{%s}%sz\zeta%s©r@  r  r¬  rÕ  rÔ   r8  r_   r_   rb   Ú_print_zeta¾  ó   zLatexPrinter._print_zetac                 C  sV   t |jƒdkrdtt| j|jƒƒ }n
d|  |jd ¡ }|d ur'd||f S d| S )Nrƒ  z_{%s}\left(%s\right)rÔ  r   z\gamma%s^{%s}rp  rµ  r8  r_   r_   rb   Ú_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  r8  r_   r_   rb   Ú_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  ra   rÿ  rÜ   r_   r_   rb   Ú_print_polylogÖ  s
   zLatexPrinter._print_polylogc                 C  óB   t | j|jƒ\}}}}d||||f }|d urd| d|  }|S )Nz*P_{%s}^{\left(%s,%s\right)}\left(%s\right)r’  ú\right)^{%s}rº  )rÈ   rÛ   r  rƒ  r‹  rŒ  rô   rÜ   r_   r_   rb   Ú_print_jacobiÝ  ó
   zLatexPrinter._print_jacobic                 C  ó>   t | j|jƒ\}}}d|||f }|d urd| d|  }|S )Nz'C_{%s}^{\left(%s\right)}\left(%s\right)r’  r½  rº  ©rÈ   rÛ   r  rƒ  r‹  rô   rÜ   r_   r_   rb   Ú_print_gegenbauerä  ó
   zLatexPrinter._print_gegenbauerc                 C  ó:   t | j|jƒ\}}d||f }|d urd| d|  }|S )NzT_{%s}\left(%s\right)r’  r½  rº  ©rÈ   rÛ   r  rƒ  rô   rÜ   r_   r_   rb   Ú_print_chebyshevtë  ó
   zLatexPrinter._print_chebyshevtc                 C  rÄ  )NzU_{%s}\left(%s\right)r’  r½  rº  rÅ  r_   r_   rb   Ú_print_chebyshevuò  rÇ  zLatexPrinter._print_chebyshevuc                 C  rÄ  )NzP_{%s}\left(%s\right)r’  r½  rº  rÅ  r_   r_   rb   Ú_print_legendreù  rÇ  zLatexPrinter._print_legendrec                 C  rÀ  )Nz'P_{%s}^{\left(%s\right)}\left(%s\right)r’  r½  rº  rÁ  r_   r_   rb   Ú_print_assoc_legendre   rÃ  z"LatexPrinter._print_assoc_legendrec                 C  rÄ  )NzH_{%s}\left(%s\right)r’  r½  rº  rÅ  r_   r_   rb   Ú_print_hermite  rÇ  zLatexPrinter._print_hermitec                 C  rÄ  )NzL_{%s}\left(%s\right)r’  r½  rº  rÅ  r_   r_   rb   Ú_print_laguerre  rÇ  zLatexPrinter._print_laguerrec                 C  rÀ  )Nz'L_{%s}^{\left(%s\right)}\left(%s\right)r’  r½  rº  rÁ  r_   r_   rb   Ú_print_assoc_laguerre  rÃ  z"LatexPrinter._print_assoc_laguerrec                 C  r¼  )NzY_{%s}^{%s}\left(%s,%s\right)r’  r½  rº  ©rÈ   rÛ   r  rƒ  ÚmÚthetaÚphirÜ   r_   r_   rb   Ú
_print_Ynm  r¿  zLatexPrinter._print_Ynmc                 C  r¼  )NzZ_{%s}^{%s}\left(%s,%s\right)r’  r½  rº  rÎ  r_   r_   rb   Ú
_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  rq   r  r‹  r˜  rÿ  Úsupr_   r_   rb   Z__print_mathieu_functions*  s   z&LatexPrinter.__print_mathieu_functionsc                 C  ó   | j d|j|d�S )NÚCr–  ©Ú&_LatexPrinter__print_mathieu_functionsr  r  r_   r_   rb   Ú_print_mathieuc0  rW  zLatexPrinter._print_mathieucc                 C  rÖ  )Nr   r–  rØ  r  r_   r_   rb   Ú_print_mathieus3  rW  zLatexPrinter._print_mathieusc                 C  ó   | j d|jd|d�S )Nr×  T©rq   r  rØ  r  r_   r_   rb   Ú_print_mathieucprime6  ó   z!LatexPrinter._print_mathieucprimec                 C  rÜ  )Nr   TrÝ  rØ  r  r_   r_   rb   Ú_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   r€  rŒ   z	%s%d / %dz%s\frac{%d}{%d})r˜  r“  rÂ   rÔ   )rÈ   rÛ   Úsignr“  r_   r_   rb   Ú_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“  r_   r_   rb   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Û   ra   r_   r_   rb   Ú_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  r_   r_   rb   Ú_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 )
Nrs   r©   r  z\_rƒ   z\^c                 S  ó   g | ]}t |ƒ‘qS r_   ©Ú	translate)ró   rÕ  r_   r_   rb   r  j  rµ  z1LatexPrinter._split_super_sub.<locals>.<listcomp>c                 S  rì  r_   rí  )ró   r†  r_   r_   rb   r  k  rµ  )rÂ   r„   r   rî  )rÈ   r  Úsupersrí  r_   r_   rb   Ú_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 )Nru   ú\mathbf{{{}}}r÷  r­   rÔ  )rð  rÎ   r  )rÈ   rñ  ré  r  rï  rí  r_   r_   rb   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Úcharmapr_   r_   rb   Ú_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  r…   r  r_   rb   r  ’  s    ÿz1LatexPrinter._print_Piecewise.<locals>.<listcomp>r,  z%s & \text{otherwise}rü  z\begin{cases} %s \end{cases}z \\)r  Úcondr   rË  rÔ   rÛ   r  )rÈ   rÛ   ZecpairsrÜ   r_   r  rb   Ú_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
  r_   r  r§  r  r_   rb   r  ¢  r  z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>r”   r•   r«   Úsmallmatrixé
   TÚmatrixÚarrayú \begin{%MATSTR%}%s\end{%MATSTR%}ú%MATSTR%r  rs   r…   ú}%sr±  )r?  ÚrowsrË  r  rÂ   Úcolsr„   )rÈ   rÛ   ÚlinesÚliner”   Úout_strr_   r  rb   Ú_print_matrix_contentsž  s   ,
z#LatexPrinter._print_matrix_contentsc                 C  s@   |   |¡}| jd r| jd }| j| }d| | d | }|S )Nr’   ú\leftú\right)r  rÂ   rÆ   )rÈ   rÛ   r
  Ú
left_delimÚright_delimr_   r_   rb   Ú_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.  rs   z}_{r^   )rÙ   Úparentr    rÔ   r�   r¸   )rÈ   rÛ   Zmatrix_partZ
index_partr_   r_   rb   Ú_print_MatrixElement½  s   z!LatexPrinter._print_MatrixElementc                   sN   ‡ fdd„}ˆ j |jtd dd�d ||j|jjƒ d ||j|jjƒ d S )	Nc                   sZ   t | ƒ} | d dkr| d= | d dkrd | d< | d |kr!d | d< d ‡ fdd„| D ƒ¡S )Nrƒ  r-  r   ú:c                 3  s&   � | ]}|d urˆ   |¡ndV  qd S ©Nr³   r  )ró   Úxir  r_   rb   rö   Ë  ó   €$ zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>)rw  r  )rô   rç  r  r_   rb   Ú
latexsliceÃ  s   z3LatexPrinter._print_MatrixSlice.<locals>.latexslicer@  Tr  ú\left[r  ú\right])rÙ   r  r    Úrowslicer  Úcolslicer  )rÈ   rÛ   r  r_   r  rb   Ú_print_MatrixSliceÂ  s   	ÿÿþþzLatexPrinter._print_MatrixSlicec                 C  rØ  rÓ   )rÔ   Úblocksrã   r_   r_   rb   Ú_print_BlockMatrixÐ  rÛ  zLatexPrinter._print_BlockMatrixc                 C  sh   |j }ddlm}m} t||ƒst||ƒs|jrd|  |¡ S |  |t|ƒd¡}d|v r0d| S d| S )Nr   ©ÚMatrixSymbolÚBlockMatrixz\left(%s\right)^{T}Trƒ   z%s^{T})	r;   Úsympy.matricesr!  r"  rs  Úis_MatrixExprrÔ   rÙ   r   )rÈ   rÛ   rD  r!  r"  ra   r_   r_   rb   Ú_print_TransposeÓ  s   
ÿÿzLatexPrinter._print_Transposec                 C  s   |j }d|  |¡ S )Nz!\operatorname{tr}\left(%s \right))r;   rÔ   ©rÈ   rÛ   rD  r_   r_   rb   Ú_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  Trƒ   r—  )rÇ   rÂ   r;   r#  r!  r"  rs  r$  rÔ   rÙ   r   )rÈ   rÛ   Zstyle_to_latexr¨   rD  r!  r"  ra   r_   r_   rb   Ú_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)rs  r	   rÔ   rÙ   r   rt  ©r+  rÛ   rÈ   r_   rb   rc   û  s    z,LatexPrinter._print_MatMul.<locals>.<lambda>r,  r-  r€  r­   )Úsympyr+  rw  r  rû   r  rÕ  )rÈ   rÛ   Úparensr  r_   r-  rb   Ú_print_MatMul÷  s   
zLatexPrinter._print_MatMulc                 C  s0   t |ƒ}|j\}}|  ||¡› d|  ||¡› �S )Nr®   )r   r  rÙ   )rÈ   rÛ   rÖ   ÚleftÚrightr_   r_   rb   Ú_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"  rs  r  r  rÔ   )rÈ   rÛ   rD  r"  r_   r_   rb   Ú_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 %sr|  r  r_   r_   rb   Ú
_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  Nr_   r;  ©r/  Úprecr_   rb   rö   ,  ó   € z6LatexPrinter._print_HadamardProduct.<locals>.<genexpr>©r  r    rÙ   r  ©rÈ   rÛ   r  r_   r:  rb   Ú_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�  r_   r_   rb   Ú_print_HadamardPower.  s   z!LatexPrinter._print_HadamardPowerc                   r7  )Nr   ú	 \otimes c                 3  r8  r9  r_   r;  r:  r_   rb   rö   ;  r<  z7LatexPrinter._print_KroneckerProduct.<locals>.<genexpr>r=  r>  r_   r:  rb   Ú_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  rƒ   r—  )r  r  r#  r!  rs  r$  rÔ   )rÈ   rÛ   r  r  r!  Zbase_strr_   r_   rb   Ú_print_MatPow=  s   
ÿ
zLatexPrinter._print_MatPowc                 C  s   | j || jd d�S )Nr›   rè  )rê  rÂ   rã   r_   r_   rb   Ú_print_MatrixSymbolJ  s   
ÿz LatexPrinter._print_MatrixSymbolc                 C  ó   | j d dkr	dS dS )Nr›   r–   Ú0z
\mathbf{0}©rÂ   )rÈ   ÚZr_   r_   rb   Ú_print_ZeroMatrixN  ó   ÿÿÿzLatexPrinter._print_ZeroMatrixc                 C  rF  )Nr›   r–   Ú1z
\mathbf{1}rH  )rÈ   ÚOr_   r_   rb   Ú_print_OneMatrixR  rK  zLatexPrinter._print_OneMatrixc                 C  rF  )Nr›   r–   z
\mathbb{I}z
\mathbf{I}rH  )rÈ   rl  r_   r_   rb   Ú_print_IdentityV  rK  zLatexPrinter._print_Identityc                 C  s   |   |jd ¡}d| S )Nr   zP_{%s}r£  )rÈ   ÚPZperm_strr_   r_   rb   Ú_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   r_   r”   r•   r«   rÿ  r,  r   r  r  r  r  r  rs   r…   r  r’   r  r  r³   c                 S  s   g | ]}g ‘qS r_   r_   r§  r_   r_   rb   r  z  s    z1LatexPrinter._print_NDimArray.<locals>.<listcomp>r-  c                 S  s   g | ]}t t|ƒƒ‘qS r_   )rw  r?  r§  r_   r_   rb   r  {  ó    Tr<  r±  r  r  rƒ  )ÚrankrÔ   rÂ   Úshaper„   rÆ   r?  Ú	itertoolsÚproductrË  r@  r  )rÈ   rÛ   r”   Z	block_strr  r  Ú	level_strÚshape_rangesÚouter_iÚevenÚback_outer_ir
  r_   r_   rb   Ú_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.  r^   z{}^{z{}_{r   rë  TF)rÔ   Úis_upr  )	rÈ   r  rÖ  r]  r
  Úlast_valenceÚprev_mapÚindexZnew_valencer_   r_   rb   Ú_printer_tensor_indices•  s0   

z$LatexPrinter._printer_tensor_indicesc                 C  s&   |j d j d }| ¡ }|  ||i ¡S r¢  )r  Úget_indicesrc  )rÈ   rÛ   r  rÖ  r_   r_   rb   Ú_print_Tensor±  s   zLatexPrinter._print_Tensorc                 C  s0   |j jd jd }|j  ¡ }|j}|  |||¡S r¢  )rÛ   r  rd  r]  rc  )rÈ   rÛ   r  rÖ  r]  r_   r_   rb   Ú_print_TensorElement¶  s   
z!LatexPrinter._print_TensorElementc                   s*   ˆ   ¡ \}}|d ‡ ‡fdd„|D ƒ¡ S )Nr³   c                   s   g | ]
}ˆ  |tˆ ƒ¡‘qS r_   )rÙ   r   r;  ©rÛ   rÈ   r_   rb   r  À  ó    z/LatexPrinter._print_TensMul.<locals>.<listcomp>)Ú!_get_args_for_traditional_printerr  )rÈ   rÛ   rá  r  r_   rg  rb   Ú_print_TensMul¼  s   ÿzLatexPrinter._print_TensMulc                 C  sL   g }|j }|D ]}| |  |t|ƒ¡¡ q| ¡  d |¡}| dd¡}|S )Nr!  z+ -r€  )r  rË  rÙ   r   rÊ  r  r„   )rÈ   rÛ   r‹  r  rô   ra   r_   r_   rb   Ú_print_TensAddÃ  s   
zLatexPrinter._print_TensAddc                 C  s"   d|j rdnd|  |jd ¡f S )Nz{}%s{%s}rƒ   r  r   )r_  rÔ   r  rã   r_   r_   rb   Ú_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                   r4  )z\partial {%s}r  r§  r  r_   rb   r  Ü  r  z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>)r@  rå  rÔ   rÙ   rÛ   r    r  rã   r_   r  rb   Ú_print_PartialDerivativeÓ  s   þýz%LatexPrinter._print_PartialDerivativec                 C  rØ  rÓ   )rÔ   r  rã   r_   r_   rb   Ú_print_ArraySymbolà  rÛ  zLatexPrinter._print_ArraySymbolc                   s2   dˆ   |jtd d¡d ‡ fdd„|jD ƒ¡f S )Nz{{%s}_{%s}}r{  Tr  c                   s   g | ]}ˆ   |¡› ‘qS r_   r  r§  r  r_   rb   r  æ  rR  z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>)rÙ   r  r    r  rÖ  rã   r_   r  rb   Ú_print_ArrayElementã  s   þz LatexPrinter._print_ArrayElementc                 C  r1  )Nz
\mathbb{U}r_   rã   r_   r_   rb   Ú_print_UniversalSetè  r3  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  r_   r_   rb   Ú_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¢   rM  ú;rž   r.  úUnknown Decimal Separatorr-  r   z \  c                   r
  r_   r  r§  r  r_   rb   r  ÿ  r  z-LatexPrinter._print_tuple.<locals>.<listcomp>)rÂ   rÃ   r@  rÒ   rÔ   r  )rÈ   rÛ   Úsepr_   r  rb   Ú_print_tupleò  s   ÿzLatexPrinter._print_tuplec                   ó   ‡ fdd„|j D ƒ}d |¡S )Nc                   r
  r_   r  ©ró   r‹  r  r_   rb   r    r  z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>rB  ©r  r  ©rÈ   rÛ   Úelementsr_   r  rb   Ú_print_TensorProduct  ó   
z!LatexPrinter._print_TensorProductc                   rv  )Nc                   r
  r_   r  rw  r  r_   rb   r    r  z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>z \wedge rx  ry  r_   r  rb   Ú_print_WedgeProduct  r|  z LatexPrinter._print_WedgeProductc                 C  ó
   |   |¡S rÓ   )ru  rã   r_   r_   rb   Ú_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¢   rM  z\left[ %s\right]z; \  c                   r
  r_   r  r§  r  r_   rb   r    r  z,LatexPrinter._print_list.<locals>.<listcomp>rž   ú, \  c                   r
  r_   r  r§  r  r_   rb   r    r  rs  )rÂ   r  rÃ   rã   r_   r  rb   Ú_print_list  s   ÿÿzLatexPrinter._print_listc                 C  sR   t | ¡ td�}g }|D ]}|| }| d|  |¡|  |¡f ¡ qdd |¡ S )NrÁ  z%s : %sz\left\{ %s\right\}r€  )r5  Úkeysr   rË  rÔ   r  )rÈ   rŸ   r‚  rÈ  rÂ  Úvalr_   r_   rb   Ú_print_dict  s    zLatexPrinter._print_dictc                 C  r~  rÓ   )r„  rã   r_   r_   rb   Ú_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  rc  r8  r_   r_   rb   Ú_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-  rƒ  z${\left\langle %s \right\rangle}^{%s}z-{\left({\langle %s \rangle}^{%s}\right)}^{%s}r£  )rÈ   rÛ   r  Úshiftr  rÜ   r_   r_   rb   Ú_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  r_   rb   rö   7  r÷   z0LatexPrinter._print_Heaviside.<locals>.<genexpr>z\theta\left(%s\right)r  )r  Úpargs)rÈ   rÛ   r  r‰  rÜ   r_   r  rb   Ú_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Ü   r_   r_   rb   Ú_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ò   r_   r_   rb   rö   J  s   € z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}r­   r  r  )rÕ  rÔ   r  rø  r  )rÈ   rÛ   r  rÖ  rÜ   r_   r_   rb   Ú_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 })rr  rÔ   r�  rú  rŽ  )rÈ   rŸ   r_   r_   rb   Ú_print_RandomDomainR  s   


ÿ

z LatexPrinter._print_RandomDomainc                 C  s   t |jtd�}|  |¡S )NrÁ  )r5  r  r   Ú
_print_set©rÈ   ra   rÈ  r_   r_   rb   Ú_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¢   rM  rã  rž   r  rs  ú\left\{%s\right\})r5  r   rÂ   r  rÕ  rÔ   rÃ   r‘  r_   r_   rb   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   rƒ  r-  r  c                 3  rï   rÓ   r  r;  r  r_   rb   rö   u  r÷   zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>c                 3  rï   rÓ   r  r;  r  r_   rb   rö   x  r÷   c                 3  rï   rÓ   r  r;  r  r_   rb   rö   z  r÷   z\text{Range}\left(r/  )r  rÔ   r  )Úcont)ra   rÈ   r_   rb   Ú_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È   r_   rb   rö   •  r  z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})ÚobjectÚstartÚis_infiniteÚstopÚstepÚis_positiveÚiterÚnextÚis_emptyr1  r¬  Úis_iterabler  )rÈ   ra   r•  ÚprintsetÚitr_   )r›  ra   rÈ   rb   Ú_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 )Nrƒ  z%s_{%s}^{%s}\left(%s\right)r   r-  r‰  z%s_{%s}r—  rc  )rÈ   rÛ   Úletterr  rÜ   r_   r_   rb   Z__print_number_polynomial˜  s   þÿz&LatexPrinter.__print_number_polynomialc                 C  ó   |   |d|¡S ©Nrh  ©Ú&_LatexPrinter__print_number_polynomialr  r_   r_   rb   Ú_print_bernoulli¦  r  zLatexPrinter._print_bernoullic                 C  rª  )NÚGr¬  r  r_   r_   rb   Ú_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  r_   rb   rö   °  s   € ÿz+LatexPrinter._print_bell.<locals>.<genexpr>rƒ  rY  rh  )r@  r  rÔ   r  r­  )rÈ   rÛ   r  Ztex1Ztex2rÜ   r_   r  rb   Ú_print_bell¬  s   ÿ
ÿÿzLatexPrinter._print_bellc                 C  rª  ©NÚFr¬  r  r_   r_   rb   Ú_print_fibonacci¹  r  zLatexPrinter._print_fibonaccic                 C  ó,   d|   |jd ¡ }|d urd||f }|S )NzL_{%s}r   r—  r£  r8  r_   r_   rb   Ú_print_lucas¼  ó   zLatexPrinter._print_lucasc                 C  rª  )NÚTr¬  r  r_   r_   rb   Ú_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  r_   r_   rb   Ú_print_mobiusÅ  s   zLatexPrinter._print_mobiusc                   sø   t ƒ ‰ t|jjƒdkst|jjƒdkr-dˆ |j¡ˆ |jd ¡ˆ |j¡ˆ |j¡f S |jtj	u rP|j}ˆ | 
|d ¡| 
|d ¡| 
|d ¡| 
|¡f}n|jtju s[|jdkrg|d d… }| ˆ ¡ nt|ƒ}dd ‡ ‡fd	d
„|D ƒ¡ d S )Nr   z\left\{%s\right\}_{%s=%s}^{%s}rÄ  rƒ  r-  rð  r  r  c                 3  r–  r—  r  r˜  rš  r_   rb   rö   Þ  r  z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>r  )rœ  r@  r�  Úfree_symbolsrŸ  rÔ   Úformularå  r   rþ  Úcoeffrý  ÚlengthrË  r¬  r  )rÈ   ra   rŸ  r¦  r_   rš  rb   Ú_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�   r1  r2  r_   r_   rb   Ú_print_Intervalå  s   ÿzLatexPrinter._print_Intervalc                 C  r   )Nz \left\langle %s, %s\right\rangle)rÔ   r¥   r¦   ©rÈ   r�   r_   r_   rb   Ú_print_AccumulationBounds÷  s   ÿz&LatexPrinter._print_AccumulationBoundsc                   ó(   t |ƒ‰ ‡ ‡fdd„|jD ƒ}d |¡S )Nc                   ó   g | ]}ˆ  |ˆ ¡‘qS r_   ©rÙ   r§  ©r;  rÈ   r_   rb   r  ý  rR  z-LatexPrinter._print_Union.<locals>.<listcomp>z \cup ©r   r  r  ©rÈ   ÚuÚargs_strr_   rÉ  rb   Ú_print_Unionû  ó   
zLatexPrinter._print_Unionc                   rÆ  )Nc                   rÇ  r_   rÈ  r§  rÉ  r_   rb   r  	  rR  z2LatexPrinter._print_Complement.<locals>.<listcomp>z \setminus rÊ  rË  r_   rÉ  rb   Ú_print_Complement 	  rÏ  zLatexPrinter._print_Complementc                   rÆ  )Nc                   rÇ  r_   rÈ  r§  rÉ  r_   rb   r  	  rR  z4LatexPrinter._print_Intersection.<locals>.<listcomp>z \cap rÊ  rË  r_   rÉ  rb   Ú_print_Intersection	  rÏ  z LatexPrinter._print_Intersectionc                   rÆ  )Nc                   rÇ  r_   rÈ  r§  rÉ  r_   rb   r  	  rR  z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>z \triangle rÊ  rË  r_   rÉ  rb   Ú_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É  r_   rb   rö   	  s   € 
ÿz1LatexPrinter._print_ProductSet.<locals>.<genexpr>)r   r@  Úsetsr#   rÙ   r  ©rÈ   r“  r_   rÉ  rb   Ú_print_ProductSet	  s    ÿzLatexPrinter._print_ProductSetc                 C  r1  )Nz	\emptysetr_   r  r_   r_   rb   Ú_print_EmptySet	  r3  zLatexPrinter._print_EmptySetc                 C  r1  )Nz
\mathbb{N}r_   ©rÈ   rƒ  r_   r_   rb   Ú_print_Naturals	  r3  zLatexPrinter._print_Naturalsc                 C  r1  )Nz\mathbb{N}_0r_   r×  r_   r_   rb   Ú_print_Naturals0	  r3  zLatexPrinter._print_Naturals0c                 C  r1  ©Nz
\mathbb{Z}r_   rÄ  r_   r_   rb   Ú_print_Integers	  r3  zLatexPrinter._print_Integersc                 C  r1  ©Nz
\mathbb{Q}r_   rÄ  r_   r_   rb   Ú_print_Rationals"	  r3  zLatexPrinter._print_Rationalsc                 C  r1  ©Nz
\mathbb{R}r_   rÄ  r_   r_   rb   Ú_print_Reals%	  r3  zLatexPrinter._print_Realsc                 C  r1  ©Nz
\mathbb{C}r_   rÄ  r_   r_   rb   Ú_print_Complexes(	  r3  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ô   rf  r  r_   rb   rö   .	  s   €& z/LatexPrinter._print_ImageSet.<locals>.<genexpr>r  c                 s  s   � | ]}d | V  qdS )ú	%s \in %sNr_   )ró   Úxyr_   r_   rb   rö   /	  râ  z!\left\{%s\; \middle|\; %s\right\})rW   rÛ   Ú	signaturerì  Ú	base_setsr  rÔ   )rÈ   ra   rÛ   ÚsigZxysZxinysr_   r  rb   Ú_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
  r_   r  ©ró   rG  r  r_   rb   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   rˆ  Úbase_setr   ÚUniversalSetrÔ   Ú	condition©rÈ   ra   Z
vars_printr_   r  rb   Ú_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_printr_   r_   rb   Ú_print_PowerSet>	  s   
zLatexPrinter._print_PowerSetc                   s8   d  ‡ fdd„|jD ƒ¡}dˆ  |j¡|ˆ  |j¡f S )Nr  c                   r
  r_   r  rè  r  r_   rb   r  C	  r  z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z)\left\{%s\; \middle|\; %s \in %s \right\})r  rå  rÔ   rÛ   rÓ  rì  r_   r  rb   Ú_print_ComplexRegionB	  s   

ýz!LatexPrinter._print_ComplexRegionc                   s   dt ‡ fdd„|jD ƒƒ S )Nrâ  c                 3  rï   rÓ   r  rw  r  r_   rb   rö   J	  r÷   z/LatexPrinter._print_Contains.<locals>.<genexpr>)r¬  r  r  r_   r  rb   Ú_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Ï   r_   r_   rb   Ú_print_FourierSeriesL	  s   z!LatexPrinter._print_FourierSeriesc                 C  rØ  rÓ   )r(  ÚinfiniterÏ   r_   r_   rb   Ú_print_FormalPowerSeriesQ	  rÛ  z%LatexPrinter._print_FormalPowerSeriesc                 C  s
   d|j  S )Nz\mathbb{F}_{%s})Úmodrã   r_   r_   rb   Ú_print_FiniteFieldT	  rÑ   zLatexPrinter._print_FiniteFieldc                 C  r1  rÚ  r_   rã   r_   r_   rb   Ú_print_IntegerRingW	  r3  zLatexPrinter._print_IntegerRingc                 C  r1  rÜ  r_   rã   r_   r_   rb   Ú_print_RationalFieldZ	  r3  z!LatexPrinter._print_RationalFieldc                 C  r1  rÞ  r_   rã   r_   r_   rb   Ú_print_RealField]	  r3  zLatexPrinter._print_RealFieldc                 C  r1  rà  r_   rã   r_   r_   rb   Ú_print_ComplexField`	  r3  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ú  r_   r_   rb   Ú_print_PolynomialRingc	  ó   z"LatexPrinter._print_PolynomialRingc                 C  r   )Nr  rü  r  r  r_   r_   rb   Ú_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ú  Úinvr_   r_   rb   Ú_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"  rL  rÃ  r­   )rÃ  rL  z	domain=%sr  z\%s {\left(%s \right)}z$\operatorname{%s}{\left( %s \right)})r  r  r%  r$  rÔ   ÚgensÚpowré   r   r†  Úextendrá   r   Úpopr  rw  rÕ  Ú
get_domainr  )rÈ   Úpolyr.  r%  Úmonomr½  Ús_monomr�   r  Ús_coeffÚs_termÚmodifierrÛ   r
  r  r  rÜ   r_   r_   rb   Ú_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Û   rb  r  )rÈ   r:   r.  rÛ   rb  r_   r_   rb   Ú_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  r_   r_   rb   Ú_print_RootSumº	  s   ÿzLatexPrinter._print_RootSumc                 C  r1  )Nú\omegar_   rã   r_   r_   rb   Ú_print_OrdinalOmegaÇ	  r3  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  Úmulr_   r_   rb   Ú_print_OmegaPowerÊ	  s   


zLatexPrinter._print_OmegaPowerc                   s   d  ‡ fdd„|jD ƒ¡S )Nr!  c                   r
  r_   r  r;  r  r_   rb   r  Ø	  r  z/LatexPrinter._print_Ordinal.<locals>.<listcomp>)r  r  rã   r_   r  rb   Ú_print_Ordinal×	  s   zLatexPrinter._print_Ordinalc                 C  s   | j d }| | td|¡S )Nr±   z	{%s}^{%d})rÂ   r   r    )rÈ   r  r—   r_   r_   rb   Ú_print_PolyElementÚ	  s   
zLatexPrinter._print_PolyElementc                 C  s:   |j dkr|  |j¡S |  |j¡}|  |j ¡}d||f S )Nr-  r„  )r‰  rÔ   rˆ  )rÈ   r9   rˆ  r‰  r_   r_   rb   Ú_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ü  rc  )rÈ   rÛ   r  rÏ  rô   rÜ   r_   r_   rb   Ú_print_euleræ	  s   &zLatexPrinter._print_eulerc                 C  rµ  )NzC_{%s}r   r—  r£  r8  r_   r_   rb   Ú_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   rƒ  ©rÎ   rÔ   r  )rÈ   rÛ   ra   Úinverser_   r_   rb   Ú_print_UnifiedTransformõ	  s   >z$LatexPrinter._print_UnifiedTransformc                 C  ó   |   |d¡S )NÚM©r'  rã   r_   r_   rb   Ú_print_MellinTransformø	  rÛ  z#LatexPrinter._print_MellinTransformc                 C  ó   |   |dd¡S )Nr)  Tr*  rã   r_   r_   rb   Ú_print_InverseMellinTransformû	  r  z*LatexPrinter._print_InverseMellinTransformc                 C  r(  )NÚLr*  rã   r_   r_   rb   Ú_print_LaplaceTransformþ	  rÛ  z$LatexPrinter._print_LaplaceTransformc                 C  r,  )Nr.  Tr*  rã   r_   r_   rb   Ú_print_InverseLaplaceTransform
  r  z+LatexPrinter._print_InverseLaplaceTransformc                 C  r(  r²  r*  rã   r_   r_   rb   Ú_print_FourierTransform
  rÛ  z$LatexPrinter._print_FourierTransformc                 C  r,  )Nr³  Tr*  rã   r_   r_   rb   Ú_print_InverseFourierTransform
  r  z+LatexPrinter._print_InverseFourierTransformc                 C  r(  )NÚSINr*  rã   r_   r_   rb   Ú_print_SineTransform

  rÛ  z!LatexPrinter._print_SineTransformc                 C  r,  )Nr3  Tr*  rã   r_   r_   rb   Ú_print_InverseSineTransform
  r  z(LatexPrinter._print_InverseSineTransformc                 C  r(  )NÚCOSr*  rã   r_   r_   rb   Ú_print_CosineTransform
  rÛ  z#LatexPrinter._print_CosineTransformc                 C  r,  )Nr6  Tr*  rã   r_   r_   rb   Ú_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Ô  r_   r_   rb   Ú
_print_DMP
  s   
þÿzLatexPrinter._print_DMPc                 C  r~  rÓ   )r<  rÔ  r_   r_   rb   Ú
_print_DMF
  rÑ   zLatexPrinter._print_DMFc                 C  s   |   t|jƒ¡S rÓ   ©rÔ   r   r  )rÈ   rœ  r_   r_   rb   Ú_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Úarg1r_   r_   rb   Ú_print_LambertW%
  s   þzLatexPrinter._print_LambertWc                 C  ó   d  |  |jd ¡¡S )Nz!\operatorname{{E}}\left[{}\right]r   r%  rã   r_   r_   rb   Ú_print_Expectation/
  ó   zLatexPrinter._print_Expectationc                 C  rD  )Nz#\operatorname{{Var}}\left({}\right)r   r%  rã   r_   r_   rb   Ú_print_Variance2
  rF  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  r_   rb   rö   6
  r÷   z1LatexPrinter._print_Covariance.<locals>.<genexpr>)rÎ   r  r  rã   r_   r  rb   Ú_print_Covariance5
  s    zLatexPrinter._print_Covariancec                 C  rD  )Nz!\operatorname{{P}}\left({}\right)r   r%  rã   r_   r_   rb   Ú_print_Probability8
  rF  zLatexPrinter._print_Probabilityc                 C  s$   |   |j¡}|   |j¡}d||f S )Nz%s\rightarrow %s)rÔ   r  Úcodomain)rÈ   Úmorphismr  rJ  r_   r_   rb   Ú_print_Morphism;
  s   zLatexPrinter._print_Morphismc                 C  s&   |   |j¡|   |j¡}}d||f S )Nr„  )rÔ   rè  Úden)rÈ   rÛ   rè  rM  r_   r_   rb   Ú_print_TransferFunction@
  s   z$LatexPrinter._print_TransferFunctionc                   s(   t ˆ jƒ}‡ ‡fdd„}d t||ƒ¡S )Nc                   s   ˆ  | tˆ ƒd¡S r,  )rÙ   r   rt  rg  r_   rb   rc   F
  s    ÿz,LatexPrinter._print_Series.<locals>.<lambda>r­   )rw  r  r  rÕ  ©rÈ   rÛ   r  r/  r_   rg  rb   Ú_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,  )rs  rÙ   r   rÔ   rt  ©rQ  rÛ   rÈ   r_   rb   rc   M
  s
   ÿÿ
z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>z\cdot)Úsympy.physics.control.ltirQ  rw  r  r  rÕ  rO  r_   rR  rb   Ú_print_MIMOSeriesJ
  s   zLatexPrinter._print_MIMOSeriesc                 C  ó   d  t| j|jƒ¡S ©Nr!  ©r  rÕ  rÔ   r  rã   r_   r_   rb   Ú_print_ParallelQ
  rß  zLatexPrinter._print_Parallelc                 C  rU  rV  rW  rã   r_   r_   rb   Ú_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,  rL  rÃ  z\frac{%s}{%s %s %s})Úsympy.physics.controlrZ  r[  Úsys1rG  rs  rw  r  Úsys2rÔ   rá  )rÈ   rÛ   rZ  r[  rè  ÚtfÚnum_arg_listÚden_arg_listZ
den_term_1Z
den_term_2rˆ  Zdenom_1Zdenom_2Ú_signr_   r_   rb   Ú_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,  rL  rÃ  z)\left(I_{\tau} %s %s\right)^{-1} \cdot %s)r\  rd  rÔ   r^  r]  rá  )rÈ   rÛ   rd  Úinv_matr]  rb  r_   r_   rb   Ú_print_MIMOFeedback{
  s
   z LatexPrinter._print_MIMOFeedbackc                 C  s   |   |j¡}d| S )Nz%s_\tau)rÔ   Ú	_expr_matr&  r_   r_   rb   Ú_print_TransferFunctionMatrix‚
  s   z*LatexPrinter._print_TransferFunctionMatrixc                 C  s   d  |jj|j¡S )Nz\text{{{}}}_{{{}}})rÎ   r  r  rƒ  rã   r_   r_   rb   Ú
_print_DFT†
  rW  zLatexPrinter._print_DFTc                 C  s&   |   t|jƒ¡}|  |¡}d||f S )Nz%s:%s)rÔ   r   r  rL  )rÈ   rK  Úpretty_nameÚpretty_morphismr_   r_   rb   Ú_print_NamedMorphismŠ
  s   
z!LatexPrinter._print_NamedMorphismc                 C  s"   ddl m} |  ||j|jdƒ¡S )Nr   )ÚNamedMorphismÚid)Úsympy.categoriesrm  rl  r  rJ  )rÈ   rK  rm  r_   r_   rb   Ú_print_IdentityMorphism�
  s   
ÿz$LatexPrinter._print_IdentityMorphismc                   s<   ‡ fdd„|j D ƒ}| ¡  d |¡d }ˆ  |¡}|| S )Nc                   s   g | ]
}ˆ   t|jƒ¡‘qS r_   r>  )ró   Ú	componentr  r_   rb   r  —
  s    ÿz9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z\circ r  )rÉ  Úreverser  rL  )rÈ   rK  Úcomponent_names_listÚcomponent_namesrk  r_   r  rb   Ú_print_CompositeMorphism”
  s   
ÿ
z%LatexPrinter._print_CompositeMorphismc                 C  s   d  |  t|jƒ¡¡S ©Nrò  )rÎ   rÔ   r   r  )rÈ   rK  r_   r_   rb   Ú_print_CategoryŸ
  rF  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_resultr_   r_   rb   Ú_print_Diagram¢
  s   
ÿzLatexPrinter._print_Diagramc                 C  s–   dd|j   }t|jƒD ]8}t|j ƒD ]!}|||f r%|t|||f ƒ7 }|d7 }||j d kr4|d7 }q||jd kr@|d7 }|d7 }q|d7 }|S )	Nz\begin{array}{%s}
r…   r­   r-  ú& r±  Ú
z\end{array}
)Úwidthr?  ÚheightÚlatex)rÈ   Úgridr|  r�   r¸   r_   r_   rb   Ú_print_DiagramGrid®
  s   €
zLatexPrinter._print_DiagramGridc                 C  ó   d  |  |j¡|  |j¡¡S )Nz{{{}}}^{{{}}})rÎ   rÔ   r9  rS  ©rÈ   r)  r_   r_   rb   Ú_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 ©rs   r^   Nr  rò   r  r_   rb   rö   Å
  ó   € 
ÿz8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>)rÎ   r  )rÈ   rÏ  r_   r  rb   Ú_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 r_   )rÔ   r9  r:  rò   ©rÏ  rÈ   r_   rb   r  É
  ó    z<LatexPrinter._print_SubModule.<locals>.<listcomp>.<listcomp>r_   ©ró   Úgr�  r_   rb   r  É
  s     z1LatexPrinter._print_SubModule.<locals>.<listcomp>c                 S  r]   )Nrs   r^   r_   ©rL   r_   r_   rb   rc   Ê
  rd   z/LatexPrinter._print_SubModule.<locals>.<lambda>c                 S  r]   )Nz\left[ z \right]r_   r‘  r_   r_   rb   rc   Ë
  rd   r.  c                 3  s0   � | ]}ˆ ˆd   ‡ fdd„|D ƒ¡ƒƒV  qdS )r.  c                 3  s   � | ]}ˆ |ƒV  qd S rÓ   r_   rò   )Úcurlyr_   rb   rö   Ì
  râ  z:LatexPrinter._print_SubModule.<locals>.<genexpr>.<genexpr>N)r  r�  )r’  Úsquarer_   rb   rö   Ì
  s   €. z0LatexPrinter._print_SubModule.<locals>.<genexpr>ú\left\langle {} \right\rangle)r
  r  rÎ   ©rÈ   rÏ  r
  Ú
gens_latexr_   )r’  rÏ  rÈ   r“  rb   Ú_print_SubModuleÈ
  s
   
zLatexPrinter._print_SubModulec                   s$   d  ‡ fdd„|jD ƒ¡}d |¡S )Nr.  c                   s   g | ]}d ˆ   |¡ d ‘qS )rs   r^   r  r�  r  r_   rb   r  Ð
  rŽ  z9LatexPrinter._print_SubQuotientModule.<locals>.<listcomp>r”  )r  r
  rÎ   )rÈ   rÏ  r–  r_   r  rb   Ú_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 r_   )r9  r:  rò   ©rÏ  r_   rb   r  Ô
  r  z>LatexPrinter._print_ModuleImplementedIdeal.<locals>.<listcomp>r.  c                 3  r‰  rŠ  r  rò   r  r_   rb   rö   Õ
  s   €  z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>r”  )Ú_moduler
  r  rÎ   r•  r_   r�  rb   Ú_print_ModuleImplementedIdealÓ
  s   
z*LatexPrinter._print_ModuleImplementedIdealc                   sD   ‡ fdd„|j D ƒ}|d gdd„ t|dd … dƒD ƒ }d |¡S )Nc                   s    g | ]}ˆ j |td  dd�‘qS )r	   Tr  )rÙ   r    r§  r  r_   rb   r  Û
  s    ÿz2LatexPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]
\}}|d  | ‘qS )r­   r_   )ró   r�   r¸   r_   r_   rb   r  Ý
  rh  r-  Úijkr!  )r  rì  r  )rÈ   rÛ   ra   r‹  r_   r  rb   Ú_print_QuaternionØ
  s
   
ÿ&
zLatexPrinter._print_Quaternionc                 C  r…  ©Nz\frac{{{}}}{{{}}})rÎ   rÔ   r9  Ú
base_ideal)rÈ   ÚRr_   r_   rb   Ú_print_QuotientRingà
  ó   
ÿz LatexPrinter._print_QuotientRingc                 C  s(   |   |j |¡¡}d ||   |jj¡¡S )Nú{{{}}} + {{{}}})rÔ   r9  r:  rÎ   rŸ  )rÈ   rô   Zx_latexr_   r_   rb   Ú_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 r_   )Úmoduler9  r:  rò   r™  r_   rb   r  ë
  r  z=LatexPrinter._print_QuotientModuleElement.<locals>.<listcomp>rˆ  r.  c                 3  r‰  rŠ  r  rò   r  r_   rb   rö   ì
  r‹  z<LatexPrinter._print_QuotientModuleElement.<locals>.<genexpr>r£  )ÚdatarÎ   r  rÔ   r¥  Úkilled_module)rÈ   rÏ  r¦  Z
data_latexr_   r�  rb   Ú_print_QuotientModuleElementê
  s   
ÿÿz)LatexPrinter._print_QuotientModuleElementc                 C  r…  rž  )rÎ   rÔ   r  r§  r†  r_   r_   rb   Ú_print_QuotientModuleñ
  r¢  z"LatexPrinter._print_QuotientModulec                 C  s(   d  |  | ¡ ¡|  |j¡|  |j¡¡S )Nz{{{}}} : {{{}}} \to {{{}}})rÎ   rÔ   Ú_sympy_matrixr  rJ  )rÈ   r  r_   r_   rb   Ú_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í  r_   r_   rb   Ú_print_Manifoldú
  s   zLatexPrinter._print_Manifoldc                 C  r   )Nz\text{%s}_{%s})rÔ   r  r¬  )rÈ   Úpatchr_   r_   rb   Ú_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coordsysr_   r_   rb   Ú_print_CoordSystem  s    ÿzLatexPrinter._print_CoordSystemc                 C  s   d|   |j¡ S )Nz\mathbb{\nabla}_{%s})rÔ   Z_wrt)rÈ   Zcvdr_   r_   rb   Ú_print_CovarDerivativeOp  r¥  z%LatexPrinter._print_CovarDerivativeOpc                 C  ó$   |j j|j j}d |  t|ƒ¡¡S rv  ©Ú
_coord_sysrú  Ú_indexr  rÎ   rÔ   r   ©rÈ   Úfieldrñ  r_   r_   rb   Ú_print_BaseScalarField  ó   z#LatexPrinter._print_BaseScalarFieldc                 C  r²  )Nz\partial_{{{}}}r³  r¶  r_   r_   rb   Ú_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_fieldrr  r´  rú  rµ  r  rÎ   rÔ   r   )rÈ   Údiffr·  rñ  r_   r_   rb   Ú_print_Differential  s   


z LatexPrinter._print_Differentialc                 C  rî  )Nr   z"\operatorname{{tr}}\left({}\right)rï  )rÈ   r“  Úcontentsr_   r_   rb   Ú	_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  r_   r_   rb   Ú_print_totient&  ó
   ÿzLatexPrinter._print_totientc                 C  rÀ  )Nz(\left(\lambda\left(%s\right)\right)^{%s}r   z\lambda\left(%s\right)r£  r  r_   r_   rb   Ú_print_reduced_totient,  rÂ  z#LatexPrinter._print_reduced_totientc                 C  ód   t |jƒdkrdtt| j|jd |jd fƒƒ }n
d|  |jd ¡ }|d ur.d||f S d| S )Nrƒ  ú_%s\left(%s\right)r-  r   r"  z\sigma^{%s}%sz\sigma%srµ  r8  r_   r_   rb   Ú_print_divisor_sigma2  ó   

ÿz!LatexPrinter._print_divisor_sigmac                 C  rÄ  )Nrƒ  rÅ  r-  r   r"  z\sigma^*^{%s}%sz
\sigma^*%srµ  r8  r_   r_   rb   Ú_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  r_   r_   rb   Ú_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  r_   r_   rb   Ú_print_primeomegaL  rÂ  zLatexPrinter._print_primeomegac                 C  s
   t |jƒS rÓ   )r   r  rÏ   r_   r_   rb   Ú
_print_StrR  rÑ   zLatexPrinter._print_Strc                 C  r  rÓ   )rÔ   r   rã   r_   r_   rb   Ú_print_floatU  r  zLatexPrinter._print_floatc                 C  ó   t |ƒS rÓ   ©r   rã   r_   r_   rb   Ú
_print_intX  r  zLatexPrinter._print_intc                 C  rÍ  rÓ   rÎ  rã   r_   r_   rb   Ú
_print_mpz[  r  zLatexPrinter._print_mpzc                 C  rÍ  rÓ   rÎ  rã   r_   r_   rb   Ú
_print_mpq^  r  zLatexPrinter._print_mpqc                 C  rÍ  rÓ   rÎ  rã   r_   r_   rb   Ú_print_fmpza  r  zLatexPrinter._print_fmpzc                 C  rÍ  rÓ   rÎ  rã   r_   r_   rb   Ú_print_fmpqd  r  zLatexPrinter._print_fmpqc                 C  s   d  tt|jƒƒ¡S )Nz"\operatorname{{Q}}_{{\text{{{}}}}})rÎ   r†   r   r  rã   r_   r_   rb   Ú_print_Predicateg  rß  zLatexPrinter._print_Predicatec                   s:   |j }|j}ˆ  |¡}d ‡ fdd„|D ƒ¡}d||f S )Nr  c                   r
  r_   r  rw  r  r_   rb   r  n  r  z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>z%s(%s))r¸  Ú	argumentsrÔ   r  )rÈ   rÛ   Úpredr  Z
pred_latexZ
args_latexr_   r  rb   Ú_print_AppliedPredicatej  s
   
z$LatexPrinter._print_AppliedPredicatec                   s   t ƒ  |¡}dt|ƒ S )Nz\mathtt{\text{%s}})ÚsuperÚemptyPrinterr†   ræ  ©r  r_   rb   rÙ  q  s   zLatexPrinter.emptyPrinterrÓ   r…  )FF)r€   rÝ   )rÛ   r   )r  r  )rÛ   r   )rÛ   r   )r�  r   r€   r   )rÛ   r¾  )rj  r   r€   r   )rÛ   r   r€   r   r«  )rˆ  r   r€   r   r  )FN)r–   )rÛ   r   )r  r   r€   rë  )rñ  r   r€   r   )rÛ   r%   )r]  r^  )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(  r5  rE  rH  rW  r_  re  rg  rh  rk  rl  r�  r‘  r•  rœ  r›  r¤  r»  r½  rÓ  r×  rÚ  rÞ  ré  rï  rû  r  r  r  r  r!  Úpropertyr,  r/  r0  r2  r6  Z
_print_MinZ
_print_Maxr9  r;  r<  r>  rB  rD  rK  rN  rR  rT  rU  rI  rH  rX  r[  r\  r]  r_  rb  rd  re  rg  rk  rm  rn  rq  rs  Ú_print_gammart  rw  rx  ry  r}  r  r€  r�  r„  r‡  r‹  rŒ  r�  r‘  r“  r•  r–  r—  r˜  r™  rš  r›  rŸ  r¡  r¥  r¨  rª  r«  r¯  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*  r0  r3  r5  r6  r?  rA  rC  rD  rE  rJ  rN  rO  rQ  r\  rc  re  rf  rj  rk  rl  rm  rn  ro  rp  rq  ru  r{  r}  r  r�  r„  r…  r†  rˆ  rŠ  r‹  rŒ  r�  r’  r�  Ú_print_frozensetr¨  r­  r®  r°  r±  r´  r¶  r¹  rº  r¿  Ú_print_SeqPerÚ_print_SeqAddÚ_print_SeqMulrÃ  rÅ  rÎ  rÐ  rÑ  rÒ  rÕ  rÖ  rØ  rÙ  rÛ  rÝ  rß  rá  rç  rí  rð  rñ  rò  r÷  rù  rû  rü  rý  rþ  rÿ  r  r  r	  r  r  r  r  r  r   r!  r"  r#  r$  r'  r+  r-  r/  r0  r1  r2  r4  r5  r7  r8  r<  r=  r?  rC  rE  rG  rH  rI  rL  rN  rP  rT  rX  rY  rc  rf  rh  ri  Z_print_IDFTrl  rp  ru  rw  r}  r„  r‡  rŒ  r—  r˜  r›  r�  r¡  r¤  r¨  r©  r«  r­  r¯  r°  r±  r¸  rº  r½  r¿  rÁ  rÃ  rÆ  rÈ  rÉ  rÊ  rË  rÌ  rÏ  rÐ  rÑ  rÒ  rÓ  rÔ  r×  rÙ  Ú__classcell__r_   r_   rÚ  rb   r‡   Ž   sÔ  
 ÿþýüûúùø	÷
öõôóòñðïæ=

	!s-!
$ L

										
7



*9		
$	

r‡   c                 C  s–   t  | ¡}|r	|S |  ¡ tv rd|  ¡  S | tv rd|  S tt ¡ tdd�D ]"}|  ¡  	|¡rHt| ƒt|ƒkrHt| t
| dt|ƒ … ƒƒ  S q&| S )aŽ  
    Check for a modifier ending the string.  If present, convert the
    modifier to latex and translate the rest recursively.

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

    Let everything else pass as given.

    >>> from sympy.printing.latex import translate
    >>> translate('alphahatdotprime')
    "{\\dot{\\hat{\\alpha}}}'"
    r�   T)rÂ  rr  N)Útex_greek_dictionaryrÇ   rA  Úgreek_letters_setÚother_symbolsr5  r~   r‚  r@  r¡  rî  )ra   rÜ   rÂ  r_   r_   rb   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.

    )r‡   rÚ   ©rÛ   rÉ   r_   r_   rb   r‚  —  s    Xr‚  c                 K  s   t t| fi |¤Žƒ dS )z`Prints LaTeX representation of the given expression. Takes the same
    settings as ``latex()``.N)Úprintr‚  rì  r_   r_   rb   Ú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-  rL  z& & r~  r±  r  r   r,  rÃ  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s}Nr_   )r‡   rÃ   rÎ   Úas_ordered_termsr@  r?  rv  rÚ   )rõ  r÷  Zterms_per_lineÚenvironmentZuse_dotsrÉ   r®  rA  Z
first_termZnonumberZend_termZdoubleetr›  r%  Zn_termsZ
term_countr�   r&  Z
term_startZterm_endrá  r_   r_   rb   Úmultiline_latexx  sn   Cÿ

ÿ
rò  )ra   r   r€   r   )r-  rï  F)JÚ__doc__Ú
__future__r   Útypingr   r   r   rU  Ú
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   rG  r   r   r   Úsympy.printing.precedencer   Úsympy.printing.printerr   r   Úsympy.printing.conventionsr   r   r   r    Zmpmath.libmp.libmpfr!   r"   rP  Úsympy.utilities.iterablesr#   r$   r7   Úsympy.tensor.arrayr%   Zsympy.vector.basisdependentr&   r  ré  rë  r~   rÞ  Ú	frozensetrê  Úcompiler|  r†   r‡   rî  r‚  rî  rò  r_   r_   r_   rb   Ú<module>   sZ   (ÿþýüûúùø	÷
öõôóòñðïîíìëêéèçæåäãâá à!ß"Þ#Ü'þýüûúùø	÷
öõôóòñðîíåþ
                     

 Z