← Back
Editing: latextools.cpython-311.pyc
� �@�cu � � � d Z ddlmZmZ ddlZddlZddlZddlZddlm Z ddl Z ddlmZm Z ddlmZmZ ddlmZ ddlmZ dd lmZmZmZ dd lmZ G d� de� � Z dd�Zdd�Zdd�Zd� Zd� Z dZ!dd�Z"dS )zTools for handling LaTeX.� )�BytesIO�openN)�encodebytes)�Path�PurePath)�find_cmd�FindCmdError�� get_config)�SingletonConfigurable)�List�Bool�Unicode)�cast_unicodec �8 � e Zd ZdZd� Z e e� � ddgd�� � � d�� � Z e dd �� � � d�� � Z eg d �d�� � � d�� � Z ed�� � � d�� � Zd S )� LaTeXToolz3An object to store configuration of the LaTeX tool.c � � t � � S )Nr )�selfs �8/usr/lib/python3/dist-packages/IPython/lib/latextools.py�_config_defaultzLaTeXTool._config_default s � ��|�|�� � matplotlib�dvipnga Preferred backend to draw LaTeX math equations. Backends in the list are checked one by one and the first usable one is used. Note that `matplotlib` backend is usable only for inline style equations. To draw display style equations, `dvipng` backend must be specified. )�helpT)�configzmUse breqn.sty to automatically break long equations. This configuration takes effect only for dvipng backend.)�amsmath�amsthm�amssymb�bmziA list of packages to use for dvipng backend. 'breqn' will be automatically appended when use_breqn=True.zKAdditional preamble to use when generating LaTeX source for dvipng backend.N) �__name__� __module__�__qualname__�__doc__r r r �tag�backendsr � use_breqn�packages�preamble� r r r r s � � � � � �=�=�� � � �t��� � �L�(�+�H� � � � �#�T�#� � � � ���C� � � � �#�T�#� � � � �t�.�.�.�F� � � � �#�T�#� � � � �w�� � � � �#�T�#� � � �H�Hr r F�Black� �?c �� � t | � � } t � � � j }|�|d }||vrdS |dk rt }n�|dk r�t }|� d� � r�t |� � dk r� d� d� d � t j |d d� d� � D � � � � � � }nz# t $ r(}t d� |� � � � |�d}~ww xY wt d� |� � � � �n"t d � |� � � � � || |||� � } |r| rt | � � } | S )al Render a LaTeX string to PNG. Parameters ---------- s : str The raw string containing valid inline LaTeX. encode : bool, optional Should the PNG data base64 encoded to make it JSON'able. backend : {matplotlib, dvipng} Backend for producing PNG data. wrap : bool If true, Automatically wrap `s` as a LaTeX equation. color : string Foreground color name among dvipsnames, e.g. 'Maroon' or on hex RGB format, e.g. '#AA20FA'. scale : float Scale factor for the resulting PNG. None is returned when the backend cannot be used. Nr r r �#� zRGB {}� c �H � g | ]}t t |d � � � � �� S )� )�str�int)�.0�xs r � <listcomp>z latex_to_png.<locals>.<listcomp>a s8 � � 6S� 6S� 6S�!�c�#�a��*�*�o�o� 6S� 6S� 6Sr � � zInvalid color specification {}.zNo such backend {0})r r �instancer% �latex_to_png_mpl�latex_to_png_dvipng� startswith�len�format�join�textwrap�wrap� ValueErrorr ) �s�encode�backendrA �color�scale�allowed_backends�f�e�bin_datas r �latex_to_pngrL = s� � �, �Q���A� �)�)�+�+�4����"�1�%���&�&�&��t��,������ �H� � ������C� � � R��5�z�z�Q���]�$�O�O�C�H�H� 6S� 6S�6>�m�E�!�"�"�I�q�6Q�6Q�6S� 6S� 6S� -T� -T� U� U�E�E��!� ]� ]� ]�$�%F�%M�%M�e�%T�%T�U�U�[\�\�����]���� !�!B�!I�!I�%�!P�!P�Q�Q�Q� R� �.�5�5�g�>�>�?�?�?��q��D�%��'�'�H� � )�(� )��x�(�(���Os �A C � D�#C=�=Dc � � ddl m}m}m} ddlm} ddlm} n# t $ r Y d S w xY w| � dd� � } |rd� | � � } |� d� � � } d |z } t � � }|� d� � }|� | d| � � � \ } }}}}|� | dz |dz f�� � }|� d||z | | |�� � |� |� � |� || dd�� � |� � � S # t( t* |f$ r Y d S w xY w)Nr )�figure�font_manager�mathtext)�backend_agg)�ParseFatalExceptionz$$�$z${0}$� )�size�x �path�H )�dpi�prop)�figsize)�fontpropertiesrF �pngT)rY r>