o
    GZŽhã ã                	   @  s€  U d Z ddlmZ ddlmZmZmZ ddlZddlm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z(m)Z) ddl*m+Z+m,Z, ddl%m-Z-m.Z. ddl/m0Z0m1Z2 ddl3m4Z4m5Z5 ddl6Z6e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_„ dd_„ d‚d_„ dƒd_„ d„d_„ d…d_„ d†d_„ d‡œ¥Z>dˆe?d‰< e@eƒZAe6 BdŠ¡e6 Bd‹¡fZCdždd„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)ZarcsinZarccosZarctanÚsinÚcosÚtanÚsinhÚcoshÚtanhÚsqrtÚlnÚlogÚsecZcscZcotZcothÚreZimÚfracÚrootÚargÚAlphaz
\mathrm{A}ÚBetaz
\mathrm{B}ÚGammaú\GammaÚDeltaz\DeltaÚEpsilonz
\mathrm{E}ÚZetaz
\mathrm{Z}ÚEtaz
\mathrm{H}ÚThetaz\ThetaÚIotaz
\mathrm{I}ÚKappaz
\mathrm{K}ÚLambdaz\LambdaÚMuz
\mathrm{M}ÚNuz
\mathrm{N}ÚXiz\XiÚomicronÚoÚOmicronz
\mathrm{O}ÚPiz\PiÚRhoz
\mathrm{P}ÚSigmaz\SigmaÚTauz
\mathrm{T}ÚUpsilonz\UpsilonÚPhiz\PhiÚChiz
\mathrm{X}ÚPsiz\PsiÚOmegaz\OmegaÚlamdaz\lambdaZLamdaZkhiz\chiZKhiZ
varepsilonz\varepsilonZvarkappaz	\varkappaZvarphiz\varphiZvarpiz\varpiZvarrhoz\varrhoz	\varsigmaz	\vartheta)ZvarsigmaZvartheta>
   ZhslashZdalethZellÚethZmhoZalephZbethZhbarZgimelZwpZmathringc                 C  ó   d|  d S )Nz
