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\lambdaÚLamdaÚkhiz\chiÚKhiÚ
varepsilonz\varepsilonÚvarkappaz	\varkappaÚvarphiz\varphiÚvarpiz\varpiÚvarrhoz\varrhoz	\varsigmaz	\vartheta)ÚvarsigmaÚvartheta>
   ÚwpÚellÚethÚmhoÚbethÚhbarÚalephÚgimelÚdalethÚhslashÚmathringc                 C  ó   d|  d S )Nz
\mathring{Ú}© ©Úsro   ro   ú–/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/venv/lib/python3.10/site-packages/sympy/printing/latex.pyÚ<lambda>[   ó    rs   Úddddotc                 C  rm   )Nz\ddddot{rn   ro   rp   ro   ro   rr   rs   \   rt   Údddotc                 C  rm   )Nz\dddot{rn   ro   rp   ro   ro   rr   rs   ]   rt   Úddotc                 C  rm   )Nz\ddot{rn   ro   rp   ro   ro   rr   rs   ^   rt   Údotc                 C  rm   )Nz\dot{rn   ro   rp   ro   ro   rr   rs   _   rt   Úcheckc                 C  rm   )Nz\check{rn   ro   rp   ro   ro   rr   rs   `   rt   Úbrevec                 C  rm   )Nz\breve{rn   ro   rp   ro   ro   rr   rs   a   rt   Úacutec                 C  rm   )Nz\acute{rn   ro   rp   ro   ro   rr   rs   b   rt   Úgravec                 C  rm   )Nz\grave{rn   ro   rp   ro   ro   rr   rs   c   rt   Útildec                 C  rm   )Nz\tilde{rn   ro   rp   ro   ro   rr   rs   d   rt   Úhatc                 C  rm   )Nz\hat{rn   ro   rp   ro   ro   rr   rs   e   rt   Úbarc                 C  rm   )Nz\bar{rn   ro   rp   ro   ro   rr   rs   f   rt   Úvecc                 C  rm   )Nz\vec{rn   ro   rp   ro   ro   rr   rs   g   rt   Úprimec                 C  rm   ©NÚ{z}'ro   rp   ro   ro   rr   rs   h   rt   Úprmc                 C  rm   r‚   ro   rp   ro   ro   rr   rs   i   rt   Úboldc                 C  rm   ©Nz\boldsymbol{rn   ro   rp   ro   ro   rr   rs   k   rt   Úbmc                 C  rm   r†   ro   rp   ro   ro   rr   rs   l   rt   c                 C  rm   )Nz	\mathcal{rn   ro   rp   ro   ro   rr   rs   m   rt   c                 C  rm   )Nz	\mathscr{rn   ro   rp   ro   ro   rr   rs   n   rt   c                 C  rm   )Nz
\mathfrak{rn   ro   rp   ro   ro   rr   rs   o   rt   c                 C  rm   )Nz\left\|{z	}\right\|ro   rp   ro   ro   rr   rs   q   rt   c                 C  rm   )Nz\left\langle{z}\right\ranglero   rp   ro   ro   rr   rs   r   rt   c                 C  rm   ©Nz\left|{z}\right|ro   rp   ro   ro   rr   rs   s   rt   c                 C  rm   rˆ   ro   rp   ro   ro   rr   rs   t   rt   )ÚcalÚscrÚfrakÚnormÚavgÚabsÚmagzdict[str, Callable[[str], str]]Úmodifier_dictz[0-9][} ]*$z(\d|\\frac{\d+}{\d+})rq   ÚstrÚreturnc                 C  sB   |   dd¡} dD ]
}|   |d| ¡} q|   dd¡} |   dd¡} | S )zÉ
    Escape a string such that latex interprets it as plaintext.

    We cannot use verbatim easily with mathjax, so escaping is easier.
    Rules from https://tex.stackexchange.com/a/34586/41112.
    ú\z\textbackslashz&%$#_{}ú~z\textasciitildeú^z\textasciicircum)Úreplace)rq   Úcro   ro   rr   Úlatex_escape   s   r˜   c                      s  e Zd ZU dZi dd“dd“dd“dd“dd	“d
d“dd“dd“dd“dd“dd“dd“dd“di “dd“dd“dd“ddddddddd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 )NÚldotrx   Útimesr©   Úmul_symbol_latexrx   Úmul_symbol_latex_numbers)Ú r¿   r“   z\,z\:ú\;z\quadú)ú])ú(r¥   r¯   z
\mathrm{i}z\text{i}Újz
\mathrm{j}z\text{j})Nr¯   ÚriÚtirË   ÚrjÚtjr®   Úimaginary_unit_latexr±   z
\mathrm{d}z\text{d})Nr±   ÚrdÚtdr¹   Údiff_operator_latex)r   Ú__init__Ú	_settingsÚ
ValueErrorÚKeyErrorÚstripÚ_delim_dictÚget)ÚselfÚsettingsÚvalid_modesÚmul_symbol_tableÚimaginary_unit_tableÚ	imag_unitÚdiff_operator_tabler¹   ro   ro   rr   rÔ   ®   sf   

üÿÿÿÿÿ
ÿÿ€ú	ù
	ü
zLatexPrinter.__init__r’   r‘   c                 C  ó
   d  |¡S )Nz\left({}\right)©Úformat©rÛ   rq   ro   ro   rr   Ú_add_parensë   ó   
zLatexPrinter._add_parensc                 C  râ   )Nz\left( {}\right)rã   rå   ro   ro   rr   Ú_add_parens_lspaceï   rç   zLatexPrinter._add_parens_lspacec                 C  sN   t |ƒ}|r|r|  |  |¡¡S ||k s|s"||kr"|  |  |¡¡S |  |¡S ©N)r   ræ   Ú_print)rÛ   ÚitemÚlevelÚis_negÚstrictÚprec_valro   ro   rr   Úparenthesizeò   s   
zLatexPrinter.parenthesizec                 C  s*   d|v r| j d r|  |¡S d |¡S |S )z”
        Protect superscripts in s

        If the parenthesize_super option is set, protect with parentheses, else
        wrap in braces.
        r•   r¶   z{{{}}})rÕ   ræ   rä   rå   ro   ro   rr   r¶   ü   s
   


zLatexPrinter.parenthesize_superc                 C  s^   t  | |¡}| jd dkr|S | jd dkrd| S | jd r#d| S | jd }d|||f S )Nr§   r¨   r½   z$%s$r¡   z$$%s$$z\begin{%s}%s\end{%s})r   ÚdoprintrÕ   )rÛ   ÚexprÚtexÚenv_strro   ro   rr   rñ   
  s   

zLatexPrinter.doprintÚboolc                 C  s(   |j r|jp|jo|tjuo|jdu  S )zÁ
        Returns True if the expression needs to be wrapped in brackets when
        printed, False otherwise. For example: a + b => True; a => False;
        10 => False; -10 => True.
        F)Ú
is_IntegerÚis_nonnegativeÚis_Atomr   ÚNegativeOneÚis_Rational©rÛ   rò   ro   ro   rr   Ú_needs_brackets  s   þzLatexPrinter._needs_bracketsc                 C  sJ   |   |¡sdS |jr|  |¡sdS |jr|  |¡sdS |js!|jr#dS dS )aˆ  
        Returns True if the expression needs to be wrapped in brackets when
        passed as an argument to a function, False otherwise. This is a more
        liberal version of _needs_brackets, in that many expressions which need
        to be wrapped in brackets when added/subtracted/raised to a power do
        not need them when passed to a function. Such an example is a*b.
        FT)rü   Úis_MulÚ_mul_is_cleanÚis_PowÚ_pow_is_cleanÚis_AddÚis_Functionrû   ro   ro   rr   Ú_needs_function_brackets!  s   
z%LatexPrinter._needs_function_bracketsc                   s¨   ddl m} ddlm} ddlm} ˆ jr|sˆ  ¡ rdS ntˆ ƒt	d k r(dS ˆ j
r-dS ˆ jr2dS t‡ fdd„tfD ƒƒr@dS |sRt‡ fd	d„|||fD ƒƒrRdS d
S )aÇ  
        Returns True if the expression needs to be wrapped in brackets when
        printed as part of a Mul, False otherwise. This is True for Add,
        but also for some container objects that would not need brackets
        when appearing last in a Mul, e.g. an Integral. ``last=True``
        specifies that this expr is the last to appear in a Mul.
        ``first=True`` specifies that this expr is the first to appear in
        a Mul.
        r   )ÚProduct)ÚSum)ÚIntegralTr	   c                 3  ó   � | ]}ˆ   |¡V  qd S ré   ©Úhas©Ú.0Úx©rò   ro   rr   Ú	<genexpr>O  ó   € z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>c                 3  r  ré   r  r
  r  ro   rr   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  ro   r  rr   Ú_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  ro   rr   r  _  r  z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>F)r  r  r   r  rû   ro   r  rr   Ú_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;   ro   ro   rr   rþ   e  s
   
ÿzLatexPrinter._mul_is_cleanc                 C  s   |   |j¡ S ré   )rü   Úbaserû   ro   ro   rr   r   k  ó   zLatexPrinter._pow_is_cleanrò   c                 C  s   |d ur
d||f S |S )Nú\left(%s\right)^{%s}ro   ©rÛ   rò   Úexpro   ro   rr   Ú_do_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 ro   ©rê   )r  rL   ©rÛ   ro   rr   Ú
<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Úlsrq   ro   r$  rr   Ú_print_Basict  s   
zLatexPrinter._print_BasicÚeú!bool | BooleanTrue | BooleanFalsec                 C  ó   d| S ©Nú	\text{%s}ro   ©rÛ   r/  ro   ro   rr   Ú_print_bool}  ó   zLatexPrinter._print_boolc                 C  r1  r2  ro   r4  ro   ro   rr   Ú_print_NoneTypeƒ  r6  zLatexPrinter._print_NoneTypec                 C  sv   | j ||d�}d}t|ƒD ]+\}}|dkrn| ¡ r"|d7 }| }n|d7 }|  |¡}|  |¡r4d| }||7 }q|S )N)rª   rÆ   r   ú - ú + ú\left(%s\right))Ú_as_ordered_termsÚ	enumerater  rê   r  )rÛ   rò   rª   Útermsró   r¯   ÚtermÚterm_texro   ro   rr   Ú
_print_Add†  s   


zLatexPrinter._print_Addc                 C  sŽ   ddl m} |jdkrdS ||ƒ}|j}|j}|jd |d kr(||d gg }d}|D ]}|t|ƒ dd¡7 }q,| d	d
¡}| dd¡}|S )Nr   ©ÚPermutationú\left( \right)éÿÿÿÿé   rÆ   ú,rÇ   r¥   z\left( rÉ   ú\right))Ú sympy.combinatorics.permutationsrB  ÚsizeÚcyclic_formÚ
array_formr‘   r–   )rÛ   rò   rB  Ú	expr_permÚsizr?  r¯   ro   ro   rr   Ú_print_Cycle™  s   
zLatexPrinter._print_Cyclec           
        sÂ   ddl m} ddlm} |j}|d ur |d|› d�dddd	� nˆ j d
d¡}|r.ˆ  |¡S |jdkr5dS ‡ fdd„|j	D ƒ}‡ fdd„t
t|ƒƒD ƒ}d |¡}d |¡}d ||f¡}	d|	 S )Nr   rA  )Ú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µ   TrC  c                   r"  ro   r#  ©r  r;   r$  ro   rr   r%  Á  r&  z3LatexPrinter._print_Permutation.<locals>.<listcomp>c                   r"  ro   r#  rT  r$  ro   rr   r%  Â  r&  ú & z \\ z \begin{pmatrix} %s \end{pmatrix})rH  rB  Úsympy.utilities.exceptionsrO  Úprint_cyclicrÕ   rÚ   rN  rI  rK  ÚrangeÚlenr+  )
rÛ   rò   rB  rO  rµ   ÚlowerÚupperÚrow1Úrow2Úmatro   r$  rr   Ú_print_Permutation©  s.   þù




zLatexPrinter._print_Permutationc                 C  s"   |j \}}d|  |¡|  |¡f S )Nz\sigma_{%s}(%s))r  rê   )rÛ   rò   ÚpermÚvarro   ro   rr   Ú_print_AppliedPermutationÊ  s   
z&LatexPrinter._print_AppliedPermutationc           
      C  sö   t |jƒ}| jd rdnd}d| jv r| jd nd }d| jv r$| jd nd }t|j||||d�}| jd }d|v r`| d¡\}}	|	d	 d
krL|	dd … }	| jd dkrY| dd¡}d|||	f S |dkrfdS |dkrldS | jd dkry| dd¡}|S )Nr›   FTr·   r¸   )Ústrip_zerosÚ	min_fixedÚ	max_fixedrÅ   r/  r   ú+rE  r´   ÚcommaÚ.z{,}z%s%s10^{%s}z+infz\inftyz-infz- \infty)r!   Ú_precrÕ   Úmlib_to_strÚ_mpf_Úsplitr–   )
rÛ   rò   ÚdpsrØ   ÚlowÚhighÚstr_realÚ	separatorÚmantr   ro   ro   rr   Ú_print_FloatÎ  s(   

zLatexPrinter._print_Floatc                 C  ó0   |j }|j}d|  |td ¡|  |td ¡f S )Nz%s \times %sr	   ©Ú_expr1Ú_expr2rð   r    ©rÛ   rò   Úvec1Úvec2ro   ro   rr   Ú_print_Crossì  ó
   ÿzLatexPrinter._print_Crossc                 C  ó   |j }d|  |td ¡ S )Nz\nabla\times %sr	   ©Ú_exprrð   r    ©rÛ   rò   r€   ro   ro   rr   Ú_print_Curlò  ó   zLatexPrinter._print_Curlc                 C  r}  )Nz\nabla\cdot %sr	   r~  r€  ro   ro   rr   Ú_print_Divergenceö  r‚  zLatexPrinter._print_Divergencec                 C  rt  )Nz%s \cdot %sr	   ru  rx  ro   ro   rr   Ú
