K i:T|dZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z dZd Zd Zd Z dd Zy )z7Tools for setting up printing in interactive sessions. )BytesIO)latex)preview)debug) Printable) import_modulec 6ddl}ddlfd}||_y)z.Setup printing in Python interactive session. rNcL|!d_t|fi|_yy)zPython's pretty-printer display hook. This function was adapted from: https://www.python.org/dev/peps/pep-0217/ N)_print)argbuiltinssettingsstringify_funcs `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/interactive/printing.py _displayhookz+_init_python_printing.._displayhooks/ ?HJ .11 2HJ )sysr displayhook)rrrrrs`` @r_init_python_printingr s #COrc  T  !"#$%&'tdd ddlm&8|jj } | dk(rdn | d k(rd nd t d |d k(rdz$nd$d} d}td z}d| |||fz}|j"d z}ddj|g#t d"t d#| xst%fd}"$fd #$fd!& fdd''fd % fd}!% fd }% fd!}% fd"}tttttt t"g}|j$j&d#}|t(gzD]}|j+|||j$j&d$}|d%vr0t d&|D]}|j+|||t(_nUt d'|D],}||j.vs|j.j1|.t(j2t(_|j$j&d(}|d)vr0t d*|D]}|j+|||t(_n|d+k(r0t d,|D]}|j+|||t(_nUt d-|D],}||j.vs|j.j1|.t(j2t(_|j$j&d.}|d/vr0t d0|D]}|j+|||t(_yt d1|D],}||j.vs|j.j1|.t(j2t(_y#t$rY~wxYw)2z/Setup printing in IPython interactive session. IPythonz1.0)min_module_versionr) latex_to_pngNlightbgBlacklinuxWhiteGrayz*init_printing: Automatic foreground color:svgz \special{color %s}tightz0cm,0cmz-T %s -D %d -bg %s -fg %s -O %sg@z --no-fontsz --scale={}zinit_printing: DVIOPTIONS:zinit_printing: DVIOPTIONS_SVG:c|r|j|y|jjjj|y)z*caller for pretty, for use in IPython 0.11N)textlibpretty)r pcycler _can_printrs r _print_plainz,_init_ipython_printing.._print_plainPs< c? FF>#& ' FF7;;%%,,S1 2rc t} t|dd||j S#t$r}tddt |d}~wwxYw)Npngroutputviewereuler outputbufferextra_preamble dvioptionsfontsizez png printing:"_preview_wrapper exception raised:)rr Exceptionrreprgetvalue)o exprbufferer4r1r3r5s r_preview_wrapperz0_init_ipython_printing.._preview_wrapperWscY   AeIU!+N)H >""$$   /#Gq'    s0 AAAc t} t|dd||j j dS#t$r}tddt |d}~wwxYw)Nr rr.z svg printing:r6zutf-8)rrr7rr8r9decode)r:r;r<dvioptions_svgr1r3r5s r _svg_wrapperz,_init_ipython_printing.._svg_wrapperdsoY   AeIU!+N- B""$++G44   /#Gq'    s? A$AA$c |S#t$r |cYSwxYw#t$r}tdt|Yd}~yd}~wwxYw)N)colorscalezmatplotlib exception caught:) TypeError ValueErrorrr8)r:r< forecolorrrDs r_matplotlib_wrapperz3_init_ipython_printing.._matplotlib_wrapperqsV  '#AYeDD '#A& '  0$q' : s$ #&#& AA  A)_latex _sympystr_pretty _sympyreprc ttttf}t |rQt j d|Dvst jd|DvrytfdDSt trtfdDSt tryt trytfdDryt ttfrryy#t$rYywxYw)zReturn True if type o can be printed with one of the SymPy printers. If o is a container type, this is True if and only if every element of o can be printed in this way. c34K|]}|jywN)__str__.0is r z=_init_ipython_printing.._can_print..s+M!AII+Mc34K|]}|jywrO)__repr__rQs rrTz=_init_ipython_printing.._can_print..s,OAQZZ,OrUFc3.K|] }|ywrO)rRrSr*s rrTz=_init_ipython_printing.._can_print..s4Q:a=4sc3HK|]}|xr |ywrOrY)rRrSr*r:s rrTz=_init_ipython_printing.._can_print..s&I!:a==Z!-==Is"Tc36K|]}t|ywrO)hasattr)rRhookr:s rrTz=_init_ipython_printing.._can_print..sA$WQ%As)listtupleset frozenset isinstancetyperPrWalldictboolranyfloatint RuntimeError)r: builtin_typesr* print_builtinprinting_hookss` rr*z*_init_ipython_printing.._can_prints "5#y9M!]+GOO+M}+MMG$$,O,OO 4!444At$IqIIIAt$Ay)A.AAAs|,  s6AC-#C-7$C-C--C->C-C-- C98C9c|r|fdi}dk(rd|z} |Sy#t$r8}tdt|ddk7r |fddi}|cYd}~Sd}~wwxYw)z A function that returns a png rendered by an external latex distribution, falling back to matplotlib rendering modeplain$\displaystyle %s$preview failed with:z# Falling back to matplotlib backendinlineNrjrr8) r:sr<r*rHr=r latex_moders r_print_latex_pngz0_init_ipython_printing.._print_latex_pngs a=a5j5H5AW$)A- .'**    .,d1g;=)a;h;(;A*1--  .s) A*-A%A*%A*c|r|fdi}dk(rd|z} |Sy#t$r }tdt|dYd}~yd}~wwxYw)zz A function that returns a svg rendered by an external latex distribution, no fallback available. rorprqrrz No fallback available.Nrt)r:rur<r*rArrvrs r_print_latex_svgz0_init_ipython_printing.._print_latex_svgsq a=a5j5H5AW$)A- 1#A&    1,d1g/11 1s) AA  Ac<|r|fddi}|Sy)zD A function that returns a png rendered by mathtext rorsNrY)r:rur*rHrrs r_print_latex_matplotlibz7_init_ipython_printing.._print_latex_matplotlibs0 a=a3h3(3A&q) ) rcD|r|fdi}dk(rd|zS|Sy)zW A function to generate the latex representation of SymPy expressions. rorprqNrY)r:rur*rrvrs r_print_latex_textz1_init_ipython_printing.._print_latex_texts= a=a5j5H5AW$,q00H rz text/plainz image/svg+xml)r z"init_printing: using svg formatterz*init_printing: not using any svg formatterz image/png)Tr-z"init_printing: using png formatter matplotlibz)init_printing: using matplotlib formatterz*init_printing: not using any png formatterz text/latex)Tmathjaxz&init_printing: using mathjax formatterz-init_printing: not using text/latex formatter)rIPython.lib.latextoolsr ImportErrorcolorslowerrroundsplitformat default_latexrhr_r^r`rareridisplay_formatter formattersrfor_type _repr_svg_ type_printerspop_repr_disabled _repr_png_ _repr_latex_)(ipr use_latexr1rG backcolorr5rvrl latex_printerrDrrC imagesizeoffset resolutiondvi svg_scaler+rwryr{r}printable_typesplaintext_formattercls svg_formatter png_formatterlatex_formatterrr*rHr=rAr4r@r3rrrms( ` `` ``` `` @@@@@@@@@@@r_init_ipython_printingr!sI%@G 7 ! I I g II :IFE09<I Fs5y!J ,:y)V0= =CJu I"L$7$7 $BCN & 3 *N;  *]E3 % 5 FN!L..$ 1 1*eT3 4EO..99,G ),8$$S,78((33ODMI 23" :C  " "3(8 9 :/  :;" 5Cm111++//4  5 )77 ((33K@MM! 23" :C  " "3(8 9 :/  l " 9:" AC  " "3(? @ A6  :;" 5Cm111++//4  5 )77 **55lCO%% 67" =C  $ $S*; < =!2  =>" 7Co333--11#6  7 "+!9!9 e    sN N'&N'cddlm}d|vry ddlm}t ||S#t$r ddlm}n#t$rYYywxYwY/wxYw)z%Is a shell instance an IPython shell?r)modulesrF)InteractiveShell)rrIPython.core.interactiveshellrr IPython.iplibrb)shellrrs r _is_ipythonrs\ B e- ..   6   7s* A0A =A=AAFNc vddl}ddlm}|r ||}nddlm}n ||}nddlm}d}| t }|du}|r |s t|}|rY|rW ddl m }ddl m }t|||fs>> from sympy.interactive import init_printing >>> from sympy import Symbol, sqrt >>> from sympy.abc import x, y >>> sqrt(5) sqrt(5) >>> init_printing(pretty_print=True) # doctest: +SKIP >>> sqrt(5) # doctest: +SKIP ___ \/ 5 >>> theta = Symbol('theta') # doctest: +SKIP >>> init_printing(use_unicode=True) # doctest: +SKIP >>> theta # doctest: +SKIP \u03b8 >>> init_printing(use_unicode=False) # doctest: +SKIP >>> theta # doctest: +SKIP theta >>> init_printing(order='lex') # doctest: +SKIP >>> str(y + x + y**2 + x**2) # doctest: +SKIP x**2 + x + y**2 + y >>> init_printing(order='grlex') # doctest: +SKIP >>> str(y + x + y**2 + x**2) # doctest: +SKIP x**2 + x + y**2 + y >>> init_printing(order='grevlex') # doctest: +SKIP >>> str(y * x**2 + x * y**2) # doctest: +SKIP x**2*y + x*y**2 >>> init_printing(order='old') # doctest: +SKIP >>> str(x**2 + y**2 + x + y) # doctest: +SKIP x**2 + x + y**2 + y >>> init_printing(num_columns=10) # doctest: +SKIP >>> x**2 + x + y**2 + y # doctest: +SKIP x + y + x**2 + y**2 Notes ===== The foreground and background colors can be selected when using ``'png'`` or ``'svg'`` LaTeX rendering. Note that before the ``init_printing`` command is executed, the LaTeX rendering is handled by the IPython console and not SymPy. The colors can be selected among the 68 standard colors known to ``dvips``, for a list see [1]_. In addition, the background color can be set to ``'Transparent'`` (which is the default value). When using the ``'Auto'`` foreground color, the guess is based on the ``colors`` variable in the IPython console, see [2]_. Hence, if that variable is set correctly in your IPython console, there is a high chance that the output will be readable, although manual settings may be needed. References ========== .. [1] https://en.wikibooks.org/wiki/LaTeX/Colors#The_68_standard_colors_known_to_dvips .. [2] https://ipython.readthedocs.io/en/stable/config/details.html#terminal-colors See Also ======== sympy.printing.latex sympy.printing.pretty rN)Printer)r')sstrreprF)TerminalInteractiveShell)InteractiveConsolezipython-consoler!z*init_printing: Setting use_unicode to TrueTz(init_printing: Setting use_latex to Trueorder use_unicode wrap_line num_columnsc |fd|S)NrrY)exprr_stringify_funcrrrrs rzinit_printing..s,,T99D7@9D908 9rc|fdi|S)NrrY)rrrrs rrzinit_printing..s*3 %*3)1*3rrozMinit_printing: Mode is not able to be set due to internalsof IPython printing)rsympy.printing.printerrsympy.printingr'r get_ipython NameErrorr!IPython.terminal.interactiveshellrcoderrbjoinargvrr NO_GLOBALset_global_settingsrrr) pretty_printrrrrr no_globalrr1rGrr5rvrl str_printerpretty_printerrrDrrrr in_ipythonrrmode_in_settingsrs `` `` @r init_printingr1sv.  %+N ?  "(N AJ z *BD.J * _ l % R / b#57O"PQ)1BB&FG"&K$DE $I Y##%[.7[ $ R) 9N3 #<<5  ( )r>9e()Xz,mU +"* + n99k      s# D D, D)(D), D87D8)TNNNNNFNFN Transparent10ptrpTNNNg?)__doc__iorsympy.printing.latexrrsympy.printing.previewrsympy.utilities.miscrsympy.printing.defaultsrsympy.externalrrrrrrrYrrrsM=7*&-(#*y:v/&  =A>BCG4:4837,/ c:r