\mathring{Ú}© ©ÚsrT   rT   úC/var/www/auris/lib/python3.10/site-packages/sympy/printing/latex.pyÚ<lambda>[   ó    rX   Zddddotc                 C  rR   )Nz\ddddot{rS   rT   rU   rT   rT   rW   rX   \   rY   Zdddotc                 C  rR   )Nz\dddot{rS   rT   rU   rT   rT   rW   rX   ]   rY   Zddotc                 C  rR   )Nz\ddot{rS   rT   rU   rT   rT   rW   rX   ^   rY   Údotc                 C  rR   )Nz\dot{rS   rT   rU   rT   rT   rW   rX   _   rY   Úcheckc                 C  rR   )Nz\check{rS   rT   rU   rT   rT   rW   rX   `   rY   Zbrevec                 C  rR   )Nz\breve{rS   rT   rU   rT   rT   rW   rX   a   rY   Úacutec                 C  rR   )Nz\acute{rS   rT   rU   rT   rT   rW   rX   b   rY   Zgravec                 C  rR   )Nz\grave{rS   rT   rU   rT   rT   rW   rX   c   rY   Útildec                 C  rR   )Nz\tilde{rS   rT   rU   rT   rT   rW   rX   d   rY   Zhatc                 C  rR   )Nz\hat{rS   rT   rU   rT   rT   rW   rX   e   rY   Úbarc                 C  rR   )Nz\bar{rS   rT   rU   rT   rT   rW   rX   f   rY   Úvecc                 C  rR   )Nz\vec{rS   rT   rU   rT   rT   rW   rX   g   rY   Úprimec                 C  rR   ©NÚ{z}'rT   rU   rT   rT   rW   rX   h   rY   Zprmc                 C  rR   ra   rT   rU   rT   rT   rW   rX   i   rY   Úboldc                 C  rR   ©Nz\boldsymbol{rS   rT   rU   rT   rT   rW   rX   k   rY   Úbmc                 C  rR   rd   rT   rU   rT   rT   rW   rX   l   rY   c                 C  rR   )Nz	\mathcal{rS   rT   rU   rT   rT   rW   rX   m   rY   c                 C  rR   )Nz	\mathscr{rS   rT   rU   rT   rT   rW   rX   n   rY   c                 C  rR   )Nz
\mathfrak{rS   rT   rU   rT   rT   rW   rX   o   rY   c                 C  rR   )Nz\left\|{z	}\right\|rT   rU   rT   rT   rW   rX   q   rY   c                 C  rR   )Nz\left\langle{z}\right\ranglerT   rU   rT   rT   rW   rX   r   rY   c                 C  rR   ©Nz\left|{z}\right|rT   rU   rT   rT   rW   rX   s   rY   c                 C  rR   rf   rT   rU   rT   rT   rW   rX   t   rY   )ÚcalZscrZfrakZnormZavgÚabsÚmagzdict[str, Callable[[str], str]]Úmodifier_dictz[0-9][} ]*$z(\d|\\frac{\d+}{\d+})rV   Ú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)rV   ÚcrT   rT   rW   Úlatex_escape   s   rr   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%dddde„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 dd‚„Z3d–d¡d„d…„Z4d†d‡„ Z5dˆd‰„ Z6e7dŠd‹„ ƒZ8dŒd„ Z9dŽd„ Z:dd‘„ 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„ZeZ‘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 (­  ÚLatexPrinterZ_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   Zequationz	equation*zB'mode' must be one of 'inline', 'plain', 'equation' or 'equation*'rw   r–   Tú z \,.\, ú \cdot ú \times )NZldotrZ   Útimesr‚   Úmul_symbol_latexrZ   Úmul_symbol_latex_numbers)Ú r—   rm   z\,z\:ú\;z\quadú)ú])ú(r~   rˆ   z
\mathrm{i}z\text{i}Újz
\mathrm{j}z\text{j})Nrˆ   ÚriÚtir¢   ZrjZtjr‡   Z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ÚsettingsZvalid_modesZmul_symbol_tableZimaginary_unit_tableZ	imag_unitZdiff_operator_tabler’   rT   rT   rW   r¨   ®   sf   

üÿÿÿÿÿ
ÿÿ€ú	ù
	ü
zLatexPrinter.__init__rl   rk   c                 C  ó
   d  |¡S )Nz\left({}\right)©Úformat©r¯   rV   rT   rT   rW   Ú_add_parensë   ó   
zLatexPrinter._add_parensc                 C  r±   )Nz\left( {}\right)r²   r´   rT   rT   rW   Ú_add_parens_lspaceï   r¶   zLatexPrinter._add_parens_lspacec                 C  sN   t |ƒ}|r|r|  |  |¡¡S ||k s|s"||kr"|  |  |¡¡S |  |¡S ©N)r   rµ   Ú_print)r¯   ÚitemÚlevelÚis_negÚstrictZprec_valrT   rT   rW   Ú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.
        ro   r   z{{{}}})r©   rµ   r³   r´   rT   rT   rW   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$rz   z$$%s$$z\begin{%s}%s\end{%s})r   Údoprintr©   )r¯   ÚexprÚtexZenv_strrT   rT   rW   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)Z
is_IntegerZis_nonnegativeÚis_Atomr   ÚNegativeOneÚis_Rational©r¯   rÀ   rT   rT   rW   Ú_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_cleanZis_PowÚ_pow_is_cleanÚis_AddÚis_FunctionrÆ   rT   rT   rW   Ú_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À   rT   rW   Ú	<genexpr>O  ó   € z3LatexPrinter._needs_mul_brackets.<locals>.<genexpr>c                 3  rÑ   r¸   rÒ   rÔ   r×   rT   rW   rØ   R  rÙ   F)Zsympy.concrete.productsrÎ   Zsympy.concrete.summationsrÏ   Zsympy.integrals.integralsrÐ   rÈ   Úcould_extract_minus_signr   r    Úis_RelationalZis_PiecewiseÚanyr   )r¯   rÀ   ÚfirstÚlastrÎ   rÏ   rÐ   rT   r×   rW   Ú_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×   rT   rW   rØ   _  rÙ   z3LatexPrinter._needs_add_brackets.<locals>.<genexpr>F)rÛ   rÜ   r   rË   rÆ   rT   r×   rW   Ú_needs_add_bracketsW  s   z LatexPrinter._needs_add_bracketsc                 C  s   |j D ]}|jr dS qdS )NFT)ÚargsrÌ   )r¯   rÀ   r4   rT   rT   rW   rÉ   e  s
   
ÿzLatexPrinter._mul_is_cleanc                 C  s   |   |j¡ S r¸   )rÇ   ÚbaserÆ   rT   rT   rW   rÊ   k  ó   zLatexPrinter._pow_is_cleanrÀ   c                 C  s   |d ur
d||f S |S )Nú\left(%s\right)^{%s}rT   ©r¯   rÀ   ÚexprT   rT   rW   Ú_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 rT   ©r¹   )rÕ   rE   ©r¯   rT   rW   Ú
<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À   ÚnameZlsrV   rT   rê   rW   Ú_print_Basict  s   
zLatexPrinter._print_BasicÚeú!bool | BooleanTrue | BooleanFalsec                 C  ó   d| S ©Nú	\text{%s}rT   ©r¯   rô   rT   rT   rW   Ú_print_bool}  ó   zLatexPrinter._print_boolc                 C  rö   r÷   rT   rù   rT   rT   rW   Ú_print_NoneTypeƒ  rû   zLatexPrinter._print_NoneTypec                 C  sv   | j ||d}d}t|ƒD ]+\}}|dkrn| ¡ r"|d7 }| }n|d7 }|  |¡}|  |¡r4d| }||7 }q|S )N)rƒ   r   r   ú - ú + ú\left(%s\right))Z_as_ordered_termsÚ	enumeraterÚ   r¹   rà   )r¯   rÀ   rƒ   ÚtermsrÁ   rˆ   ÚtermÚterm_texrT   rT   rW   Ú
_print_Add†  s   


zLatexPrinter._print_Addc                 C  sŽ   ddl m} |jdkrdS ||ƒ}|j}|j}|jd |d kr(||d gg }d}|D ]}|t|ƒ dd¡7 }q,| d	d
¡}| dd¡}|S )Nr   ©ÚPermutationú\left( \right)éÿÿÿÿé   r   ú,rž   r~   z\left( r    ú\right))Ú sympy.combinatorics.permutationsr  ÚsizeZcyclic_formÚ
array_formrk   rp   )r¯   rÀ   r  Z	expr_permZsizr  rˆ   rT   rT   rW   Ú_print_Cycle™  s   
zLatexPrinter._print_Cyclec           
        sÂ   ddl m} ddlm} |j}|d ur |d|› ddddd	 nˆ j d
d¡}|r.ˆ  |¡S |jdkr5dS ‡ fdd„|j	D ƒ}‡ fdd„t
t|ƒƒD ƒ}d |¡}d |¡}d ||f¡}	d|	 S )Nr   r  )Úsympy_deprecation_warningzw
                Setting Permutation.print_cyclic is deprecated. Instead use
                init_printing(perm_cyclic=z).
                z1.6z#deprecated-permutation-print_cyclicé   )Zdeprecated_since_versionZactive_deprecations_targetÚ
stacklevelrŽ   Tr  c                   rè   rT   ré   ©rÕ   r4   rê   rT   rW   rë   Á  rì   z3LatexPrinter._print_Permutation.<locals>.<listcomp>c                   rè   rT   ré   r  rê   rT   rW   rë   Â  rì   ú & z \\ z \begin{pmatrix} %s \end{pmatrix})r  r  Zsympy.utilities.exceptionsr  Zprint_cyclicr©   r®   r  r  r  ÚrangeÚlenrñ   )
r¯   rÀ   r  r  rŽ   ÚlowerÚupperZrow1Zrow2ÚmatrT   rê   rW   Ú_print_Permutation©  s.   þù




zLatexPrinter._print_Permutationc                 C  s"   |j \}}d|  |¡|  |¡f S )Nz\sigma_{%s}(%s))rá   r¹   )r¯   rÀ   ÚpermÚvarrT   rT   rW   Ú_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 )Nrt   FTr   r‘   )Zstrip_zerosZ	min_fixedZ	max_fixedrœ   rô   r   ú+r	  r   ÚcommaÚ.z{,}z%s%s10^{%s}z+infz\inftyz-infz- \infty)r!   Z_precr©   Úmlib_to_strZ_mpf_Úsplitrp   )
r¯   rÀ   Zdpsr¬   ÚlowÚhighZstr_realÚ	separatorZmantræ   rT   rT   rW   Ú_print_FloatÎ  s(   

zLatexPrinter._print_Floatc                 C  ó0   |j }|j}d|  |td ¡|  |td ¡f S )Nz%s \times %sr	   ©Z_expr1Z_expr2r¾   r    ©r¯   rÀ   Zvec1Zvec2rT   rT   rW   Ú_print_Crossì  ó
   ÿzLatexPrinter._print_Crossc                 C  ó   |j }d|  |td ¡ S )Nz\nabla\times %sr	   ©Z_exprr¾   r    ©r¯   rÀ   r_   rT   rT   rW   Ú_print_Curlò  ó   zLatexPrinter._print_Curlc                 C  r,  )Nz\nabla\cdot %sr	   r-  r.  rT   rT   rW   Ú_print_Divergenceö  r0  zLatexPrinter._print_Divergencec                 C  r'  )Nz%s \cdot %sr	   r(  r)  rT   rT   rW   Ú
_print_Dotú  r+  zLatexPrinter._print_Dotc                 C  r,  )Nz	\nabla %sr	   r-  ©r¯   rÀ   ÚfuncrT   rT   rW   Ú_print_Gradient   r0  zLatexPrinter._print_Gradientc                 C  r,  )Nz	\Delta %sr	   r-  r3  rT   rT   rW   Ú_print_Laplacian  r0  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œ   rl   rk   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Ö   rT   rT   rW   rX     s    
z:LatexPrinter._print_Mul.<locals>.convert.<locals>.<lambda>T)Úbinaryc                 S  s
   t | dƒS )Nr:  )r<  r>  rT   rT   rW   rX     s   
 )rÈ   rk   r¹   rƒ   Úas_ordered_factorsÚlistrá   r$   )rÀ   rá   ZunitsZnonunitsÚprefixes)Úconvert_argsr¯   rT   rW   Úconvert  s   




þz(LatexPrinter._print_Mul.<locals>.convertc                   s°   d }}t | ƒD ]M\}}ˆ |¡}t|dƒsIt|dƒsIˆj||dk|t| ƒd kdr/d| }td  |¡rBtd  |¡rB|ˆ 7 }n|rH|ˆ7 }n|rO|ˆ7 }||7 }|}q|S )Nr   r:  r;  r   r	  )rÝ   rÞ   rÿ   )r   r¹   r<  rß   r  Ú_between_two_numbers_pÚsearchÚmatch)rá   Z_texZlast_term_texrˆ   r  r  )Ú	numbersepr¯   r%  rT   rW   rC    s(   
ÿÿ
€z-LatexPrinter._print_Mul.<locals>.convert_argsc                 s  s    | ]}t |tƒV  qd S r¸   )r=  r
   r  rT   rT   rW   rØ   ;  rÙ   z*LatexPrinter._print_Mul.<locals>.<genexpr>r	  Fú- r¡   Tr   )Úexactr  )Úevaluater|   rw   é   ro   )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Ÿ   ©rl   rk   )Zsympy.simplifyr7  r©   r=  r	   rá   r   ÚOnerÜ   rÚ   rË   r   r  r"  rß   rÈ   Úis_commutative)r¯   rÀ   r7  rD  rá   Zinclude_parensrÁ   ÚnumerÚdenomZsnumerZsdenomZldenomÚratioÚaÚbrÖ   rT   )rC  rH  r¯   r%  rW   Ú
_print_Mul  sr   


(€

ÿ
 

ÿÿzLatexPrinter._print_Mulc                 C  s&   |j r|  | ¡  ¡ ¡S |  | ¡ ¡S r¸   )Z
is_aliasedr¹   Zas_polyÚas_exprrÆ   rT   rT   rW   Ú_print_AlgebraicNumber{  s   z#LatexPrinter._print_AlgebraicNumberc                 C  s@   |   |j¡}|jrd|› dS |   |j ¡ ¡}d|› d|› dS )Nú\left(r  rí   )r¹   ÚpZis_inertÚalpharW  )r¯   rÀ   rZ  r[  rT   rT   rW   Ú_print_PrimeIdeal  s
   zLatexPrinter._print_PrimeIdealr   c                 C  s¦  |j jr»|j j}|j j}t|ƒdkrF|dkrF| jd rF|  |j¡}|dkr*d| }n| jd r6d||f }nd||f }|j jrDd| S |S | jd	 rx|dkrx|  	|jt
d
 ¡}|jjra|  |¡}|jjrq| j|jd||f dS d|||f S |j jr»|jjr»|jdkrd|j|j f S |jjr¶|jj}|jj}|| t|ƒkr¶|j dkr¬d||f S d||t|j ƒf S |  |¡S |jjrË| j|j|  |j ¡dS d}|  ||¡S )Nr	  r…   rL  z	\sqrt{%s}rz   z\root{%d}{%s}z\sqrt[%d]{%s}z\frac{1}{%s}ru   r   z%s/%s©ræ   z
%s^{%s/%s}ú%s^{%s}r  z\frac{1}{\frac{%s}{%s}}z\frac{1}{(\frac{%s}{%s})^{%s}})ræ   rÅ   rZ  Úqrh   r©   r¹   râ   Zis_negativer¾   r    Ú	is_Symbolr   rÌ   rP  rV  Ú_helper_print_standard_power)r¯   rÀ   rZ  r_  râ   rÁ   Zbase_pZbase_qrT   rT   rW   Ú
_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}rY  z\\left\(\\d?d?dotr  é   iùÿÿÿ)r¹   ræ   r¾   râ   r    r`  r   Zis_Floatr=  r   Ú
startswithr1   rG  Úendswith)r¯   rÀ   rc  ræ   râ   rT   rT   rW   ra  µ  s   
ÿ
þýz)LatexPrinter._helper_print_standard_powerc                 C  s   |   |jd ¡S ©Nr   ©r¹   rá   rÆ   rT   rT   rW   Ú_print_UnevaluatedExprÆ  ó   z#LatexPrinter._print_UnevaluatedExprc                   ó”   t |jƒdkrdt‡fdd„|jd D ƒƒ }n‡fdd„‰ dt d	‡ fd
d„|jD ƒ¡ }t|jtƒr@|dˆ |j¡ 7 }|S |ˆ |j¡7 }|S )Nr	  z\sum_{%s=%s}^{%s} c                   rè   rT   ré   ©rÕ   rˆ   rê   rT   rW   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è   rT   ré   ©rÕ   rV   rê   rT   rW   rë   Ð  rì   zALatexPrinter._print_Sum.<locals>._format_ineq.<locals>.<listcomp>r	  r   rL  ©Útuple©Úlrê   rT   rW   Ú_format_ineqÎ  ó   &ÿz-LatexPrinter._print_Sum.<locals>._format_ineqz\sum_{\substack{%s}} ú\\c                   ó   g | ]}ˆ |ƒ‘qS rT   rT   ©rÕ   rs  ©rt  rT   rW   rë   Ó  ó    rÿ   ©	r  Úlimitsrq  rk   rñ   r=  Úfunctionr   r¹   ©r¯   rÀ   rÁ   rT   ©rt  r¯   rW   Ú
_print_SumÉ  ó   ÿÿþzLatexPrinter._print_Sumc                   rk  )Nr	  z\prod_{%s=%s}^{%s} c                   rè   rT   ré   rl  rê   rT   rW   rë   ß  rì   z/LatexPrinter._print_Product.<locals>.<listcomp>r   c                   rm  )Nrn  c                   rè   rT   ré   ro  rê   rT   rW   rë   ã  rì   zELatexPrinter._print_Product.<locals>._format_ineq.<locals>.<listcomp>r	  r   rL  rp  rr  rê   rT   rW   rt  á  ru  z1LatexPrinter._print_Product.<locals>._format_ineqz\prod_{\substack{%s}} rv  c                   rw  rT   rT   rx  ry  rT   rW   rë   æ  rz  rÿ   r{  r~  rT   r  rW   Ú_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 rg  )Ú__str__r>  rT   rT   rW   rX   ü  rY   z4LatexPrinter._print_BasisDependent.<locals>.<lambda>©Úkeyr	  rþ   r  rý   rY  r  r   ú-é   )Zsympy.vectorr„  ÚzeroZ_latex_formr=  ZseparateÚitemsrA  Ú
componentsÚsortÚappendr¹   rñ   )r¯   rÀ   r„  Zo1r‹  ÚsystemZvectZ
inneritemsÚkÚvZarg_strZoutstrrT   rT   rW   Ú_print_BasisDependentï  s0   


ù
	ÿz"LatexPrinter._print_BasisDependentc                 C  s4   |   |j¡}d| d dd t| j |jƒ¡  }|S )Nrb   rS   ú_{%s}r
  )r¹   râ   rñ   ÚmapÚindices)r¯   rÀ   Ztex_baserÁ   rT   rT   rW   Ú_print_Indexed  s
   ÿzLatexPrinter._print_Indexedc                 C  ó   |   |j¡S r¸   )r¹   ÚlabelrÆ   rT   rT   rW   Ú_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})r  r  z{{{label}}}_{{{interval}}})r˜  Úinterval)r¹   r˜  r  r  r   ÚZeror³   )r¯   rÀ   r˜  r  r  r›  rT   rT   rW   Ú