_print_Dotú  r|  zLatexPrinter._print_Dotc                 C  r}  )Nz	\nabla %sr	   r~  ©rÛ   rò   Úfuncro   ro   rr   Ú_print_Gradient   r‚  zLatexPrinter._print_Gradientc                 C  r}  )Nz	\Delta %sr	   r~  r…  ro   ro   rr   Ú_print_Laplacian  r‚  zLatexPrinter._print_Laplacianr   c                   s¢  ddl m} ˆjd ‰ˆjd ‰d#‡ ‡fdd„}d#‡‡‡fd	d
„‰ t|tƒrA|j}|d tju s=tdd„ |dd … D ƒƒrAˆ |ƒS d}| 	¡ rV| }d}|j
rU|d7 }d}nd}||dd�\}}|tju rvtdddd�|jvrv|||ƒ7 }nÒ||ƒ}	||ƒ}
t|
 ¡ ƒ}ˆjd }ˆjd r¯|dk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  ro   ro   rr   rs     s    
z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>T)Úbinaryc                 S  s
   t | dƒS )NrŒ  )rŽ  r�  ro   ro   rr   rs     s   
 )rý   r‘   rê   rª   Úas_ordered_factorsÚlistr  r$   )rò   r  ÚunitsÚnonunitsÚprefixes)Úconvert_argsrÛ   ro   rr   Úconvert  s   




þz(LatexPrinter._print_Mul.<locals>.convertc                   s°   d }}t | ƒD ]M\}}ˆ |¡}t|dƒsIt|dƒsIˆj||dk|t| ƒd kd�r/d| }td  |¡rBtd  |¡rB|ˆ 7 }n|rH|ˆ7 }n|rO|ˆ7 }||7 }|}q|S )NrÆ   rŒ  r�  r   rE  )r  r  r:  )r<  rê   rŽ  r  rY  Ú_between_two_numbers_pÚsearchÚmatch)r  Ú_texÚlast_term_texr¯   r>  r?  )Ú	numberseprÛ   rq  ro   rr   r—    s(   
ÿÿ
€z-LatexPrinter._print_Mul.<locals>.convert_argsc                 s  s   � | ]}t |tƒV  qd S ré   )r�  r
   rT  ro   ro   rr   r  ;  r  z*LatexPrinter._print_Mul.<locals>.<genexpr>rE  Fú- rÊ   TrÆ   )ÚexactrD  )Úevaluater£   rž   é   r•   )r  z\left(%s\right) / %sz%s / %sz\frac{1}{%s}%s\left(%s\right)z\frac{%s}{%s}%s\left(%s\right)z\frac{%s}{%s}%s%sz\frac{1}{%s}%s%sú\frac{%s}{%s}rÈ   ©r’   r‘   )Úsympy.simplifyr‰  rÕ   r�  r	   r  r   ÚOner  r  r  r   rY  rl  r  rý   Úis_commutative)rÛ   rò   r‰  r˜  r  Úinclude_parensró   ÚnumerÚdenomÚsnumerÚsdenomÚldenomÚratioÚaÚbr  ro   )r—  rž  rÛ   rq  rr   Ú
_print_Mul  sr   


(€

ÿ
 

ÿÿzLatexPrinter._print_Mulc                 C  s&   |j r|  | ¡  ¡ ¡S |  | ¡ ¡S ré   )Ú
is_aliasedrê   Úas_polyÚas_exprrû   ro   ro   rr   Ú_print_AlgebraicNumber{  s   z#LatexPrinter._print_AlgebraicNumberc                 C  s@   |   |j¡}|jrd|› d�S |   |j ¡ ¡}d|› d|› d�S )Nú\left(rG  r'  )rê   ÚpÚis_inertÚalphar´  )rÛ   rò   r·  r¹  ro   ro   rr   Ú_print_PrimeIdeal�  s
   zLatexPrinter._print_PrimeIdealr   c                 C  s¦  |j jr»|j j}|j j}t|ƒdkrF|dkrF| jd rF|  |j¡}|dkr*d| }n| jd r6d||f }nd||f }|j jrDd| S |S | jd	 rx|dkrx|  	|jt
d
 ¡}|jjra|  |¡}|jjrq| j|jd||f d�S d|||f S |j jr»|jjr»|jdk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 )NrE  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}rD  z\frac{1}{\frac{%s}{%s}}z\frac{1}{(\frac{%s}{%s})^{%s}})r   rú   r·  ÚqrŽ   rÕ   rê   r  Úis_negativerð   r    Ú	is_Symbolr¶   r  r§  r±  Ú_helper_print_standard_power)rÛ   rò   r·  r½  r  ró   Úbase_pÚbase_qro   ro   rr   Ú
_print_Powˆ  sF   





zLatexPrinter._print_PowÚtemplatec                 C  sˆ   |   |j¡}|  |jtd ¡}|jjr|  |¡}n%|jjr"d| }nt|jt	ƒr>| 
d¡r>t d|¡r>| d¡r>|dd… }|||f S )Nr   z{%s}r¶  z\\left\(\\d?d?dotrG  é   iùÿÿÿ)rê   r   rð   r  r    r¿  r¶   Úis_Floatr�  r   Ú
startswithr7   r›  Úendswith)rÛ   rò   rÄ  r   r  ro   ro   rr   rÀ  µ  s   
ÿ
þýz)LatexPrinter._helper_print_standard_powerc                 C  s   |   |jd ¡S ©Nr   ©rê   r  rû   ro   ro   rr   Ú_print_UnevaluatedExprÆ  ó   z#LatexPrinter._print_UnevaluatedExprc                   ó”   t |jƒdkrdt‡fdd„|jd D ƒƒ }n‡fdd„‰ dt d	‡ fd
d„|jD ƒ¡ }t|jtƒr@|dˆ |j¡ 7 }|S |ˆ |j¡7 }|S )NrE  z\sum_{%s=%s}^{%s} c                   r"  ro   r#  ©r  r¯   r$  ro   rr   r%  Ì  r&  z+LatexPrinter._print_Sum.<locals>.<listcomp>r   c                   ó,   dt ‡ fdd„| d | d | d fD ƒƒ S )Nú%s \leq %s \leq %sc                   r"  ro   r#  ©r  rq   r$  ro   rr   r%  Ð  r&  zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>rE  r   r¢  ©Útuple©Úlr$  ro   rr   Ú_format_ineqÎ  ó   &ÿz-LatexPrinter._print_Sum.<locals>._format_ineqz\sum_{\substack{%s}} ú\\c                   ó   g | ]}ˆ |ƒ‘qS ro   ro   ©r  rÕ  ©rÖ  ro   rr   r%  Ó  ó    r:  ©	rY  ÚlimitsrÓ  r‘   r+  r�  Úfunctionr   rê   ©rÛ   rò   ró   ro   ©rÖ  rÛ   rr   Ú
_print_SumÉ  ó   ÿÿþzLatexPrinter._print_Sumc                   rÍ  )NrE  z\prod_{%s=%s}^{%s} c                   r"  ro   r#  rÎ  r$  ro   rr   r%  ß  r&  z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                   rÏ  )NrÐ  c                   r"  ro   r#  rÑ  r$  ro   rr   r%  ã  r&  zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>rE  r   r¢  rÒ  rÔ  r$  ro   rr   rÖ  á  r×  z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} rØ  c                   rÙ  ro   ro   rÚ  rÛ  ro   rr   r%  æ  rÜ  r:  rÝ  rà  ro   rá  rr   Ú_print_ProductÜ  rã  zLatexPrinter._print_Productú'BasisDependent'c                 C  s  ddl m} g }||jkr|jjS t||ƒr| ¡  ¡ }nd|fg}|D ]G\}}t|j ¡ ƒ}|j	dd„ d� |D ]1\}}	|	dkrJ| 
d|j ¡ q9|	dkrW| 
d	|j ¡ q9d
|  |	¡ d }
| 
d|
 |j ¡ q9q$d |¡}|d dkr|dd … }|S |dd … }|S )Nr   )ÚVectorc                 S  s   | d   ¡ S rÉ  )Ú__str__r�  ro   ro   rr   rs   ü  rt   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>©ÚkeyrE  r9  rD  r8  r¶  rG  rÆ   ú-é   )Úsympy.vectorræ  ÚzeroÚ_latex_formr�  ÚseparateÚitemsr“  Ú
componentsÚsortÚappendrê   r+  )rÛ   rò   ræ  Úo1rð  ÚsystemÚvectÚ
inneritemsÚkÚvÚarg_strÚoutstrro   ro   rr   Ú_print_BasisDependentï  s0   


ù
	ÿz"LatexPrinter._print_BasisDependentc                 C  s4   |   |j¡}d| d dd t| j |jƒ¡  }|S )Nrƒ   rn   ú_{%s}rF  )rê   r  r+  ÚmapÚindices)rÛ   rò   Útex_baseró   ro   ro   rr   Ú_print_Indexed  s
   ÿzLatexPrinter._print_Indexedc                 C  ó   |   |j¡S ré   )rê   Úlabelrû   ro   ro   rr   Ú_print_IndexedBase  ó   zLatexPrinter._print_IndexedBasec                 C  sf   |   |j¡}|jd ur1|   |j¡}|jd ur|   |j¡}n|   tj¡}dj||d�}dj||d�S |S )Nz%{lower}\mathrel{{..}}\nobreak {upper})rZ  r[  z{{{label}}}_{{{interval}}})r  Úinterval)rê   r  r[  rZ  r   ÚZerorä   )rÛ   rò   r  r[  rZ  r  ro   ro   rr   Ú
_print_Idx  s   

ÿÿzLatexPrinter._print_Idxc              	   C  s   t |jƒrd}n| jd }d}d}t|jƒD ]*\}}||7 }|dkr.|d||  |¡f 7 }q|d||  |  |¡¡|  |¡f 7 }q|dkrLd||f }n
d	||  |¡|f }td
d„ |jD ƒƒrpd|| j	|jt
d ddd�f S d|| j	|jt
d ddd�f S )Nz\partialrÓ   rÆ   r   rE  ú%s %sz
%s %s^{%s}r£  z\frac{%s^{%s}}{%s}c                 s  ó   � | ]}|  ¡ V  qd S ré   ©r  rÎ  ro   ro   rr   r  ;  ó   € z1LatexPrinter._print_Derivative.<locals>.<genexpr>r	   T©rí   rî   F)r   rò   rÕ   ÚreversedÚvariable_countrê   r¶   r  r  rð   r    )rÛ   rò   Údiff_symbolró   Údimr  Únumro   ro   rr   Ú_print_Derivative%  s6   


þ
ý
ýzLatexPrinter._print_Derivativec           	        s`   |j \}}}ˆ  |¡}‡ fdd„|D ƒ}‡ fdd„|D ƒ}d dd„ t||ƒD ƒ¡}d||f S )Nc                 3  r  ré   r#  ©r  r/  r$  ro   rr   r  I  r  z+LatexPrinter._print_Subs.<locals>.<genexpr>c                 3  r  ré   r#  r  r$  ro   rr   r  J  r  z\\ c                 s  s$   � | ]}|d  d |d  V  qdS )r   ú=rE  Nro   r  ro   ro   rr   r  K  s   € 
ÿz#\left. %s \right|_{\substack{ %s }})r  rê   r+  Úzip)	rÛ   Úsubsrò   rŠ  ÚnewÚ
latex_exprÚ	latex_oldÚ	latex_newÚ
latex_subsro   r$  rr   Ú_print_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 )rE  N)rY  )r  Úlimro   ro   rr   r  U  s   € z/LatexPrinter._print_Integral.<locals>.<genexpr>z\ir¯   rE  Úntc                   s"   g | ]}d ˆ ˆ  |d ¡f ‘qS )ú\, %s%sr   r#  ©r  Úsymbol©r  rÛ   ro   rr   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Î  ro   ro   rr   r  p  r  Tr  )rÕ   rY  rÞ  Úallr  rê   Úinsertrð   rß  r    r  r  r+  )rÛ   rò   ró   Úsymbolsr  r#  ro   r$  rr   Ú_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ÚNegativeInfinityr�  r   )rÛ   rò   r/  ÚzÚz0Údirró   ro   ro   rr   Ú_print_Limitt  s   
zLatexPrinter._print_Limitr†  c                 C  sø   |   |¡}| d¡}| d¡}|tv rd| }|S t|ƒdks,| d¡s,|dks,|dkr0|}|S |dkrN|dkrNd|dt||ƒ… |t||ƒd… f }|S |dkrbd|d|… ||d… f }|S |dkrvd|d|… ||d… f }|S d	| }|S )
ak  
        Logic to decide how to render a function to latex
          - if it is a recognized latex name, use the appropriate latex command
          - if it is a single letter, excluding sub- and superscripts, just use that letter
          - if it is a longer name, then put \operatorname{} around it and be
            mindful of undercores in the name
        r•   Ú_z\%srE  r“   r   z\operatorname{%s}%sNz\operatorname{%s})r(  ÚfindÚaccepted_latex_functionsrY  rÇ  r·   )rÛ   r†  ÚsuperscriptidxÚsubscriptidxr,  ro   ro   rr   Ú_hprint_Function‚  s:   


&ïòþö

þ	ú

þÿzLatexPrinter._hprint_Functionr   c                   sˆ  |j j}tˆ d| ƒrt|tƒstˆ d| ƒ||ƒS ‡ fdd„|jD ƒ}ˆ jd }d}ˆ jd o>t|ƒdko>ˆ  	|jd ¡ }g d	¢}||v rs|d
krLn'|dkra|d dkrXdnd|dd…  }n|dkrs|dd… }d}|dursd}|rƒ|t
v r~d| }	nd| }	n|dur˜ˆ  |¡}
ˆ  |
¡}
d|
|f }	nˆ  |¡}	|r­|t
v r¨|	d7 }	n	|	d7 }	n|	d7 }	|r½|dur½|	d| 7 }	|	d |¡ S )a#  
        Render functions to LaTeX, handling functions that LaTeX knows about
        e.g., sin, cos, ... by using the proper LaTeX command (\sin, \cos, ...).
        For single-letter function names, render them as regular LaTeX math
        symbols. For multi-letter function names that LaTeX does not know
        about, (e.g., Li, sech) use \operatorname{} so that the function name
        is rendered in Roman font and LaTeX handles spacing properly.

        expr is the expression involving the function
        exp is an exponent
        Ú_print_c                   s   g | ]	}t ˆ  |¡ƒ‘qS ro   )r‘   rê   rT  r$  ro   rr   r%  ³  ó    z0LatexPrinter._print_Function.<locals>.<listcomp>rŸ   Fr�   rE  r   )ÚasinÚacosÚatanÚacscÚasecÚacotÚasinhÚacoshÚatanhÚacschÚasechÚacothr    ÚfullrD  ÚhÚarÚarcNÚpowerTz\%s^{-1}z\operatorname{%s}^{-1}r¼  z {%s}ú%sú{\left(%s \right)}r%  rF  )r†  r*  rŽ  r�  r   Úgetattrr  rÕ   rY  r  r3  r6  r¶   r+  )rÛ   rò   r   r†  r  rŸ   Úinv_trig_power_caseÚcan_fold_bracketsÚinv_trig_tabler,  Úfunc_texro   r$  rr   Ú_print_Function¢  sR   ÿ


ÿþ"






zLatexPrinter._print_Functionc                 C  ó   |   t|ƒ¡S ré   )r6  r‘   rû   ro   ro   rr   Ú_print_UndefinedFunctionî  r  z%LatexPrinter._print_UndefinedFunctionc                 C  ó   d|   |j¡|   |j¡f S )Nz{%s}_{\circ}\left({%s}\right))rê   rß  rò   rû   ro   ro   rr   Ú_print_ElementwiseApplyFunctionñ  s   

þz,LatexPrinter._print_ElementwiseApplyFunctionc                 C  s\   ddl m} ddlm}m} ddlm} ddlm} ddl	m
} |d|d|d	|d
|d|diS )Nr   )ÚKroneckerDelta)ÚgammaÚ
lowergamma)Úbeta)Ú
DiracDelta)rT   z\deltar?   z\gammaz\operatorname{B}z\operatorname{Chi})Ú(sympy.functions.special.tensor_functionsrV  Ú'sympy.functions.special.gamma_functionsrW  rX  Ú&sympy.functions.special.beta_functionsrY  Ú'sympy.functions.special.delta_functionsrZ  Ú'sympy.functions.special.error_functionsrT   )rÛ   rV  rW  rX  rY  rZ  rT   ro   ro   rr   Ú_special_function_classes÷  s   ûz&LatexPrinter._special_function_classesc                 C  s>   | j D ]}t||ƒr|j|jkr| j |   S q|  t|ƒ¡S ré   )r`  Ú
issubclassr*  r6  r‘   )rÛ   rò   Úclsro   ro   rr   Ú_print_FunctionClass  s
   
