403Webshell
Server IP : 93.86.61.54  /  Your IP : 216.73.216.60
Web Server : Apache/2.4.62 (Ubuntu)
System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64
User : www-data ( 33)
PHP Version : 8.4.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/matplotlib/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/matplotlib/__pycache__/_mathtext.cpython-310.pyc
o

�:�a���
@s�dZddlmZddlZddlZddlmZddlZddlZddl	Z	ddl
Z
ddlZddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddl Z!ddl"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*dd	l+m,Z,dd
l-m.Z.m/Z/m0Z0ddl1m2Z2e�3�e�4d�Z5dzdd�Z6Gdd�d�Z7Gdd�de7�Z8Gdd�de8�Z9Gdd�de8�Z:Gdd�de:�Z;Gdd�de;�Z<Gdd�de;�Z=Gdd�de:�Z>Gd d!�d!e>�Z?Gd"d#�d#e7�Z@d$ZAdeAZBd%ZCGd&d'�d'�ZDGd(d)�d)eD�ZEGd*d+�d+eD�ZFGd,d-�d-eD�ZGGd.d/�d/eD�ZHGd0d1�d1eD�ZIid2eI�d3eI�d4eH�d5eE�d6eE�d7eE�d8eE�d9eE�d:eE�d;eE�d<eF�d=eF�d>eF�d?eF�d@eF�dAeF�dBeF�eIeIdC��ZJdDdE�ZKGdFdG�dG�ZLGdHdI�dIeL�ZMGdJdK�dKeM�ZNGdLdM�dMeM�ZOGdNdO�dOeL�ZPGdPdQ�dQeP�ZQGdRdS�dSeM�ZRGdTdU�dUeR�ZSGdVdW�dWeR�ZTGdXdY�dYeM�ZUGdZd[�d[eU�ZVGd\d]�d]eU�ZWed^d_�ZXeXd`dadd`d�eXd`dadbd`d�eXd`dadcd`d�eXd`d`ddad�eXd`d`ddadb�eXd`d`ddadc�eXd`d`dd`d�eXd`dadddd�de�eX_YGdfdg�dgeL�ZZGdhdi�dieS�Z[Gdjdk�dkeT�Z\Gdldm�dmeL�Z]Gdndo�doeS�Z^Gdpdq�dqeS�Z_Gdrds�dseS�Z`Gdtdu�du�Zaea�Zbdvdw�ZcGdxdy�dy�ZddS){z.
Implementation details for :mod:`.mathtext`.
�)�
namedtupleN��StringIO)�Combine�Empty�Forward�Group�Literal�oneOf�	OneOrMore�Optional�ParseBaseException�ParseFatalException�
ParserElement�ParseResults�QuotedString�Regex�	StringEnd�Suppress�White�
ZeroOrMore�)�_api�cbook)�latex_to_bakoma�latex_to_standard�stix_glyph_fixes�stix_virtual_fonts�tex2uni)�AFM)�FontProperties�findfont�get_font)�KERNING_DEFAULTzmatplotlib.mathtextTc
Csp|st|�S|dkrdSzt|�WStyYnwzt|�d�WSty7}ztd�|��|�d}~ww)aB
    Return the integer index (from the Unicode table) of *symbol*.

    Parameters
    ----------
    symbol : str
        A single unicode character, a TeX command (e.g. r'\pi') or a Type1
        symbol name (e.g. 'phi').
    math : bool, default: True
        If False, always treat as a single unicode character.
    �-�"�\z9'{}' is not a valid Unicode character or TeX/Type1 symbolN)�ord�	TypeErrorr�strip�KeyError�
ValueError�format)�symbol�math�err�r0�6/usr/lib/python3/dist-packages/matplotlib/_mathtext.py�get_unicode_index&s(

�����r2cs�eZdZdZdd�Ze�d�dd��Zdd�Zdd
d�Z	dd
�Z
e�ddd�dd��Zdd�Z
dd�Zdd�Zdd�Z�fdd�Zdd�Z�ZS)�Fontsz�
    An abstract base class for a system of fonts to use for mathtext.

    The class must be able to take symbol keys and font file names and
    return the character metrics.  It also delegates to a backend class
    to do the actual drawing.
    cCs||_||_i|_dS)aI
        Parameters
        ----------
        default_font_prop : `~.font_manager.FontProperties`
            The default non-math font, or the base font for Unicode (generic)
            font rendering.
        mathtext_backend : `MathtextBackend` subclass
            Backend to which rendering is actually delegated.
        N)�default_font_prop�mathtext_backend�used_characters)�selfr4r5r0r0r1�__init__Qs

zFonts.__init__�3.4cCs
d|_dS)za
        Fix any cyclical references before the object is about
        to be destroyed.
        N�r6�r7r0r0r1�destroy_s
z
Fonts.destroyc

C�dS)z�
        Get the kerning distance for font between *sym1* and *sym2*.

        See `~.Fonts.get_metrics` for a detailed description of the parameters.
        �r0)
r7�font1�
fontclass1�sym1�	fontsize1�font2�
fontclass2�sym2�	fontsize2�dpir0r0r1�get_kerngszFonts.get_kernTcCs|�||||||�}|jS)a�
        Parameters
        ----------
        font : str
            One of the TeX font names: "tt", "it", "rm", "cal", "sf", "bf",
            "default", "regular", "bb", "frak", "scr".  "default" and "regular"
            are synonyms and use the non-math font.
        font_class : str
            One of the TeX font names (as for *font*), but **not** "bb",
            "frak", or "scr".  This is used to combine two font classes.  The
            only supported combination currently is ``get_metrics("frak", "bf",
            ...)``.
        sym : str
            A symbol in raw TeX form, e.g., "1", "x", or "\sigma".
        fontsize : float
            Font size in points.
        dpi : float
            Rendering dots-per-inch.
        math : bool
            Whether we are currently in math mode or not.

        Returns
        -------
        object

            The returned object has the following attributes (all floats,
            except *slanted*):

            - *advance*: The advance distance (in points) of the glyph.
            - *height*: The height of the glyph in points.
            - *width*: The width of the glyph in points.
            - *xmin*, *xmax*, *ymin*, *ymax*: The ink rectangle of the glyph
            - *iceberg*: The distance from the baseline to the top of the
              glyph.  (This corresponds to TeX's definition of "height".)
            - *slanted*: Whether the glyph should be considered as "slanted"
              (currently used for kerning sub/superscripts).
        )�	_get_info�metrics)r7�font�
font_class�sym�fontsizerGr.�infor0r0r1�get_metricsps&zFonts.get_metricscCs6t�|||g�\|_|_|_|j�|j|j|j�dS)z�
        Set the size of the buffer used to render the math expression.
        Only really necessary for the bitmap backends.
        N)�np�ceil�width�height�depthr5�set_canvas_size)r7�w�h�dr0r0r1rV�s�zFonts.set_canvas_size�facenamerKc	CsB|�|||||�}|j�|jjt���|j�|j�	|||�dS)z�
        At position (*ox*, *oy*), draw the glyph specified by the remaining
        parameters (see `get_metrics` for their detailed description).
        N)
rIr6�
setdefaultrK�fname�set�add�numr5�render_glyph)	r7�ox�oyrKrLrMrNrGrOr0r0r1r`�szFonts.render_glyphcCs|j�||||�dS)zL
        Draw a filled rectangle from (*x1*, *y1*) to (*x2*, *y2*).
        N)r5�render_rect_filled�r7�x1�y1�x2�y2r0r0r1rc�szFonts.render_rect_filledcC�t��)zF
        Get the xheight for the given *font* and *fontsize*.
        ��NotImplementedError�r7rKrNrGr0r0r1�get_xheight�szFonts.get_xheightcCri)z�
        Get the line thickness that matches the given font.  Used as a
        base unit for drawing lines such as in a fraction or radical.
        rjrlr0r0r1�get_underline_thickness�szFonts.get_underline_thicknesscC�|jS)z�
        Get the set of characters that were used in the math
        expression.  Used by backends that need to subset fonts so
        they know which glyphs to include.
        r:r;r0r0r1�get_used_characters�szFonts.get_used_characterscsD|j�||���}|jtj�|�kr tj�j|dd�}|r |�|S)z�
        Get the data needed by the backend to render the math
        expression.  The return value is backend-specific.
        r9)�since)r5�get_resultsrpr<�
TruetypeFonts�__get__r�deprecate_method_override)r7�box�resultr<��	__class__r0r1rr�s��zFonts.get_resultscCs
||fgS)a
        Override if your font provides multiple sizes of the same
        symbol.  Should return a list of symbols matching *sym* in
        various sizes.  The expression renderer will select the most
        appropriate size for a given situation from this list.
        r0�r7�fontnamerMr0r0r1�!get_sized_alternatives_for_symbol�s
z'Fonts.get_sized_alternatives_for_symbol�T)�__name__�
__module__�__qualname__�__doc__r8r�
deprecatedr<rHrPrV�rename_parameterr`rcrmrnrprrr|�
__classcell__r0r0rxr1r3Hs 

	)	
	r3csleZdZdZ�fdd�Ze�d��fdd��Zdd�Zd	d