_print_Idx  s   

ÿÿzLatexPrinter._print_Idxc              	   C  s   t |jƒrd}n| jd }d}d}t|jƒD ]*\}}||7 }|dkr.|d||  |¡f 7 }q|d||  |  |¡¡|  |¡f 7 }q|dkrLd||f }n
d	||  |¡|f }td
d„ |jD ƒƒrpd|| j	|jt
d dddf S d|| j	|jt
d dddf S )Nz\partialr§   r   r   r	  ú%s %sz
%s %s^{%s}rM  z\frac{%s^{%s}}{%s}c                 s  ó    | ]}|  ¡ V  qd S r¸   ©rÚ   rl  rT   rT   rW   rØ   ;  ó   € z1LatexPrinter._print_Derivative.<locals>.<genexpr>r	   T©r¼   r½   F)r   rÀ   r©   ÚreversedZvariable_countr¹   r   rÜ   rá   r¾   r    )r¯   rÀ   Údiff_symbolrÁ   ÚdimrÖ   ÚnumrT   rT   rW   Ú_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ê   rT   rW   rØ   I  rÙ   z+LatexPrinter._print_Subs.<locals>.<genexpr>c                 3  rÑ   r¸   ré   r¨  rê   rT   rW   rØ   J  rÙ   z\\ c                 s  s$    | ]}|d  d |d  V  qdS )r   ú=r	  NrT   r¨  rT   rT   rW   rØ   K  s   € 
ÿz#\left. %s \right|_{\substack{ %s }})rá   r¹   rñ   Úzip)	r¯   ÚsubsrÀ   r8  ÚnewZ
latex_exprZ	latex_oldZ	latex_newZ
latex_subsrT   rê   rW   Ú_print_SubsF  s   

ÿÿzLatexPrinter._print_Subsc              	     sX  dg }}ˆj d ‰ t|jƒdkr4tdd„ |jD ƒƒr4ddt|jƒd   d	 }‡ ‡fd
d„|jD ƒ}n\t|jƒD ]V}|d }|d7 }t|ƒdkr‚ˆj d dkrYˆj d sY|d7 }t|ƒdkrq|dˆ |d ¡ˆ |d ¡f 7 }t|ƒdkr‚|dˆ |d ¡ 7 }| ddˆ ˆ |¡f ¡ q9d|ˆj|jt	d t
dd„ |jD ƒƒddd |¡f S )Nr   r§   é   c                 s  s    | ]	}t |ƒd kV  qdS )r	  N)r  )rÕ   ÚlimrT   rT   rW   rØ   U  s   € z/LatexPrinter._print_Integral.<locals>.<genexpr>z\irˆ   r	  Úntc                   s"   g | ]}d ˆ ˆ  |d ¡f ‘qS )ú\, %s%sr   ré   ©rÕ   Úsymbol©r¤  r¯   rT   rW   rë   Y  s    ÿz0LatexPrinter._print_Integral.<locals>.<listcomp>r   z\intr€   r–   rz   z\limitsr‰  z
_{%s}^{%s}rL  ú^{%s}r±  z%s %s%sr	   c                 s  rŸ  r¸   r   rl  rT   rT   rW   rØ   p  r¡  Tr¢  )r©   r  r|  Úallr£  r¹   Úinsertr¾   r}  r    rÜ   rá   rñ   )r¯   rÀ   rÁ   Úsymbolsr¯  r³  rT   r´  rW   Ú_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¹   rk   r   ÚInfinityÚNegativeInfinityr=  r   )r¯   rÀ   rô   ÚzZz0ÚdirrÁ   rT   rT   rW   Ú_print_Limitt  s   
zLatexPrinter._print_Limitr4  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
        ro   Ú_z\%sr	  rm   r   z\operatorname{%s}%sNz\operatorname{%s})rî   ÚfindÚaccepted_latex_functionsr  re  r   )r¯   r4  ZsuperscriptidxZsubscriptidxrò   rT   rT   rW   Ú_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
        Z_print_c                   s   g | ]	}t ˆ  |¡ƒ‘qS rT   )rk   r¹   r  rê   rT   rW   rë   ³  ó    z0LatexPrinter._print_Function.<locals>.<listcomp>rx   Frv   r	  r   )ÚasinÚacosÚatanZacscZasecZacotÚasinhÚacoshÚatanhZacschZasechZacothry   Úfullr  ÚhÚarÚarcNÚpowerTz\%s^{-1}z\operatorname{%s}^{-1}r^  z {%s}ú%sú{\left(%s \right)}rµ  r
  )r4  rð   r<  r=  r   Úgetattrrá   r©   r  rÍ   rÂ  rÃ  r   rñ   )r¯   rÀ   ræ   r4  rá   rx   Zinv_trig_power_caseZcan_fold_bracketsZinv_trig_tablerò   Zfunc_texrT   rê   rW   Ú_print_Function¢  sR   ÿ


ÿþ"






zLatexPrinter._print_Functionc                 C  ó   |   t|ƒ¡S r¸   )rÃ  rk   rÆ   rT   rT   rW   Ú_print_UndefinedFunctionî  rã   z%LatexPrinter._print_UndefinedFunctionc                 C  ó   d|   |j¡|   |j¡f S )Nz{%s}_{\circ}\left({%s}\right))r¹   r}  rÀ   rÆ   rT   rT   rW   Ú_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)rM   z\deltar8   z\gammaz\operatorname{B}z\operatorname{Chi})Z(sympy.functions.special.tensor_functionsrØ  Z'sympy.functions.special.gamma_functionsrÙ  rÚ  Z&sympy.functions.special.beta_functionsrÛ  Z'sympy.functions.special.delta_functionsrÜ  Z'sympy.functions.special.error_functionsrM   )r¯   rØ  rÙ  rÚ  rÛ  rÜ  rM   rT   rT   rW   Ú_special_function_classes÷  s   ûz&LatexPrinter._special_function_classesc                 C  s>   | j D ]}t||ƒr|j|jkr| j |   S q|  t|ƒ¡S r¸   )rÝ  Ú
issubclassrð   rÃ  rk   )r¯   rÀ   ÚclsrT   rT   rW   Ú_print_FunctionClass  s
   
€z!LatexPrinter._print_FunctionClassc                 C  sJ   |j \}}t|ƒdkr|  |d ¡}n|  t|ƒ¡}d||  |¡f }|S )Nr	  r   z\left( %s \mapsto %s \right))rá   r  r¹   rq  )r¯   rÀ   r¸  rÁ   rT   rT   rW   Ú_print_Lambda  s   
zLatexPrinter._print_Lambdac                 C  ó   dS )Nz\left( x \mapsto x \right)rT   rÆ   rT   rT   rW   Ú_print_IdentityFunction  ó   z$LatexPrinter._print_IdentityFunctionc                   sT   t |jtd}‡ fdd„|D ƒ}dt|jƒ ¡ d |¡f }|d ur(d||f S |S )Nr†  c                   ó   g | ]	}d ˆ   |¡ ‘qS )rÐ  ré   r²  rê   rT   rW   rë     rÄ  z:LatexPrinter._hprint_variadic_function.<locals>.<listcomp>z\%s\left(%s\right)rí   r^  )Úsortedrá   r   rk   r4  r  rñ   )r¯   rÀ   ræ   rá   ZtexargsrÁ   rT   rê   rW   Ú_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^  rh  ©r¯   rÀ   ræ   rÁ   rT   rT   rW   Ú_print_floor&  ó   zLatexPrinter._print_floorc                 C  rè  )Nz\left\lceil{%s}\right\rceilr   r^  rh  ré  rT   rT   rW   Ú_print_ceiling.  rë  zLatexPrinter._print_ceilingc                 C  sL   | j d sd|  |jd ¡ }n
d|  |jd ¡ }|d ur$d||f S |S )Nr{   z\log{\left(%s \right)}r   z\ln{\left(%s \right)}r^  )r©   r¹   rá   ré  rT   rT   rW   Ú
_print_log6  s   
zLatexPrinter._print_logc                 C  rè  )Nú\left|{%s}\right|r   r^  rh  ré  rT   rT   rW   Ú
_print_AbsA  rë  zLatexPrinter._print_Absc                 C  óN   | j d rd|  |jd td ¡ }nd |  |jd td ¡¡}|  ||¡S )NrŒ   z\Re{%s}r   ÚAtomz\operatorname{{re}}{{{}}}©r©   r¾   rá   r    r³   rç   ré  rT   rT   rW   Ú	_print_reI  ó   
zLatexPrinter._print_rec                 C  rð  )NrŒ   z\Im{%s}r   rñ  z\operatorname{{im}}{{{}}}rò  ré  rT   rT   rW   Ú	_print_imQ  rô  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.boolalgrö  r÷  r=  rá   Ú_print_EquivalentÚ_print_ImpliesÚ
is_Booleanr¹   )r¯   rô   rö  r÷  rT   rT   rW   Ú
_print_NotY  s   zLatexPrinter._print_Notc                 C  s‚   |d }|j r|jsd|  |¡ }nd|  |¡ }|dd … D ]}|j r3|js3|d||  |¡f 7 }q|d||  |¡f 7 }q|S )Nr   rÿ   rÐ  r	  z %s \left(%s\right)z %s %s)rû  Zis_Notr¹   )r¯   rá   Úcharr4   rÁ   rT   rT   rW   Ú_print_LogOpd  s   zLatexPrinter._print_LogOpc                 C  ó   t |jtd}|  |d¡S )Nr†  z\wedge©ræ  rá   r   rþ  ©r¯   rô   rá   rT   rT   rW   Ú
_print_Ands  ó   zLatexPrinter._print_Andc                 C  rÿ  )Nr†  z\veer   r  rT   rT   rW   Ú	_print_Orw  r  zLatexPrinter._print_Orc                 C  rÿ  )Nr†  z\veebarr   r  rT   rT   rW   Ú
_print_Xor{  r  zLatexPrinter._print_Xorc                 C  s   |   |j|pd¡S )Nz\Rightarrow)rþ  rá   )r¯   rô   ÚaltcharrT   rT   rW   rú    ó   zLatexPrinter._print_Impliesc                 C  s   t |jtd}|  ||pd¡S )Nr†  z\Leftrightarrowr   )r¯   rô   r  rá   rT   rT   rW   rù  ‚  s   zLatexPrinter._print_Equivalentc                 C  rè  )Nz\overline{%s}r   r^  rh  ré  rT   rT   rW   Ú_print_conjugate†  rë  zLatexPrinter._print_conjugatec                 C  s:   d}d|   |jd ¡ }|d urd|||f S d||f S )Nz\operatorname{polar\_lift}rÑ  r   ú	%s^{%s}%sú%s%srh  )r¯   rÀ   ræ   r4  r4   rT   rT   rW   Ú_print_polar_liftŽ  s
   zLatexPrinter._print_polar_liftc                 C  s    d|   |jd ¡ }|  ||¡S )Nze^{%s}r   )r¹   rá   rç   ré  rT   rT   rW   Ú_print_ExpBase—  s   zLatexPrinter._print_ExpBasec                 C  râ  )Nrô   rT   rå   rT   rT   rW   Ú_print_Exp1  rä  zLatexPrinter._print_Exp1c                 C  ó0   d|   |jd ¡ }|d urd||f S d| S )Nrÿ   r   zK^{%s}%szK%srh  ré  rT   rT   rW   Ú_print_elliptic_k   s   zLatexPrinter._print_elliptic_kc                 C  ó@   d|   |jd ¡|   |jd ¡f }|d urd||f S d| S )Nú\left(%s\middle| %s\right)r   r	  zF^{%s}%szF%srh  ré  rT   rT   rW   Ú_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 )NrL  r  r   r	  rÿ   zE^{%s}%szE%s©r  rá   r¹   ré  rT   rT   rW   Ú_print_elliptic_e¯  s   ÿzLatexPrinter._print_elliptic_ec                 C  s‚   t |jƒdkr!d|  |jd ¡|  |jd ¡|  |jd ¡f }nd|  |jd ¡|  |jd ¡f }|d ur=d||f S d| S )	Nr‰  z\left(%s; %s\middle| %s\right)r   r	  rL  r  z