€z!LatexPrinter._print_FunctionClassc                 C  sJ   |j \}}t|ƒdkr|  |d ¡}n|  t|ƒ¡}d||  |¡f }|S )NrE  r   z\left( %s \mapsto %s \right))r  rY  rê   rÓ  )rÛ   rò   r(  ró   ro   ro   rr   Ú_print_Lambda  s   
zLatexPrinter._print_Lambdac                 C  ó   dS )Nz\left( x \mapsto x \right)ro   rû   ro   ro   rr   Ú_print_IdentityFunction  ó   z$LatexPrinter._print_IdentityFunctionc                   sT   t |jtd�}‡ fdd„|D ƒ}dt|jƒ ¡ d |¡f }|d ur(d||f S |S )Nrè  c                   ó   g | ]	}d ˆ   |¡ ‘qS )rJ  r#  r"  r$  ro   rr   r%    r8  z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)r'  r¼  )Úsortedr  r   r‘   r†  rZ  r+  )rÛ   rò   r   r  Útexargsró   ro   r$  rr   Ú_hprint_variadic_function  s   ÿz&LatexPrinter._hprint_variadic_functionc                 C  ó,   d|   |jd ¡ }|d urd||f S |S )Nz\left\lfloor{%s}\right\rfloorr   r¼  rÊ  ©rÛ   rò   r   ró   ro   ro   rr   Ú_print_floor&  ó   zLatexPrinter._print_floorc                 C  rl  )Nz\left\lceil{%s}\right\rceilr   r¼  rÊ  rm  ro   ro   rr   Ú_print_ceiling.  ro  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  rm  ro   ro   rr   Ú
_print_log6  s   
zLatexPrinter._print_logc                 C  rl  )Nú\left|{%s}\right|r   r¼  rÊ  rm  ro   ro   rr   Ú
_print_AbsA  ro  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!  rm  ro   ro   rr   Ú	_print_reI  ó   
zLatexPrinter._print_rec                 C  rt  )Nr³   z\Im{%s}r   ru  z\operatorname{{im}}{{{}}}rv  rm  ro   ro   rr   Ú	_print_imQ  rx  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.boolalgrz  r{  r�  r  Ú_print_EquivalentÚ_print_ImpliesÚ
is_Booleanrê   )rÛ   r/  rz  r{  ro   ro   rr   Ú
_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:  rJ  rE  z %s \left(%s\right)z %s %s)r  Úis_Notrê   )rÛ   r  Úcharr;   ró   ro   ro   rr   Ú_print_LogOpd  s   zLatexPrinter._print_LogOpc                 C  ó   t |jtd�}|  |d¡S )Nrè  z\wedge©ri  r  r   rƒ  ©rÛ   r/  r  ro   ro   rr   Ú
_print_Ands  ó   zLatexPrinter._print_Andc                 C  r„  )Nrè  z\veer…  r†  ro   ro   rr   Ú	_print_Orw  rˆ  zLatexPrinter._print_Orc                 C  r„  )Nrè  z\veebarr…  r†  ro   ro   rr   Ú
_print_Xor{  rˆ  zLatexPrinter._print_Xorc                 C  s   |   |j|pd¡S )Nz\Rightarrow)rƒ  r  )rÛ   r/  Úaltcharro   ro   rr   r~    ó   zLatexPrinter._print_Impliesc                 C  s   t |jtd�}|  ||pd¡S )Nrè  z\Leftrightarrowr…  )rÛ   r/  r‹  r  ro   ro   rr   r}  ‚  s   zLatexPrinter._print_Equivalentc                 C  rl  )Nz\overline{%s}r   r¼  rÊ  rm  ro   ro   rr   Ú_print_conjugate†  ro  zLatexPrinter._print_conjugatec                 C  s:   d}d|   |jd ¡ }|d urd|||f S d||f S )Nz\operatorname{polar\_lift}rK  r   ú	%s^{%s}%sú%s%srÊ  )rÛ   rò   r   r†  r;   ro   ro   rr   Ú_print_polar_liftŽ  s
   zLatexPrinter._print_polar_liftc                 C  s    d|   |jd ¡ }|  ||¡S )Nze^{%s}r   )rê   r  r!  rm  ro   ro   rr   Ú_print_ExpBase—  s   zLatexPrinter._print_ExpBasec                 C  re  )Nr/  ro   r  ro   ro   rr   Ú_print_Exp1�  rg  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Ê  rm  ro   ro   rr   Ú_print_elliptic_k   s   zLatexPrinter._print_elliptic_kc                 C  ó@   d|   |jd ¡|   |jd ¡f }|d urd||f S d| S )Nú\left(%s\middle| %s\right)r   rE  zF^{%s}%szF%srÊ  rm  ro   ro   rr   Ú_print_elliptic_f§  s   ÿzLatexPrinter._print_elliptic_fc                 C  sd   t |jƒdkrd|  |jd ¡|  |jd ¡f }n
d|  |jd ¡ }|d ur.d||f S d| S )Nr¢  r–  r   rE  r:  zE^{%s}%szE%s©rY  r  rê   rm  ro   ro   rr   Ú_print_elliptic_e¯  s   ÿzLatexPrinter._print_elliptic_ec                 C  s‚   t |jƒdkr!d|  |jd ¡|  |jd ¡|  |jd ¡f }nd|  |jd ¡|  |jd ¡f }|d ur=d||f S d| S )	Nrë  z\left(%s; %s\middle| %s\right)r   rE  r¢  r–  z
\Pi^{%s}%sz\Pi%sr˜  rm  ro   ro   rr   Ú_print_elliptic_piº  s   ÿÿÿzLatexPrinter._print_elliptic_pic                 C  sZ   |j d }t|j ƒdkr|j d n|j d }d|› d|› d�}|d ur)d||f S d| S )Nr   rE  r¶  r'  rG  z\operatorname{B}^{%s}%sz\operatorname{B}%s)r  rY  )rÛ   rò   r   r  Úyró   ro   ro   rr   Ú_print_betaÇ  s   
"zLatexPrinter._print_betaÚBc                   sb   ‡ fdd„|j D ƒ}d|d |d f }|d ur%d||d |d ||f S d	||d |d |f S )
Nc                   r"  ro   r#  rT  r$  ro   rr   r%  Ó  r&  z/LatexPrinter._print_betainc.<locals>.<listcomp>ú\left(%s, %s\right)r   rE  z#\operatorname{%s}_{(%s, %s)}^{%s}%sr¢  rë  z\operatorname{%s}_{(%s, %s)}%s)r  )rÛ   rò   r   ÚoperatorÚlargsró   ro   r$  rr   Ú_print_betaincÒ  s
   zLatexPrinter._print_betaincc                 C  s   | j ||dd�S )NÚI)rŸ  )r¡  r  ro   ro   rr   Ú_print_betainc_regularizedÛ  rÌ  z'LatexPrinter._print_betainc_regularizedc                 C  r•  )Nrž  r   rE  z\Gamma^{%s}%sz\Gamma%srÊ  rm  ro   ro   rr   Ú_print_uppergammaÞ  ó   ÿzLatexPrinter._print_uppergammac                 C  r•  )Nrž  r   rE  z\gamma^{%s}%sú\gamma%srÊ  rm  ro   ro   rr   Ú_print_lowergammaç  r¥  zLatexPrinter._print_lowergammac                 C  sF   d|   |jd ¡ }|d urd|   |j¡||f S d|   |j¡|f S ©Nr:  r   rŽ  r�  )rê   r  r†  rm  ro   ro   rr   Ú_hprint_one_arg_funcð  s   z!LatexPrinter._hprint_one_arg_funcc                 C  r“  )Nr:  r   z\operatorname{Chi}^{%s}%sz\operatorname{Chi}%srÊ  rm  ro   ro   rr   Ú
_print_Chiú  ó   zLatexPrinter._print_Chic                 C  sF   d|   |jd ¡ }|   |jd ¡}|d urd|||f S d||f S )Nr:  rE  r   z\operatorname{E}_{%s}^{%s}%sz\operatorname{E}_{%s}%srÊ  )rÛ   rò   r   ró   Únuro   ro   rr   Ú_print_expint  s
   zLatexPrinter._print_expintc                 C  r“  )Nr:  r   zS^{%s}%szS%srÊ  rm  ro   ro   rr   Ú_print_fresnels  r«  zLatexPrinter._print_fresnelsc                 C  r“  )Nr:  r   zC^{%s}%szC%srÊ  rm  ro   ro   rr   Ú_print_fresnelc  r«  zLatexPrinter._print_fresnelcc                 C  ó2   d|   |jd td ¡ }|d urd||f S |S )Nz!%sr   ÚFuncr  ©rð   r  r    rm  ro   ro   rr   Ú_print_subfactorial  ó   z LatexPrinter._print_subfactorialc                 C  r°  )Nz%s!r   r±  r¼  r²  rm  ro   ro   rr   Ú_print_factorial#  r´  zLatexPrinter._print_factorialc                 C  r°  )Nz%s!!r   r±  r¼  r²  rm  ro   ro   rr   Ú_print_factorial2+  r´  zLatexPrinter._print_factorial2c                 C  s<   d|   |jd ¡|   |jd ¡f }|d urd||f S |S )Nz{\binom{%s}{%s}}r   rE  r¼  rÊ  rm  ro   ro   rr   Ú_print_binomial3  s   ÿzLatexPrinter._print_binomialc                 C  s<   |j \}}d|  |td ¡ }d||  |¡f }|  ||¡S )NrJ  r±  z{%s}^{\left(%s\right)}©r  rð   r    rê   r!  )rÛ   rò   r   Únrø  r  ró   ro   ro   rr   Ú_print_RisingFactorial<  ó   
