� ��g�X��~�dZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z d�Zd �Zd �Zd Z dd�Zd S)z7Tools for setting up printing in interactive sessions. �)� version_tuple)�BytesIO)�latex)�preview)�debug)� Printablec �8����ddl}ddl����fd�}||_dS)z.Setup printing in Python interactive session. rNc�X��|�&d�_t�|fi�����|�_dSdS)z�Python'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 ����j/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/interactive/printing.py� _displayhookz+_init_python_printing.<locals>._displayhooksC��� �?��H�J� �.�.��1�1��1�1� 2� 2� 2��H�J�J�J� �?�)�sysr� displayhook)rrrrrs`` @r�_init_python_printingr sG������J�J�J��O�O�O� � � � � � � �#�C�O�O�Orc  ��������� � ��� �!�"�#�$�%�&�'�(� ddlm�'n#t$rYnwxYw��=|j���} | dkrd�n | dkrd�nd�t d ���|d krd �z�%nd �%d } d}t d� z��}d| ||�|fz}|����#d� z}dd�|��g�$t d�#��t d�$��| pt�&���fd�}�#��%�fd��!�$��%�fd��"��'� fd�� d�(���(fd���� �!�&�� fd�}��"�&�� fd�}�� �&� fd�}��&�� fd�}�fd �}ddl �t�j ��td!��k�rptttt t"t$t&g}|jjd"}|t,gzD]}|�||���|jjd#}|d$vr7t d%��|D]}|�||���|t,_nMt d&��|D]%}||jvr|j�|���&t,jt,_|jjd'}|d(vr7t d)��|D]}|�||���|t,_n�|d*kr7t d+��|D]}|�||���|t,_nMt d,��|D]%}||jvr|j�|���&t,jt,_|jjd-}|d.vr8t d/��|D]}|�||���|t,_dSt d0��|D]%}||jvr|j�|���&t,jt,_dS|�d1|��dS)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}��tightz0cm,0cm�z-T %s -D %d -bg %s -fg %s -O %sg������@z --no-fontsz --scale={}zinit_printing: DVIOPTIONS:zinit_printing: DVIOPTIONS_SVG:c�����|��r |��|����dS|��jj�|����dS)z*caller for pretty, for use in IPython 0.11N)�text�lib�pretty)r �p�cycle�IPython� _can_printrs ���r� _print_plainz,_init_ipython_printing.<locals>._print_plainOs`��� �:�c�?�?� 3� �F�F�>�>�#�&�&� '� '� '� '� '� �F�F�7�;�%�,�,�S�1�1� 2� 2� 2� 2� 2rc ����t��} t|dd�|������n1#t$r$}tddt |�����d}~wwxYw|���S)N�pngr��output�viewer�euler� outputbuffer�extra_preamble� dvioptions�fontsizez png printing:�"_preview_wrapper exception raised:)rr� Exceptionr�repr�getvalue)�o� exprbuffer�er3r0r2r4s ����r�_preview_wrapperz0_init_ipython_printing.<locals>._preview_wrapperVs�����Y�Y� � � �A�e�I�U�!+�N�)�H� >� >� >� >� >��� � � � �/�#G��q�'�'� � � � �����  ���� �"�"�$�$�$��)� A�A�Ac ���t��} t|dd�|������n1#t$r$}tddt |�����d}~wwxYw|����d��S)Nrrr-z svg printing:r5zutf-8)rrr6rr7r8�decode)r9r:r;�dvioptions_svgr0r2r4s ����r� _svg_wrapperz,_init_ipython_printing.<locals>._svg_wrappercs�����Y�Y� � � �A�e�I�U�!+�N�-�� B� B� B� B� B��� � � � �/�#G��q�'�'� � � � �����  ���� �"�"�$�$�+�+�G�4�4�4r=c���� �|�����S#t$r�|��cYSwxYw#t$r(}tdt|����Yd}~dSd}~wwxYw)N)�color�scalezmatplotlib exception caught:)� TypeError� ValueErrorrr7)r9r;� forecolorrrDs ���r�_matplotlib_wrapperz3_init_ipython_printing.<locals>._matplotlib_wrapperps���� � '�#�|�A�Y�e�D�D�D�D��� '� '� '�#�|�A���&�&�&� '������ � � � �0�$�q�'�'� :� :� :��4�4�4�4�4����� ���s$� �*�-�*�-� A�A�A)�_latex� _sympystr�_pretty� _sympyreprc�t��� ttttf}t �|��r]t ���jd�|D��vs t ���jd�|D��vrdSt�fd��D����St �t��rt��fd��D����St �t��rdSt �t��rdSt�fd��D����rdSt �ttf��r�rdSdS#t$rYdSwxYw)z�Return 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. c3�$K�|] }|jV�� dS�N)�__str__��.0�is r� <genexpr>z=_init_ipython_printing.<locals>._can_print.<locals>.<genexpr>�s$����+M�+M�!�A�I�+M�+M�+M�+M�+M�+Mrc3�$K�|] }|jV�� dSrO)�__repr__rQs rrTz=_init_ipython_printing.<locals>._can_print.<locals>.<genexpr>�s$����,O�,O�A�Q�Z�,O�,O�,O�,O�,O�,OrFc3�.�K�|]}�|��V��dSrO�)rRrSr)s �rrTz=_init_ipython_printing.<locals>._can_print.<locals>.<genexpr>�s+�����4�4�Q�:�:�a�=�=�4�4�4�4�4�4rc3�P�K�|] }�|��o��|��V��!dSrOrX)rRrSr)r9s ��rrTz=_init_ipython_printing.<locals>._can_print.<locals>.<genexpr>�s>�����I�I�!�:�:�a�=�=�=�Z�Z��!��-=�-=�I�I�I�I�I�IrTc3�8�K�|]}t�|��V��dSrO)�hasattr)rR�hookr9s �rrTz=_init_ipython_printing.<locals>._can_print.<locals>.<genexpr>�s-�����A�A�$�W�Q��%�%�A�A�A�A�A�Ar)�list�tuple�set� frozenset� isinstance�typerPrV�all�dict�boolr�any�float�int� RuntimeError)r9� builtin_typesr)� print_builtin�printing_hookss` ���rr)z*_init_ipython_printing.<locals>._can_print�ss���� �"�5�#�y�9�M��!�]�+�+� ���G�G�O�+M�+M�}�+M�+M�+M�M�M���G�G�$�,O�,O��,O�,O�,O�O�O� �5��4�4�4�4�!�4�4�4�4�4�4��A�t�$�$� ��I�I�I�I�I�q�I�I�I�I�I�I��A�t�$�$� ��u��A�y�)�)� ��t��A�A�A�A�.�A�A�A�A�A� ��t��A��s�|�,�,� �� ��t��5��� � � ��5�5� ���s6�A*D)�0D)� 0D)�<D)�D)�*D)�D)�) D7�6D7c����|��rs�|fd�i���}�dkrd|z} �|��S#t$rD}tdt|��d���dkr �|fddi���}�|��cYd}~Sd}~wwxYwdS)z� 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�rirr7) r9�sr;r)rHr<r� latex_moders ������r�_print_latex_pngz0_init_ipython_printing.<locals>._print_latex_png�s���� �:�a�=�=� .���a�5�5�j�5�H�5�5�A��W�$�$�)�A�-�� .�'�'��*�*�*��� .� .� .��,�d�1�g�g�;�=�=�=���)�)���a�;�;�h�;�(�;�;�A�*�*�1�-�-�-�-�-�-�-�-�����  .���� .� .s� /� A=�9A8�2A=�8A=c�����|��rX�|fd�i���}�dkrd|z} �|��S#t$r)}tdt|��d��Yd}~dSd}~wwxYwdS)zz A function that returns a svg rendered by an external latex distribution, no fallback available. rnrorprqz No fallback available.Nrs)r9rtr;r)rArrurs �����r�_print_latex_svgz0_init_ipython_printing.<locals>._print_latex_svg�s���� �:�a�=�=� 1���a�5�5�j�5�H�5�5�A��W�$�$�)�A�-�� 1�#�|�A���&��� 1� 1� 1��,�d�1�g�g�/�1�1�1�1�1�1�1�1�1����� 1����  1� 1s� /� A"�A�A"c�J���|��r�|fddi���}�|��SdS)zD A function that returns a png rendered by mathtext rnrrNrX)r9rtr)rHrrs ����r�_print_latex_matplotlibz7_init_ipython_printing.<locals>._print_latex_matplotlib�sL��� �:�a�=�=� *���a�3�3�h�3�(�3�3�A�&�&�q�)�)� )� *� *rc�N���|��r�|fd�i���}�dkrd|zS|SdS)zW A function to generate the latex representation of SymPy expressions. rnrorpNrX)r9rtr)rrurs ����r�_print_latex_textz1_init_ipython_printing.<locals>._print_latex_text�sV��� �:�a�=�=� ���a�5�5�j�5�H�5�5�A��W�$�$�,�q�0�0��H�  � rc���|jjr.�|��}d|vrt��t|��dStt|����dS)z�IPython's pretty-printer display hook, for use in IPython 0.10 This function was adapted from: ipython/IPython/hooks.py:155 � N)�rc�pprintr r7)�selfr �outrs �r�_result_displayz/_init_ipython_printing.<locals>._result_display�s[��� �7�>� � �.��%�%�C��s�{�{����� �#�J�J�J�J�J� �$�s�)�)� � � � � rz0.11z text/plainz image/svg+xml)rz"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__rgr^r]r_r`rdrh�display_formatter� formattersr�for_type� _repr_svg_� type_printers�pop�_repr_disabled� _repr_png_� _repr_latex_�set_hook))�ipr� use_latexr0rG� backcolorr4rurk� latex_printerrDrrC� imagesize�offset� resolution�dvi� svg_scaler*rvrxrzr|r��printable_types�plaintext_formatter�cls� svg_formatter� png_formatter�latex_formatterr(r)rHr<rAr3r@r2rrrls) ` `` ``` `` @@@@@@@@@@@r�_init_ipython_printingr�!s���������������������� �7�7�7�7�7�7�7�� � � � � �� ������� ���!�!�� �I� � ��I�I� �g� � ��I�I��I� �:�I�F�F�F��E���0�9�<������I� �F��s�5�y�!�!�J� ,��:�y�)�V�0=� =�C������J��u� �I�"�L�$7�$7� �$B�$B�C�N� � &� �3�3�3� � *�N�;�;�;� � *�]�E�3�3�3�3�3�3�3� %� %� %� %� %� %� %� %� 5� 5� 5� 5� 5� 5� 5� 5� � � � � � � �F�N�!�!�!�!�!�!�!�L.�.�.�.�.�.�.�.�.�.�$ 1� 1� 1� 1� 1� 1� 1� 1� 1�*�*�*�*�*�*�*�*��������������$�N�N�N��W�(�)�)�]�6�-B�-B�B�B� !�%��s�I�t�S�I�� �2�=�l�K�� #�i�[�0� <� <�C� � (� (��l� ;� ;� ;� ;��,�7��H� � � � !� !� �6� 7� 7� 7�&� >� >���&�&�s�,<�=�=�=�=�#3�I� � � �>� ?� ?� ?�&� 9� 9���-�5�5�5�!�/�3�3�C�8�8�8��#,�#;�I� ��,�7� �D� � � � %� %� �6� 7� 7� 7�&� >� >���&�&�s�,<�=�=�=�=�#3�I� � � �,� &� &� �=� >� >� >�&� E� E���&�&�s�,C�D�D�D�D�#:�I� � � �>� ?� ?� ?�&� 9� 9���-�5�5�5�!�/�3�3�C�8�8�8��#,�#;�I� ��.�9�,�G�� �)� )� )� �:� ;� ;� ;�&� A� A���(�(��.?�@�@�@�@�%6�I� "� "� "� �A� B� B� B�&� ;� ;���/�7�7�7�#�1�5�5�c�:�:�:��%.�%=�I� "� "� "� � � �$�o�6�6�6�6�6s �� )�)c��ddlm}d|vrdS ddlm}n*#t$r ddlm}n#t$rYYdSwxYwYnwxYwt ||��S)z%Is a shell instance an IPython shell?r)�modulesr(F)�InteractiveShell)rr��IPython.core.interactiveshellr�r�� IPython.iplibra)�shellr�r�s r� _is_ipythonr�3s��������������u� �B�B�B�B�B�B�B�� ���� � 6� 6� 6� 6� 6� 6� 6��� � � ��5�5�5� ���� 7� 6����� �e�-� .� .�.s$�� <�'�<� 6�<�6�<�<FTN� Transparent�10ptro��?c �$������ddl}ddlm}|r |�|}nddlm}n |�|}nddlm}d}|�$ t ��}|du}n#t$rYnwxYw|r|st|��}|r�|r� ddl }t|j ��td��krddl m }nddlm }dd lm}t#|||f��sBd d �|j��vr&��t)d ��d �|�t)d��d }n#t*$rYnwxYwt,s|s|��������n|�|r �����fd�}n��fd�}|r@|�dd��}|rt)d��t3||||| | | | | ||f i|��dSt5|fi|��dS)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 rN)�Printer)r%)�sstrreprFz1.0)�TerminalInteractiveShell)�InteractiveConsolezipython-consolerz*init_printing: Setting use_unicode to TrueTz(init_printing: Setting use_latex to True��order� use_unicode� wrap_line� num_columnsc� ���|f����d�|��S)Nr�rX)�exprr�_stringify_funcr�r�r�r�s �����r�<lambda>zinit_printing.<locals>.<lambda>s8���,�_�T�9��9D�7@�9D�9�9�08� 9�9�rc����|fd�i|��S)Nr�rX)r�rr�r�s ��rr�zinit_printing.<locals>.<lambda>%s+������*3�*3� %�*3�)1�*3�*3�rrnzMinit_printing: Mode is not able to be set due to internalsof IPython printing)r�sympy.printing.printerr��sympy.printingr%r�� get_ipython� NameErrorr�r(rr��!IPython.terminal.interactiveshellr��*IPython.frontend.terminal.interactiveshell�coder�ra�join�argvrr�� NO_GLOBAL�set_global_settingsr�r�r)� pretty_printr�r�r�r�r�� no_globalr�r0rGr�r4rurk� str_printer�pretty_printerr�rDrrr�r� in_ipythonr(r�r��mode_in_settingsr�s `` `` @r� init_printingr�Hs �������v�J�J�J�.�.�.�.�.�.�� B� � %�+�N�N� ?� ?� ?� ?� ?� ?� ?� � "�(�N�N� A� A� A� A� A� A��J� �z� *����B��D�.�J�J��� � � � �D� ����  �%�*�%� ��_�_� ��%�l�%� %� �N�N�N��W�0�1�1�]�5�5I�5I�I�I�V�V�V�V�V�V�V�_�_�_�_�_�_� /� /� /� /� /� /� �b�#5�7O�"P�Q�Q� %�)������1B�1B�B�B��&��F�G�G�G�"&�K��$��D�E�E�E� $�I���� � � � �D� ���� �3�Y�3��#�#�%�[�.7�[� $� R� R� R� R�)�� � 3�9�9�9�9�9�9�9�9�N�N�3�3�3�3�3� �� :�#�<�<���5�5�� � )� �(� )� )� )��r�>�9�e�(�)�X�z�,�m�U� +� +�"*� +� +� +� +� +� �n�9�9��9�9�9�9�9s#�A� A� A�)<C:�: D�D)TNNNNNFNFNr�r�roTNNNr�)�__doc__�sympy.external.importtoolsr�ior�sympy.printing.latexrr��sympy.printing.previewr�sympy.utilities.miscr�sympy.printing.defaultsrrr�r�r�r�rXrr�<module>r�s���=�=�4�4�4�4�4�4�������7�7�7�7�7�7�*�*�*�*�*�*�&�&�&�&�&�&�-�-�-�-�-�-�#�#�#�*P7�P7�P7�d/�/�/�& � �=A�>B�CG�4:�48�37�,/� j:�j:�j:�j:�j:�j:r
Memory