�Z	ddd
�Z
dd�Zdd�Z�fdd�Z
�ZS)rsza
    A generic base class for all font setups that use Truetype fonts
    (through FT2Font).
    csBt��||�i|_i|_t|�}t|�}||jd<||jd<dS)N�default�regular)�superr8�glyphd�_fontsr!r")r7r4r5�filename�default_fontrxr0r1r8�s
zTruetypeFonts.__init__r9csd|_t���dS�N)r�r�r<r;rxr0r1r<�szTruetypeFonts.destroycCsl||jvr|j|}n|}|j�|�}|dur4tj�|�r4t|�}||j|<||j|j<||j|j��<|Sr�)	�fontmapr��get�os�path�existsr"�postscript_name�lower)r7rK�basename�cached_fontr0r0r1�	_get_font�s

zTruetypeFonts._get_fontcCs,|jdkr|jdd|d|dSdS)N�Cmex10�@���Hr>)r�rT)r7rK�glyphrNrGr0r0r1�_get_offsets
zTruetypeFonts._get_offsetTcCs�|||||f}|j�|�}|dur|S|�|||||�\}	}
}}}|	�||�|	j|
|j��d�}
dd�|
jD�\}}}}|�|	|
||�}t	j
|
jd|
jd|
j
d|||||||
jd||d�	}t	j
|	||	j|||
|
|d�}|j|<|S)N)�flagscSsg|]}|d�qS)�P@r0��.0�valr0r0r1�
<listcomp>�z+TruetypeFonts._get_info.<locals>.<listcomp>g�@r�)	�advancerTrS�xmin�xmax�ymin�ymax�iceberg�slanted�rKrNr�rJ�symbol_namer_r��offset)r�r��
_get_glyph�set_size�	load_charr5�get_hinting_type�bboxr��types�SimpleNamespace�linearHoriAdvancerTrS�horiBearingYr�)r7r{rLrMrNrGr.�key�bunchrKr_r�r�r�r�r�r�r�r�rJrwr0r0r1rIsF���
�
zTruetypeFonts._get_infocCsf|�|�}|�||�|�d�}|dur#|�|tjdd||�}|jS|dd|d|d}|S)N�pclt�mathtext.default�x�xHeightr�g(@gY@)r�r��get_sfnt_tablerP�mpl�rcParamsr�)r7r{rNrGrKr�rJr�r0r0r1rm.s

�zTruetypeFonts.get_xheightcCsd||dS)Ng�?gR@r0rlr0r0r1rn:sz%TruetypeFonts.get_underline_thicknessc

sl||kr(||kr(|�|||||	�}
|�|||||	�}|
j}|�|
j|jt�dSt��|||||||||	�	S)Nr�)rIrK�get_kerningr_r#r�rH�
r7r?r@rArBrCrDrErFrG�info1�info2rKrxr0r1rH@s
�zTruetypeFonts.get_kernr})r~rr�r�r8rr�r<r�r�rIrmrnrHr�r0r0rxr1rs�s

)rscs,eZdZdZdddddddd	�Z�fd
d�Zed���Zd:dd�Z	idgd��dgd��dgd��dgd��dgd��dgd��dgd��dgd��d gd!��d"gd#��d$gd%��d&gd'��d(gd)��d*gd+��d,gd-��d.gd/��d0gd1��d2d3gd4d5gd6��Z
d7D]
\ZZe
ee
e<q�d8d9�Z
�ZS);�BakomaFontsz�
    Use the Bakoma TrueType fonts for rendering.

    Symbols are strewn about a number of font files, each of which has
    its own proprietary 8-bit encoding.
    �cmsy10�cmr10�cmtt10�cmmi10�cmb10�cmss10�cmex10)�cal�rm�tt�it�bf�sf�excs\t|i|��|_t�j|i|��i|_|j��D]\}}t|�}||j|<||j|<qdSr�)�	StixFonts�_stix_fallbackr�r8r��_fontmap�itemsr!)r7�args�kwargsr�r��fullpathrxr0r1r8\s
�zBakomaFonts.__init__�
\int \ointTcCs�d}d}||jvr"|tvr"t|\}}	|dkp||jv}
|�|�}nt|�dkr9|dk}
|�|�}|dur9t|�}	|durK|�|	�}|dkrK|�|�}|durY|j�	|||||�S||	|||
fS)Nr�rr�r)
r�r�_slanted_symbolsr��lenr'�get_char_index�get_glyph_namer�r�)r7r{rLrMrNr.r�rKr�r_r��gidr0r0r1r�hs(



�zBakomaFonts._get_glyph�())r�r�)r��¡)r��³)r��µ)r��Ã�)))r�r�)r��¢)r��´)r��¶)r��!�{))r�r�)r��©)r��n)r��½)r�r��}))r�r�)r��ª)r��o)r��¾)r�r��[))r�r�)r��£)r�rX)r��"�]))r�r�)r��¤)r��i)r��#z\lfloor))r��¥)r��j)r��¹)r��$z\rfloor))r��¦)r��k)r��º)r��%z\lceil))r��§)r��l)r��»)r��&z\rceil))r��¨)r��m)r��¼)r��'z\langle))r��­�r��D)r��¿)r��*z\rangle))r��®�r��E)r��À)r��+�	\__sqrt__))r��p)r��q)r��r)r��sz
\backslash))r��²)r��/)r��Â)r�r$r))r�r)r��±)r��.)r��Ë)r��,z\widehat))r��^)r��b)r��c)r�rYz
\widetilde))r��~)r��e)r��f)r��g)r�rXr)r�r�r)�<�>)
)z
\leftparenr�)z\rightparentr�)z
\leftbracer�)z\rightbracer�)z\leftbracketr�)z
\rightbracketr�)�\{r�)�\}r�)�\[r�)�\]r�cCs|j�|||fg�Sr�)�_size_alternativesr�rzr0r0r1r|��z-BakomaFonts.get_sized_alternatives_for_symbolr})r~rr�r�r�r8r]�splitr�r�r-�alias�targetr|r�r0r0rxr1r�Ksl�


�����
����������!�#�%�)
r�csJeZdZdZdZ�fdd�Zed���Zdd�Z	ddd	�Z
d
d�Z�ZS)
�UnicodeFontsaa
    An abstract base class for handling Unicode fonts.

    While some reasonably complete Unicode fonts (such as DejaVu) may
    work in some situations, the only Unicode font I'm aware of with a
    complete set of math symbols is STIX.

    This class will "fallback" on the Bakoma fonts when a required
    symbol can not be found in the font.
    Tcs�tjd}tttd��|�}|r||i|��nd|_t�j|i|��i|_	d�
�D]}tjd|}t|�}||j	|<q*td�}t|�}||j	d<t
|jt�rpddd	d
ddd
�}|��D]\}	}
t|
�}||j	|	<||j	|
<q]dSdS)Nzmathtext.fallback)�stix�stixsans�cmzcal rm tt it bf sfz	mathtext.r�r��STIXGeneral�STIXSizeOneSym�STIXSizeTwoSym�STIXSizeThreeSym�STIXSizeFourSym�STIXSizeFiveSym)rrr�r���)r�r�r��
StixSansFontsr�r��cm_fallbackr�r8r�r/r!r �
isinstancer�)r7r�r��fallback_rc�font_cls�texfont�proprK�stixsizedaltfonts�size�namer�rxr0r1r8�s>
��
�
�	zUnicodeFonts.__init__r�cCs||fSr�r0)r7r{rL�uniindexr0r0r1�_map_virtual_font��zUnicodeFonts._map_virtual_fontcCs�z	t||�}d}Wnty td�}d}t�d�|��Ynw|�|||�\}}|}|r~|dkrM|dkrMt|�}	t�	|	�ddksKt�
|	��d	�rMd
}|dkpU||jv}
d}|�
|�}|dur~|jdkrs|dkrstt�d
��}d}|�|�}|dkr~d}|s�|jr�|dvr�t|jt�r�d
}|j�||||�}
|
dj}|ttj���vr�d}t�d||�|
S|dvr�t|t�r�|�d
|||�St�d�|||��d
}|�
|�}d}|�|�}d}
|�|�}|||||
fS)NT�?Fz#No TeX to unicode mapping for {!a}.r�ir�Lz
GREEK CAPITALr�r�r%zfonts/ttf/cmsy10.ttf�)r�r�zComputer ModernzSubstituting symbol %s from %szTFont {!r} does not have a glyph for {!a} [U+{:x}], substituting with a dummy symbol.�)r2r+r'�_log�warningr,rI�chr�unicodedata�categoryrG�
startswithr�r��family_namer"r�_get_data_pathr�r?r@r�r��listr�r��valuesrOr�)r7r{rLrMrNr.rH�found_symbol�new_fontname�charr�rK�
glyphindexr&r\r�r0r0r1r��sv
���
�

�
�
�
�


zUnicodeFonts._get_glyphcCs|jr
|j�||�S||fgSr�)r?r|rzr0r0r1r|2s
�
z.UnicodeFonts.get_sized_alternatives_for_symbolr})
r~rr�r��use_cmexr8r]r/r�rIr�r|r�r0r0rxr1r2�s
"
Br2cs*eZdZdZdd�Zd�fdd�	Z�ZS)�DejaVuFontsFcOs�t|t�rt|i|��|_nt|i|��|_t|i|��|_tj|g|�Ri|��i|_	|j
�dddddd��|j
��D]\}}t
|�}||j	|<||j	|<q>dS)Nr7r8r9r:r;)rr�r�r<r=)r@�DejaVuSerifFontsr�r?r>r��bakomarsr8r�r��updater�r!�r7r�r�r�rGr�r0r0r1r8<s$
�
�zDejaVuFonts.__init__Tc	sp|dkr|j�|||||�St|�}|�d�}|dur.|�|�}|dkr.t��d||||�St��|||||�S)N�\primer�r)r`r�r2r�r�r�)	r7r{rLrMrNr.rHrKr\rxr0r1r�Rs
�


�
�zDejaVuFonts._get_glyphr})r~rr�r]r8r�r�r0r0rxr1r^9sr^c@s$eZdZdZdddddddd�Zd	S)
r_zv
    A font handling class for the DejaVu Serif fonts

    If a glyph is not found it will fallback to Stix Serif
    �DejaVu SerifzDejaVu Serif:italiczDejaVu Serif:weight=bold�DejaVu Sans�DejaVu Sans MonozDejaVu Serif Display�r�r�r�r�r�r�rN�r~rr�r�r�r0r0r0r1r_e�
�r_c@s$eZdZdZdddddddd�ZdS)	�DejaVuSansFontszt
    A font handling class for the DejaVu Sans fonts

    If a glyph is not found it will fallback to Stix Sans
    rezDejaVu Sans:italiczDejaVu Sans:weight=boldrfzDejaVu Sans DisplayrgNrhr0r0r0r1rjvrirjc
@sZeZdZdZddddddddd	d
ddd
�ZdZdZdZdd�Zdd�Z	e
��dd��ZdS)r�aa
    A font handling class for the STIX fonts.

    In addition to what UnicodeFonts provides, this class:

    - supports "virtual fonts" which are complete alpha numeric
      character sets with different font styles at special Unicode
      code points, such as "Blackboard".

    - handles sized alternative characters for the STIXSizeX fonts.
    r6zSTIXGeneral:italiczSTIXGeneral:weight=bold�STIXNonUnicodezSTIXNonUnicode:italiczSTIXNonUnicode:weight=boldr7r8r9r:r;)r�r�r��nonunirm�nonuniit�nonunibfrrr�r�r<r=FcOsRtj|g|�Ri|��i|_|j��D]\}}t|�}||j|<||j|<qdSr�)rsr8r�r�r�r!rbr0r0r1r8�s
�zStixFonts.__init__c
Cs^t�|�}|jr|dur|dvrtd}d}nd}|dur�t|t�r6z||}Wn
ty5|d}Ynwd}t|�}||krb||d}||}	||	dkrS|}n||	dkrZn|d}||ks@|	d|krp|	dkr�nn||	d|	d	}|	d}n	|s�d}tjd
}|dvr�t	�||�}|dvr�d
|kr�dkr�n||fSd|}||fS)N)r�r�r�TFr�rr�rr�r�)r�r�)r�r�r�i�i���nonuni)
rr��_sansr@�dictr*r�r�r�r)
r7r{rLrH�mapping�doing_sans_conversion�lo�hi�mid�ranger0r0r1rI�sH

�� 


�zStixFonts._map_virtual_fontcsxddddddd�}|�||�}zt|��Wnty#||fgYSw��fdd	�td
�D�}|dkr:|dd�}|S)
Nr�r�r�r�u⟨u⟩)r)r*r+r,r'r(cs,g|]}��|����dkr|t��f�qS)r)r�r�rQ)r�r��r7rHr0r1r��s
�z?StixFonts.get_sized_alternatives_for_symbol.<locals>.<listcomp>�r���)r�r2r+rw)r7r{rM�fixes�alternativesr0rxr1r|�s��z+StixFonts.get_sized_alternatives_for_symbolN)
r~rr�r�r�r]r?rpr8rI�	functools�	lru_cacher|r0r0r0r1r��s,�1r�c@seZdZdZdZdS)r>zd
    A font handling class for the STIX fonts (that uses sans-serif
    characters by default).
    TN)r~rr�r�rpr0r0r0r1r>�sr>cs�eZdZdZee�d��Zddddddd	d
�Zd�fdd
�	Z	e
�d�edd���Z
dd�Zddd�Z�fdd�Zdd�Zdd�Z�ZS)�StandardPsFontsz�
    Use the standard postscript fonts for rendering to backend_ps

    Unlike the other font classes, BakomaFont and UnicodeFont, this
    one requires the Ps backend.
    z	fonts/afm�pzcmi8a�pncr8a�pcrr8a�pncri8a�phvr8a�pncb8a�psyr)r�r�r�r�r�r�NNcs�|durddlm}|��}t��||�i|_i|_t|d|jd�}|dur/tdd|jd�}t	|d��}t
|�}Wd�n1sCwY||_||jd<||jd<dS)	Nr)�mathtext�afm)�fontext�	directory�	Helvetica�rbr�r�)�r��MathtextBackendPathr�r8r��fontsr!�basepath�openrr\)r7r4r5r�r��fdr�rxr0r1r8s&��
�
zStandardPsFonts.__init__r9cCst�Sr�rr;r0r0r1�<lambda>%szStandardPsFonts.<lambda>cCs�||jvr|j|}n|}|j�|�}|durItj�|j|d�}t|d��}t|�}Wd�n1s5wY||_	||j|<||j|�
�<|S)Nz.afmr�)r�r�r�r�r��joinr�r�rr\�get_fontname)r7rKr�r�r\r�r0r0r1r�'s

�
zStandardPsFonts._get_fontTcs�||||f}|j�|�}|dur|S|dkr&t|�dks$t�|��d�s&d}d}	|tvr9t|\}}
t|
�}d}	nt|�dkrH|}t|�}
d}	nt	�
d�|��|dk}|�|�}
|	ryz|
�
|�}Wntyxt	�
d	�|
��|��d}	Ynw|	s�d
}t|�}
|
�
|�}d}d|��fd
d�|
�|�D�\}}}}tj|
�|��|
�|��|
�|��|||||||||d�	}tj|
||
��|||
||d�|j|<|j|S)z0Load the cmfont, metrics and glyph with caching.Nr�rrLr�FTz.No TeX to built-in Postscript mapping for {!r}z2No glyph in standard Postscript font {!r} for {!r}rKr���MbP?csg|]}|��qSr0r0r���scaler0r1r�is�z-StandardPsFonts._get_info.<locals>.<listcomp>)	r�rSrTr�r�r�r�r�r�r�)r�r�r�rRrSrTrrQr'rOrPr,r��
get_name_charr*r��
get_bbox_charr�r��get_width_char�get_height_char)r7r{rLrMrNrGr.r��tuprYr_r�r�rKr�r�r�r�r�r�rJr0r�r1rI7s���
��

��
�
zStandardPsFonts._get_infoc

sn||kr)||kr)|�|||||	�}
|�|||||	�}|
j}|�|
j|j�d|St��|||||||||	�	S�Nr�)rIrK�
get_kern_distr�r�rHr�rxr0r1rH�s��
�zStandardPsFonts.get_kerncC�|�|�}|��d|Sr�)r�rmrlr0r0r1rm��
zStandardPsFonts.get_xheightcCr�r�)r�rnrlr0r0r1rn�r�z'StandardPsFonts.get_underline_thicknessr�r})r~rr�r��strrrVr�r�r8rr��property�pswriterr�rIrHrmrnr�r0r0rxr1r�s$�

Nr�ffffff�?ryc@s0eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
S)�FontConstantsBasez�
    A set of constants that controls how certain things, such as sub-
    and superscripts are laid out.  These are all metrics that can't
    be reliably retrieved from the font metrics in the font itself.
    皙�����?g�������?r��333333�?��?g�������?皙�����?皙�����?N)r~rr�r��script_space�subdrop�sup1�sub1�sub2�delta�
delta_slanted�delta_integralr0r0r0r1r��sr�c@s,eZdZdZdZdZdZdZdZdZ	dZ
dS)�ComputerModernFontConstantsg333333�?r�g�������?r�N)r~rr�r�r�r�r�r�r�r�r�r0r0r0r1r��sr�c@s$eZdZdZdZdZdZdZdZdS)�STIXFontConstantsr�皙�����?�333333�?r�r�N)	r~rr�r�r�r�r�r�r�r0r0r0r1r��sr�c@seZdZdZdZdZdZdS)�STIXSansFontConstantsr�r�r�r�N)r~rr�r�r�r�r�r0r0r0r1r��s
r�c@�eZdZdS)�DejaVuSerifFontConstantsN�r~rr�r0r0r0r1r���r�c@r�)�DejaVuSansFontConstantsNr�r0r0r0r1r��r�r�rerfrdr�r�r�r�r�r�r�r6rkr;r:r9r8r7)zBitstream Vera SanszBitstream VeracCs4t�|j�|j�jt�}|turt|jt	�rt
S|Sr�)�_font_constant_mappingr��font_outputr�rKrUr�r�r@r>r�)�state�	constantsr0r0r1�_get_font_constant_sets�
�r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�NodezA node in the TeX box model.cCs
d|_dS�Nr�rFr;r0r0r1r8)�
z
Node.__init__cC�|jjSr�)ryr~r;r0r0r1�__repr__,rJz
Node.__repr__cCr=�Nr>r0)r7�nextr0r0r1r�/�zNode.get_kerningcCs|jd7_dS)z�
        Shrinks one level smaller.  There are only three levels of
        sizes, after which things will no longer get smaller.
        rNr�r;r0r0r1�shrink2�zNode.shrinkcCs|jd8_dS)zb
        Grows one level larger.  There is no limit to how big
        something can get.
        rNr�r;r0r0r1�grow9r�z	Node.growcC�dSr�r0�r7r��yr0r0r1�render@r�zNode.renderN)
r~rr�r�r8r�r�r�r�r�r0r0r0r1r�&sr�cs@eZdZdZ�fdd�Z�fdd�Z�fdd�Zdd	�Z�ZS)
�Boxz A node with a physical location.cs t���||_||_||_dSr�)r�r8rSrTrU)r7rSrTrUrxr0r1r8Gs

zBox.__init__csFt���|jtkr!|jt9_|jt9_|jt9_dSdSr�)r�r�rF�NUM_SIZE_LEVELSrS�
SHRINK_FACTORrTrUr;rxr0r1r�Ms

�z
Box.shrinkcs8t���|jt9_|jt9_|jt9_dSr�)r�r�rS�GROW_FACTORrTrUr;rxr0r1r�Ts
zBox.growcCr�r�r0rdr0r0r1r�Zr�z
Box.render)	r~rr�r�r8r�r�r�r�r0r0rxr1r�Dsr�c� eZdZdZ�fdd�Z�ZS)�Vboxz$A box with only height (zero width).cst��d||�dSr��r�r8)r7rTrUrxr0r1r8ar.z
Vbox.__init__�r~rr�r�r8r�r0r0rxr1r�^�r�cr�)�Hboxz.A box with only width (zero height and depth).cst��|dd�dSr�r��r7rSrxr0r1r8hr.z
Hbox.__init__r�r0r0rxr1r�er�r�csbeZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�fdd�Z
�fdd�Z�ZS)�Chara�
    A single character.

    Unlike TeX, the font information and metrics are stored with each `Char`
    to make it easier to lookup the font metrics when needed.  Note that TeX
    boxes have a width, height, and depth, unlike Type1 and TrueType which use
    a full bounding box and an advance in the x-direction.  The metrics must
    be converted to the TeX model, and the advance (if different from width)
    must be converted into a `Kern` node when the `Char` is added to its parent
    `Hlist`.
    TcsJt���||_|j|_|j|_|j|_|j|_|j|_||_|�	�dSr�)
r�r8r"r�rKrLrNrGr.�_update_metrics)r7r"r�r.rxr0r1r8ys
z
Char.__init__cC�
d|jS)Nz`%s`)r"r;r0r0r1r��r�z
Char.__repr__cCs`|j�|j|j|j|j|j|j�}|_|jdkr|j	|_
n|j
|_
|j|_|j|j|_
dS)N� )r�rPrKrLr"rNrGr.�_metricsr�rSr�rTrU�r7rJr0r0r1r��s
�

zChar._update_metricscCr�r�)r�r�r;r0r0r1�
is_slanted�rJzChar.is_slantedcCsR|jj|j}d}t|t�r%|j�|j|j|j	|j
|j|j|j	|j
|j�	}||S)z�
        Return the amount of kerning between this and the given character.

        This method is called when characters are strung together into `Hlist`
        to create `Kern` nodes.
        r>)r�r�rSr@r�r�rHrKrLr"rNrG)r7r�r��kernr0r0r1r��s
�zChar.get_kerningc	Cs&|j�|||j|j|j|j|j�dS)z4
        Render the character to the canvas
        N)r�r`rKrLr"rNrGr�r0r0r1r��s�zChar.rendercsTt���|jtkr(|jt9_|jt9_|jt9_|jt9_dSdSr�)	r�r�rFr�rNr�rSrTrUr;rxr0r1r��s

�zChar.shrinkcsFt���|jt9_|jt9_|jt9_|jt9_dSr�)r�r�rNr�rSrTrUr;rxr0r1r��s

z	Char.growr})
r~rr�r�r8r�r�r�r�r�r�r�r�r0r0rxr1r�ls
r�cs<eZdZdZdd�Z�fdd�Z�fdd�Zdd	�Z�ZS)
�Accentz�
    The font metrics need to be dealt with differently for accents,
    since they are already offset correctly from the baseline in
    TrueType fonts.
    cCsJ|j�|j|j|j|j|j�}|_|j|j	|_
|j|j|_
d|_dSr�)r�rPrKrLr"rNrGr�r�r�rSr�r�rTrUr�r0r0r1r��s
�
zAccent._update_metricsc�t���|��dSr�)r�r�r�r;rxr0r1r���
z
Accent.shrinkcr�r�)r�r�r�r;rxr0r1r��r�zAccent.growc	Cs6|j�||jj||jj|j|j|j|j|j	�dS)z5
        Render the character to the canvas.
        N)
r�r`r�r�r�rKrLr"rNrGr�r0r0r1r��s�z
Accent.render)	r~rr�r�r�r�r�r�r�r0r0rxr1r��sr�csXeZdZdZ�fdd�Z�fdd�Zedd��Zdd	�Z�fd
d�Z	�fdd
�Z
�ZS)�Listz0A list of nodes (either horizontal or vertical).cs2t��ddd�d|_||_d|_d|_d|_dS)Nr>r)r�r8�shift_amount�children�glue_set�	glue_sign�
glue_order�r7�elementsrxr0r1r8�s
z
List.__init__c
s4dt���|j|j|j|jd�dd�|jD��fS)Nz![%s <%.02f %.02f %.02f %.02f> %s]r�cSsg|]}t|��qSr0)�repr�r�r�r0r0r1r��r�z!List.__repr__.<locals>.<listcomp>)r�r�rSrTrUr�r�r�r;rxr0r1r��s�z
List.__repr__cCs4tt|��ddd�D]}||dkr|SqdS)z�
        Determine the highest order of glue used by the members of this list.

        Helper function used by vpack and hpack.
        Nrzr)rwr�)�totalsr�r0r0r1�_determine_order�s
�zList._determine_ordercCsp|�|�}||_||_||dkr||||_nd|_d|_|dkr4t|j�r6t�d||j	j
|�dSdSdS)Nr>rz	%s %s: %r)r�r�r�r��
glue_ratior�r�rOrPryr~)r7r��signr��
error_typer�r0r0r1�	_set_glue�s


��zList._set_gluecsL|jD]}|��qt���|jtkr$|jt9_|jt9_dSdSr�)r�r�r�rFr�r�r�r��r7�childrxr0r1r�
s



�zList.shrinkcs>|jD]}|��qt���|jt9_|jt9_dSr�)r�r�r�r�r�r�r�rxr0r1r�s



z	List.grow)r~rr�r�r8r��staticmethodr�r�r�r�r�r0r0rxr1r��s	
r�cs4eZdZdZd�fdd�	Zdd�Zdd	d
�Z�ZS)
�HlistzA horizontal list of boxes.r>�
additionalTcs$t��|�|r|��|��dSr�)r�r8r��hpack)r7r�rWr�do_kernrxr0r1r8szHlist.__init__cCs�g}t|j�}|rAt|�D].}|j|}||dkr"|j|d}nd}|�|�|�|�}|dkr;t|�}|�|�q
||_dSdS)z�
        Insert `Kern` nodes between `Char` nodes to set kerning.

        The `Char` nodes themselves determine the amount of kerning they need
        (in `~Char.get_kerning`), and this function just creates the correct
        linked list.
        rNr>)r�r�rw�appendr��Kern)r7�new_children�num_childrenr��elemr��kerning_distancer�r0r0r1r�#s 




�
�z
Hlist.kerncCs�d}d}d}dgd}dgd}|jD]r}t|t�r,||j7}t||j�}t||j�}qt|t�rY||j7}t�	|j�sXt�	|j�sXt
|dd�}	t||j|	�}t||j|	�}qt|t�r{|j}
||
j7}||
j
|
j7<||
j|
j7<qt|t�r�||j7}q||_||_|dkr�||7}||_||}|dkr�d|_d|_d|_dS|dkr�|�|d|d�dS|�|d	|d
�dS)a
        Compute the dimensions of the resulting boxes, and adjust the glue if
        one of those dimensions is pre-specified.  The computed sizes normally
        enclose all of the material inside the new box; but some items may
        stick out if negative glue is used, if the box is overfull, or if a
        ``\vbox`` includes other boxes that have been shifted left.

        Parameters
        ----------
        w : float, default: 0
            A width.
        m : {'exactly', 'additional'}, default: 'additional'
            Whether to produce a box whose width is 'exactly' *w*; or a box
            with the natural width of the contents, plus *w* ('additional').

        Notes
        -----
        The defaults produce a box with the natural width of the contents.
        r>r<r�r�rNr�Overfullrz�	Underfull)r�r@r�rS�maxrTrUr�rQ�isinf�getattr�Glue�	glue_spec�
stretch_order�stretch�shrink_orderr�rr�r�r�r�)r7rWrrXrYr��
total_stretch�total_shrinkrrrr0r0r1r�JsN






�



�zHlist.hpack)r>r�T�r>r�)r~rr�r�r8r�r�r�r0r0rxr1r�s
'r�cs4eZdZdZd�fdd�	Zddejfdd�Z�ZS)	�VlistzA vertical list of boxes.r>r�cst��|�|��dSr�)r�r8�vpack)r7r�rXrrxr0r1r8�szVlist.__init__cCs�d}d}d}dgd}dgd}|jD]f}	t|	t�r9|||	j7}|	j}t�|	j�s8t|	dd�}
t	||	j|
�}qt|	t
�ra||7}d}|	j}||j7}||j|j
7<||j|j7<qt|	t�rp|||	j7}d}qt|	t�rytd��q||_||kr�|||7}||_n||_|dkr�||7}||_||}|dkr�d|_d|_d|_dS|dkr�|�|d|d	�dS|�|d
|d�dS)ak
        Compute the dimensions of the resulting boxes, and to adjust the glue
        if one of those dimensions is pre-specified.

        Parameters
        ----------
        h : float, default: 0
            A height.
        m : {'exactly', 'additional'}, default: 'additional'
            Whether to produce a box whose height is 'exactly' *w*; or a box
            with the natural height of the contents, plus *w* ('additional').
        l : float, default: np.inf
            The maximum height.

        Notes
        -----
        The defaults produce a box with the natural height of the contents.
        r>r<r�z1Internal mathtext error: Char node found in Vlistr�rNrrrzr)r�r@r�rTrUrQr	rSr
rrrr
rrr�rr��RuntimeErrorr�r�r�r�)r7rXrrrWrYr�rrrrrr0r0r1r�sZ



�



��zVlist.vpackr)	r~rr�r�r8rQ�infrr�r0r0rxr1r�srcs(eZdZdZ�fdd�Zdd�Z�ZS)�Rulea�
    A solid black rectangle.

    It has *width*, *depth*, and *height* fields just as in an `Hlist`.
    However, if any of these dimensions is inf, the actual value will be
    determined by running the rule up to the boundary of the innermost
    enclosing box.  This is called a "running dimension".  The width is never
    running in an `Hlist`; the height and depth are never running in a `Vlist`.
    cst��|||�|j|_dSr�)r�r8r�)r7rSrTrUr�rxr0r1r8�sz
Rule.__init__cCs|j�||||||�dSr�)r�rc)r7r�r�rWrXr0r0r1r��szRule.render)r~rr�r�r8r�r�r0r0rxr1r�s
rcs"eZdZdZd�fdd�	Z�ZS)�Hrulez.Convenience class to create a horizontal rule.NcsB|dur|j�|j|j|j�}|d}}t��tj|||�dS)Nr��	r�rnrKrNrGr�r8rQr)r7r��	thicknessrTrUrxr0r1r8�s�zHrule.__init__r�r�r0r0rxr1r�srcr�)�Vrulez,Convenience class to create a vertical rule.cs0|j�|j|j|j�}t��|tjtj|�dSr�r)r7r�rrxr0r1r8�s�zVrule.__init__r�r0r0rxr1r�r�r�	_GlueSpecz/width stretch stretch_order shrink shrink_orderr>��?r�r�g�)�fil�fill�filll�neg_fil�neg_fill�	neg_filll�empty�sscs8eZdZdZ�fdd�Z�fdd�Z�fdd�Z�ZS)ra
    Most of the information in this object is stored in the underlying
    ``_GlueSpec`` class, which is shared between multiple glue objects.
    (This is a memory optimization which probably doesn't matter anymore, but
    it's easier to stick to what TeX does.)
    csBt���t|t�rtj|}nt|t�r|}ntd��||_dS)Nz.glue_type must be a glue spec name or instance)r�r8r@r�r�_namedr+r)r7�	glue_typerrxr0r1r8s



z
Glue.__init__cs6t���|jtkr|j}|j|jtd�|_dSdS�N�rS)r�r�rFr�r�_replacerSr��r7r&rxr0r1r�!s


�zGlue.shrinkcs(t���|j}|j|jtd�|_dSr()r�r�rr*rSr�r+rxr0r1r�'s
z	Glue.grow)r~rr�r�r8r�r�r�r0r0rxr1rs

rcr�)�	HCenteredzl
    A convenience class to create an `Hlist` whose contents are
    centered within its enclosing box.
    cs&t�jtd�g|�td��dd�dS)Nr%F�r��r�r8rr�rxr0r1r83s&zHCentered.__init__r�r0r0rxr1r,-�r,cr�)�	VCenteredzk
    A convenience class to create a `Vlist` whose contents are
    centered within its enclosing box.
    cs"t��td�g|�td���dS)Nr%r.r�rxr0r1r8=s"zVCentered.__init__r�r0r0rxr1r07r/r0csHeZdZdZdZdZ�fdd�Zdd�Z�fdd�Z�fd	d
�Z	�Z
S)ra�
    A `Kern` node has a width field to specify a (normally
    negative) amount of spacing. This spacing correction appears in
    horizontal lists between letters like A and V when the font
    designer said that it looks better to move them closer together or
    further apart. A kern node can also appear in a vertical list,
    when its *width* denotes additional spacing in the vertical
    direction.
    rcst���||_dSr�)r�r8rSr�rxr0r1r8Os

z
Kern.__init__cCr�)Nzk%.02fr)r;r0r0r1r�Sr�z
Kern.__repr__cs*t���|jtkr|jt9_dSdSr�)r�r�rFr�rSr�r;rxr0r1r�Vs

�zKern.shrinkcst���|jt9_dSr�)r�r�rSr�r;rxr0r1r�[s
z	Kern.grow)r~rr�r�rTrUr8r�r�r�r�r0r0rxr1rAs
rcr�)�SubSuperClustera,
    A hack to get around that fact that this code does a two-pass parse like
    TeX.  This lets us store enough information in the hlist itself, namely the
    nucleus, sub- and super-script, such that if another script follows that
    needs to be attached, it can be reconfigured on the fly.
    cs"d|_d|_d|_t��g�dSr�)�nucleus�subr�r8r;rxr0r1r8hszSubSuperCluster.__init__r�r0r0rxr1r1`sr1cs"eZdZdZd�fdd�	Z�ZS)�AutoHeightChara
    A character as close to the given height and depth as possible.

    When using a font with multiple height versions of some characters (such as
    the BaKoMa fonts), the correct glyph will be selected, otherwise this will
    always just return a scaled version of the glyph.
    FNcs�|j�|j|�}|j�|j|j|j�}|��}||}	|D]\}
}|
|_t||�}|j|j	|	d|kr7nqd}
|jdkr\|durK|	|j|j	}|j|9_t||�}||j	}
t
��|g�|
|_dS)Nr�r)
r�r|rKrmrNrG�copyr�rTrUr�r8r�)r7r"rTrUr��always�factorr|r��target_totalr{rMr[�shiftrxr0r1r8xs.��
�



zAutoHeightChar.__init__)FNr�r0r0rxr1r4osr4cs&eZdZdZdef�fdd�	Z�ZS)�
AutoWidthChara
    A character as close to the given width as possible.

    When using a font with multiple width versions of some characters (such as
    the BaKoMa fonts), the correct glyph will be selected, otherwise this will
    always just return a scaled version of the glyph.
    Fcs�|j�|j|�}|��}|D]\}}||_|||�}	|	j|kr!nq||	j}
|j|
9_|||�}	t��|	g�|	j|_dSr�)r�r|rKr5rSrNr�r8)r7r"rSr�r6�
char_classr|r{rMr[r7rxr0r1r8�s�

�

zAutoWidthChar.__init__)r~rr�r�r�r8r�r0r0rxr1r:�sr:c@s4eZdZdZdd�Zedd��Zdd�Zdd	�Zd
S)�Shipa�
    Ship boxes to output once they have been set up, this sends them to output.

    Since boxes can be inside of boxes inside of boxes, the main work of `Ship`
    is done by two mutually recursive routines, `hlist_out` and `vlist_out`,
    which traverse the `Hlist` nodes and `Vlist` nodes inside of horizontal
    and vertical boxes.  The global variables used in TeX to store state as it
    processes have become member variables here.
    cCs8d|_d|_d|_d|_||_||j|_|�|�dS)Nrr>)�max_push�cur_s�cur_v�cur_h�off_hrT�off_v�	hlist_out)r7rarbrvr0r0r1�__call__�sz