z#LatexPrinter._print_RisingFactorialc                 C  s<   |j \}}d|  |td ¡ }d|  |¡|f }|  ||¡S )NrJ  r±  z{\left(%s\right)}_{%s}r¸  )rÛ   rò   r   r¹  rø  Úsubró   ro   ro   rr   Ú_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 )NrJ  Fr•   rD  r¼  Tú%s_{%s}\left(%s\right))r2  rê   rª   Úargumentr!  )rÛ   rò   r   r¾  ró   Úneed_expro   ro   rr   Ú_hprint_BesselBaseL  s   
ÿzLatexPrinter._hprint_BesselBasec                 C  sF   |sdS d}|d d… D ]}|d|   |¡ 7 }q||   |d ¡7 }|S )NrÆ   rD  z%s, r#  )rÛ   r€   rq   r¯   ro   ro   rr   Ú_hprint_vec]  s   zLatexPrinter._hprint_vecc                 C  ó   |   ||d¡S )NÚJ©rÂ  r  ro   ro   rr   Ú_print_besseljf  r  zLatexPrinter._print_besseljc                 C  rÄ  )Nr¢  rÆ  r  ro   ro   rr   Ú_print_besselii  r  zLatexPrinter._print_besselic                 C  rÄ  )NÚKrÆ  r  ro   ro   rr   Ú_print_besselkl  r  zLatexPrinter._print_besselkc                 C  rÄ  )NÚYrÆ  r  ro   ro   rr   Ú_print_besselyo  r  zLatexPrinter._print_besselyc                 C  rÄ  )Nr›  rÆ  r  ro   ro   rr   Ú	_print_ynr  r  zLatexPrinter._print_ync                 C  rÄ  )NrË   rÆ  r  ro   ro   rr   Ú	_print_jnu  r  zLatexPrinter._print_jnc                 C  rÄ  )NzH^{(1)}rÆ  r  ro   ro   rr   Ú_print_hankel1x  r  zLatexPrinter._print_hankel1c                 C  rÄ  )NzH^{(2)}rÆ  r  ro   ro   rr   Ú_print_hankel2{  r  zLatexPrinter._print_hankel2c                 C  rÄ  )Nzh^{(1)}rÆ  r  ro   ro   rr   Ú
_print_hn1~  r  zLatexPrinter._print_hn1c                 C  rÄ  )Nzh^{(2)}rÆ  r  ro   ro   rr   Ú
_print_hn2�  r  zLatexPrinter._print_hn2rÆ   c                 C  ó6   d|   |jd ¡ }|d urd|||f S d||f S r¨  rÊ  ©rÛ   rò   r   Únotationró   ro   ro   rr   Ú_hprint_airy„  ó   zLatexPrinter._hprint_airyc                 C  rÓ  )Nr:  r   z{%s^\prime}^{%s}%sz%s^\prime%srÊ  rÔ  ro   ro   rr   Ú_hprint_airy_primeŒ  r×  zLatexPrinter._hprint_airy_primec                 C  rÄ  ©NÚAi©rÖ  r  ro   ro   rr   Ú_print_airyai”  r  zLatexPrinter._print_airyaic                 C  rÄ  ©NÚBirÛ  r  ro   ro   rr   Ú_print_airybi—  r  zLatexPrinter._print_airybic                 C  rÄ  rÙ  ©rØ  r  ro   ro   rr   Ú_print_airyaiprimeš  r  zLatexPrinter._print_airyaiprimec                 C  rÄ  rÝ  rà  r  ro   ro   rr   Ú_print_airybiprime�  r  zLatexPrinter._print_airybiprimec                 C  sZ   d|   t|jƒ¡|   t|jƒ¡|  |j¡|  |j¡|   |j¡f }|d ur+d||f }|S )NzN{{}_{%s}F_{%s}\left(\begin{matrix} %s \\ %s \end{matrix}\middle| {%s} \right)}ú	{%s}^{%s})rê   rY  ÚapÚbqrÃ  rÀ  rm  ro   ro   rr   Ú_print_hyper   s   
þþzLatexPrinter._print_hyperc                 C  sŠ   d|   t|jƒ¡|   t|jƒ¡|   t|jƒ¡|   t|jƒ¡|  |j¡|  |j¡|  |j¡|  |j¡|   |j	¡f	 }|d urCd||f }|S )Nz^{G_{%s, %s}^{%s, %s}\left(\begin{matrix} %s & %s \\%s & %s \end{matrix} \middle| {%s} \right)}rã  )
rê   rY  rä  rå  r‡   ÚanrÃ  ÚaotherÚbotherrÀ  rm  ro   ro   rr   Ú_print_meijerg«  s   
üþzLatexPrinter._print_meijergc                 C  r“  )Nr:  r   z\eta^{%s}%sz\eta%srÊ  rm  ro   ro   rr   Ú_print_dirichlet_eta¸  s   z!LatexPrinter._print_dirichlet_etac                 C  sV   t |jƒdkrdtt| j|jƒƒ }n
d|  |jd ¡ }|d ur'd||f S d| S )Nr¢  rž  r:  r   z\zeta^{%s}%sz\zeta%s©rY  r  rÓ  rþ  rê   rm  ro   ro   rr   Ú_print_zeta¾  ó   zLatexPrinter._print_zetac                 C  sV   t |jƒdkrdtt| j|jƒƒ }n
d|  |jd ¡ }|d ur'd||f S d| S )Nr¢  z_{%s}\left(%s\right)rý  r   z\gamma%s^{%s}r¦  rì  rm  ro   ro   rr   Ú_print_stieltjesÇ  rî  zLatexPrinter._print_stieltjesc                 C  s2   dt t| j|jƒƒ }|d u rd| S d||f S )Nz\left(%s, %s, %s\right)z\Phi%sz\Phi^{%s}%s)rÓ  rþ  rê   r  rm  ro   ro   rr   Ú_print_lerchphiÐ  s   zLatexPrinter._print_lerchphic                 C  s<   t | j|jƒ\}}d| }|d u rd||f S d|||f S )Nr:  z\operatorname{Li}_{%s}%sz\operatorname{Li}_{%s}^{%s}%s©rþ  rê   r  )rÛ   rò   r   rq   r-  ró   ro   ro   rr   Ú_print_polylogÖ  s
   zLatexPrinter._print_polylogc                 C  óB   t | j|jƒ\}}}}d||||f }|d urd| d|  }|S )Nz*P_{%s}^{\left(%s,%s\right)}\left(%s\right)r¶  ú\right)^{%s}rñ  )rÛ   rò   r   r¹  r¯  r°  r  ró   ro   ro   rr   Ú_print_jacobiÝ  ó
   zLatexPrinter._print_jacobic                 C  ó>   t | j|jƒ\}}}d|||f }|d urd| d|  }|S )Nz'C_{%s}^{\left(%s\right)}\left(%s\right)r¶  rô  rñ  ©rÛ   rò   r   r¹  r¯  r  ró   ro   ro   rr   Ú_print_gegenbauerä  ó
   zLatexPrinter._print_gegenbauerc                 C  ó:   t | j|jƒ\}}d||f }|d urd| d|  }|S )NzT_{%s}\left(%s\right)r¶  rô  rñ  ©rÛ   rò   r   r¹  r  ró   ro   ro   rr   Ú_print_chebyshevtë  ó
   zLatexPrinter._print_chebyshevtc                 C  rû  )NzU_{%s}\left(%s\right)r¶  rô  rñ  rü  ro   ro   rr   Ú_print_chebyshevuò  rþ  zLatexPrinter._print_chebyshevuc                 C  rû  )NzP_{%s}\left(%s\right)r¶  rô  rñ  rü  ro   ro   rr   Ú_print_legendreù  rþ  zLatexPrinter._print_legendrec                 C  r÷  )Nz'P_{%s}^{\left(%s\right)}\left(%s\right)r¶  rô  rñ  rø  ro   ro   rr   Ú_print_assoc_legendre   rú  z"LatexPrinter._print_assoc_legendrec                 C  rû  )NzH_{%s}\left(%s\right)r¶  rô  rñ  rü  ro   ro   rr   Ú_print_hermite  rþ  zLatexPrinter._print_hermitec                 C  rû  )NzL_{%s}\left(%s\right)r¶  rô  rñ  rü  ro   ro   rr   Ú_print_laguerre  rþ  zLatexPrinter._print_laguerrec                 C  r÷  )Nz'L_{%s}^{\left(%s\right)}\left(%s\right)r¶  rô  rñ  rø  ro   ro   rr   Ú_print_assoc_laguerre  rú  z"LatexPrinter._print_assoc_laguerrec                 C  ró  )NzY_{%s}^{%s}\left(%s,%s\right)r¶  rô  rñ  ©rÛ   rò   r   r¹  ÚmÚthetaÚphiró   ro   ro   rr   Ú
_print_Ynm  rö  zLatexPrinter._print_Ynmc                 C  ró  )NzZ_{%s}^{%s}\left(%s,%s\right)r¶  rô  rñ  r  ro   ro   rr   Ú
_print_Znm#  rö  zLatexPrinter._print_Znmc           	      C  sB   t | j|ƒ\}}}|rdnd}|sdnd| }d||||||f S )Nz	^{\prime}rÆ   r%  z%s%s\left(%s, %s, %s\right)%s)rþ  rê   )	rÛ   Ú	characterr  r�   r   r¯  r½  r-  Úsupro   ro   rr   Ú__print_mathieu_functions*  s   z&LatexPrinter.__print_mathieu_functionsc                 C  ó   | j d|j|d�S )NÚCr»  ©Ú&_LatexPrinter__print_mathieu_functionsr  r  ro   ro   rr   Ú_print_mathieuc0  rŒ  zLatexPrinter._print_mathieucc                 C  r  )Nr   r»  r  r  ro   ro   rr   Ú_print_mathieus3  rŒ  zLatexPrinter._print_mathieusc                 C  ó   | j d|jd|d�S )Nr  T©r�   r   r  r  ro   ro   rr   Ú_print_mathieucprime6  ó   z!LatexPrinter._print_mathieucprimec                 C  r  )Nr   Tr  r  r  ro   ro   rr   Ú_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 )NrE  rÆ   r   rŸ  rž   z	%s%d / %dz%s\frac{%d}{%d})r½  r·  rÕ   rê   )rÛ   rò   Úsignr·  ro   ro   rr   Ú_print_Rational<  s   


zLatexPrinter._print_Rationalc                 C  sÀ   |   |j¡}|jrtdd„ |jD ƒƒst|jƒdkr\|d7 }t|jƒdkr.||   |j¡7 }n|jr;||   |jd ¡7 }|d7 }t|jƒdkrR||   |j¡7 }d| S ||   |jd ¡7 }d| S )Nc                 s  s   � | ]}|t jkV  qd S ré   )r   r  )r  r·  ro   ro   rr   r  K  r  z,LatexPrinter._print_Order.<locals>.<genexpr>rE  ú; r   z\rightarrow zO\left(%s\right))rê   rò   Úpointr  rY  Ú	variables©rÛ   rò   rq   ro   ro   rr   Ú_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,  ro   ro   rr   Ú_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 )
Nrƒ   r»   r1  z\_r•   z\^c                 S  ó   g | ]}t |ƒ‘qS ro   ©Ú	translate)r  r  ro   ro   rr   r%  j  rÜ  z1LatexPrinter._split_super_sub.<locals>.<listcomp>c                 S  r$  ro   r%  )r  r¼  ro   ro   rr   r%  k  rÜ  )rÕ   r–   r   r&  )rÛ   r,  Úsupersr  ro   ro   rr   Ú_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 )Nr…   ú\mathbf{{{}}}r%  r¿   rý  )r(  rä   r+  )rÛ   r)  r!  r,  r'  r  ro   ro   rr   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Úcharmapro   ro   rr   Ú_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$  ro   rr   r%  ’  s    ÿz1LatexPrinter._print_Piecewise.<locals>.<listcomp>rD  z%s & \text{otherwise}r4  z\begin{cases} %s \end{cases}z \\)r  Úcondr   ró  rê   rò   r+  )rÛ   rò   Úecpairsró   ro   r$  rr   Ú_print_Piecewise‘  s   
ÿÿÿÿzLatexPrinter._print_Piecewisec              
     s¼   g }t |jƒD ]}| d ‡ fdd„||d d …f D ƒ¡¡ qˆ jd }|d u r>ˆ jd dkr2d}n|jdkd	u r<d
}nd}d}| d|¡}|dkrW| ddd|j  d ¡}|d |¡ S )NrU  c                   r"  ro   r#  rÎ  r$  ro   rr   r%  ¢  r&  z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>r¦   r§   r½   Úsmallmatrixé
   TÚmatrixÚarrayú \begin{%MATSTR%}%s\end{%MATSTR%}ú%MATSTR%rJ  rƒ   r—   ú}%srØ  )rX  Úrowsró  r+  rÕ   Úcolsr–   )rÛ   rò   ÚlinesÚliner¦   Úout_strro   r$  rr   Ú_print_matrix_contentsž  s   ,
z#LatexPrinter._print_matrix_contentsc                 C  s@   |   |¡}| jd r| jd }| j| }d| | d | }|S )Nr¤   ú\leftú\right)rD  rÕ   rÙ   )rÛ   rò   rC  Ú
left_delimÚright_delimro   ro   rr   Ú_print_MatrixBase´  s   