\Pi^{%s}%sz\Pi%sr  ré  rT   rT   rW   Ú_print_elliptic_piº  s   ÿÿÿzLatexPrinter._print_elliptic_pic                 C  sZ   |j d }t|j ƒdkr|j d n|j d }d|› d|› d}|d ur)d||f S d| S )Nr   r	  rY  rí   r  z\operatorname{B}^{%s}%sz\operatorname{B}%s)rá   r  )r¯   rÀ   ræ   rÖ   ÚyrÁ   rT   rT   rW   Ú_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è   rT   ré   r  rê   rT   rW   rë   Ó  rì   z/LatexPrinter._print_betainc.<locals>.<listcomp>ú\left(%s, %s\right)r   r	  z#\operatorname{%s}_{(%s, %s)}^{%s}%srL  r‰  z\operatorname{%s}_{(%s, %s)}%s)rá   )r¯   rÀ   ræ   ÚoperatorÚlargsrÁ   rT   rê   rW   Ú_print_betaincÒ  s
   zLatexPrinter._print_betaincc                 C  s   | j ||ddS )NÚI)r  )r  rå   rT   rT   rW   Ú_print_betainc_regularizedÛ  rj  z'LatexPrinter._print_betainc_regularizedc                 C  r  )Nr  r   r	  z\Gamma^{%s}%sz\Gamma%srh  ré  rT   rT   rW   Ú_print_uppergammaÞ  ó   ÿzLatexPrinter._print_uppergammac                 C  r  )Nr  r   r	  z\gamma^{%s}%sú\gamma%srh  ré  rT   rT   rW   Ú_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á   r4  ré  rT   rT   rW   Ú_hprint_one_arg_funcð  s   z!LatexPrinter._hprint_one_arg_funcc                 C  r  )Nrÿ   r   z\operatorname{Chi}^{%s}%sz\operatorname{Chi}%srh  ré  rT   rT   rW   Ú
_print_Chiú  ó   zLatexPrinter._print_Chic                 C  sF   d|   |jd ¡ }|   |jd ¡}|d urd|||f S d||f S )Nrÿ   r	  r   z\operatorname{E}_{%s}^{%s}%sz\operatorname{E}_{%s}%srh  )r¯   rÀ   ræ   rÁ   ÚnurT   rT   rW   Ú_print_expint  s
   zLatexPrinter._print_expintc                 C  r  )Nrÿ   r   zS^{%s}%szS%srh  ré  rT   rT   rW   Ú_print_fresnels  r&  zLatexPrinter._print_fresnelsc                 C  r  )Nrÿ   r   zC^{%s}%szC%srh  ré  rT   rT   rW   Ú_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    ré  rT   rT   rW   Ú_print_subfactorial  ó   z LatexPrinter._print_subfactorialc                 C  r+  )Nz%s!r   r,  r^  r-  ré  rT   rT   rW   Ú_print_factorial#  r/  zLatexPrinter._print_factorialc                 C  r+  )Nz%s!!r   r,  r^  r-  ré  rT   rT   rW   Ú_print_factorial2+  r/  zLatexPrinter._print_factorial2c                 C  s<   d|   |jd ¡|   |jd ¡f }|d urd||f S |S )Nz{\binom{%s}{%s}}r   r	  r^  rh  ré  rT   rT   rW   Ú_print_binomial3  s   ÿzLatexPrinter._print_binomialc                 C  s<   |j \}}d|  |td ¡ }d||  |¡f }|  ||¡S )NrÐ  r,  z{%s}^{\left(%s\right)}©rá   r¾   r    r¹   rç   )r¯   rÀ   ræ   Únr  râ   rÁ   rT   rT   rW   Ú_print_RisingFactorial<  ó   
z#LatexPrinter._print_RisingFactorialc                 C  s<   |j \}}d|  |td ¡ }d|  |¡|f }|  ||¡S )NrÐ  r,  z{\left(%s\right)}_{%s}r3  )r¯   rÀ   ræ   r4  r  ÚsubrÁ   rT   rT   rW   Ú_print_FallingFactorialD  r6  z$LatexPrinter._print_FallingFactorialÚsymc                 C  sf   d| }d}|d ur|  d¡dkrd||f }nd}d||  |j¡|  |j¡f }|r1|  ||¡}|S )NrÐ  Fro   r  r^  Tú%s_{%s}\left(%s\right))rÁ  r¹   rƒ   Úargumentrç   )r¯   rÀ   ræ   r9  rÁ   Zneed_exprT   rT   rW   Ú_hprint_BesselBaseL  s   
ÿzLatexPrinter._hprint_BesselBasec                 C  sF   |sdS d}|d d… D ]}|d|   |¡ 7 }q||   |d ¡7 }|S )Nr   r  z%s, ré   )r¯   r_   rV   rˆ   rT   rT   rW   Ú_hprint_vec]  s   zLatexPrinter._hprint_vecc                 C  ó   |   ||d¡S )NÚJ©r<  rå   rT   rT   rW   Ú_print_besseljf  rã   zLatexPrinter._print_besseljc                 C  r>  )Nr  r@  rå   rT   rT   rW   Ú_print_besselii  rã   zLatexPrinter._print_besselic                 C  r>  )NÚKr@  rå   rT   rT   rW   Ú_print_besselkl  rã   zLatexPrinter._print_besselkc                 C  r>  )NÚYr@  rå   rT   rT   rW   Ú_print_besselyo  rã   zLatexPrinter._print_besselyc                 C  r>  )Nr  r@  rå   rT   rT   rW   Ú	_print_ynr  rã   zLatexPrinter._print_ync                 C  r>  )Nr¢   r@  rå   rT   rT   rW   Ú	_print_jnu  rã   zLatexPrinter._print_jnc                 C  r>  )NzH^{(1)}r@  rå   rT   rT   rW   Ú_print_hankel1x  rã   zLatexPrinter._print_hankel1c                 C  r>  )NzH^{(2)}r@  rå   rT   rT   rW   Ú_print_hankel2{  rã   zLatexPrinter._print_hankel2c                 C  r>  )Nzh^{(1)}r@  rå   rT   rT   rW   Ú
_print_hn1~  rã   zLatexPrinter._print_hn1c                 C  r>  )Nzh^{(2)}r@  rå   rT   rT   rW   Ú
_print_hn2  rã   zLatexPrinter._print_hn2r   c                 C  ó6   d|   |jd ¡ }|d urd|||f S d||f S r#  rh  ©r¯   rÀ   ræ   ÚnotationrÁ   rT   rT   rW   Ú_hprint_airy„  ó   zLatexPrinter._hprint_airyc                 C  rM  )Nrÿ   r   z{%s^\prime}^{%s}%sz%s^\prime%srh  rN  rT   rT   rW   Ú_hprint_airy_primeŒ  rQ  zLatexPrinter._hprint_airy_primec                 C  r>  ©NZAi©rP  rå   rT   rT   rW   Ú_print_airyai”  rã   zLatexPrinter._print_airyaic                 C  r>  ©NZBirT  rå   rT   rT   rW   Ú_print_airybi—  rã   zLatexPrinter._print_airybic                 C  r>  rS  ©rR  rå   rT   rT   rW   Ú_print_airyaiprimeš  rã   zLatexPrinter._print_airyaiprimec                 C  r>  rV  rX  rå   rT   rT   rW   Ú_print_airybiprime  rã   zLatexPrinter._print_airybiprimec                 C  sZ   d|   t|jƒ¡|   t|jƒ¡|  |j¡|  |j¡|   |j¡f }|d ur+d||f }|S )NzN{{}_{%s}F_{%s}\left(\begin{matrix} %s \\ %s \end{matrix}\middle| {%s} \right)}ú	{%s}^{%s})r¹   r  ÚapÚbqr=  r;  ré  rT   rT   rW   Ú_print_hyper   s   
þþzLatexPrinter._print_hyperc                 C  sŠ   d|   t|jƒ¡|   t|jƒ¡|   t|jƒ¡|   t|jƒ¡|  |j¡|  |j¡|  |j¡|  |j¡|   |j	¡f	 }|d urCd||f }|S )Nz^{G_{%s, %s}^{%s, %s}\left(\begin{matrix} %s & %s \\%s & %s \end{matrix} \middle| {%s} \right)}r[  )
r¹   r  r\  r]  re   Úanr=  ZaotherZbotherr;  ré  rT   rT   rW   Ú_print_meijerg«  s   
üþzLatexPrinter._print_meijergc                 C  r  )Nrÿ   r   z\eta^{%s}%sz\eta%srh  ré  rT   rT   rW   Ú_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 )NrL  r  rÿ   r   z\zeta^{%s}%sz\zeta%s©r  rá   rq  r”  r¹   ré  rT   rT   rW   Ú_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 )NrL  z_{%s}\left(%s\right)r“  r   z\gamma%s^{%s}r!  rb  ré  rT   rT   rW   Ú_print_stieltjesÇ  rd  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)rq  r”  r¹   rá   ré  rT   rT   rW   Ú_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æ   rV   r½  rÁ   rT   rT   rW   Ú_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)rY  ú\right)^{%s}rg  )r¯   rÀ   ræ   r4  rT  rU  rÖ   rÁ   rT   rT   rW   Ú_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)rY  rj  rg  ©r¯   rÀ   ræ   r4  rT  rÖ   rÁ   rT   rT   rW   Ú_print_gegenbauerä  ó
   zLatexPrinter._print_gegenbauerc                 C  ó:   t | j|jƒ\}}d||f }|d urd| d|  }|S )NzT_{%s}\left(%s\right)rY  rj  rg  ©r¯   rÀ   ræ   r4  rÖ   rÁ   rT   rT   rW   Ú_print_chebyshevtë  ó
   zLatexPrinter._print_chebyshevtc                 C  rq  )NzU_{%s}\left(%s\right)rY  rj  rg  rr  rT   rT   rW   Ú_print_chebyshevuò  rt  zLatexPrinter._print_chebyshevuc                 C  rq  )NzP_{%s}\left(%s\right)rY  rj  rg  rr  rT   rT   rW   Ú_print_legendreù  rt  zLatexPrinter._print_legendrec                 C  rm  )Nz'P_{%s}^{\left(%s\right)}\left(%s\right)rY  rj  rg  rn  rT   rT   rW   Ú_print_assoc_legendre   rp  z"LatexPrinter._print_assoc_legendrec                 C  rq  )NzH_{%s}\left(%s\right)rY  rj  rg  rr  rT   rT   rW   Ú_print_hermite  rt  zLatexPrinter._print_hermitec                 C  rq  )NzL_{%s}\left(%s\right)rY  rj  rg  rr  rT   rT   rW   Ú_print_laguerre  rt  zLatexPrinter._print_laguerrec                 C  rm  )Nz'L_{%s}^{\left(%s\right)}\left(%s\right)rY  rj  rg  rn  rT   rT   rW   Ú_print_assoc_laguerre  rp  z"LatexPrinter._print_assoc_laguerrec                 C  ri  )NzY_{%s}^{%s}\left(%s,%s\right)rY  rj  rg  ©r¯   rÀ   ræ   r4  ÚmÚthetaÚphirÁ   rT   rT   rW   Ú
