
    ЦiX                     ~    S r SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  S rS	 rS
 rSr       SS jrg)z7Tools for setting up printing in interactive sessions.     )version_tuple)BytesIO)latex)preview)debug)	Printablec                 6   ^ ^^ SSK nSSKmUUU 4S jnX2l        g)z.Setup printing in Python interactive session. r   Nc                 N   > U b!  STl         [        T" U 40 TD65        U Tl         gg)ztPython's pretty-printer display hook.

This function was adapted from:

 https://www.python.org/dev/peps/pep-0217/

N)_print)argbuiltinssettingsstringify_funcs    Y/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/sympy/interactive/printing.py_displayhook+_init_python_printing.<locals>._displayhook   s/     ?HJ.112HJ     )sysr   displayhook)r   r   r   r   r   s   ``  @r   _init_python_printingr      s     #Or   c                   ^^^^^^^
^^^^ ^!^"^#^$^%^&^'^(  SSK Jm'  Tc:  U R                  R	                  5       nUS:X  a  SmOUS:X  a  SmOSm[        S	T5        US
:X  a  ST-  m%OSm%SnSn[        ST
-  5      nSXUTU4-  nUR                  5       m#ST
-  nSSR                  U5      /m$[        ST#5        [        ST$5        U	=(       d    [        m&UUU4S jnU#UU%U4S jm!U$UU%U4S jm"UU'U
4S jm Sm(UUU(4S jmUU U!U&UU4S jnUU"U&UU4S jnUU U&U4S jnUU&UU4S jnU4S  jnSSK
m[        TR                  5      [        S!5      :  Ga  [        [        [        [         ["        [$        [&        /nU R(                  R*                  S"   nU[,        /-    H  nUR/                  UU5        M     U R(                  R*                  S#   nUS$;   a2  [        S%5        U H  nUR/                  UU5        M     U[,        l        OZ[        S&5        U H0  nUUR2                  ;   d  M  UR2                  R5                  U5        M2     [,        R6                  [,        l        U R(                  R*                  S'   nUS(;   a2  [        S)5        U H  nUR/                  UU5        M     U[,        l        OUS*:X  a2  [        S+5        U H  nUR/                  UU5        M     U[,        l        OZ[        S,5        U H0  nUUR2                  ;   d  M  UR2                  R5                  U5        M2     [,        R6                  [,        l        U R(                  R*                  S-   nUS.;   a2  [        S/5        U H  nUR/                  UU5        M     U[,        l        g[        S05        U H0  nUUR2                  ;   d  M  UR2                  R5                  U5        M2     [,        R6                  [,        l        gU R=                  S1U5        g! [         a     GNf = f)2z/Setup printing in IPython interactive session. r   )latex_to_pngNlightbgBlacklinuxWhiteGrayz*init_printing: Automatic foreground color:svgz
\special{color %s} tightz0cm,0cm   z-T %s -D %d -bg %s -fg %s -O %sg @z
--no-fontsz
--scale={}zinit_printing: DVIOPTIONS:zinit_printing: DVIOPTIONS_SVG:c                    > T" U 5      (       a  UR                  T" U 5      5        gUR                  TR                  R                  R                  U 5      5        g)z*caller for pretty, for use in IPython 0.11N)textlibpretty)r   pcycleIPython
_can_printr   s      r   _print_plain,_init_ipython_printing.<locals>._print_plainO   s>    c??FF>#&'FF7;;%%,,S12r   c                    > [        5       n [        U SSTUTTTS9  UR                  5       $ ! [         a  n[        SS[	        U5      5        e S nAff = f)Npngr   outputviewereuleroutputbufferextra_preamble
dvioptionsfontsizezpng printing:"_preview_wrapper exception raised:)r   r   	Exceptionr   reprgetvalue)o
exprbufferer5   r2   r4   r6   s      r   _preview_wrapper0_init_ipython_printing.<locals>._preview_wrapperV   sc    Y
	AeIU!+N)H> ""$$  	/#Gq'		s   - 
AAAc                    > [        5       n [        U SSTUTTTS9  UR                  5       R                  S5      $ ! [         a  n[        SS[	        U5      5        e S nAff = f)Nr   r   r/   zsvg printing:r7   zutf-8)r   r   r8   r   r9   r:   decode)r;   r<   r=   dvioptions_svgr2   r4   r6   s      r   _svg_wrapper,_init_ipython_printing.<locals>._svg_wrapperc   so    Y
	AeIU!+N-B ""$++G44  	/#Gq'		s   < 
A"AA"c                    >   T" U TTS9$ ! [          a    T" U 5      s $ f = f! [         a  n[        S[        U5      5         S nAg S nAff = f)N)colorscalezmatplotlib exception caught:)	TypeError
ValueErrorr   r9   )r;   r=   	forecolorr   rG   s     r   _matplotlib_wrapper3_init_ipython_printing.<locals>._matplotlib_wrapperp   sV    	'#AYeDD '#A&' 	0$q':	s$    !$ !$ 
AAA)_latex	_sympystr_pretty
_sympyreprc                 N  >^   [         [        [        [        4n[	        T U5      (       aV  [        T 5      R                  S U 5       ;  d   [        T 5      R                  S U 5       ;  a  g[        U4S jT  5       5      $ [	        T [        5      (       a  [        UU 4S jT  5       5      $ [	        T [        5      (       a  g[	        T [        5      (       a  g[        U 4S jT 5       5      (       a  g[	        T [        [        45      (       a  T(       a  gg! [         a     gf = f)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.
c              3   8   #    U  H  oR                   v   M     g 7fN)__str__.0is     r   	<genexpr>=_init_ipython_printing.<locals>._can_print.<locals>.<genexpr>   s     +M}!II}   c              3   8   #    U  H  oR                   v   M     g 7frS   )__repr__rU   s     r   rX   rY      s     ,OAZZrZ   Fc              3   4   >#    U  H  nT" U5      v   M     g 7frS    )rV   rW   r*   s     r   rX   rY      s     4!Q:a==!s   c              3   X   >#    U  H  nT" U5      =(       a    T" TU   5      v   M!     g 7frS   r^   )rV   rW   r*   r;   s     r   rX   rY      s&     Iq!:a==Z!-==qs   '*Tc              3   <   >#    U  H  n[        TU5      v   M     g 7frS   )hasattr)rV   hookr;   s     r   rX   rY      s     A.$WQ%%.s   )listtupleset	frozenset
isinstancetyperT   r\   alldictboolr   anyfloatintRuntimeError)r;   builtin_typesr*   print_builtinprinting_hookss   ` r   r*   *_init_ipython_printing.<locals>._can_print   s    	 "5#y9M!]++ GOO+M}+MMG$$,O,OO 4!444At$$IqIIIAt$$Ay))A.AAAAs|,, 		s6   A'D ,D *D ,D D D 3"D 
D$#D$c                    > T" U 5      (       a  T" U 4ST0TD6nTS:X  a  SU-  n T" U5      $ g! [          a9  n[        S[        U5      S5        TS:w  a  T" U 4SS0TD6nT" U5      s SnA$ SnAff = f)zp
A function that returns a png rendered by an external latex
distribution, falling back to matplotlib rendering
modeplain$\displaystyle %s$preview failed with:z# Falling back to matplotlib backendinlineNro   r   r9   )	r;   sr=   r*   rK   r>   r   
latex_moder   s	      r   _print_latex_png0_init_ipython_printing.<locals>._print_latex_png   s    
 a==a5j5H5AW$)A-.'**    .,d1g;=)a;h;(;A*1--.s   / 
A2.A-'A2-A2c                    > T" U 5      (       a  T" U 4ST0TD6nTS:X  a  SU-  n T" U5      $ g! [          a   n[        S[        U5      S5         SnAgSnAff = f)zb
A function that returns a svg rendered by an external latex
distribution, no fallback available.
ru   rv   rw   rx   z No fallback available.Nrz   )r;   r{   r=   r*   rC   r   r|   r   s      r   _print_latex_svg0_init_ipython_printing.<locals>._print_latex_svg   ss    
 a==a5j5H5AW$)A-1#A&    1,d1g/1 11s   / 
AAAc                 F   > T" U 5      (       a  T" U 4SS0TD6nT" U5      $ g)z4
A function that returns a png rendered by mathtext
ru   ry   Nr^   )r;   r{   r*   rK   r   r   s     r   _print_latex_matplotlib7_init_ipython_printing.<locals>._print_latex_matplotlib   s2     a==a3h3(3A&q)) r   c                 P   > T" U 5      (       a  T" U 4ST0TD6nTS:X  a  SU-  $ U$ g)zG
A function to generate the latex representation of SymPy expressions.
ru   rv   rw   Nr^   )r;   r{   r*   r   r|   r   s     r   _print_latex_text1_init_ipython_printing.<locals>._print_latex_text   s?     a==a5j5H5AW$,q00H	 r   c                    > U R                   R                  (       a$  T" U5      nSU;   a
  [        5         [        U5        g[        [        U5      5        g)zIPython's pretty-printer display hook, for use in IPython 0.10

This function was adapted from:

 ipython/IPython/hooks.py:155


N)rcpprintr   r9   )selfr   outr   s      r   _result_display/_init_ipython_printing.<locals>._result_display   s9     77>> %Cs{#J$s)r   z0.11z
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)Tmathjaxz&init_printing: using mathjax formatterz-init_printing: not using text/latex formatterresult_display)IPython.lib.latextoolsr   ImportErrorcolorslowerr   roundsplitformatdefault_latexr)   r   __version__rm   rd   rc   re   rf   rj   rn   display_formatter
formattersr   for_type
_repr_svg_type_printerspop_repr_disabled
_repr_png__repr_latex_set_hook))ipr   	use_latexr2   rJ   	backcolorr6   r|   rq   latex_printerrG   r   rF   	imagesizeoffset
resolutiondvi	svg_scaler+   r}   r   r   r   r   printable_typesplaintext_formatterclssvg_formatterpng_formatterlatex_formatterr)   r*   rK   r>   rC   r5   rB   r4   r   r   rr   s)    ` `` ``` ``                  @@@@@@@@@@@r   _init_ipython_printingr   !   s   7 		!IIgI I:IFE09<IFs5y!J
,y)V0= =CJuI"L$7$7	$BCN	
&
3	
*N;*]E3% %5 5 FN!L. .$1 1* * $ W(()]6-BB !%sItSI 22==lK
 #i[0C((l; 1 ,,77H	!67&&&s,<= '#3I >?& -555!//33C8	 '
 $-#;#;I ,,77D%67&&&s,<= '#3I ,&=>&&&s,CD '#:I >?& -555!//33C8	 '
 $-#;#;I ..99,G)):;&((.?@ '%6I"AB& /777#1155c:	 '
 &/%=%=I" 	$o6U  s   O> >
PPc                     SSK Jn  SU;  a  g SSKJn  [        X5      $ ! [         a     SSKJn   N! [         a      gf = ff = f)z%Is a shell instance an IPython shell?r   )modulesr)   F)InteractiveShell)r   r   IPython.core.interactiveshellr   r   IPython.iplibrg   )shellr   r   s      r   _is_ipythonr   3  sT     	B e..  	6 	 		s#     
A3
AA AAFNc                 H  ^^^^^ SSK nSSKJn  U (       a  Ub  UnOSSKJn  OUb  UnOSSKJn  SnUc   [        5       nUSLnU(       a  U(       d  [        U5      nU(       a  U (       a   SSK	n[        UR                  5      [        S5      :  a  SSKJn  OSSKJn  SS	KJn  [#        UUU45      (       d?  S
SR%                  UR&                  5      ;  a   Tc  [)        S5        SmUc  [)        S5        Sn[,        (       d  U(       d  UR/                  TTTTS9  OUmU (       a  UUUUU4S jnOUU4S jnU(       a8  UR1                  SS5      nU(       a  [)        S5        [3        UUX8XXUUU40 UD6  g[5        U40 UD6  g! [         a     GNLf = f! [*         a     Nf = f)a"  
Initializes pretty-printer depending on the environment.

Parameters
==========

pretty_print : bool, default=True
    If ``True``, use :func:`~.pretty_print` to stringify or the provided pretty
    printer; if ``False``, use :func:`~.sstrrepr` to stringify or the provided string
    printer.
order : string or None, default='lex'
    There are a few different settings for this parameter:
    ``'lex'`` (default), which is lexographic order;
    ``'grlex'``, which is graded lexographic order;
    ``'grevlex'``, which is reversed graded lexographic order;
    ``'old'``, which is used for compatibility reasons and for long expressions;
    ``None``, which sets it to lex.
use_unicode : bool or None, default=None
    If ``True``, use unicode characters;
    if ``False``, do not use unicode characters;
    if ``None``, make a guess based on the environment.
use_latex : string, bool, or None, default=None
    If ``True``, use default LaTeX rendering in GUI interfaces (png and
    mathjax);
    if ``False``, do not use LaTeX rendering;
    if ``None``, make a guess based on the environment;
    if ``'png'``, enable LaTeX rendering with an external LaTeX compiler,
    falling back to matplotlib if external compilation fails;
    if ``'matplotlib'``, enable LaTeX rendering with matplotlib;
    if ``'mathjax'``, enable LaTeX text generation, for example MathJax
    rendering in IPython notebook or text rendering in LaTeX documents;
    if ``'svg'``, enable LaTeX rendering with an external latex compiler,
    no fallback
wrap_line : bool
    If True, lines will wrap at the end; if False, they will not wrap
    but continue as one line. This is only relevant if ``pretty_print`` is
    True.
num_columns : int or None, default=None
    If ``int``, number of columns before wrapping is set to num_columns; if
    ``None``, number of columns before wrapping is set to terminal width.
    This is only relevant if ``pretty_print`` is ``True``.
no_global : bool, default=False
    If ``True``, the settings become system wide;
    if ``False``, use just for this console/session.
ip : An interactive console
    This can either be an instance of IPython,
    or a class that derives from code.InteractiveConsole.
euler : bool, optional, default=False
    Loads the euler package in the LaTeX preamble for handwritten style
    fonts (https://www.ctan.org/pkg/euler).
forecolor : string or None, optional, default=None
    DVI setting for foreground color. ``None`` means that either ``'Black'``,
    ``'White'``, or ``'Gray'`` will be selected based on a guess of the IPython
    terminal color setting. See notes.
backcolor : string, optional, default='Transparent'
    DVI setting for background color. See notes.
fontsize : string or int, optional, default='10pt'
    A font size to pass to the LaTeX documentclass function in the
    preamble. Note that the options are limited by the documentclass.
    Consider using scale instead.
latex_mode : string, optional, default='plain'
    The mode used in the LaTeX printer. Can be one of:
    ``{'inline'|'plain'|'equation'|'equation*'}``.
print_builtin : boolean, optional, default=True
    If ``True`` then floats and integers will be printed. If ``False`` the
    printer will only print SymPy types.
str_printer : function, optional, default=None
    A custom string printer function. This should mimic
    :func:`~.sstrrepr()`.
pretty_printer : function, optional, default=None
    A custom pretty printer. This should mimic :func:`~.pretty()`.
latex_printer : function, optional, default=None
    A custom LaTeX printer. This should mimic :func:`~.latex()`.
scale : float, optional, default=1.0
    Scale the LaTeX output when using the ``'png'`` or ``'svg'`` backends.
    Useful for high dpi screens.
settings :
    Any additional settings for the ``latex`` and ``pretty`` commands can
    be used to fine-tune the output.

Examples
========

>>> 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

r   N)Printer)r&   )sstrreprFz1.0)TerminalInteractiveShell)InteractiveConsolezipython-consoler    z*init_printing: Setting use_unicode to TrueTz(init_printing: Setting use_latex to Trueorderuse_unicode	wrap_linenum_columnsc                     > T" U 4TTTTS.UD6$ )Nr   r^   )exprr   _stringify_funcr   r   r   r   s     r   <lambda>init_printing.<locals>.<lambda>  s'    ,T 99D7@9D9 08	9r   c                    > T" U 4ST0UD6$ )Nr   r^   )r   r   r   r   s     r   r   r   %  s    *3 %*3)1*3r   ru   zMinit_printing: Mode is not able to be set due to internalsof IPython printing)r   sympy.printing.printerr   sympy.printingr&   r   get_ipython	NameErrorr   r)   r   r   !IPython.terminal.interactiveshellr   *IPython.frontend.terminal.interactiveshellcoder   rg   joinargvr   r   	NO_GLOBALset_global_settingsr   r   r   )pretty_printr   r   r   r   r   	no_globalr   r2   rJ   r   r6   r|   rq   str_printerpretty_printerr   rG   r   r   r   r   
in_ipythonr)   r   r   mode_in_settingsr   s    `` ``                     @r   init_printingr   H  s   v .%+N?"(NA J	z	*B D.J	* _
l	% W001]55IIV_/
 b#57O"PQQ)1BB&FG"&K$DE $I9Y##%[.7[ 	$ 	R )9 9N3  #<<5 ( )r>9(X,mU	+ "*	+
 	n99y  		&  		s#   
F ,9F 
FF
F! F!)TNNNNNFNFNTransparent10ptrv   TNNNg      ?)__doc__sympy.external.importtoolsr   ior   sympy.printing.latexr   r   sympy.printing.previewr   sympy.utilities.miscr   sympy.printing.defaultsr   r   r   r   r   r   r^   r   r   <module>r      sM    = 4  7 * & -#*P7d/& 	=A>BCG4:4837,/j:r   