ÿÿzLatexPrinter._print_MatrixBasec                 C  sF   | j |jtd dd�}|  |j¡› d|  |j¡› �}d|› d|› d�S )Nru  T©rî   rF  rƒ   z}_{rn   )rð   Úparentr    rê   r¯   rË   )rÛ   rò   Úmatrix_partÚ
index_partro   ro   rr   Ú_print_MatrixElement½  s   z!LatexPrinter._print_MatrixElementc                   sN   ‡ fdd„}ˆ j |jtd dd�d ||j|jjƒ d ||j|jjƒ d S )	Nc                   sZ   t | ƒ} | d dkr| d= | d dkrd | d< | d |kr!d | d< d ‡ fdd„| D ƒ¡S )Nr¢  rE  r   ú:c                 3  s&   � | ]}|d urˆ   |¡ndV  qd S ©NrÆ   r#  )r  Úxir$  ro   rr   r  Ë  ó   €$ zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>)r“  r+  )r  r  r$  ro   rr   Ú
latexsliceÃ  s   z3LatexPrinter._print_MatrixSlice.<locals>.latexsliceru  TrJ  ú\left[r'  ú\right])rð   rK  r    Úrowslicer?  Úcolslicer@  )rÛ   rò   rS  ro   r$  rr   Ú_print_MatrixSliceÂ  s   	ÿÿþþzLatexPrinter._print_MatrixSlicec                 C  r  ré   )rê   Úblocksrû   ro   ro   rr   Ú_print_BlockMatrixÐ  r  zLatexPrinter._print_BlockMatrixc                 C  sh   |j }ddlm}m} t||ƒst||ƒs|jrd|  |¡ S |  |t|ƒd¡}d|v r0d| S d| S )Nr   ©ÚMatrixSymbolÚBlockMatrixz\left(%s\right)^{T}Tr•   z%s^{T})	r;   Úsympy.matricesr\  r]  r�  Úis_MatrixExprrê   rð   r   )rÛ   rò   r^  r\  r]  rq   ro   ro   rr   Ú_print_TransposeÓ  s   
ÿÿzLatexPrinter._print_Transposec                 C  s   |j }d|  |¡ S )Nz!\operatorname{tr}\left(%s \right))r;   rê   ©rÛ   rò   r^  ro   ro   rr   Ú_print_Traceà  s   zLatexPrinter._print_Tracec                 C  s’   ddddœ}|  | jd d¡}|j}ddlm}m} t||ƒs0t||ƒs0|jr0d|  |¡|f S |  	|t
|ƒd	¡}d
|v rCd||f S d||f S )Nz\daggerz\astz
\mathsf{H})r²   ÚstarÚ	hermitianrº   r   r[  r  Tr•   r¼  )rÚ   rÕ   r;   r^  r\  r]  r�  r_  rê   rð   r   )rÛ   rò   Ústyle_to_latexrº   r^  r\  r]  rq   ro   ro   rr   Ú_print_Adjointä  s"   ý
ÿÿzLatexPrinter._print_Adjointc                   sz   ddl m‰  ‡ ‡‡fdd„}tˆjƒ}ˆ ¡ r5|d dkr$|dd … }n|d  |d< dd t||ƒ¡ S d t||ƒ¡S )	Nr   )ÚMatMulc                   s0   t | tƒrt | ˆ ƒsˆ | ¡S ˆ | tˆƒd¡S ©NF)r�  r	   rê   rð   r   r�  ©rg  rò   rÛ   ro   rr   rs   û  s    z,LatexPrinter._print_MatMul.<locals>.<lambda>rD  rE  rŸ  r¿   )Úsympyrg  r“  r  r  r+  rþ  )rÛ   rò   Úparensr  ro   ri  rr   Ú_print_MatMul÷  s   
zLatexPrinter._print_MatMulc                 C  s0   t |ƒ}|j\}}|  ||¡› d|  ||¡› �S )NrÀ   )r   r  rð   )rÛ   rò   rì   ÚleftÚrightro   ro   rr   Ú_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]  rr  )r;   r_  Ú&sympy.matrices.expressions.blockmatrixr]  r�  rD  rY  rê   )rÛ   rò   r^  r]  ro   ro   rr   Ú_print_Determinant  s   
zLatexPrinter._print_Determinantc                 C  sz   |d ur!d| j |jd td dd�| j |jd td dd�|f S d| j |jd td dd�| j |jd td dd�f S )Nz\left(%s \bmod %s\right)^{%s}r   r	   TrJ  rE  z%s \bmod %sr²  r  ro   ro   rr   Ú
_print_Mod  s(   ÿÿüÿþþýzLatexPrinter._print_Modc                   ó.   |j }td ‰| j‰ d ‡ ‡fdd„|D ƒ¡S )Nr   z \circ c                 3  ó   � | ]
}ˆ |ˆd d�V  qdS ©TrJ  Nro   rT  ©rk  Úprecro   rr   r  ,  ó   € z6LatexPrinter._print_HadamardProduct.<locals>.<genexpr>©r  r    rð   r+  ©rÛ   rò   r  ro   rv  rr   Ú_print_HadamardProduct&  ó   ÿz#LatexPrinter._print_HadamardProductc                 C  s(   t |jƒtd k rd}nd}|  ||¡S )Nr	   z%s^{\circ \left({%s}\right)}z%s^{\circ {%s}})r   r   r    rÀ  )rÛ   rò   rÄ  ro   ro   rr   Ú_print_HadamardPower.  s   z!LatexPrinter._print_HadamardPowerc                   rs  )Nr   ú	 \otimes c                 3  rt  ru  ro   rT  rv  ro   rr   r  ;  rx  z7LatexPrinter._print_KroneckerProduct.<locals>.<genexpr>ry  rz  ro   rv  rr   Ú_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\  r�  r_  rê   )rÛ   rò   r  r   r\  Úbase_strro   ro   rr   Ú_print_MatPow=  s   
ÿ
zLatexPrinter._print_MatPowc                 C  s   | j || jd d�S )Nr­   r   )r"  rÕ   rû   ro   ro   rr   Ú_print_MatrixSymbolJ  s   
ÿz LatexPrinter._print_MatrixSymbolc                 C  ó   | j d dkr	dS dS )Nr­   r¨   Ú0z
\mathbf{0}©rÕ   )rÛ   ÚZro   ro   rr   Ú_print_ZeroMatrixN  ó   ÿÿÿzLatexPrinter._print_ZeroMatrixc                 C  rƒ  )Nr­   r¨   Ú1z
\mathbf{1}r…  )rÛ   ÚOro   ro   rr   Ú_print_OneMatrixR  rˆ  zLatexPrinter._print_OneMatrixc                 C  rƒ  )Nr­   r¨   z
\mathbb{I}z
\mathbf{I}r…  )rÛ   r¢  ro   ro   rr   Ú_print_IdentityV  rˆ  zLatexPrinter._print_Identityc                 C  s   |   |jd ¡}d| S )Nr   zP_{%s}rÊ  )rÛ   ÚPÚperm_strro   ro   rr   Ú_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   ro   r¦   r§   r½   r8  rD  r9  r:  r;  r<  r=  rJ  rƒ   r—   r>  r¤   rE  rF  rÆ   c                 S  s   g | ]}g ‘qS ro   ro   rÎ  ro   ro   rr   r%  z  s    z1LatexPrinter._print_NDimArray.<locals>.<listcomp>rE  c                 S  s   g | ]}t t|ƒƒ‘qS ro   )r“  rX  rÎ  ro   ro   rr   r%  {  ó    TrU  rØ  rT  rU  r¢  )Úrankrê   rÕ   Úshaper–   rÙ   rX  Ú	itertoolsÚproductró  rY  r+  )rÛ   rò   r¦   Ú	block_strrG  rH  Ú	level_strÚshape_rangesÚouter_iÚevenÚback_outer_irC  ro   ro   rr   Ú_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 )	NrF  rn   z{}^{z{}_{r   r  TF)rê   Úis_upr  )	rÛ   r,  rÿ  rœ  rC  Úlast_valenceÚprev_mapÚindexÚnew_valencero   ro   rr   Ú_printer_tensor_indices•  s0   

z$LatexPrinter._printer_tensor_indicesc                 C  s&   |j d j d }| ¡ }|  ||i ¡S rÉ  )r  Úget_indicesr£  )rÛ   rò   r,  rÿ  ro   ro   rr   Ú_print_Tensor±  s   zLatexPrinter._print_Tensorc                 C  s0   |j jd jd }|j  ¡ }|j}|  |||¡S rÉ  )rò   r  r¤  rœ  r£  )rÛ   rò   r,  rÿ  rœ  ro   ro   rr   Ú_print_TensorElement¶  s   
z!LatexPrinter._print_TensorElementc                   s*   ˆ   ¡ \}}|d ‡ ‡fdd„|D ƒ¡ S )NrÆ   c                   s   g | ]
}ˆ  |tˆ ƒ¡‘qS ro   )rð   r   rT  ©rò   rÛ   ro   rr   r%  À  ó    z/LatexPrinter._print_TensMul.<locals>.<listcomp>)Ú!_get_args_for_traditional_printerr+  )rÛ   rò   r  r  ro   r§  rr   Ú_print_TensMul¼  s   ÿzLatexPrinter._print_TensMulc                 C  sL   g }|j }|D ]}| |  |t|ƒ¡¡ q| ¡  d |¡}| dd¡}|S )Nr9  z+ -rŸ  )r  ró  rð   r   rò  r+  r–   )rÛ   rò   r¯  r  r  rq   ro   ro   rr   Ú_print_TensAddÃ  s   
zLatexPrinter._print_TensAddc                 C  s"   d|j rdnd|  |jd ¡f S )Nz{}%s{%s}r•   r1  r   )rž  rê   r  rû   ro   ro   rr   Ú_print_TensorIndexÍ  s   þzLatexPrinter._print_TensorIndexc                   sp   t |jƒdkrdˆ  |jd ¡ˆ  |jtd d¡f S dt |jƒd ‡ fdd	„|jD ƒ¡ˆ  |jtd d¡f S )
NrE  z"\frac{\partial}{\partial {%s}}{%s}r   r	   Fz\frac{\partial^{%s}}{%s}{%s}r¿   c                   rh  )z\partial {%s}r#  rÎ  r$  ro   rr   r%  Ü  r8  z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>)rY  r  rê   rð   rò   r    r+  rû   ro   r$  rr   Ú_print_PartialDerivativeÓ  s   þýz%LatexPrinter._print_PartialDerivativec                 C  r  ré   )rê   r,  rû   ro   ro   rr   Ú_print_ArraySymbolà  r  zLatexPrinter._print_ArraySymbolc                   s2   dˆ   |jtd d¡d ‡ fdd„|jD ƒ¡f S )Nz{{%s}_{%s}}r±  Tr'  c                   s   g | ]}ˆ   |¡› ‘qS ro   r#  rÎ  r$  ro   rr   r%  æ  r�  z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>)rð   r,  r    r+  rÿ  rû   ro   r$  rr   Ú_print_ArrayElementã  s   þz LatexPrinter._print_ArrayElementc                 C  re  )Nz
\mathbb{U}ro   rû   ro   ro   rr   Ú_print_UniversalSetè  rg  z LatexPrinter._print_UniversalSetc                 C  s4   |d u rd|   |jd ¡ S d|   |jd ¡|f S )Nz$\operatorname{frac}{\left(%s\right)}r   z)\operatorname{frac}{\left(%s\right)}^{%s}rÊ  r  ro   ro   rr   Ú_print_fracë  s
   ÿzLatexPrinter._print_fracc                   sv   ˆ j d dkr
d}nˆ j d dkrd}ntdƒ‚t|ƒdkr*ˆ  ˆ  |d ¡| ¡S ˆ  |d	  ‡ fd
d„|D ƒ¡¡S )Nr´   rg  ú;r°   rF  úUnknown Decimal SeparatorrE  r   z \  c                   r"  ro   r#  rÎ  r$  ro   rr   r%  ÿ  r&  z-LatexPrinter._print_tuple.<locals>.<listcomp>)rÕ   rÖ   rY  rè   rê   r+  )rÛ   rò   Úsepro   r$  rr   Ú_print_tupleò  s   ÿzLatexPrinter._print_tuplec                   ó   ‡ fdd„|j D ƒ}d |¡S )Nc                   r"  ro   r#  ©r  r¯  r$  ro   rr   r%    r&  z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>r~  ©r  r+  ©rÛ   rò   Úelementsro   r$  rr   Ú_print_TensorProduct  ó   
z!LatexPrinter._print_TensorProductc                   r¶  )Nc                   r"  ro   r#  r·  r$  ro   rr   r%    r&  z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>z \wedge r¸  r¹  ro   r$  rr   Ú_print_WedgeProduct  r¼  z LatexPrinter._print_WedgeProductc                 C  ó
   |   |¡S ré   )rµ  rû   ro   ro   rr   Ú_print_Tuple	  rç   zLatexPrinter._print_Tuplec                   s\   ˆ j d dkrdd ‡ fdd„|D ƒ¡ S ˆ j d dkr*dd ‡ fd	d„|D ƒ¡ S td
ƒ‚)Nr´   rg  z\left[ %s\right]z; \  c                   r"  ro   r#  rÎ  r$  ro   rr   r%    r&  z,LatexPrinter._print_list.<locals>.<listcomp>r°   ú, \  c                   r"  ro   r#  rÎ  r$  ro   rr   r%    r&  r³  )rÕ   r+  rÖ   rû   ro   r$  rr   Ú_print_list  s   ÿÿzLatexPrinter._print_listc                 C  sR   t | ¡ td�}g }|D ]}|| }| d|  |¡|  |¡f ¡ qdd |¡ S )Nrè  z%s : %sz\left\{ %s\right\}rÀ  )ri  Úkeysr   ró  rê   r+  )rÛ   r±   rÂ  rð  ré  Úvalro   ro   rr   Ú_print_dict  s    zLatexPrinter._print_dictc                 C  r¾  ré   )rÄ  rû   ro   ro   rr   Ú_print_Dict!  rç   zLatexPrinter._print_Dictc                 C  sj   t |jƒdks|jd dkrd|  |jd ¡ }nd|  |jd ¡|  |jd ¡f }|r3d||f }|S )NrE  r   z\delta\left(%s\right)z+\delta^{\left( %s \right)}\left( %s \right)r  r˜  rm  ro   ro   rr   Ú_print_DiracDelta$  s   ÿzLatexPrinter._print_DiracDeltac                 C  sP   |   |jd |jd  ¡}|   |jd ¡}d||f }|d ur&d|||f }|S )Nr   rE  r¢  z${\left\langle %s \right\rangle}^{%s}z-{\left({\langle %s \rangle}^{%s}\right)}^{%s}rÊ  )rÛ   rò   r   ÚshiftrI  ró   ro   ro   rr   Ú_print_SingularityFunction.  s   z'LatexPrinter._print_SingularityFunctionc                   s6   d  ‡ fdd„|jD ƒ¡}d| }|rd||f }|S )Nr'  c                 3  r  ré   r#  rT  r$  ro   rr   r  7  r  z0LatexPrinter._print_Heaviside.<locals>.<genexpr>z\theta\left(%s\right)r  )r+  Úpargs)rÛ   rò   r   rÉ  ró   ro   r$  rr   Ú_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   rE  z\delta_{%s %s}z\delta_{%s, %s}r  )rê   r  rø   )rÛ   rò   r   r¯   rË   ró   ro   ro   rr   Ú_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
  ro   ro   rr   r  J  s   € z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}r¿   r'  r  )rþ  rê   r  r&  r+  )rÛ   rò   r   rÿ  ró   ro   ro   rr   Ú_print_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 })rŽ  rê   rÍ  r(  rÎ  )rÛ   r±   ro   ro   rr   Ú_print_RandomDomainR  s   


ÿ