_print_Ynm  rl  zLatexPrinter._print_Ynmc                 C  ri  )NzZ_{%s}^{%s}\left(%s,%s\right)rY  rj  rg  r{  rT   rT   rW   Ú
_print_Znm#  rl  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æ   rT  r_  r½  ÚsuprT   rT   rW   Z__print_mathieu_functions*  s   z&LatexPrinter.__print_mathieu_functionsc                 C  ó   | j d|j|dS )NÚCr]  ©Ú&_LatexPrinter__print_mathieu_functionsrá   rå   rT   rT   rW   Ú_print_mathieuc0  r  zLatexPrinter._print_mathieucc                 C  rƒ  )Nr   r]  r…  rå   rT   rT   rW   Ú_print_mathieus3  r  zLatexPrinter._print_mathieusc                 C  ó   | j d|jd|dS )Nr„  T©r`   ræ   r…  rå   rT   rT   rW   Ú_print_mathieucprime6  ó   z!LatexPrinter._print_mathieucprimec                 C  r‰  )Nr   TrŠ  r…  rå   rT   rT   rW   Ú_print_mathieusprime9  rŒ  z!LatexPrinter._print_mathieusprimec                 C  s^   |j dkr)d}|j}|jdk rd}| }| jd r!d|||j f S d|||j f S |  |j¡S )Nr	  r   r   rI  rw   z	%s%d / %dz%s\frac{%d}{%d})r_  rZ  r©   r¹   )r¯   rÀ   ÚsignrZ  rT   rT   rW   Ú_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Õ   rZ  rT   rT   rW   rØ   K  rÙ   z,LatexPrinter._print_Order.<locals>.<genexpr>r	  ú; r   z\rightarrow zO\left(%s\right))r¹   rÀ   ÚpointrÜ   r  Ú	variables©r¯   rÀ   rV   rT   rT   rW   Ú_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ò   rT   rT   rW   Ú_print_SymbolY  s   zLatexPrinter._print_Symbolrò   ú tuple[str, list[str], list[str]]c                 C  s‚   |d u sd|v r|g g fS | j d r#| dd¡ dd¡g g }}}nt|ƒ\}}}t|ƒ}dd„ |D ƒ}d	d„ |D ƒ}|||fS )
Nrb   r”   rÀ  z\_ro   z\^c                 S  ó   g | ]}t |ƒ‘qS rT   ©Ú	translate)rÕ   r‚  rT   rT   rW   rë   j  rz  z1LatexPrinter._split_super_sub.<locals>.<listcomp>c                 S  r™  rT   rš  )rÕ   r7  rT   rT   rW   rë   k  rz  )r©   rp   r   r›  )r¯   rò   Úsupersr«  rT   rT   rW   Ú_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 )Nrc   ú\mathbf{{{}}}rµ  r—   r“  )r  r³   rñ   )r¯   rž  r–  rò   rœ  r«  rT   rT   rW   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 )Nrz   z\gtz\ltú>ú<r©  z\geqz\leqz\neq)z==r   r¡  z>=z<=z!=z%s %s %s)r©   r¹   ÚlhsZrel_opÚrhs)r¯   rÀ   ÚgtÚltÚcharmaprT   rT   rW   Ú_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ô   rq   rê   rT   rW   rë   ’  s    ÿz1LatexPrinter._print_Piecewise.<locals>.<listcomp>r  z%s & \text{otherwise}r¨  z\begin{cases} %s \end{cases}z \\)rá   Zcondr   rŽ  r¹   rÀ   rñ   )r¯   rÀ   ZecpairsrÁ   rT   rê   rW   Ú_print_Piecewise‘  s   
ÿÿÿÿzLatexPrinter._print_Piecewisec              
     s¼   g }t |jƒD ]}| d ‡ fdd„||d d …f D ƒ¡¡ qˆ jd }|d u r>ˆ jd dkr2d}n|jdkd	u r<d
}nd}d}| d|¡}|dkrW| ddd|j  d ¡}|d |¡ S )Nr  c                   rè   rT   ré   rl  rê   rT   rW   rë   ¢  rì   z7LatexPrinter._print_matrix_contents.<locals>.<listcomp>r   r€   r–   Úsmallmatrixé
   TÚmatrixÚarrayú \begin{%MATSTR%}%s\end{%MATSTR%}ú%MATSTR%rÐ  rb   rq   ú}%srv  )r  ÚrowsrŽ  rñ   r©   Úcolsrp   )r¯   rÀ   ÚlinesÚliner   Úout_strrT   rê   rW   Ú_print_matrix_contentsž  s   ,
z#LatexPrinter._print_matrix_contentsc                 C  s@   |   |¡}| jd r| jd }| j| }d| | d | }|S )Nr}   ú\leftú\right)r¶  r©   r­   )r¯   rÀ   rµ  Ú
left_delimÚright_delimrT   rT   rW   Ú_print_MatrixBase´  s   




ÿÿzLatexPrinter._print_MatrixBasec                 C  sF   | j |jtd dd}|  |j¡› d|  |j¡› }d|› d|› dS )Nrñ  T©r½   r
  rb   z}_{rS   )r¾   Úparentr    r¹   rˆ   r¢   )r¯   rÀ   Zmatrix_partZ
index_partrT   rT   rW   Ú_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 )NrL  r	  r   ú:c                 3  s&    | ]}|d urˆ   |¡ndV  qd S ©Nr   ré   )rÕ   Úxirê   rT   rW   rØ   Ë  ó   €$ zFLatexPrinter._print_MatrixSlice.<locals>.latexslice.<locals>.<genexpr>)rA  rñ   )rÖ   r¥  rê   rT   rW   Ú
latexsliceÃ  s   z3LatexPrinter._print_MatrixSlice.<locals>.latexslicerñ  Tr¼  ú\left[rí   ú\right])r¾   r½  r    Zrowslicer±  Zcolslicer²  )r¯   rÀ   rÃ  rT   rê   rW   Ú_print_MatrixSliceÂ  s   	ÿÿþþzLatexPrinter._print_MatrixSlicec                 C  r—  r¸   )r¹   ÚblocksrÆ   rT   rT   rW   Ú_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}Tro   z%s^{T})	r4   Úsympy.matricesrÊ  rË  r=  Úis_MatrixExprr¹   r¾   r   )r¯   rÀ   r  rÊ  rË  rV   rT   rT   rW   Ú_print_TransposeÓ  s   
ÿÿzLatexPrinter._print_Transposec                 C  s   |j }d|  |¡ S )Nz!\operatorname{tr}\left(%s \right))r4   r¹   ©r¯   rÀ   r  rT   rT   rW   Ú_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‹   ÚstarZ	hermitianr“   r   rÉ  rä   Tro   r^  )r®   r©   r4   rÌ  rÊ  rË  r=  rÍ  r¹   r¾   r   )r¯   rÀ   Zstyle_to_latexr“   r  rÊ  rË  rV   rT   rT   rW   Ú_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>  ©rÓ  rÀ   r¯   rT   rW   rX   û  s    z,LatexPrinter._print_MatMul.<locals>.<lambda>r  r	  rI  r—   )ZsympyrÓ  rA  rá   rÚ   rñ   r”  )r¯   rÀ   Úparensrá   rT   rÕ  rW   Ú_print_MatMul÷  s   
zLatexPrinter._print_MatMulc                 C  s0   t |ƒ}|j\}}|  ||¡› d|  ||¡› S )Nr˜   )r   rá   r¾   )r¯   rÀ   r»   ÚleftÚrightrT   rT   rW   Ú_print_DotProduct  s   
zLatexPrinter._print_DotProductc                 C  sN   |j }|jr ddlm} t||ƒrd|  |j¡ S d|  |¡ S d|  |¡ S )Nr   )rË  rî  )r4   rÍ  Z&sympy.matrices.expressions.blockmatrixrË  r=  r¶  rÇ  r¹   )r¯   rÀ   r  rË  rT   rT   rW   Ú_print_Determinant  s   
zLatexPrinter._print_Determinantc                 C  sz   |d ur!d| j |jd td dd| j |jd td dd|f S d| j |jd td dd| j |jd td ddf S )Nz\left(%s \bmod %s\right)^{%s}r   r	   Tr¼  r	  z%s \bmod %sr-  rå   rT   rT   rW   Ú
_print_Mod  s(   ÿÿüÿþþýzLatexPrinter._print_Modc                   ó.   |j }td ‰| j‰ d ‡ ‡fdd„|D ƒ¡S )Nr   z \circ c                 3  ó    | ]
}ˆ |ˆd dV  qdS ©Tr¼  NrT   r  ©rÖ  ÚprecrT   rW   rØ   ,  ó   € z6LatexPrinter._print_HadamardProduct.<locals>.<genexpr>©rá   r    r¾   rñ   ©r¯   rÀ   rá   rT   rà  rW   Ú_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    ra  )r¯   rÀ   rc  rT   rT   rW   Ú_print_HadamardPower.  s   z!LatexPrinter._print_HadamardPowerc                   rÝ  )Nr   ú	 \otimes c                 3  rÞ  rß  rT   r  rà  rT   rW   rØ   ;  râ  z7LatexPrinter._print_KroneckerProduct.<locals>.<genexpr>rã  rä  rT   rà  rW   Ú_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ä   ro   r^  )râ   ræ   rÌ  rÊ  r=  rÍ  r¹   )r¯   rÀ   râ   ræ   rÊ  Zbase_strrT   rT   rW   Ú_print_MatPow=  s   
ÿ
zLatexPrinter._print_MatPowc                 C  s   | j || jd dS )Nr†   r•  )r—  r©   rÆ   rT   rT   rW   Ú_print_MatrixSymbolJ  s   
ÿz LatexPrinter._print_MatrixSymbolc                 C  ó   | j d dkr	dS dS )Nr†   r   Ú0z
\mathbf{0}©r©   )r¯   ÚZrT   rT   rW   Ú_print_ZeroMatrixN  ó   ÿÿÿzLatexPrinter._print_ZeroMatrixc                 C  rì  )Nr†   r   Ú1z
\mathbf{1}rî  )r¯   ÚOrT   rT   rW   Ú_print_OneMatrixR  rñ  zLatexPrinter._print_OneMatrixc                 C  rì  )Nr†   r   z
\mathbb{I}z
\mathbf{I}rî  )r¯   r  rT   rT   rW   Ú_print_IdentityV  rñ  zLatexPrinter._print_Identityc                 C  s   |   |jd ¡}d| S )Nr   zP_{%s}rh  )r¯   ÚPZperm_strrT   rT   rW   Ú_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   rT   r   r€   r–   rª  r  r«  r¬  r­  r®  r¯  rÐ  rb   rq   r°  r}   r·  r¸  r   c                 S  s   g | ]}g ‘qS rT   rT   rl  rT   rT   rW   rë   z  s    z1LatexPrinter._print_NDimArray.<locals>.<listcomp>r	  c                 S  s   g | ]}t t|ƒƒ‘qS rT   )rA  r  rl  rT   rT   rW   rë   {  ó    Tr  rv  rÄ  rÅ  rL  )Úrankr¹   r©   Úshaperp   r­   r  Ú	itertoolsÚproductrŽ  r  rñ   )r¯   rÀ   r   Z	block_strr¹  rº  Z	level_strZshape_rangesZouter_iZevenZback_outer_irµ  rT   rT   rW   Ú_print_NDimArray^  sf   