Ship.__call__cCs|dkrdS|dkrdS|S)Nge��ge��Ar0)�valuer0r0r1�clamp�s
z
Ship.clampcCsFd}d}|j}|j}|j}|j}|jd7_t|j|j�|_|j}|jD]�}	t	|	t
�rC|	�|j|j|j|j
�|j|	j7_q%t	|	t�rQ|j|	j7_q%t	|	t�r�t|	j�dkrf|j|	j7_q%|j}
||	j|_t	|	t�rz|�|	�n|�|	�|
|	j|_||_q%t	|	t�r�|	j}|	j}|	j}
t�|�r�|j}t�|�r�|j}|dkr�|
dkr�|||_|	�|j|j|j|j
|
|�||_|j|
7_q%t	|	t��r|	j}|j|}
|dk�r|dkr�|j|kr�||j7}t||j |��}n|j!|k�r||j"7}t||j |��}|
|7}
|j|
7_q%|jd8_dS)Nrr>r)#r�r�r?r@r>rr=rFr�r@r�r�rArBrSrr�r�r�r�rC�	vlist_outr�rTrUrQr	rrr
r�roundr�rr�)r7rv�cur_g�cur_gluer�r��	base_line�	left_edgerFr�edge�rule_height�
rule_depth�
rule_widthrr0r0r1rC�sr










�



�
�zShip.hlist_outcCs6d}d}|j}|j}|jd7_t|j|j�|_|j}|j|j8_|j}|j}|j	D]�}	t
|	t�r=|j|	j7_q-t
|	t
�r�t|	j	�dkrU|j|	j|	j7_q-|j|	j7_||	j|_|j}
|j|	_t
|	t�ru|�|	�n|�|	�|
|	j|_||_q-t
|	t�r�|	j}|	j}|	j}
t�|
�r�|j}
||7}|dkr�|dkr�|j|7_|	�|j|j|j|j|
|�q-t
|	t��r|	j}|j|}|dkr�|dkr�|j|kr�||j7}t||j|��}n|j |kr�||j!7}t||j|��}||7}|j|7_q-t
|	t"��rt#d��q-|jd8_dS)Nrr>rz1Internal mathtext error: Char node found in vlist)$r�r�r>rr=r@r?rTrFr�r@rrSr�r�rUr�r�rCrGr�rQr	r�rArBrrr
rrHr�rr�r�r)r7rvrIrJr�r�rL�top_edgerFr�save_vrNrOrPrr0r0r1rG
sv







��


�

��zShip.vlist_outN)	r~rr�r�rDr�rFrCrGr0r0r0r1r<�s
	
?r<cs �fdd�}t�}|�|�|S)z$Helper class to raise parser errors.cst||���r��r)r�loc�toks��msgr0r1�raise_errorRszError.<locals>.raise_error)r�setParseAction)rWrXr$r0rVr1�ErrorPs
rZc
s�eZdZdZGdd�dej�Zed���Z	ed���Z
ed���Ze	e
BeBZed���Z
ed���Zed	���Zed
���Zed���Zed���Zed
���Zed���Zed���Zdd�Zdd�ZGdd�d�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Z d&d&d&d'd'd(d)d)d*d+d,d-d.�Z!d/d0�Z"d1d2�Z#d3d4�Z$e$Z%d5d6�Z&d7d8iZ'd9d:�Z(id;d<�d=d>�d?d@�dAdB�dCdD�dEdF�dGdH�dIdJ�dKdL�dMdN�dOdP�dQdJ�dRdB�dSdD�dTdF�dUdH�dVd<�dWdXdYdZ��Z)ed[���Z*d\d]�ee)��Z+d^d_�Z,d`da�Z-dbdc�Z.ddde�Z/dfdg�Z0e0Z1Z2dhdi�Z3djdk�Z4dldm�Z5dndo�Z6dpdq�Z7drds�Z8�fdtdu�Z9dvdw�Z:dxdy�Z;dzd{�Z<d|d}�Z=d~d�Z>d�d��Z?e?Z@ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZE�ZFS)��Parserz�
    A pyparsing-based parser for strings containing math expressions.

    Raw text may also appear outside of pairs of ``$``.

    The grammar is based directly on that in TeX, though it cuts a few corners.
    c@s,eZdZe��Ze��Ze��Ze��ZdS)zParser._MathStyleN)	r~rr��enum�auto�DISPLAYSTYLE�	TEXTSTYLE�SCRIPTSTYLE�SCRIPTSCRIPTSTYLEr0r0r0r1�
_MathStylecs
rba�
      + * -
      \pm             \sqcap                   \rhd
      \mp             \sqcup                   \unlhd
      \times          \vee                     \unrhd
      \div            \wedge                   \oplus
      \ast            \setminus                \ominus
      \star           \wr                      \otimes
      \circ           \diamond                 \oslash
      \bullet         \bigtriangleup           \odot
      \cdot           \bigtriangledown         \bigcirc
      \cap            \triangleleft            \dagger
      \cup            \triangleright           \ddagger
      \uplus          \lhd                     \amalga�
      = < > :
      \leq        \geq        \equiv   \models
      \prec       \succ       \sim     \perp
      \preceq     \succeq     \simeq   \mid
      \ll         \gg         \asymp   \parallel
      \subset     \supset     \approx  \bowtie
      \subseteq   \supseteq   \cong    \Join
      \sqsubset   \sqsupset   \neq     \smile
      \sqsubseteq \sqsupseteq \doteq   \frown
      \in         \ni         \propto  \vdash
      \dashv      \dots       \dotplus \doteqdota�
      \leftarrow              \longleftarrow           \uparrow
      \Leftarrow              \Longleftarrow           \Uparrow
      \rightarrow             \longrightarrow          \downarrow
      \Rightarrow             \Longrightarrow          \Downarrow
      \leftrightarrow         \longleftrightarrow      \updownarrow
      \Leftrightarrow         \Longleftrightarrow      \Updownarrow
      \mapsto                 \longmapsto              \nearrow
      \hookleftarrow          \hookrightarrow          \searrow
      \leftharpoonup          \rightharpoonup          \swarrow
      \leftharpoondown        \rightharpoondown        \nwarrow
      \rightleftharpoons      \leadstoz, ; . ! \ldotp \cdotpz}
       \sum \prod \coprod \bigcap \bigcup \bigsqcup \bigvee
       \bigwedge \bigodot \bigotimes \bigoplus \biguplus
       zlim liminf limsup sup max minr�z.rm cal it tt sf bf default bb frak scr regularz�
      arccos csc ker min arcsin deg lg Pr arctan det lim sec arg dim
      liminf sin cos exp limsup sinh cosh gcd ln sup cot hom log tan
      coth inf max tanhzr
      | \| / \backslash \uparrow \downarrow \updownarrow \Uparrow
      \Downarrow \Updownarrow . \vert \Vert \\|z( [ \{ < \lfloor \langle \lceilz) ] \} > \rfloor \rangle \rceilc
CsD	t��}t�|_t�|_t�|_t�|_t�|_t�|_t�|_	t�|_
t�|_t�|_t�|_
t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_t�|_ t�|_!t�|_"t�|_#t�|_$t�|_%t�|_&t�|_'t�|_(t�|_)t�|_*t�|_+t�|_,t�|_-t�|_.t�|_/t�|_0t�|_1t�|_2t3|��4�D]\}}|�5d�s�|�6|�q�|jt7d�K_|jt7d�K_|jt8d��9�K_|j t8d��9�K_ |jt8d��9�K_|j!t8d��9�K_!|jt8d�K_|j)t:t;|j<��K_)|j
t=t8d	��|j|j|j t>d
�BK_
d}|j't7d|�K_'|j(t=|j�t:|j?�K_(|j/t@|jt:t;tA���t=t7d
��B��K_/|j.|j'|j/B�B�K_.|jt7d�K_|j	t=|j�t:t;|jC��K_	|jtDt=|j�t:g|jE�|jF��t=tGtH���|j�K_|jt=|j�t:t;|jI��K_|j+tG|j�|jK_+|j|j �J�K_|j&tD|jtK|j0�|j �K_&|j"tD|jtL|j0�|j �K_"|jtD|j+tK|j0�|j�K_|j
t=|j�t:t;|jM��K_
|jt=|j�t:dd�|jMD��K_|jtDt=t8d��|j"|j"t>d�B�K_|jtDt=t8d��|j"|j"t>d�B�K_|jtDt=t8d��|j"|j"t>d�B�K_|jt:t;|jN��K_|jt:t;|jO��K_|j#t:t;|jP��K_#|j$t:g|jPdh�d��K_$|jtDt=t8d��|jtG|j|jBdd�|j |jtG|j|j$Bdd�|j |j|j|j |j&|j"|j"t>d�B�K_|j*tDt=t8d��tDtG|jtL|j!|j0�|j!��|j"t>d�B�K_*|jtDt=t8d��|j"t>d�B�K_|jtDt=t8d ��|j&|j&t>d!�B�K_|j1tDt=t8d"��|j&|j&t>d#�B�K_1|j2t@|jt7d$��K_2|jtDt=t8d%��|jtK|j%|j2B�|j t>d&�B�K_|j|j(|jB|j.B|j	B|jB|jB|jB|jB|jB|jB|jB|j1B|j*B|jB|jBK_|j%|j)|j
B|j
B|j,BK_%|j-t:dd'g�K_-|j,tDtG|j�tL|j-|j�tG|j�|jtG|j�B|jB�K_,|j0|j%|jB|j2BK_0|jt=t8d(��|j|jBt>d)�BtDtK|j%|jB��t=t8d*��|j#|jBt>d)�BK_|jtL|j0�K_|jtQd+dd,d-�K_|jt7d.��B�K_|j|jtK|j|j�tR�K_t3|��4�D]\}}|�5d��s�tS||��r�|�TtU||���q~|j|_V|j|_WdS)/N�_z[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)z[-+]?[0-9]+r�r�r�r�r&z\hspacezExpected \hspace{n}u€-🿿z;([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])z(?=[^A-Za-z]|$)z'+cSsg|]}d|�qS�r.r0r�r0r0r1r�!r�z#Parser.__init__.<locals>.<listcomp>z\fraczExpected \frac{num}{den}z\dfraczExpected \dfrac{num}{den}z\binomzExpected \binom{num}{den}r*z\genfracr�)r�z<Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}z\sqrtzExpected \sqrt{value}z	\overlinezExpected \overline{value}z\oversetz#Expected \overset{body}{annotation}z	\undersetz$Expected \underset{body}{annotation}z	[A-Za-z]*z
\operatornamezExpected \operatorname{value}r z\leftzExpected a delimiterz\rightr�F)�unquoteResultsz(?:(?:\\[$])|[^$])*)Xr�r�r�accent�
ambi_delim�
apostrophe�
auto_delim�binom�bslash�c_over_c�customspace�	end_group�
float_literalrK�frac�dfrac�function�genfrac�group�int_literal�	latexfont�lbracket�
left_delim�lbrace�mainr.�math_string�non_math�operatorname�overline�overset�	placeable�rbrace�rbracket�required_group�right_delim�right_delim_safe�simple�simple_group�
single_symbol�accentprefixed�space�sqrt�start_group�subsuper�
subsuperopr-r��token�underset�unknown_symbol�varsr�rT�setNamerr	�suppressr
rW�
_space_widthsrrZ�_accentprefixedrr�leaveWhitespace�_char_over_charsr�_accent_map�
_wide_accentsrr�_function_namesr5rr�
_fontnames�_ambi_delim�_left_delim�_right_delimrr�hasattrrYr
�_expression�_math_expression)r7rr�r��
unicode_ranger0r0r1r8�sB