z LatexPrinter._print_RandomDomainc                 C  s   t |jtd�}|  |¡S )Nrè  )ri  r  r   Ú
_print_set©rÛ   rq   rð  ro   ro   rr   Ú_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´   rg  r  r°   r'  r³  ú\left\{%s\right\})ri  r   rÕ   r+  rþ  rê   rÖ   rÑ  ro   ro   rr   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¢  rE  r'  c                 3  r  ré   r#  rT  r$  ro   rr   r  u  r  zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>c                 3  r  ré   r#  rT  r$  ro   rr   r  x  r  c                 3  r  ré   r#  rT  r$  ro   rr   r  z  r  z\text{Range}\left(rG  )r  rê   r+  )Úcont)rq   rÛ   ro   rr   Ú_print_symbolic_rangeo  s   $z8LatexPrinter._print_Range.<locals>._print_symbolic_rangerD  r   rE  r  Tz\left\{r'  c                 3  ó&   � | ]}|ˆ urˆ  |¡nd V  qdS ©z\ldotsNr#  ©r  Úel©ÚdotsrÛ   ro   rr   r  •  rR  z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})ÚobjectÚstartÚis_infiniteÚstopÚstepÚis_positiveÚiterÚnextÚis_emptyrI  rÓ  Úis_iterabler+  )rÛ   rq   rÕ  ÚprintsetÚitro   )rÛ  rq   rÛ   rr   Ú_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   rE  r¿  z%s_{%s}r¼  r˜  )rÛ   rò   Úletterr   ró   ro   ro   rr   Ú__print_number_polynomial˜  s   þÿz&LatexPrinter.__print_number_polynomialc                 C  ó   |   |d|¡S ©Nr�  ©Ú&_LatexPrinter__print_number_polynomialr  ro   ro   rr   Ú_print_bernoulli¦  r  zLatexPrinter._print_bernoullic                 C  rë  )NÚGrí  r  ro   ro   rr   Ú_print_genocchi©  r  zLatexPrinter._print_genocchic                   sˆ   t |jƒdkr=dˆ  |jd ¡ˆ  |jd ¡f }dd ‡ fdd„|jd	 D ƒ¡ }|d ur7d
|||f }|S || }|S ˆ  |d|¡S )Nrë  z
B_{%s, %s}r   rE  r:  r'  c                 3  r  ré   r#  rØ  r$  ro   rr   r  °  s   € ÿz+LatexPrinter._print_bell.<locals>.<genexpr>r¢  rŽ  r�  )rY  r  rê   r+  rî  )rÛ   rò   r   Útex1Útex2ró   ro   r$  rr   Ú_print_bell¬  s   ÿ
ÿÿzLatexPrinter._print_bellc                 C  rë  ©NÚFrí  r  ro   ro   rr   Ú_print_fibonacci¹  r  zLatexPrinter._print_fibonaccic                 C  ó,   d|   |jd ¡ }|d urd||f }|S )NzL_{%s}r   r¼  rÊ  rm  ro   ro   rr   Ú_print_lucas¼  ó   zLatexPrinter._print_lucasc                 C  rë  )NÚTrí  r  ro   ro   rr   Ú_print_tribonacciÂ  r  zLatexPrinter._print_tribonaccic                 C  s4   |d u rd|   |jd ¡ S d||   |jd ¡f S )Nz\mu\left(%s\right)r   z\mu^{%s}\left(%s\right)rÊ  r  ro   ro   rr   Ú_print_mobiusÅ  s   zLatexPrinter._print_mobiusc                   sø   t ƒ ‰ t|jjƒdkst|jjƒdkr-dˆ |j¡ˆ |jd ¡ˆ |j¡ˆ |j¡f S |jtj	u rP|j}ˆ | 
|d ¡| 
|d ¡| 
|d ¡| 
|¡f}n|jtju s[|jdkrg|d d… }| ˆ ¡ nt|ƒ}dd ‡ ‡fd	d
„|D ƒ¡ d S )Nr   z\left\{%s\right\}_{%s=%s}^{%s}rë  r¢  rE  r  rT  r'  c                 3  rÖ  r×  r#  rØ  rÚ  ro   rr   r  Þ  rR  z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>rU  )rÜ  rY  rÝ  Úfree_symbolsrß  rê   Úformular  r   r,  Úcoeffr+  Úlengthró  rÓ  r+  )rÛ   rq   rß  ræ  ro   rÚ  rr   Ú_print_SeqFormulaÊ  s,    


üÿÿþzLatexPrinter._print_SeqFormulac                 C  s\   |j |jkrd|  |j ¡ S |jrd}nd}|jrd}nd}d||  |j ¡|  |j¡|f S )NrÓ  rÊ   r¥   rÈ   rÉ   z\left%s%s, %s\right%s)rÝ  Úendrê   Ú	left_openÚ
right_open)rÛ   r¯   rm  rn  ro   ro   rr   Ú_print_Intervalå  s   ÿzLatexPrinter._print_Intervalc                 C  rT  )Nz \left\langle %s, %s\right\rangle)rê   r·   r¸   ©rÛ   r¯   ro   ro   rr   Ú_print_AccumulationBounds÷  s   ÿz&LatexPrinter._print_AccumulationBoundsc                   ó(   t |ƒ‰ ‡ ‡fdd„|jD ƒ}d |¡S )Nc                   ó   g | ]}ˆ  |ˆ ¡‘qS ro   ©rð   rÎ  ©rw  rÛ   ro   rr   r%  ý  r�  z-LatexPrinter._print_Union.<locals>.<listcomp>z \cup ©r   r  r+  ©rÛ   ÚuÚargs_strro   r  rr   Ú_print_Unionû  ó   
zLatexPrinter._print_Unionc                   r	  )Nc                   r
  ro   r  rÎ  r  ro   rr   r%  	  r�  z2LatexPrinter._print_Complement.<locals>.<listcomp>z \setminus r  r  ro   r  rr   Ú_print_Complement 	  r  zLatexPrinter._print_Complementc                   r	  )Nc                   r
  ro   r  rÎ  r  ro   rr   r%  	  r�  z4LatexPrinter._print_Intersection.<locals>.<listcomp>z \cap r  r  ro   r  rr   Ú_print_Intersection	  r  z LatexPrinter._print_Intersectionc                   r	  )Nc                   r
  ro   r  rÎ  r  ro   rr   r%  	  r�  z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>z \triangle r  r  ro   r  rr   Ú_print_SymmetricDifference
	  r  z'LatexPrinter._print_SymmetricDifferencec                   s\   t |ƒ‰ t|jƒdkr t|jƒs ˆ |jd ˆ ¡dt|jƒ  S d ‡ ‡fdd„|jD ƒ¡S )NrE  r   z^{%d}rÁ   c                 3  s   � | ]	}ˆ  |ˆ ¡V  qd S ré   r  )r  rÎ  r  ro   rr   r  	  s   € 
ÿz1LatexPrinter._print_ProductSet.<locals>.<genexpr>)r   rY  Úsetsr#   rð   r+  ©rÛ   r·  ro   r  rr   Ú_print_ProductSet	  s    ÿzLatexPrinter._print_ProductSetc                 C  re  )Nz	\emptysetro   r4  ro   ro   rr   Ú_print_EmptySet	  rg  zLatexPrinter._print_EmptySetc                 C  re  )Nz
\mathbb{N}ro   ©rÛ   r¹  ro   ro   rr   Ú_print_Naturals	  rg  zLatexPrinter._print_Naturalsc                 C  re  )Nz\mathbb{N}_0ro   r  ro   ro   rr   Ú_print_Naturals0	  rg  zLatexPrinter._print_Naturals0c                 C  re  ©Nz
\mathbb{Z}ro   r  ro   ro   rr   Ú_print_Integers	  rg  zLatexPrinter._print_Integersc                 C  re  ©Nz
\mathbb{Q}ro   r  ro   ro   rr   Ú_print_Rationals"	  rg  zLatexPrinter._print_Rationalsc                 C  re  ©Nz
\mathbb{R}ro   r  ro   ro   rr   Ú_print_Reals%	  rg  zLatexPrinter._print_Realsc                 C  re  ©Nz
\mathbb{C}ro   r  ro   ro   rr   Ú_print_Complexes(	  rg  zLatexPrinter._print_Complexesc                   sP   |j j}|j j}‡ fdd„t||jƒD ƒ}d dd„ |D ƒ¡}dˆ  |¡|f S )Nc                 3  s(   � | ]\}}ˆ   |¡ˆ   |¡fV  qd S ré   r#  )r  r  r›  r$  ro   rr   r  .	  s   €& z/LatexPrinter._print_ImageSet.<locals>.<genexpr>r'  c                 s  s   � | ]}d | V  qdS )ú	%s \in %sNro   )r  Úxyro   ro   rr   r  /	  r  z!\left\{%s\; \middle|\; %s\right\})rW   rò   Ú	signaturer  Ú	base_setsr+  rê   )rÛ   rq   rò   ÚsigÚxysÚxinysro   r$  rr   Ú_print_ImageSet+	  s
   zLatexPrinter._print_ImageSetc                   s^   d  ‡ fdd„t|jƒD ƒ¡}|jtju rd|ˆ  |j¡f S d||ˆ  |j¡ˆ  |j¡f S )Nr'  c                   r"  ro   r#  ©r  ra  r$  ro   rr   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Û   rq   Ú
vars_printro   r$  rr   Ú_print_ConditionSet2	  s   ÿ

üz LatexPrinter._print_ConditionSetc                 C  ó   |   |jd ¡}d |¡S )Nr   z\mathcal{{P}}\left({}\right)©rê   r  rä   )rÛ   rò   Ú	arg_printro   ro   rr   Ú_print_PowerSet>	  s   
zLatexPrinter._print_PowerSetc                   s8   d  ‡ fdd„|jD ƒ¡}dˆ  |j¡|ˆ  |j¡f S )Nr'  c                   r"  ro   r#  r-  r$  ro   rr   r%  C	  r&  z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z)\left\{%s\; \middle|\; %s \in %s \right\})r+  r  rê   rò   r  r1  ro   r$  rr   Ú_print_ComplexRegionB	  s   

ýz!LatexPrinter._print_ComplexRegionc                   s   dt ‡ fdd„|jD ƒƒ S )Nr%  c                 3  r  ré   r#  r·  r$  ro   rr   r  J	  r  z/LatexPrinter._print_Contains.<locals>.<genexpr>)rÓ  r  r4  ro   r$  rr   Ú_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å   ro   ro   rr   Ú_print_FourierSeriesL	  s   z!LatexPrinter._print_FourierSeriesc                 C  r  ré   )r@  Úinfiniterå   ro   ro   rr   Ú_print_FormalPowerSeriesQ	  r  z%LatexPrinter._print_FormalPowerSeriesc                 C  s
   d|j  S )Nz\mathbb{F}_{%s})Úmodrû   ro   ro   rr   Ú_print_FiniteFieldT	  rç   zLatexPrinter._print_FiniteFieldc                 C  re  r  ro   rû   ro   ro   rr   Ú_print_IntegerRingW	  rg  zLatexPrinter._print_IntegerRingc                 C  re  r  ro   rû   ro   ro   rr   Ú_print_RationalFieldZ	  rg  z!LatexPrinter._print_RationalFieldc                 C  re  r!  ro   rû   ro   ro   rr   Ú_print_RealField]	  rg  zLatexPrinter._print_RealFieldc                 C  re  r#  ro   rû   ro   ro   rr   Ú_print_ComplexField`	  rg  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ò   rI  r(  ro   ro   rr   Ú_print_PolynomialRingc	  ó   z"LatexPrinter._print_PolynomialRingc                 C  rG  )Nr'  r*  rH  rJ  ro   ro   rr   Ú_print_FractionFieldh	  rL  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ê   rI  r+  rþ  r(  Úis_Poly)rÛ   rò   rI  r(  Úinvro   ro   rr   Ú_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   rE  r:  rf  rê  r¿   )rê  rf  z	domain=%sr'  z\%s {\left(%s \right)}z$\operatorname{%s}{\left( %s \right)})r)  r*  r=  r<  rê   ÚgensÚpowr  r   r¦  Úextendrù   rÇ  Úpopr+  r“  rþ  Ú
