� ��g7����ddlZddlmZddlZddlZ ddlmZmZmZn #e $rYnwxYwddl m Z ddl m Z ddlmZdd giZd �Zd �Zd �Zdd dddd�d�Ze ddd��� dd���ZdS)�N)�join)�STDOUT�CalledProcessError� check_output)�doctest_depends_on)�debug�)�latex)�preview�pygletc�H�tjdkrd}nd}t|d|i|��S)N�ntir� creationflags)�os�namer)�args�kwargs� creation_flags �f/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/sympy/printing/preview.py�_check_output_no_windowrs3�� �w�$���"� � �� � �� E�]� E�f� E� E�E�c�F�tjdtj�|��dd���5}t |d��5}t j||��ddd��n #1swxYwYddd��n #1swxYwYddl}|� ��dkr"ddl }|� d |j f��dS|� ��d krtj |j ��dSddl }|� d |j f��dS) a Open fname with the default system viewer. In practice, it is impossible for python to know when the system viewer is done. For this reason, we ensure the passed file will not be deleted under it, and this function does not attempt to block. zsympy-preview-r F)�prefix�suffix�delete�rbNr�Darwin�open�Windowszxdg-open)�tempfile�NamedTemporaryFiler�path�splitextr�shutil� copyfileobj�platform�system� subprocess�callr� startfile)�fname�fmt�temp_f�fr&r(s r�system_default_viewerr/s��� � $�,<�,.�G�,<�,<�U�,C�,C�A�,F�,1� 3� 3� 3�*�6<� �%�� � � *�!� � �q�&� )� )� )� *� *� *� *� *� *� *� *� *� *� *���� *� *� *� *�*�*�*�*�*�*�*�*�*�*�*����*�*�*�*� �O�O�O������H�$�$�����������-�.�.�.�.�.� ��� � �i� '� '� � �V�[�!�!�!�!�!���������V�[�1�2�2�2�2�2s5�B� A.�" B�.A2 �2B�5A2 �6B�B � B c�� � � � � � ddlm}m}m� ddlm� ddlm}n#t$rtd���wxYw |� |��� n+#|$r#td� |�����wxYwd}� � d� ��}|� � jd |zz� jd |zzd d|� ��� � �d�� � fd �� � � _� � fd�}|� _� � � fd�}|� _� js/� ���� ���� j�/n#t.$rYnwxYw� ���dS)Nr)�window�image�gl)�key)�ImageDecodeExceptionz:pyglet is required for preview. visit https://pyglet.org/z,pyglet preview does not work for '{}' files.�F)� double_buffer��SymPy)�width�height�caption� resizable�configc���d�_dS)NT)�has_exit)�wins�r�on_closezpyglet_viewer.<locals>.on_closePs����C�L�L�Lrc�@��|�j�jfvr ���dSdS)N)�Q�ESCAPE)�symbol� modifiersr4rBs ��r� on_key_pressz#pyglet_viewer.<locals>.on_key_pressUs.����#�%���,�,�,��� � � � � �-�,rc������dddd�����j�����j�jz dz �j�jz dz ��dS)Ng�?r8)� glClearColor�glClear�GL_COLOR_BUFFER_BIT�blitr:r;)r3�imgrAs���r� on_exposez pyglet_viewer.<locals>.on_expose[sr��� �O�O�C��c�3� /� /� /� �J�J�r�-� .� .� .� �H�H���S�Y�&�!�+���c�j�(�A�-� � � � � r)r r1r2r3� pyglet.windowr4�pyglet.image.codecsr5� ImportError�load� ValueError�format�Config�Windowr:r;� set_vsyncrBrHrOr@�dispatch_events�flip�KeyboardInterrupt�close)r+r,r1r2r5�offsetr>rHrOr3rNr4rBrAs @@@@@r� pyglet_viewerr^5s&�������Y�,�,�,�,�,�,�,�,�,�,�%�%�%�%�%�%�<�<�<�<�<�<�<�� �Y�Y�Y��W�X�X�X�Y����U��j�j������� �U�U�U��G�N�N�s�S�S�T�T�T�U�����F� �Y�Y�U�Y� +� +�F� �-�-��i�!�F�(�"��z�A�f�H�$���� � � �C��M�M�%���� � � � � � � �� � � � � � � �(��� � � � � � � �"�� ��,� � � � � !� !� !� �H�H�J�J�J��,� ��� � � � � �� �����I�I�K�K�K�K�Ks&��8�A�(A:�AD9�9 E�E�T)�preamble�packages�extra_preamble�euler�fontsizec �~�|�n|dz}|r|dz }dd�d�|D����z}|r||z }|sd}n*t|t��rd�|��}d|�d |�d �}n|s|rt d ���t|t ��r|} nd t |fd di|��zdz} |dz| zdzdzS)zA Generate string of a LaTeX document rendering ``expr``. N)�amsmath�amsfonts)rc� c��g|]}d|z��S)z\usepackage{%s}r_)�.0�ps r� <listcomp>z#_get_latex_main.<locals>.<listcomp>xs4��-G�-G�-G�12�.@�!�-C�-G�-G�-Gr�12ptz{}ptz\documentclass[varwidth,z]{standalone} z \begin{document} zcThe "packages" or "extra_preamble" keywordsmust not be set if a custom LaTeX preamble was specifiedz$\displaystyle �mode�plain�$z z\end{document})r� isinstance�intrUrT�strr ) �exprr`rarbrcrd�latex_settings�actual_packages�package_includes� latex_strings r�_get_latex_mainryosW�� ��"�%<�<�� � *� �z� )�O��$�)�)�-G�-G�6E�-G�-G�-G�#H�#H�H�� � /� �� .� �� /��H�H� ��#� &� &� /��}�}�X�.�.�H�� �x�x�!�!�!� #��� � D�~� D��C�D�D� D��$������ � �*��d�C�C��C�N�C�C�D��� � �d�?�\� )�F� 2�5F� F�Fr)r �dvipng)r )�evince�gimpzsuperior-dvi-viewer)�exe�modules�disable_viewers�pngc �2 �|�#|dkr ddl} t}n#t$rYnwxYw|�?gd�gd�gd�d�}|�|g��D]}t j|��}|�|}n�|�t }|dkr|�td ���nM|d kr|�td ���n5t|��s&t j|��std |z���t|f|||| | d �| ��}td��t|��tj ��5}tt|d��dd���5}|�|��ddd��n #1swxYwY| �#t jt|d��| ��t jd��st%d��� t'gd�|t(���n)#t*$r}t%d|jz���d}~wwxYwd|z}|dk�r}dggd�dgdgd�} ||}n!#t.$rtd|z��d�wxYw|D]}t j|��}|r|g}nQ�t1|��d kr%t%d!d"�|��z���t%d#|dz���gd$�d%gd&�}d'|d(gd(|gd'|d(gd'|d(gd'|d(gd'|d(gd)�}|�|�|��n)|�|�|g����|�||�� t'||t(���n?#t*$r2}t%d*d+�|���d,|j�����d}~wwxYw|dkr$t jt||��|��n�|d kr^tt||��d-��5}|�|�����ddd��n #1swxYwYnut|��r|t||��|�.��nJ t'||g|t(���n/#t*$r"}t%d*|�d+|�d,|j�����d}~wwxYwddd��dS#1swxYwYdS)/a� View expression or LaTeX markup in PNG, DVI, PostScript or PDF form. If the expr argument is an expression, it will be exported to LaTeX and then compiled using the available TeX distribution. The first argument, 'expr', may also be a LaTeX string. The function will then run the appropriate viewer for the given output format or use the user defined one. By default png output is generated. By default pretty Euler fonts are used for typesetting (they were used to typeset the well known "Concrete Mathematics" book). For that to work, you need the 'eulervm.sty' LaTeX style (in Debian/Ubuntu, install the texlive-fonts-extra package). If you prefer default AMS fonts or your system lacks 'eulervm' LaTeX package then unset the 'euler' keyword argument. To use viewer auto-detection, lets say for 'png' output, issue >>> from sympy import symbols, preview, Symbol >>> x, y = symbols("x,y") >>> preview(x + y, output='png') This will choose 'pyglet' by default. To select a different one, do >>> preview(x + y, output='png', viewer='gimp') The 'png' format is considered special. For all other formats the rules are slightly different. As an example we will take 'dvi' output format. If you would run >>> preview(x + y, output='dvi') then 'view' will look for available 'dvi' viewers on your system (predefined in the function, so it will try evince, first, then kdvi and xdvi). If nothing is found, it will fall back to using a system file association (via ``open`` and ``xdg-open``). To always use your system file association without searching for the above readers, use >>> from sympy.printing.preview import system_default_viewer >>> preview(x + y, output='dvi', viewer=system_default_viewer) If this still does not find the viewer you want, it can be set explicitly. >>> preview(x + y, output='dvi', viewer='superior-dvi-viewer') This will skip auto-detection and will run user specified 'superior-dvi-viewer'. If ``view`` fails to find it on your system it will gracefully raise an exception. You may also enter ``'file'`` for the viewer argument. Doing so will cause this function to return a file object in read-only mode, if ``filename`` is unset. However, if it was set, then 'preview' writes the generated file to this filename instead. There is also support for writing to a ``io.BytesIO`` like object, which needs to be passed to the ``outputbuffer`` argument. >>> from io import BytesIO >>> obj = BytesIO() >>> preview(x + y, output='png', viewer='BytesIO', ... outputbuffer=obj) The LaTeX preamble can be customized by setting the 'preamble' keyword argument. This can be used, e.g., to set a different font size, use a custom documentclass or import certain set of LaTeX packages. >>> preamble = "\\documentclass[10pt]{article}\n" \ ... "\\usepackage{amsmath,amsfonts}\\begin{document}" >>> preview(x + y, output='png', preamble=preamble) It is also possible to use the standard preamble and provide additional information to the preamble using the ``extra_preamble`` keyword argument. >>> from sympy import sin >>> extra_preamble = "\\renewcommand{\\sin}{\\cos}" >>> preview(sin(x), output='png', extra_preamble=extra_preamble) If the value of 'output' is different from 'dvi' then command line options can be set ('dvioptions' argument) for the execution of the 'dvi'+output conversion tool. These options have to be in the form of a list of strings (see ``subprocess.Popen``). Additional keyword args will be passed to the :func:`~sympy.printing.latex.latex` call, e.g., the ``symbol_names`` flag. >>> phidd = Symbol('phidd') >>> preview(phidd, symbol_names={phidd: r'\ddot{\varphi}'}) For post-processing the generated TeX File can be written to a file by passing the desired filename to the 'outputTexFile' keyword argument. To write the TeX code to a file named ``"sample.tex"`` and run the default png viewer to display the resulting bitmap, do >>> preview(x + y, outputTexFile="sample.tex") Nr�r)r{�okular�kdvi�xdvi)r{r��gsview�gv)r{r��kpdf�acroread�xpdfr�)�dvi�ps�pdf�filez-filename has to be specified if viewer="file"�BytesIOzFoutputbuffer has to be a BytesIO compatible object if viewer="BytesIO"zUnrecognized viewer: %s)r`rarcrbrdz Latex code:� texput.tex�wzutf-8)�encodingr zlatex program is not installed)r z-halt-on-errorz-interaction=nonstopmoder�)�cwd�stderrz7'latex' exited abnormally with the following output: %sz texput.%sr��dvips)�dvipdfmx�dvipdfm�dvipdfrz�dvisvgm)r�r�r��svgzInvalid output format: %sr zNone of %s are installedz, z%s is not installed)z-T�tightz-z�9z --truecolorz --no-fonts)rzr�z-oz texput.dvi)r�r�r�r�rzr��'� z/' exited abnormally with the following output: r)r,)r r^rR�getr$�whichr/rT�callable�OSErrorryrr �TemporaryDirectoryrr�write�copyfile� RuntimeErrorrrr�output�KeyError�len�extend�move�read)rtr��viewerrcra�filename� outputbufferr`� dvioptions� outputTexFilerbrdrur � candidates� candidater"� latex_main�workdir�fh�e�src� commandnames� cmd_variants� cmd_variant�cmd_path�cmd�defaultoptions� commandends rr r �s��T�~�&�E�/�/� #� �M�M�M�#�F�F��� � � � �D� ���� �~�:�9�9�8�8�8�K�K�K� � � � $�����3�3� � �I��<� �*�*�D������� � �~�&�� ���� � ��N�O�O� O� � �9� � � � ��G�H�H� H� ��f� � �:�f�l�6�&:�&:�:��/�&�8�9�9�9� ��F��8�',�^�*2�F�F�6D�F�F�J� �-���� �*���� � $� &� &�Z-�'� �$�w� �-�-�s�W� E� E� E� !�� �H�H�Z� � � � !� !� !� !� !� !� !� !� !� !� !���� !� !� !� !� � $� �O�D��,�7�7�� G� G� G��|�G�$�$� A��?�@�@� @� � #������  � � � � �� "� � � ��J������ ����� ���� �V�$�� �U�?�?��i�8�8�8� �z�!�{� ��L�  Q�+�F�3� � ��� Q� Q� Q� �!<�v�!E�F�F�D�P� Q���� ,� P� P� �!�<� �4�4����#�*�C��E���|�$�$�q�(�(�&�'A�D�I�I�l�D[�D[�'[�\�\�\�&�'<�|�A��'N�O�O�O�D�C�C�(�>���N� ��\�2�'��-� �#�|�4�!�3� �5���l�3� �#�|�4� ��J��%�� � �:�&�&�&�&�� � �>�-�-�k�2�>�>�?�?�?� �J�J�z�+�.� /� /� /� /�'����H�H�H�H�H��%� /� /� /�"�l��X�X�c�]�]�]�]�A�H�H�.�/�/�/����� /���� �V� � � �K��W�c�*�*�H� 5� 5� 5� 5� �y� � ��d�7�C�(�(�$�/�/� .�2��"�"�2�7�7�9�9�-�-�-� .� .� .� .� .� .� .� .� .� .� .���� .� .� .� .�� �f� � � -� �F�4���%�%�6� 2� 2� 2� 2� 2� -�'��S�M�w�v�?�?�?�?�?��%� -� -� -�"�l��V�V�S�S�S�!�(�(�,�-�-�-����� -����oZ-�Z-�Z-�Z-�Z-�Z-�Z-�Z-�Z-�Z-�Z-�Z-����Z-�Z-�Z-�Z-�Z-�Z-s��� #�#�!R �:E� R �E � R �#E �$A R �0G � R � G0�G+�+G0�0R � H�R �H3�3C1R �%L=�<R �= M9�-M4�4M9�9AR � (O>�2 R �>P �R �P �/R �6Q�R � Q<�Q7�7Q<�<R � R�R) r�NTr_NNNNNNN)r�os.pathrr$r r(rrrrR�sympy.utilities.decoratorr�sympy.utilities.miscrr �__doctest_requires__rr/r^ryr r_rr�<module>r�sv�� � � � ������� � � � ����� �C�C�C�C�C�C�C�C�C�C�C��� � � ��D� ����9�8�8�8�8�8�&�&�&�&�&�&�������$�x�j�1��F�F�F�3�3�3�27�7�7�t'+�R����$G�$G�$G�$G�$G�N��+�[�E�G�G�G�BD�HL�>B�n-�n-�n-�G�G�n-�n-�n-s � �'�'
Memory