�
���������������$$�"��

���

���

���"
������������
�����
��

���

���
���������	�
���
�����������������

���
�
���
��zParser.__init__cCs�|�|dd||�g|_i|_z|j�|�}Wn"ty8}ztd�d|jd|j	ddt
|�g��|�d}~wwd|_i|_|j��|d	S)
z�
        Parse expression *s* using the given *fonts_object* for
        output, at the given *fontsize* and *dpi*.

        Returns the parse tree of `Node` instances.
        r�r��
r�r�rr Nr)�State�_state_stack�_em_width_cacher��parseStringr
r+r��line�columnr��
resetCache)r7r�fonts_objectrNrGrwr/r0r0r1�parse�s&�����
zParser.parsec@s:eZdZdZdd�Zdd�Zedd��Zejdd��Zd	S)
zParser.Statez�
        Stores the state of the parser.

        States are pushed and popped from a stack as necessary, and
        the "current" state is always at the top of the stack.
        cCs"||_||_||_||_||_dSr�)r��_fontrLrNrG)r7r�rKrLrNrGr0r0r1r8�s

zParser.State.__init__cCst�|j|j|j|j|j�Sr�)r[r�r�rKrLrNrGr;r0r0r1r5�s�zParser.State.copycCror�)r�r;r0r0r1rK�szParser.State.fontcCs|dvr||_||_dS)N)r�r�r�)rLr�)r7rGr0r0r1rK�s
N)	r~rr�r�r8r5r�rK�setterr0r0r0r1r��s
r�cCs
|jdS)z&Get the current `State` of the parser.rz)r�r;r0r0r1�	get_state�s
zParser.get_statecCs|j��dS)zPop a `State` off of the stack.N)r��popr;r0r0r1�	pop_state�szParser.pop_statecCs|j�|�����dS)z=Push a new `State` onto the stack, copying the current state.N)r�rr�r5r;r0r0r1�
push_state�szParser.push_statecCs
t|�gSr��r��r7rrTrUr0r0r1rz�r�zParser.maincCs|j�|ddd��S)Nrrrz)r�r�r�r0r0r1r{�szParser.math_stringcCst|�}|��|gSr�)r�r��r7rrTrU�hlistr0r0r1r.�szParser.mathcsH|d�dd�}�fdd�|D�}t|�}���tjd���_|gS)Nrz\$r�csg|]}t|���dd��qS)Frd)r�r��r�r"r;r0r1r�	sz#Parser.non_math.<locals>.<listcomp>r�)�replacer�r�r�r�r�rK)r7rrTrU�symbolsr�r0r;r1r|	szParser.non_mathcCsh|��}|j|j|jf}|j�|�}|dur.|j�|jtj	dd|j|j�}|j
}||j|<t||�S)Nr�r)r�rKrNrGr�r�r�rPr�r�r�r)r7�
percentager�r�rSrJr0r0r1�_make_space	s�
zParser._make_spaceg���KqU�?g�0Bx�q�?g����%��?g��1ZGU�?r�rr�g���KqUſ)�\,z
\thinspacez\/z\>z\:z\;z\ r#z\enspacez\quadz\qquadz\!cCs |\}|j|}|�|�}|gSr�)r�r�)r7rrTrU�tokr_rvr0r0r1r�(	s

zParser.spacecCs|�t|d��gSr�)r��floatr�r0r0r1rm.	r.zParser.customspacec	
Cs�|\}z	t||���}Wnty!}z	t||d|�|�d}~ww||jvrgtdd�|d|�ddd�D�d�}||jvrWt|d|����dksT|dksT||j	vrW|gSt
|�d�||�d�gd	d
�gS||jvr�|dkr�tdd�|d|�ddd�D�d�}td
d�||dd�D�d�}|dkr�|dkr�|gS|dkr�||d�
�r�||d�
�r�|gSt
||�d�gd	d
�gS|gS)N�Unknown symbol: %scs��|]	}|dkr|VqdS�r�Nr0r�r0r0r1�	<genexpr><	��z Parser.symbol.<locals>.<genexpr>rzr�rr�r�Tr-rcsr�r�r0r�r0r0r1r�K	r�csr�r�r0r�r0r0r1r�L	r�rr�r)r�r�r+r�_spaced_symbolsr��_binary_operatorsr�r/r�r�r��_punctuation_symbols�isdigit)	r7rrTrUr"r[r/�	prev_char�	next_charr0r0r1r-1	sB����
&
 

��
& (z
Parser.symbolcCs|\}t||d|��)Nr�rS)r7rrTrUr"r0r0r1r�Y	szParser.unknown_symbol�AA))r��Ar)N�\circr�r>cCs|\}|��}|j�|j|j|j�}|j�|d�\}}}	|dur$td��|�	�}
|ddur3|d|
_|
j|d9_t
|d|
�}|�	�}|ddurR|d|_|j|d9_t|d|�}
t|j
|
j
�}t|g�}|�|d�t|
g�}|�|d�t|td||	�|g�S)N)NNr>zError parsing symbolrr�r�exactlyr>)r�r�rnrKrNrGr�r�rr5r�r�rrSr,r�rr�)r7rrTrUrMr�r�
under_desc�	over_descr��
over_state�over�under_state�underrS�
over_centered�under_centeredr0r0r1rld	s:��



�zParser.c_over_c�hatz\circumflexaccent�brevez\combiningbreve�barz\combiningoverline�gravez\combininggraveaccent�acutez\combiningacuteaccent�tildez\combiningtilde�dotz\combiningdotabove�ddotz\combiningdiaeresis�dddotz\combiningthreedotsabove�ddddotz\combiningfourdotsabove�vecz\combiningrightarrowabover��`r	r#rr z\rightarrowz
\leftarrowr�)�overrightarrow�
overleftarrow�mathringzwidehat widetilde widebarcs�fdd�tD�S)Ncs&g|]�t�fdd��D��r��qS)c3s"�|]}��|�o|�kVqdSr�)rT)r��a�rr0r1r��	s� z-Parser.<lambda>.<locals>.<listcomp>.<genexpr>)�any)r���amr�r1r��	s��z#Parser.<lambda>.<locals>.<listcomp>)rr�r0r�r1r��	s
�zParser.<lambda>c
Cs�|��}|j�|j|j|j�}|\\}}||jvr%td||j|t	d�}nt	|j
||�}|dkr9|��|��tt
|jd�|g�}	|	�|jd�t|	td|d�t|g�g�S)Nr&)r;r�g@r�r>�@)r�r�rnrKrNrGr�r:rSr�r�r�r,r�r�rr�r�)
r7rrTrUr�rrfrM�
accent_box�centeredr0r0r1rf�	s(�

��z
Parser.accentcCs|�|||�}|\|_|Sr�)r}�
function_namer�r0r0r1rr�	szParser.functionc
Cs|��|��}d|_g}|dD]'}t|t�r%d|_|��|�|�qt|t�r3|�t||��q|�|�q|t|d�d}t|dt	�rP|td�7}t
dd�||d�D�d�}|j|jB|j
B}	|	dd	hO}	||	vr�|d|jvr�||�|jd
�g7}|��t|�S)Nr�rrzoperatorname{}csr�r�r0r�r0r0r1r��	r�z&Parser.operatorname.<locals>.<genexpr>r�r rcr�)r�r�rKr@r�r�rr�r�rr�r�r�r��_overunder_functionsr�r�r�r�)
r7rrTrUr��
hlist_listr"�
next_char_locr��
delimitersr0r0r1r}�	s.

zParser.operatornamecCs*|��t|�r|ddd�|��_gS)Nrr<)r�r�r�rKr�r0r0r1r��	szParser.start_groupcCst|d�}|gSr�r�)r7rrTrU�grpr0r0r1rt�	szParser.groupcCs|��gSr�)r�r�r0r0r1rn�	szParser.end_groupcCs|\}||��_gSr�)r�rK)r7rrTrUrGr0r0r1rK�	s
zParser.fontcCs:t|t�r|j|jvSt|t�rt|d�r|j|jvSdS)Nr�F)r@r�r"�_overunder_symbolsr�r�r�r��r7r2r0r0r1�is_overunder�	s

zParser.is_overundercCst|t�r|j|jvSdS�NF)r@r�r"�_dropsub_symbolsr�r0r0r1�
is_dropsub�	s
zParser.is_dropsubcCst|t�r	|��SdSr�)r@r�r�r�r0r0r1r��	s
zParser.is_slantedcCr=r�r0)r7rrTr0r0r1�is_between_brackets
r�zParser.is_between_bracketsc&s�t|�dksJ�d}d}d}d}g}|dD]&}	t|	t�r(|	dvr(|t|	�7}qt|	t�r7|	jdkr7|d7}q|�|	�q|}t|�dkrN|sIJ�td�}nwt|�dkr_|sZ|dS|d}nft|�dvr�t|�dkro|dntd�}|dd�\}
}|
d	kr�|}nC|}n@t|�d
vr�t|�dkr�|dntd�}|dd�\}}
}}||kr�|d	kr�td
��td��|d	kr�|
}|}n	|
}|}ntd��|��}|j	�
|j|j|j
�}|j	�|j|j|j
�}|�r|dur�tg�}t|�D]}|j�|�||dg��q�|��|��|�|��r�g}d}|j}|du�r!|��t||j�}|du�r0|��t||j�}|d}|du�rNt|g�}|�|d�|�|td|�g�t|g�}|�|d�|�|�|du�r}t|g�}|�|d�|�td|�|g�|j|}t|�}||j|_t|g�}|gS|}t|t��r�|j}t|��r�t|dt ��r�t!|dd��r�|dd�}|d}t!|d��r�|j"j#|_t|dd�}nt|t��r�|j"j#|_t|g�}t$|�}|j}d}|�%|��r�|j}|j&|}|j&|} |�'|��r.||j&|7}||j(||dd7}|�%|��r,d|j&|j)|} d|j&|j)|}nd} |du�rVtt | �|g�}!|!��|�%|��rM||j*|}"n|j+|}"|"|!_nstt |�|g�}!|!��|�%|��rp||j*|}#n|j,|}#|du�r|#|!_nJtt | �|g�}$|$��|�%|��r�||j*|}"n|j-|}"d||#|!j|$j|"}%|%dk�r�|#|%7}#t|!t |#|!j|$j|"�|$g�}!|"|!_|�%|��s�|!j|j.|7_t||!g�}|gS)Nrr)r rcr	r>)r�r�r����rc)r<r=r=���zDouble subscriptzDouble superscriptzOSubscript/superscript sequence is too long. Use braces { } to remove ambiguity.rc�@r�rzr�Fr-r�)/r�r@r�r�r"rr�rr�r�rnrKrNrGrmr�rwr��extendr-r�r�r�rSr�rr,r�rTrrUr�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�)&r7rrTrUr2r3r��napostrophes�new_toksr��opr��op1�next1�op2�next2r��rule_thicknessr�r��vlistr9rS�vgapr�rw�	last_charrr��	lc_height�lc_baseline�	superkern�subkernr��
shift_down�shift_upr��clrrxr0r1r�
s6


���









	
�




�����





�
�zParser.subsupercCs4|��}|j�|j|j|j�}t|�}||jjur!|�	�|�	�t
|g�}	t
|g�}
t|j|j�}|	�
|d�|
�
|d�t|	td|d�t||�td|d�|
g�}|j�|jtjdd|j|j�}
|
j|
j|
jd|d}||_t|t|d�g�g}|s�|r�|dkr�d	}|dkr�d	}|�|||�S|S)
Nr�rr�r��=r�r�r�r)r�r�rnrKrNrGr�rbr^r�r,rrSr�rr�rrPr�r�rTr�r�r�r�r��_auto_sized_delimiter)r7�ldelim�rdelim�rule�styler_�denr�r�cnum�cdenrSrrJr9rwr0r0r1�_genfrac�
sJ�

�	
���zParser._genfraccCs|\}|j|�Sr�)r)r7rrTrUr�r0r0r1rs�
s
zParser.genfraccC�@|��}|j�|j|j|j�}|\\}}|�dd||jj||�S�Nr�)	r�r�rnrKrNrGrrbr_�r7rrTrUr�rr_rr0r0r1rp�
��
�zParser.fraccCrr)	r�r�rnrKrNrGrrbr^rr0r0r1rq�
rzParser.dfraccCs"|\\}}|�ddd|jj||�S)Nr�r�r>)rrbr_)r7rrTrUr_rr0r0r1rjs
�zParser.binomc
Cs�|\\}}|��}|j�|j|j|j�}|��t|g�}t|g�}	t|j	|	j	�}
|�
|
d�|	�
|
d�|d}||ddkrVt|	td|�|g�}|	j
|j||_|St|td|�|	g�}|S)Nr�r�r�ur)r�r�rnrKrNrGr�r,rrSr�rr�rUrTr�)
r7rrTrU�
annotation�bodyr�r�cannotation�cbodyrSrrr0r0r1�_gensets0
�

�	��zParser._gensetcCs2|\\}}|��}|j�|j|j|j�}|j|j|d}|j|j}	t	d||	|dd�}
|
j|
j}|
j|
j}	t
td|�|td|�g�}tt
|�td�|g�}|�||j|jdd|	�|snt|
jd	d
d
�}nt
|�}|��|��tt
|g�g�}
|d|
_t
|
t|
jd	�|
|g�}|gS)Ng@rT)r6r�r���@r�r�r>r�)r�r�rnrKrNrGrTr�rUr4r�r�rrrrr�rSr�r)r7rrTrU�rootr!r�rrTrU�check�padded_body�	rightside�
root_vlistr�r0r0r1r�)s8
���zParser.sqrtcCs�|\\}|��}|j�|j|j|j�}|j|j|d}|j|j}t	t
|�td�t|g�g�}	|	�
||j|jdd|�t|	g�}
|
gS)Nr�rr%r�)r�r�rnrKrNrGrTr�rUrrrr�r)r7rrTrUr!r�rrTrUr)r�r0r0r1r~Qs��
zParser.overlinec
	Cs�|��}t|�rtdd�|D��}tdd�|D��}d}nd}d}d}g}|dkr5|�t|||||d��|�|�|dkrJ|�t|||||d��t|�}	|	S)Ncs��|]}|jVqdSr�)rTr�r0r0r1r�h��z/Parser._auto_sized_delimiter.<locals>.<genexpr>csr+r�)rUr�r0r0r1r�ir,rrr)r7)r�r�rrr4r�r�)
r7�front�middle�backr�rTrUr7�partsr�r0r0r1res(�
�zParser._auto_sized_delimitercCs|\}}}|�||��|�Sr�)r�asList)r7rrTrUr-r.r/r0r0r1ri{s
zParser.auto_delim)Gr~rr�r�r\�Enumrbr]r/r��_relation_symbols�_arrow_symbolsr�r�r�r�r�r�r�r�r�r�r8r�r�r�r�r�rzr{r.r|r�r�r�rmr-r�r�r�rlr�r�r�rfrrr}r�rtr�r�rnrKr�r�r�r�r�rrsrprqrjr$rr�r�r~rrir�r0r0rxr1r[Zs
��
�
���� 	�&�%��������	�
���
�������@)(r[r})er��collectionsrr\r}�ior�loggingr�r�rR�numpyrQ�	pyparsingrrrrr	r
rrr
rrrrrrrrr�
matplotlibr�r�rr�_mathtext_datarrrrrr�r�font_managerr r!r"�ft2fontr#�
enablePackrat�	getLoggerrOr2r3rsr�r2r^r_rjr�r>rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr&rr,r0rr1r4r:r<�shiprZr[r0r0r0r1�<module>s�P

"lq},l9$	��������	�
���
������S=qO	��

'

Youez - 2016 - github.com/yon3zu
LinuXploit