get_domainr3  )rÛ   Úpolyrb  r=  Úmonomr   Ús_monomr¯   r   Ús_coeffÚs_termÚmodifierrò   rQ  rI  r  ró   ro   ro   rr   Ú_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ò   r¡  r3  )rÛ   r:   rb  rò   r¡  ro   ro   rr   Ú_print_ComplexRootOf®	  s   ÿz!LatexPrinter._print_ComplexRootOfc                 C  s`   |j j}|  |j¡g}|jtjur| |  |j¡¡ |tv r'd|d 	|¡f S d|d 	|¡f S )Nz\%s {\left(%s\right)}r'  z#\operatorname{%s} {\left(%s\right)})
r)  r*  rê   rò   Úfunr   ÚIdentityFunctionró  r3  r+  )rÛ   rò   rb  r  ro   ro   rr   Ú_print_RootSumº	  s   ÿzLatexPrinter._print_RootSumc                 C  re  )Nú\omegaro   rû   ro   ro   rr   Ú_print_OrdinalOmegaÇ	  rg  z LatexPrinter._print_OrdinalOmegac                 C  sF   |j \}}|dkr|dkrd ||¡S d |¡S |dkr!d |¡S dS )NrE  z{} \omega^{{{}}}z	{} \omegaz\omega^{{{}}}rc  )r  rä   )rÛ   rò   r   Úmulro   ro   rr   Ú_print_OmegaPowerÊ	  s   


zLatexPrinter._print_OmegaPowerc                   s   d  ‡ fdd„|jD ƒ¡S )Nr9  c                   r"  ro   r#  rT  r$  ro   rr   r%  Ø	  r&  z/LatexPrinter._print_Ordinal.<locals>.<listcomp>)r+  r  rû   ro   r$  rr   Ú_print_Ordinal×	  s   zLatexPrinter._print_Ordinalc                 C  s   | j d }| | td|¡S )NrÄ   z	{%s}^{%d})rÕ   r‘   r    )rÛ   rV  r©   ro   ro   rr   Ú_print_PolyElementÚ	  s   
zLatexPrinter._print_PolyElementc                 C  s:   |j dkr|  |j¡S |  |j¡}|  |j ¡}d||f S )NrE  r£  )rª  rê   r©  )rÛ   r9   r©  rª  ro   ro   rr   Ú_print_FracElementÞ	  s
   
zLatexPrinter._print_FracElementc                 C  sf   t |jƒdkr|jd d fn|j\}}d|  |¡ }|d ur$d||f }|d ur1d||  |¡f }|S )NrE  r   zE_{%s}r¼  r*  r˜  )rÛ   rò   r   r  r  ró   ro   ro   rr   Ú_print_euleræ	  s   &zLatexPrinter._print_eulerc                 C  rø  )NzC_{%s}r   r¼  rÊ  rm  ro   ro   rr   Ú_print_catalanï	  rú  zLatexPrinter._print_catalanc              
   C  s>   d  ||rdnd|  |jd ¡|  |jd ¡|  |jd ¡¡S )Nz5\mathcal{{{}}}{}_{{{}}}\left[{}\right]\left({}\right)z^{-1}rÆ   rE  r   r¢  ©rä   rê   r  )rÛ   rò   rq   Úinversero   ro   rr   Ú_print_UnifiedTransformõ	  s   >z$LatexPrinter._print_UnifiedTransformc                 C  ó   |   |d¡S )NÚM©rn  rû   ro   ro   rr   Ú_print_MellinTransformø	  r  z#LatexPrinter._print_MellinTransformc                 C  ó   |   |dd¡S )Nrp  Trq  rû   ro   ro   rr   Ú_print_InverseMellinTransformû	  r  z*LatexPrinter._print_InverseMellinTransformc                 C  ro  )NÚLrq  rû   ro   ro   rr   Ú_print_LaplaceTransformþ	  r  z$LatexPrinter._print_LaplaceTransformc                 C  rs  )Nru  Trq  rû   ro   ro   rr   Ú_print_InverseLaplaceTransform
  r  z+LatexPrinter._print_InverseLaplaceTransformc                 C  ro  rõ  rq  rû   ro   ro   rr   Ú_print_FourierTransform
  r  z$LatexPrinter._print_FourierTransformc                 C  rs  )Nrö  Trq  rû   ro   ro   rr   Ú_print_InverseFourierTransform
  r  z+LatexPrinter._print_InverseFourierTransformc                 C  ro  )NÚSINrq  rû   ro   ro   rr   Ú_print_SineTransform

  r  z!LatexPrinter._print_SineTransformc                 C  rs  )Nrz  Trq  rû   ro   ro   rr   Ú_print_InverseSineTransform
  r  z(LatexPrinter._print_InverseSineTransformc                 C  ro  )NÚCOSrq  rû   ro   ro   rr   Ú_print_CosineTransform
  r  z#LatexPrinter._print_CosineTransformc                 C  rs  )Nr}  Trq  rû   ro   ro   rr   Ú_print_InverseCosineTransform
  r  z*LatexPrinter._print_InverseCosineTransformc                 C  sD   z|j d ur|  |j  |¡¡W S W n	 ty   Y nw |  t|ƒ¡S ré   )Úringrê   Úto_sympyr   Úreprr  ro   ro   rr   Ú
_print_DMP
  s   
þÿzLatexPrinter._print_DMPc                 C  r¾  ré   )rƒ  r  ro   ro   rr   Ú
_print_DMF
  rç   zLatexPrinter._print_DMFc                 C  s   |   t|jƒ¡S ré   ©rê   r   r,  )rÛ   rÜ  ro   ro   rr   Ú_print_Object"
  rÌ  zLatexPrinter._print_Objectc                 C  sf   |   |jd ¡}|d urd|f nd}t|jƒdkr"d||f }|S |   |jd ¡}d |||¡}|S )Nr   r%  rÆ   rE  zW%s\left(%s\right)zW{0}_{{{1}}}\left({2}\right))rê   r  rY  rä   )rÛ   rò   r   Úarg0ÚresultÚarg1ro   ro   rr   Ú_print_LambertW%
  s   þzLatexPrinter._print_LambertWc                 C  ó   d  |  |jd ¡¡S )Nz!\operatorname{{E}}\left[{}\right]r   rl  rû   ro   ro   rr   Ú_print_Expectation/
  ó   zLatexPrinter._print_Expectationc                 C  r‹  )Nz#\operatorname{{Var}}\left({}\right)r   rl  rû   ro   ro   rr   Ú_print_Variance2
  r�  zLatexPrinter._print_Variancec                   s    d  d ‡ fdd„|jD ƒ¡¡S )Nz#\operatorname{{Cov}}\left({}\right)r'  c                 3  r  ré   r#  rT  r$  ro   rr   r  6
  r  z1LatexPrinter._print_Covariance.<locals>.<genexpr>)rä   r+  r  rû   ro   r$  rr   Ú_print_Covariance5
  s    zLatexPrinter._print_Covariancec                 C  r‹  )Nz!\operatorname{{P}}\left({}\right)r   rl  rû   ro   ro   rr   Ú_print_Probability8
  r�  zLatexPrinter._print_Probabilityc                 C  s$   |   |j¡}|   |j¡}d||f S )Nz%s\rightarrow %s)rê   rI  Úcodomain)rÛ   ÚmorphismrI  r‘  ro   ro   rr   Ú_print_Morphism;
  s   zLatexPrinter._print_Morphismc                 C  s&   |   |j¡|   |j¡}}d||f S )Nr£  )rê   r  Úden)rÛ   rò   r  r”  ro   ro   rr   Ú_print_TransferFunction@
  s   z$LatexPrinter._print_TransferFunctionc                   s(   t ˆ jƒ}‡ ‡fdd„}d t||ƒ¡S )Nc                   s   ˆ  | tˆ ƒd¡S rh  )rð   r   r�  r§  ro   rr   rs   F
  s    ÿz,LatexPrinter._print_Series.<locals>.<lambda>r¿   )r“  r  r+  rþ  ©rÛ   rò   r  rk  ro   r§  rr   Ú_print_SeriesD
  s   
zLatexPrinter._print_Seriesc                   s@   ddl m‰  tˆjƒd d d… }‡ ‡‡fdd„}d t||ƒ¡S )Nr   )ÚMIMOParallelrD  c                   s&   t | ˆ ƒrˆ | tˆƒd¡S ˆ | ¡S rh  )r�  rð   r   rê   r�  ©r˜  rò   rÛ   ro   rr   rs   M
  s
   ÿÿ
z0LatexPrinter._print_MIMOSeries.<locals>.<lambda>z\cdot)Úsympy.physics.control.ltir˜  r“  r  r+  rþ  r–  ro   r™  rr   Ú_print_MIMOSeriesJ
  s   zLatexPrinter._print_MIMOSeriesc                 C  ó   d  t| j|jƒ¡S ©Nr9  ©r+  rþ  rê   r  rû   ro   ro   rr   Ú_print_ParallelQ
  r  zLatexPrinter._print_Parallelc                 C  rœ  r�  rž  rû   ro   ro   rr   Ú_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ÚSeriesrE  rD  rf  rê  z\frac{%s}{%s %s %s})Úsympy.physics.controlr¡  r¢  Úsys1ra  r�  r“  r  Úsys2rê   r  )rÛ   rò   r¡  r¢  r  ÚtfÚnum_arg_listÚden_arg_listÚ
den_term_1Ú
den_term_2r©  Údenom_1Údenom_2Ú_signro   ro   rr   Ú_print_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   )Ú
MIMOSeriesrD  rf  rê  z)\left(I_{\tau} %s %s\right)^{-1} \cdot %s)r£  r¯  rê   r¥  r¤  r  )rÛ   rò   r¯  Úinv_matr¤  r­  ro   ro   rr   Ú_print_MIMOFeedback{
  s
   z LatexPrinter._print_MIMOFeedbackc                 C  s   |   |j¡}d| S )Nz%s_\tau)rê   Ú	_expr_matra  ro   ro   rr   Ú_print_TransferFunctionMatrix‚
  s   z*LatexPrinter._print_TransferFunctionMatrixc                 C  s   d  |jj|j¡S )Nz\text{{{}}}_{{{}}})rä   r)  r*  r¹  rû   ro   ro   rr   Ú
_print_DFT†
  rŒ  zLatexPrinter._print_DFTc                 C  s&   |   t|jƒ¡}|  |¡}d||f S )Nz%s:%s)rê   r   r,  r“  )rÛ   r’  Úpretty_nameÚpretty_morphismro   ro   rr   Ú_print_NamedMorphismŠ
  s   
z!LatexPrinter._print_NamedMorphismc                 C  s"   ddl m} |  ||j|jdƒ¡S )Nr   )ÚNamedMorphismÚid)Úsympy.categoriesr¸  r·  rI  r‘  )rÛ   r’  r¸  ro   ro   rr   Ú_print_IdentityMorphism�
  s   
ÿz$LatexPrinter._print_IdentityMorphismc                   s<   ‡ fdd„|j D ƒ}| ¡  d |¡d }ˆ  |¡}|| S )Nc                   s   g | ]
}ˆ   t|jƒ¡‘qS ro   r…  )r  Ú	componentr$  ro   rr   r%  —
  s    ÿz9LatexPrinter._print_CompositeMorphism.<locals>.<listcomp>z\circ rO  )rñ  Úreverser+  r“  )rÛ   r’  Úcomponent_names_listÚcomponent_namesr¶  ro   r$  rr   Ú_print_CompositeMorphism”
  s   
ÿ
z%LatexPrinter._print_CompositeMorphismc                 C  s   d  |  t|jƒ¡¡S ©Nr*  )rä   rê   r   r,  )rÛ   r’  ro   ro   rr   Ú_print_CategoryŸ
  r�  zLatexPrinter._print_Categoryc                 C  s<   |j s	|  tj¡S |  |j ¡}|jr|d|  |j¡ 7 }|S )Nz\Longrightarrow %s)Úpremisesrê   r   ÚEmptySetÚconclusions)rÛ   ÚdiagramÚlatex_resultro   ro   rr   Ú_print_Diagram¢
  s   
ÿzLatexPrinter._print_Diagramc                 C  s–   dd|j   }t|jƒD ]8}t|j ƒD ]!}|||f r%|t|||f ƒ7 }|d7 }||j d kr4|d7 }q||jd kr@|d7 }|d7 }q|d7 }|S )	Nz\begin{array}{%s}
r—   r¿   rE  ú& rØ  Ú
z\end{array}
)ÚwidthrX  ÚheightÚlatex)rÛ   ÚgridrÇ  r¯   rË   ro   ro   rr   Ú_print_DiagramGrid®
  s   €
zLatexPrinter._print_DiagramGridc                 C  ó   d  |  |j¡|  |j¡¡S )Nz{{{}}}^{{{}}})rä   rê   r€  r‘  ©rÛ   rp  ro   ro   rr   Ú_print_FreeModuleÀ
  r:  zLatexPrinter._print_FreeModulec                   s   d  d ‡ fdd„|D ƒ¡¡S )Nú\left[ {} \right]rF  c                 3  ó"   � | ]}d ˆ   |¡ d V  qdS ©rƒ   rn   Nr#  r
  r$  ro   rr   r  Å
  ó   € 
ÿz8LatexPrinter._print_FreeModuleElement.<locals>.<genexpr>)rä   r+  )rÛ   r  ro   r$  rr   Ú_print_FreeModuleElementÃ
  s   
ÿz%LatexPrinter._print_FreeModuleElementc                   sJ   ‡‡fdd„ˆj D ƒ}dd„ ‰ dd„ ‰d ‡ ‡fdd„|D ƒ¡}d	 |¡S )
Nc                   s    g | ]}‡ ‡fd d„|D ƒ‘qS )c                   s   g | ]}ˆ  ˆ j |¡¡‘qS ro   )rê   r€  r�  r
  ©r  rÛ   ro   rr   r%  É
  ó    z<LatexPrinter._print_SubModule.<locals>.<listcomp>.<listcomp>ro   ©r  ÚgrØ  ro   rr   r%  É
  s     z1LatexPrinter._print_SubModule.<locals>.<listcomp>c                 S  rm   )Nrƒ   rn   ro   ©rL   ro   ro   rr   rs   Ê
  rt   z/LatexPrinter._print_SubModule.<locals>.<lambda>c                 S  rm   )Nz\left[ z \right]ro   rÜ  ro   ro   rr   rs   Ë
  rt   rF  c                 3  s0   � | ]}ˆ ˆd   ‡ fdd„|D ƒ¡ƒƒV  qdS )rF  c                 3  s   � | ]}ˆ |ƒV  qd S ré   ro   r
  )Úcurlyro   rr   r  Ì
  r  z:LatexPrinter._print_SubModule.<locals>.<genexpr>.<genexpr>N)r+  rÚ  )rÝ  Úsquarero   rr   r  Ì
  s   €. z0LatexPrinter._print_SubModule.<locals>.<genexpr>ú\left\langle {} \right\rangle)rQ  r+  rä   ©rÛ   r  rQ  Ú
gens_latexro   )rÝ  r  rÛ   rÞ  rr   Ú_print_SubModuleÈ
  s
   
zLatexPrinter._print_SubModulec                   s$   d  ‡ fdd„|jD ƒ¡}d |¡S )NrF  c                   s   g | ]}d ˆ   |¡ d ‘qS )rƒ   rn   r#  rÚ  r$  ro   rr   r%  Ð
  rÙ  z9LatexPrinter._print_SubQuotientModule.<locals>.<listcomp>rß  )r+  rQ  rä   )rÛ   r  rá  ro   r$  rr   Ú_print_SubQuotientModuleÏ
  s   
z%LatexPrinter._print_SubQuotientModulec                   s8   ‡ fdd„ˆ j jD ƒ}d ‡fdd„|D ƒ¡}d |¡S )Nc                   s   g | ]	\}ˆ j  |¡‘qS ro   )r€  r�  r
  ©r  ro   rr   r%  Ô
  r8  z>LatexPrinter._print_ModuleImplementedIdeal.<locals>.<listcomp>rF  c                 3  rÔ  rÕ  r#  r
  r$  ro   rr   r  Õ
  s   €  z=LatexPrinter._print_ModuleImplementedIdeal.<locals>.<genexpr>rß  )Ú_modulerQ  r+  rä   rà  ro   rØ  rr   Ú_print_ModuleImplementedIdealÓ
  s   
z*LatexPrinter._print_ModuleImplementedIdealc                   sD   ‡ fdd„|j D ƒ}|d gdd„ t|dd … dƒD ƒ }d |¡S )Nc                   s    g | ]}ˆ j |td  dd�‘qS )r	   TrJ  )rð   r    rÎ  r$  ro   rr   r%  Û
  s    ÿz2LatexPrinter._print_Quaternion.<locals>.<listcomp>r   c                 S  s   g | ]
\}}|d  | ‘qS )r¿   ro   )r  r¯   rË   ro   ro   rr   r%  Ý
  r¨  rE  Úijkr9  )r  r  r+  )rÛ   rò   rq   r¯  ro   r$  rr   Ú_print_QuaternionØ
  s
   
ÿ&
zLatexPrinter._print_Quaternionc                 C  rÐ  ©Nz\frac{{{}}}{{{}}})rä   rê   r€  Ú
base_ideal)rÛ   ÚRro   ro   rr   Ú_print_QuotientRingà
  ó   
ÿz LatexPrinter._print_QuotientRingc                 C  s(   |   |j |¡¡}d ||   |jj¡¡S )Nú{{{}}} + {{{}}})rê   r€  r�  rä   rê  )rÛ   r  Úx_latexro   ro   rr   Ú_print_QuotientRingElementå
  s   ÿz'LatexPrinter._print_QuotientRingElementc                   sH   ‡ fdd„ˆ j D ƒ}d d ‡fdd„|D ƒ¡¡}d |ˆ ˆ jj¡¡S )Nc                   s   g | ]	}ˆ j j |¡‘qS ro   )Úmoduler€  r�  r
  rä  ro   rr   r%  ë
  r8  z=LatexPrinter._print_QuotientModuleElement.<locals>.<listcomp>rÓ  rF  c                 3  rÔ  rÕ  r#  r
  r$  ro   rr   r  ì
  rÖ  z<LatexPrinter._print_QuotientModuleElement.<locals>.<genexpr>rî  )Údatarä   r+  rê   rñ  Úkilled_module)rÛ   r  rò  Ú
data_latexro   rØ  rr   Ú_print_QuotientModuleElementê
  s   
ÿÿz)LatexPrinter._print_QuotientModuleElementc                 C  rÐ  ré  )rä   rê   r  ró  rÑ  ro   ro   rr   Ú_print_QuotientModuleñ
  rí  z"LatexPrinter._print_QuotientModulec                 C  s(   d  |  | ¡ ¡|  |j¡|  |j¡¡S )Nz{{{}}} : {{{}}} \to {{{}}})rä   rê   Ú_sympy_matrixrI  r‘  )rÛ   rF  ro   ro   rr   Ú_print_MatrixHomomorphismö
  s   ÿz&LatexPrinter._print_MatrixHomomorphismc                 C  sL   |   |jj¡\}}}d| }|r|dd |¡ 7 }|r$|dd |¡ 7 }|S )Nr3  r%  r¿   rý  )r(  r,  r+  )rÛ   Úmanifoldr,  r'  r  ro   ro   rr   Ú_print_Manifoldú
  s   zLatexPrinter._print_Manifoldc                 C  rT  )Nz\text{%s}_{%s})rê   r,  rù  )rÛ   Úpatchro   ro   rr   Ú_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Û   Úcoordsysro   ro   rr   Ú_print_CoordSystem  s    ÿzLatexPrinter._print_CoordSystemc                 C  s   d|   |j¡ S )Nz\mathbb{\nabla}_{%s})rê   Ú_wrt)rÛ   Úcvdro   ro   rr   Ú_print_CovarDerivativeOp  rÌ  z%LatexPrinter._print_CovarDerivativeOpc                 C  ó$   |j j|j j}d |  t|ƒ¡¡S rÁ  ©Ú
_coord_sysr(  Ú_indexr,  rä   rê   r   ©rÛ   Úfieldr)  ro   ro   rr   Ú_print_BaseScalarField  ó   z#LatexPrinter._print_BaseScalarFieldc                 C  r  )Nz\partial_{{{}}}r  r  ro   ro   rr   Ú_print_BaseVectorField  r	  z#LatexPrinter._print_BaseVectorFieldc                 C  sH   |j }t|dƒr|jj|j j}d |  t|ƒ¡¡S |  |¡}d |¡S )Nr  z\operatorname{{d}}{}z!\operatorname{{d}}\left({}\right))	Ú_form_fieldrŽ  r  r(  r  r,  rä   rê   r   )rÛ   Údiffr  r)  ro   ro   rr   Ú_print_Differential  s   


z LatexPrinter._print_Differentialc                 C  r4  )Nr   z"\operatorname{{tr}}\left({}\right)r5  )rÛ   r·  Úcontentsro   ro   rr   Ú	_print_Tr!  s   
zLatexPrinter._print_Trc                 C  ó4   |d urd|   |jd ¡|f S d|   |jd ¡ S )Nz%\left(\phi\left(%s\right)\right)^{%s}r   z\phi\left(%s\right)rÊ  r  ro   ro   rr   Ú_print_totient&  ó
   ÿzLatexPrinter._print_totientc                 C  r  )Nz(\left(\lambda\left(%s\right)\right)^{%s}r   z\lambda\left(%s\right)rÊ  r  ro   ro   rr   Ú_print_reduced_totient,  r  z#LatexPrinter._print_reduced_totientc                 C  ód   t |jƒdkrdtt| j|jd |jd fƒƒ }n
d|  |jd ¡ }|d ur.d||f S d| S )Nr¢  ú_%s\left(%s\right)rE  r   r:  z\sigma^{%s}%sz\sigma%srì  rm  ro   ro   rr   Ú_print_divisor_sigma2  ó   

ÿz!LatexPrinter._print_divisor_sigmac                 C  r  )Nr¢  r  rE  r   r:  z\sigma^*^{%s}%sz
\sigma^*%srì  rm  ro   ro   rr   Ú_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  ro   ro   rr   Ú_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  ro   ro   rr   Ú_print_primeomegaL  r  zLatexPrinter._print_primeomegac                 C  s
   t |jƒS ré   )r‘   r,  rå   ro   ro   rr   Ú
_print_StrR  rç   zLatexPrinter._print_Strc                 C  rR  ré   )rê   r   rû   ro   ro   rr   Ú_print_floatU  r  zLatexPrinter._print_floatc                 C  ó   t |ƒS ré   ©r‘   rû   ro   ro   rr   Ú
_print_intX  r6  zLatexPrinter._print_intc                 C  r  ré   r  rû   ro   ro   rr   Ú
_print_mpz[  r6  zLatexPrinter._print_mpzc                 C  r  ré   r  rû   ro   ro   rr   Ú
_print_mpq^  r6  zLatexPrinter._print_mpqc                 C  r  ré   r  rû   ro   ro   rr   Ú_print_fmpza  r6  zLatexPrinter._print_fmpzc                 C  r  ré   r  rû   ro   ro   rr   Ú_print_fmpqd  r6  zLatexPrinter._print_fmpqc                 C  s   d  tt|jƒƒ¡S )Nz"\operatorname{{Q}}_{{\text{{{}}}}})rä   r˜   r‘   r,  rû   ro   ro   rr   Ú_print_Predicateg  r  zLatexPrinter._print_Predicatec                   s:   |j }|j}ˆ  |¡}d ‡ fdd„|D ƒ¡}d||f S )Nr'  c                   r"  ro   r#  r·  r$  ro   rr   r%  n  r&  z8LatexPrinter._print_AppliedPredicate.<locals>.<listcomp>z%s(%s))rß  Ú	argumentsrê   r+  )rÛ   rò   Úpredr  Ú
pred_latexÚ
args_latexro   r$  rr   Ú_print_AppliedPredicatej  s
   
z$LatexPrinter._print_AppliedPredicatec                   s   t ƒ  |¡}dt|ƒ S )Nz\mathtt{\text{%s}})ÚsuperÚemptyPrinterr˜   r  ©r)  ro   rr   r+  q  s   zLatexPrinter.emptyPrinterré   r¤  )FF)r’   rõ   )rò   r‘   )r/  r0  )rò   r   )rò   r   )rÄ  r‘   r’   r‘   )rò   rå  )r†  r‘   r’   r‘   )rò   r   r’   r‘   rì  )r¾  r‘   r’   r‘   rP  )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.  r5  Ú_print_BooleanTrueÚ_print_BooleanFalser7  r@  rN  r_  rb  rs  r{  r�  rƒ  r„  r‡  rˆ  r±  rµ  rº  rÃ  rÀ  rË  râ  rä  rü  r  r  r  r  r  r)  r0  r6  rQ  rS  rU  Úpropertyr`  rc  rd  rf  rk  Ú
_print_MinÚ
_print_Maxrn  rp  rq  rs  rw  ry  r€  rƒ  r‡  r‰  rŠ  r~  r}  r�  r�  r‘  r’  r”  r—  r™  rš  rœ  r¡  r£  r¤  r§  r©  Ú_print_gammarª  r­  r®  r¯  r³  rµ  r¶  r·  rº  r½  rÂ  rÃ  rÇ  rÈ  rÊ  rÌ  rÍ  rÎ  rÏ  rÐ  rÑ  rÒ  rÖ  rØ  rÜ  rß  rá  râ  ræ  rê  rë  rí  rï  rð  rò  rõ  rù  rý  rÿ  r   r  r  r  r  r	  r
  r  r  r  r  r  r  r  r"  Ú_print_RandomSymbolr(  r(  r3  r7  rD  rI  rN  rX  rZ  r`  rb  rf  rl  ro  rq  rr  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_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,  r3  r7  r8  r9  r>  r@  rB  rC  rD  rE  rF  rK  rM  rP  r\  r_  rb  rd  rf  rg  rh  ri  rj  rk  rn  rr  rt  rv  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´  Ú_print_IDFTr·  r»  rÀ  rÂ  rÈ  rÏ  rÒ  r×  râ  rã  ræ  rè  rì  rð  rõ  rö  rø  rú  rü  rþ  r  r  r
  r  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r#  r$  r)  r+  Ú__classcell__ro   ro   r,  rr   r™   Ž   sÔ  
 ÿþýüûúùø	÷