ÿÿÿÿ
ÿÿ€zLatexPrinter._print_NDimArrayÚ	index_mapÚdictc           	      C  sÆ   |   |¡}d }d }|D ]M}|j}||v s|r||kr|d7 }||kr6|d ur*|d7 }|jr2|d7 }n|d7 }||   |jd ¡7 }||v rT|d7 }||   || ¡7 }d}nd}|}q|d ura|d7 }|S )	Nr
  rS   z{}^{z{}_{r   r©  TF)r¹   Úis_uprá   )	r¯   rò   r•  rþ  rµ  Zlast_valenceZprev_mapÚindexZnew_valencerT   rT   rW   Ú_printer_tensor_indices•  s0   

z$LatexPrinter._printer_tensor_indicesc                 C  s&   |j d j d }| ¡ }|  ||i ¡S rg  )rá   Úget_indicesr  )r¯   rÀ   rò   r•  rT   rT   rW   Ú_print_Tensor±  s   zLatexPrinter._print_Tensorc                 C  s0   |j jd jd }|j  ¡ }|j}|  |||¡S rg  )rÀ   rá   r  rþ  r  )r¯   rÀ   rò   r•  rþ  rT   rT   rW   Ú_print_TensorElement¶  s   
z!LatexPrinter._print_TensorElementc                   s*   ˆ   ¡ \}}|d ‡ ‡fdd„|D ƒ¡ S )Nr   c                   s   g | ]
}ˆ  |tˆ ƒ¡‘qS rT   )r¾   r   r  ©rÀ   r¯   rT   rW   rë   À  ó    z/LatexPrinter._print_TensMul.<locals>.<listcomp>)Z!_get_args_for_traditional_printerrñ   )r¯   rÀ   rŽ  rá   rT   r  rW   Ú_print_TensMul¼  s   ÿzLatexPrinter._print_TensMulc                 C  sL   g }|j }|D ]}| |  |t|ƒ¡¡ q| ¡  d |¡}| dd¡}|S )Nrþ   z+ -rI  )rá   rŽ  r¾   r   r  rñ   rp   )r¯   rÀ   rT  rá   rÖ   rV   rT   rT   rW   Ú_print_TensAddÃ  s   
zLatexPrinter._print_TensAddc                 C  s"   d|j rdnd|  |jd ¡f S )Nz{}%s{%s}ro   rÀ  r   )r   r¹   rá   rÆ   rT   rT   rW   Ú_print_TensorIndexÍ  s   þzLatexPrinter._print_TensorIndexc                   sp   t |jƒdkrdˆ  |jd ¡ˆ  |jtd d¡f S dt |jƒd ‡ fdd	„|jD ƒ¡ˆ  |jtd d¡f S )
Nr	  z"\frac{\partial}{\partial {%s}}{%s}r   r	   Fz\frac{\partial^{%s}}{%s}{%s}r—   c                   rå  )z\partial {%s}ré   rl  rê   rT   rW   rë   Ü  rÄ  z9LatexPrinter._print_PartialDerivative.<locals>.<listcomp>)r  r’  r¹   r¾   rÀ   r    rñ   rÆ   rT   rê   rW   Ú_print_PartialDerivativeÓ  s   þýz%LatexPrinter._print_PartialDerivativec                 C  r—  r¸   )r¹   rò   rÆ   rT   rT   rW   Ú_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 rT   ré   rl  rê   rT   rW   rë   æ  rø  z4LatexPrinter._print_ArrayElement.<locals>.<listcomp>)r¾   rò   r    rñ   r•  rÆ   rT   rê   rW   Ú_print_ArrayElementã  s   þz LatexPrinter._print_ArrayElementc                 C  râ  )Nz
\mathbb{U}rT   rÆ   rT   rT   rW   Ú_print_UniversalSetè  rä  z LatexPrinter._print_UniversalSetc                 C  s4   |d u rd|   |jd ¡ S d|   |jd ¡|f S )Nz$\operatorname{frac}{\left(%s\right)}r   z)\operatorname{frac}{\left(%s\right)}^{%s}rh  rå   rT   rT   rW   Ú_print_fracë  s
   ÿzLatexPrinter._print_fracc                   sv   ˆ j d dkr
d}nˆ j d dkrd}ntdƒ‚t|ƒdkr*ˆ  ˆ  |d ¡| ¡S ˆ  |d	  ‡ fd
d„|D ƒ¡¡S )Nr   r  ú;r‰   r
  úUnknown Decimal Separatorr	  r   z \  c                   rè   rT   ré   rl  rê   rT   rW   rë   ÿ  rì   z-LatexPrinter._print_tuple.<locals>.<listcomp>)r©   rª   r  r·   r¹   rñ   )r¯   rÀ   ÚseprT   rê   rW   Ú_print_tupleò  s   ÿzLatexPrinter._print_tuplec                   ó   ‡ fdd„|j D ƒ}d |¡S )Nc                   rè   rT   ré   ©rÕ   rT  rê   rT   rW   rë     rì   z5LatexPrinter._print_TensorProduct.<locals>.<listcomp>rè  ©rá   rñ   ©r¯   rÀ   ÚelementsrT   rê   rW   Ú_print_TensorProduct  ó   
z!LatexPrinter._print_TensorProductc                   r  )Nc                   rè   rT   ré   r  rê   rT   rW   rë     rì   z4LatexPrinter._print_WedgeProduct.<locals>.<listcomp>z \wedge r  r  rT   rê   rW   Ú_print_WedgeProduct  r  z LatexPrinter._print_WedgeProductc                 C  ó
   |   |¡S r¸   )r  rÆ   rT   rT   rW   Ú_print_Tuple	  r¶   zLatexPrinter._print_Tuplec                   s\   ˆ j d dkrdd ‡ fdd„|D ƒ¡ S ˆ j d dkr*dd ‡ fd	d„|D ƒ¡ S td
ƒ‚)Nr   r  z\left[ %s\right]z; \  c                   rè   rT   ré   rl  rê   rT   rW   rë     rì   z,LatexPrinter._print_list.<locals>.<listcomp>r‰   ú, \  c                   rè   rT   ré   rl  rê   rT   rW   rë     rì   r  )r©   rñ   rª   rÆ   rT   rê   rW   Ú_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  )ræ  Úkeysr   rŽ  r¹   rñ   )r¯   rŠ   r   r‹  r‡  ÚvalrT   rT   rW   Ú_print_dict  s    zLatexPrinter._print_dictc                 C  r  r¸   )r"  rÆ   rT   rT   rW   Ú_print_Dict!  r¶   zLatexPrinter._print_Dictc                 C  sj   t |jƒdks|jd dkrd|  |jd ¡ }nd|  |jd ¡|  |jd ¡f }|r3d||f }|S )Nr	  r   z\delta\left(%s\right)z+\delta^{\left( %s \right)}\left( %s \right)rä   r  ré  rT   rT   rW   Ú_print_DiracDelta$  s   ÿzLatexPrinter._print_DiracDeltac                 C  sP   |   |jd |jd  ¡}|   |jd ¡}d||f }|d ur&d|||f }|S )Nr   r	  rL  z${\left\langle %s \right\rangle}^{%s}z-{\left({\langle %s \rangle}^{%s}\right)}^{%s}rh  )r¯   rÀ   ræ   ÚshiftrÏ  rÁ   rT   rT   rW   Ú_print_SingularityFunction.  s   z'LatexPrinter._print_SingularityFunctionc                   s6   d  ‡ fdd„|jD ƒ¡}d| }|rd||f }|S )Nrí   c                 3  rÑ   r¸   ré   r  rê   rT   rW   rØ   7  rÙ   z0LatexPrinter._print_Heaviside.<locals>.<genexpr>z\theta\left(%s\right)rä   )rñ   Úpargs)r¯   rÀ   ræ   r'  rÁ   rT   rê   rW   Ú_print_Heaviside6  s
   zLatexPrinter._print_Heavisidec                 C  sj   |   |jd ¡}|   |jd ¡}|jd jr#|jd jr#d||f }nd||f }|d ur3d||f }|S )Nr   r	  z\delta_{%s %s}z\delta_{%s, %s}rä   )r¹   rá   rÃ   )r¯   rÀ   ræ   rˆ   r¢   rÁ   rT   rT   rW   Ú_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Ô   rT   rT   rW   rØ   J  s   € z1LatexPrinter._print_LeviCivita.<locals>.<genexpr>z\varepsilon_{%s}r—   rí   rä   )r”  r¹   rá   r¶  rñ   )r¯   rÀ   ræ   r•  rÁ   rT   rT   rW   Ú_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Š   rT   rT   rW   Ú_print_RandomDomainR  s   