öõôóòñðïæ=

	!s-!
$ L

										
7



*9		
$	

r™   c                 C  s–   t  | ¡}|r	|S |  ¡ tv rd|  ¡  S | tv rd|  S tt ¡ tdd�D ]"}|  ¡  	|¡rHt| ƒt|ƒkrHt| t
| dt|ƒ … ƒƒ  S q&| S )aŽ  
    Check for a modifier ending the string.  If present, convert the
    modifier to latex and translate the rest recursively.

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

    Let everything else pass as given.

    >>> from sympy.printing.latex import translate
    >>> translate('alphahatdotprime')
    "{\\dot{\\hat{\\alpha}}}'"
    r“   T)ré  r½  N)Útex_greek_dictionaryrÚ   rZ  Úgreek_letters_setÚother_symbolsri  r�   rÂ  rY  rÈ  r&  )rq   ró   ré  ro   ro   rr   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Ü   ro   ro   rr   rÍ  —  s    XrÍ  c                 K  s   t t| fi |¤Žƒ dS )z`Prints LaTeX representation of the given expression. Takes the same
    settings as ``latex()``.N)ÚprintrÍ  rA  ro   ro   rr   Úprint_latexq  s   rC  rE  ú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.

    Úeqnarrayz\begin{eqnarray}
z& = &z	\nonumberz
\end{eqnarray}TÚIEEEeqnarrayz\begin{IEEEeqnarray}{rCl}
z
\end{IEEEeqnarray}rD  z\begin{align*}
z= &rÆ   z
\end{align*}FzUnknown environment: {}z\dotsrE  rf  z& & rÉ  rØ  rÊ  r   rD  rê  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s}Nro   )r™   rÖ   rä   Úas_ordered_termsrY  rX  r’  rñ   )r-  r/  Úterms_per_lineÚenvironmentÚuse_dotsrÜ   rÕ  rˆ  Ú
first_termÚnonumberÚend_termÚdoubleetrÛ  r=  Ún_termsÚ
term_countr¯   r>  Ú
term_startÚterm_endr  ro   ro   rr   Úmultiline_latexx  sn   Cÿ

ÿ
rS  )rq   r‘   r’   r‘   )rE  rD  F)JÚ__doc__Ú
__future__r   Útypingr   r   r   r“  Ú
sympy.corer   r   r   r	   r
   r   r   r   Úsympy.core.alphabetsr   Úsympy.core.containersr   Úsympy.core.functionr   r   r   Úsympy.core.operationsr   Úsympy.core.powerr   Úsympy.core.sortingr   Úsympy.core.sympifyr   r|  r   r   r   Úsympy.printing.precedencer   Úsympy.printing.printerr   r   Úsympy.printing.conventionsr   r   r   r    Úmpmath.libmp.libmpfr!   r"   rj  Úsympy.utilities.iterablesr#   r$   r7   Úsympy.tensor.arrayr%   Úsympy.vector.basisdependentr&   r3  r>  r@  r�   r0  Ú	frozensetr?  Úcompiler™  r˜   r™   r&  rÍ  rC  rS  ro   ro   ro   rr   Ú<module>   sZ   (ÿþýüûúùø	÷
öõôóòñðïîíìëêéèçæåäãâá à!ß"Þ#Ü'þýüûúùø	÷
öõôóòñðîíåþ
                     

 Z