ÿ

z LatexPrinter._print_RandomDomainc                 C  s   t |jtd}|  |¡S )Nr†  )ræ  rá   r   Ú
_print_set©r¯   rV   r‹  rT   rT   rW   Ú_print_FiniteSet]  s   
zLatexPrinter._print_FiniteSetc                 C  sd   t |td}| jd dkrd t| j|ƒ¡}d| S | jd dkr.d t| j|ƒ¡}d| S tdƒ‚)	Nr†  r   r  r  r‰   rí   r  ú\left\{%s\right\})ræ  r   r©   rñ   r”  r¹   rª   r/  rT   rT   rW   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   rL  r	  rí   c                 3  rÑ   r¸   ré   r  rê   rT   rW   rØ   u  rÙ   zKLatexPrinter._print_Range.<locals>._print_symbolic_range.<locals>.<genexpr>c                 3  rÑ   r¸   ré   r  rê   rT   rW   rØ   x  rÙ   c                 3  rÑ   r¸   ré   r  rê   rT   rW   rØ   z  rÙ   z\text{Range}\left(r  )rá   r¹   rñ   )Úcont)rV   r¯   rT   rW   Ú_print_symbolic_rangeo  s   $z8LatexPrinter._print_Range.<locals>._print_symbolic_ranger  r   r	  r®  Tz\left\{rí   c                 3  ó&    | ]}|ˆ urˆ  |¡nd V  qdS ©z\ldotsNré   ©rÕ   Úel©Údotsr¯   rT   rW   rØ   •  rÂ  z,LatexPrinter._print_Range.<locals>.<genexpr>z\right\})ÚobjectÚstartÚis_infiniteÚstopÚstepZis_positiveÚiterÚnextZis_emptyr  rq  Úis_iterablerñ   )r¯   rV   r3  ÚprintsetÚitrT   )r9  rV   r¯   rW   Ú_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 )NrL  z%s_{%s}^{%s}\left(%s\right)r   r	  r:  z%s_{%s}r^  r  )r¯   rÀ   Úletterræ   rÁ   rT   rT   rW   Z__print_number_polynomial˜  s   þÿz&LatexPrinter.__print_number_polynomialc                 C  ó   |   |d|¡S ©Nr  ©Ú&_LatexPrinter__print_number_polynomialrå   rT   rT   rW   Ú_print_bernoulli¦  rã   zLatexPrinter._print_bernoullic                 C  rF  )NÚGrH  rå   rT   rT   rW   Ú_print_genocchi©  rã   zLatexPrinter._print_genocchic                   sˆ   t |jƒdkr=dˆ  |jd ¡ˆ  |jd ¡f }dd ‡ fdd„|jd	 D ƒ¡ }|d ur7d
|||f }|S || }|S ˆ  |d|¡S )Nr‰  z
B_{%s, %s}r   r	  rÿ   rí   c                 3  rÑ   r¸   ré   r6  rê   rT   rW   rØ   °  s   € ÿz+LatexPrinter._print_bell.<locals>.<genexpr>rL  r	  r  )r  rá   r¹   rñ   rI  )r¯   rÀ   ræ   Ztex1Ztex2rÁ   rT   rê   rW   Ú_print_bell¬  s   ÿ
ÿÿzLatexPrinter._print_bellc                 C  rF  ©NÚFrH  rå   rT   rT   rW   Ú_print_fibonacci¹  rã   zLatexPrinter._print_fibonaccic                 C  ó,   d|   |jd ¡ }|d urd||f }|S )NzL_{%s}r   r^  rh  ré  rT   rT   rW   Ú_print_lucas¼  ó   zLatexPrinter._print_lucasc                 C  rF  )NÚTrH  rå   rT   rT   rW   Ú_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)rh  rå   rT   rT   rW   Ú_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‰  rL  r	  r®  rÄ  rí   c                 3  r4  r5  ré   r6  r8  rT   rW   rØ   Þ  rÂ  z1LatexPrinter._print_SeqFormula.<locals>.<genexpr>rÅ  )r:  r  r;  Zfree_symbolsr=  r¹   Úformular’  r   r¼  Úcoeffr»  ÚlengthrŽ  rq  rñ   )r¯   rV   r=  rB  rT   r8  rW   Ú_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 )Nr1  r¡   r~   rŸ   r    z\left%s%s, %s\right%s)r;  Úendr¹   Z	left_openZ
right_open)r¯   rˆ   rØ  rÙ  rT   rT   rW   Ú_print_Intervalå  s   ÿzLatexPrinter._print_Intervalc                 C  rÖ  )Nz \left\langle %s, %s\right\rangle)r¹   r   r‘   ©r¯   rˆ   rT   rT   rW   Ú_print_AccumulationBounds÷  s   ÿz&LatexPrinter._print_AccumulationBoundsc                   ó(   t |ƒ‰ ‡ ‡fdd„|jD ƒ}d |¡S )Nc                   ó   g | ]}ˆ  |ˆ ¡‘qS rT   ©r¾   rl  ©rá  r¯   rT   rW   rë   ý  rø  z-LatexPrinter._print_Union.<locals>.<listcomp>z \cup ©r   rá   rñ   ©r¯   ÚuÚargs_strrT   rb  rW   Ú_print_Unionû  ó   
zLatexPrinter._print_Unionc                   r_  )Nc                   r`  rT   ra  rl  rb  rT   rW   rë   	  rø  z2LatexPrinter._print_Complement.<locals>.<listcomp>z \setminus rc  rd  rT   rb  rW   Ú_print_Complement 	  rh  zLatexPrinter._print_Complementc                   r_  )Nc                   r`  rT   ra  rl  rb  rT   rW   rë   	  rø  z4LatexPrinter._print_Intersection.<locals>.<listcomp>z \cap rc  rd  rT   rb  rW   Ú_print_Intersection	  rh  z LatexPrinter._print_Intersectionc                   r_  )Nc                   r`  rT   ra  rl  rb  rT   rW   rë   	  rø  z;LatexPrinter._print_SymmetricDifference.<locals>.<listcomp>z \triangle rc  rd  rT   rb  rW   Ú_print_SymmetricDifference
	  rh  z'LatexPrinter._print_SymmetricDifferencec                   s\   t |ƒ‰ t|jƒdkr t|jƒs ˆ |jd ˆ ¡dt|jƒ  S d ‡ ‡fdd„|jD ƒ¡S )Nr	  r   z^{%d}r™   c                 3  s    | ]	}ˆ  |ˆ ¡V  qd S r¸   ra  )rÕ   r,  rb  rT   rW   rØ   	  s   € 
ÿz1LatexPrinter._print_ProductSet.<locals>.<genexpr>)r   r  Úsetsr#   r¾   rñ   ©r¯   rZ  rT   rb  rW   Ú_print_ProductSet	  s    ÿzLatexPrinter._print_ProductSetc                 C  râ  )Nz	\emptysetrT   rù   rT   rT   rW   Ú_print_EmptySet	  rä  zLatexPrinter._print_EmptySetc                 C  râ  )Nz
\mathbb{N}rT   ©r¯   r4  rT   rT   rW   Ú_print_Naturals	  rä  zLatexPrinter._print_Naturalsc                 C  râ  )Nz\mathbb{N}_0rT   rp  rT   rT   rW   Ú_print_Naturals0	  rä  zLatexPrinter._print_Naturals0c                 C  râ  ©Nz
\mathbb{Z}rT   r]  rT   rT   rW   Ú_print_Integers	  rä  zLatexPrinter._print_Integersc                 C  râ  ©Nz
\mathbb{Q}rT   r]  rT   rT   rW   Ú_print_Rationals"	  rä  zLatexPrinter._print_Rationalsc                 C  râ  ©Nz
\mathbb{R}rT   r]  rT   rT   rW   Ú_print_Reals%	  rä  zLatexPrinter._print_Realsc                 C  râ  ©Nz
\mathbb{C}rT   r]  rT   rT   rW   Ú_print_Complexes(	  rä  zLatexPrinter._print_Complexesc                   sP   |j j}|j j}‡ fdd„t||jƒD ƒ}d dd„ |D ƒ¡}dˆ  |¡|f S )Nc                 3  s(    | ]\}}ˆ   |¡ˆ   |¡fV  qd S r¸   ré   )rÕ   rÖ   r  rê   rT   rW   rØ   .	  s   €& z/LatexPrinter._print_ImageSet.<locals>.<genexpr>rí   c                 s  s    | ]}d | V  qdS )ú	%s \in %sNrT   )rÕ   ZxyrT   rT   rW   rØ   /	  r¡  z!\left\{%s\; \middle|\; %s\right\})rP   rÀ   Ú	signaturerª  Z	base_setsrñ   r¹   )r¯   rV   rÀ   ÚsigZxysZxinysrT   rê   rW   Ú_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è   rT   ré   ©rÕ   r  rê   rT   rW   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   r9  Zbase_setr   ZUniversalSetr¹   Ú	condition©r¯   rV   Z
vars_printrT   rê   rW   Ú_print_ConditionSet2	  s   ÿ

üz LatexPrinter._print_ConditionSetc                 C  ó   |   |jd ¡}d |¡S )Nr   z\mathcal{{P}}\left({}\right)©r¹   rá   r³   )r¯   rÀ   Z	arg_printrT   rT   rW   Ú_print_PowerSet>	  s   
zLatexPrinter._print_PowerSetc                   s8   d  ‡ fdd„|jD ƒ¡}dˆ  |j¡|ˆ  |j¡f S )Nrí   c                   rè   rT   ré   r  rê   rT   rW   rë   C	  rì   z5LatexPrinter._print_ComplexRegion.<locals>.<listcomp>z)\left\{%s\; \middle|\; %s \in %s \right\})rñ   r’  r¹   rÀ   rl  r  rT   rê   rW   Ú_print_ComplexRegionB	  s   

ýz!LatexPrinter._print_ComplexRegionc                   s   dt ‡ fdd„|jD ƒƒ S )Nr{  c                 3  rÑ   r¸   ré   r  rê   rT   rW   rØ   J	  rÙ   z/LatexPrinter._print_Contains.<locals>.<genexpr>)rq  rá   rù   rT   rê   rW   Ú_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_  rW  r   rœ  Zbnr¹   Za0r  Útruncater´   rT   rT   rW   Ú_print_FourierSeriesL	  s   z!LatexPrinter._print_FourierSeriesc                 C  r—  r¸   )r  Zinfiniter´   rT   rT   rW   Ú_print_FormalPowerSeriesQ	  rš  z%LatexPrinter._print_FormalPowerSeriesc                 C  s
   d|j  S )Nz\mathbb{F}_{%s})ÚmodrÆ   rT   rT   rW   Ú_print_FiniteFieldT	  r¶   zLatexPrinter._print_FiniteFieldc                 C  râ  rs  rT   rÆ   rT   rT   rW   Ú_print_IntegerRingW	  rä  zLatexPrinter._print_IntegerRingc                 C  râ  ru  rT   rÆ   rT   rT   rW   Ú_print_RationalFieldZ	  rä  z!LatexPrinter._print_RationalFieldc                 C  râ  rw  rT   rÆ   rT   rT   rW   Ú_print_RealField]	  rä  zLatexPrinter._print_RealFieldc                 C  râ  ry  rT   rÆ   rT   rT   rW   Ú_print_ComplexField`	  rä  z LatexPrinter._print_ComplexFieldc                 C  ó,   |   |j¡}d t| j |jƒ¡}d||f S )Nrí   z%s\left[%s\right]©r¹   Údomainrñ   r”  r¸  ©r¯   rÀ   r”  r¸  rT   rT   rW   Ú_print_PolynomialRingc	  ó   z"LatexPrinter._print_PolynomialRingc                 C  r’  )Nrí   rº  r“  r•  rT   rT   rW   Ú_print_FractionFieldh	  r—  z!LatexPrinter._print_FractionFieldc                 C  s<   |   |j¡}d t| j |jƒ¡}d}|jsd}d|||f S )Nrí   r   zS_<^{-1}z%s%s\left[%s\right])r¹   r”  rñ   r”  r¸  Zis_Poly)r¯   rÀ   r”  r¸  ÚinvrT   rT   rW   Ú_print_PolynomialRingBasem	  s   z&LatexPrinter._print_PolynomialRingBasec                 C  s¼  |j j}g }| ¡ D ]†\}}d}t|ƒD ]$\}}|dkr8|dkr+||  |j| ¡7 }q||  t|j| |ƒ¡7 }q|jrL|rFd|  |¡ }	n'|  |¡}	n!|rh|tj	u r[| 
d|g¡ q
|tju rh| 
d|g¡ q
|  |¡}	|sr|	}
n|	d | }
|
 d¡r‰| 
d|
dd … g¡ q
| 
d|
g¡ q
|d dv r¨| d¡}|dkr¨d|d  |d< d |¡}tt| j|jƒƒ}d	|  | ¡ ¡ }d
 |g| |g ¡}|tv rÖd||f }|S d||f }|S )Nr   r   r	  rÿ   r  rˆ  r—   )rˆ  r  z	domain=%srí   z\%s {\left(%s \right)}z$\operatorname{%s}{\left( %s \right)})rï   rð   r  r   r¹   ÚgensÚpowrË   r   rO  ÚextendrÄ   re  Úpoprñ   rA  r”  Z
get_domainrÂ  )r¯   Úpolyrß  r  ZmonomrX  Zs_monomrˆ   ræ   Zs_coeffZs_termÚmodifierrÀ   r›  r”  rá   rÁ   rT   rT   rW   Ú_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 )NZComplexRootOfZCRootOfz\%s {\left(%s, %d\right)}z'\operatorname{%s} {\left(%s, %d\right)})rï   rð   r¹   rÀ   r  rÂ  )r¯   r3   rß  rÀ   r  rT   rT   rW   Ú_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À   Zfunr   ZIdentityFunctionrŽ  rÂ  rñ   )r¯   rÀ   rß  rá   rT   rT   rW   Ú_print_RootSumº	  s   ÿzLatexPrinter._print_RootSumc                 C  râ  )Nú\omegarT   rÆ   rT   rT   rW   Ú_print_OrdinalOmegaÇ	  rä  z LatexPrinter._print_OrdinalOmegac                 C  sF   |j \}}|dkr|dkrd ||¡S d |¡S |dkr!d |¡S dS )Nr	  z{} \omega^{{{}}}z	{} \omegaz\omega^{{{}}}r¤  )rá   r³   )r¯   rÀ   ræ   ÚmulrT   rT   rW   Ú_print_OmegaPowerÊ	  s   


zLatexPrinter._print_OmegaPowerc                   s   d  ‡ fdd„|jD ƒ¡S )Nrþ   c                   rè   rT   ré   r  rê   rT   rW   rë   Ø	  rì   z/LatexPrinter._print_Ordinal.<locals>.<listcomp>)rñ   rá   rÆ   rT   rê   rW   Ú_print_Ordinal×	  s   zLatexPrinter._print_Ordinalc                 C  s   | j d }| | td|¡S )Nr›   z	{%s}^{%d})r©   rk   r    )r¯   rŸ  r‚   rT   rT   rW   Ú_print_PolyElementÚ	  s   
zLatexPrinter._print_PolyElementc                 C  s:   |j dkr|  |j¡S |  |j¡}|  |j ¡}d||f S )Nr	  rM  )rR  r¹   rQ  )r¯   r2   rQ  rR  rT   rT   rW   Ú_print_FracElementÞ	  s
   
zLatexPrinter._print_FracElementc                 C  sf   t |jƒdkr|jd d fn|j\}}d|  |¡ }|d ur$d||f }|d ur1d||  |¡f }|S )Nr	  r   zE_{%s}r^  rº  r  )r¯   rÀ   ræ   r|  rÖ   rÁ   rT   rT   rW   Ú_print_euleræ	  s   &zLatexPrinter._print_eulerc                 C  rQ  )NzC_{%s}r   r^  rh  ré  rT   rT   rW   Ú_print_catalanï	  rS  zLatexPrinter._print_catalanc              
   C  s>   d  ||rdnd|  |jd ¡|  |jd ¡|  |jd ¡¡S )Nz5\mathcal{{{}}}{}_{{{}}}\left[{}\right]\left({}\right)z^{-1}r   r	  r   rL  ©r³   r¹   rá   )r¯   rÀ   rV   ZinverserT   rT   rW   Ú_print_UnifiedTransformõ	  s   >z$LatexPrinter._print_UnifiedTransformc                 C  ó   |   |d¡S )NÚM©r®  rÆ   rT   rT   rW   Ú_print_MellinTransformø	  rš  z#LatexPrinter._print_MellinTransformc                 C  ó   |   |dd¡S )Nr°  Tr±  rÆ   rT   rT   rW   Ú_print_InverseMellinTransformû	  rã   z*LatexPrinter._print_InverseMellinTransformc                 C  r¯  )NÚLr±  rÆ   rT   rT   rW   Ú_print_LaplaceTransformþ	  rš  z$LatexPrinter._print_LaplaceTransformc                 C  r³  )Nrµ  Tr±  rÆ   rT   rT   rW   Ú_print_InverseLaplaceTransform
  rã   z+LatexPrinter._print_InverseLaplaceTransformc                 C  r¯  rN  r±  rÆ   rT   rT   rW   Ú_print_FourierTransform
  rš  z$LatexPrinter._print_FourierTransformc                 C  r³  )NrO  Tr±  rÆ   rT   rT   rW   Ú_print_InverseFourierTransform
  rã   z+LatexPrinter._print_InverseFourierTransformc                 C  r¯  )NÚSINr±  rÆ   rT   rT   rW   Ú_print_SineTransform

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

    )rs   r¿   ©rÀ   r°   rT   rT   rW   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ü  rZ  rT   rT   rW   Úprint_latexq  s   r\  r	  úalign*Fc              
   K  s~  t di |¤Ž}|dkrd}d}d}	d}
d}n%|dkr%d}d}d}	d	}
d}n|d
kr4d}d}d}	d}
d}ntd |¡ƒ‚d}|rAd}| ¡ }t|ƒ}d}t|ƒD ]i}|| }d}d}d}||krh|rdd}nd}d}||kr}||d k r{||	 d d }nd}| ¡ d dkr‹d| }d}|dkr§|dkr•d}|d | | ¡||| |¡|¡7 }n|d ||| |¡|¡7 }|d7 }qO||
7 }|S )a¦  
    This function generates a LaTeX equation with a multiline right-hand side
    in an ``align*``, ``eqnarray`` or ``IEEEeqnarray`` environment.

    Parameters
    ==========

    lhs : Expr
        Left-hand side of equation

    rhs : Expr
        Right-hand side of equation

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

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

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

    Examples
    ========

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

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

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

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

    Notes
    =====

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

    Zeqnarrayz\begin{eqnarray}
z& = &z	\nonumberz
\end{eqnarray}TZIEEEeqnarrayz\begin{IEEEeqnarray}{rCl}
z
\end{IEEEeqnarray}r]  z\begin{align*}
z= &r   z
\end{align*}FzUnknown environment: {}z\dotsr	  r  z& & rø  rv  rù  r   r  rˆ  z{:s} {:s}{:s} {:s} {:s}z{:s}{:s} {:s} {:s}NrT   )rs   rª   r³   Zas_ordered_termsr  r  r@  r¿   )r¢  r£  Zterms_per_lineÚenvironmentZuse_dotsr°   rs  rÇ  Z
first_termZnonumberZend_termZdoubleetr9  r  Zn_termsZ
term_countrˆ   r  Z
term_startZterm_endrŽ  rT   rT   rW   Úmultiline_latexx  sn   Cÿ

ÿ
r_  )rV   rk   rl   rk   )r	  r]  F)JÚ__doc__Ú
__future__r   Útypingr   r   r   rû  Z
sympy.corer   r   r   r	   r
   r   r   r   Zsympy.core.alphabetsr   Zsympy.core.containersr   Zsympy.core.functionr   r   r   Zsympy.core.operationsr   Zsympy.core.powerr   Zsympy.core.sortingr   Zsympy.core.sympifyr   rø  r   r   r   Zsympy.printing.precedencer   Zsympy.printing.printerr   r   Zsympy.printing.conventionsr   r   r   r    Zmpmath.libmp.libmpfr!   r"   r!  Zsympy.utilities.iterablesr#   r$   r1   Zsympy.tensor.arrayr%   Zsympy.vector.basisdependentr&   rÂ  rW  rY  rj   rT  Ú	frozensetrX  ÚcompilerE  rr   rs   r›  rü  r\  r_  rT   rT   rT   rW   Ú<module>   sZ   (ÿþýüûúùø	÷
öõôóòñðïîíìëêéèçæåäãâá à!ß"Þ#Ü'þýüûúùø	÷
öõôóòñðîíåþ
                     

 Z