a
    ضa                    @   s>  d Z ddlmZ ddlZddlZddlmZ ddlZddlZddl	Z	ddl
Z
ddlZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddl Z!ddl"m#Z#m$Z$ ddl%m&Z&m'Z'm(Z(m)Z)m*Z* dd	l+m,Z, dd
l-m.Z.m/Z/m0Z0 ddl1m2Z2 e3  e4dZ5diddZ6G dd dZ7G dd de7Z8G dd de8Z9G dd de8Z:G dd de:Z;G dd de;Z<G dd de;Z=G dd de:Z>G d d! d!e>Z?G d"d# d#e7Z@d$ZAdeA ZBd%ZCG d&d' d'ZDG d(d) d)eDZEG d*d+ d+eDZFG d,d- d-eDZGG d.d/ d/eDZHG d0d1 d1eDZIeIeIeHeEeEeEeEeEeEeEeFeFeFeFeFeFeFeIeId2ZJd3d4 ZKG d5d6 d6ZLG d7d8 d8eLZMG d9d: d:eMZNG d;d< d<eMZOG d=d> d>eLZPG d?d@ d@ePZQG dAdB dBeMZRG dCdD dDeRZSG dEdF dFeRZTG dGdH dHeMZUG dIdJ dJeUZVG dKdL dLeUZWedMdNZXeXdOdPddOdeXdOdPdQdOdeXdOdPdRdOdeXdOdOddPdeXdOdOddPdQeXdOdOddPdReXdOdOddOdeXdOdPddSddTeX_YG dUdV dVeLZZG dWdX dXeSZ[G dYdZ dZeTZ\G d[d\ d\eLZ]G d]d^ d^eSZ^G d_d` d`eSZ_G dadb dbeSZ`G dcdd ddZaea Zbdedf ZcG dgdh dhZddS )jz.
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_DEFAULTzmatplotlib.mathtextTc              
   C   s   |st | S | dkrdS z
t | W S  ty4   Y n0 zt| d W S  tyz } ztd| |W Y d}~n
d}~0 0 dS )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   d/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/matplotlib/_mathtext.pyget_unicode_index&   s$    
r2   c                       s   e Zd ZdZdd Zeddd Zdd Zdd
dZ	dd Z
eddddd Zdd Zdd Zdd Zdd Z fddZdd Z  ZS )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.
    c                 C   s   || _ || _i | _dS )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)selfr4   r5   r0   r0   r1   __init__Q   s    
zFonts.__init__3.4c                 C   s
   d| _ dS )za
        Fix any cyclical references before the object is about
        to be destroyed.
        Nr6   r7   r0   r0   r1   destroy_   s    zFonts.destroyc
           
      C   s   dS )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dpir0   r0   r1   get_kerng   s    zFonts.get_kernTc                 C   s   |  ||||||}|jS )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fontsizerF   r.   infor0   r0   r1   get_metricsp   s    &zFonts.get_metricsc                 C   s6   t |||g\| _| _| _| j| j| j| j dS )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dr0   r0   r1   rU      s    zFonts.set_canvas_sizeZfacenamerJ   c           	      C   sB   |  |||||}| j|jjt |j | j	||| dS )z
        At position (*ox*, *oy*), draw the glyph specified by the remaining
        parameters (see `get_metrics` for their detailed description).
        N)
rH   r6   
setdefaultrJ   fnamesetaddnumr5   render_glyph)	r7   oxoyrJ   rK   rL   rM   rF   rN   r0   r0   r1   r^      s    zFonts.render_glyphc                 C   s   | j |||| dS )zL
        Draw a filled rectangle from (*x1*, *y1*) to (*x2*, *y2*).
        N)r5   render_rect_filledr7   x1y1Zx2y2r0   r0   r1   ra      s    zFonts.render_rect_filledc                 C   s
   t  dS )zF
        Get the xheight for the given *font* and *fontsize*.
        NNotImplementedErrorr7   rJ   rM   rF   r0   r0   r1   get_xheight   s    zFonts.get_xheightc                 C   s
   t  dS )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.
        Nrf   rh   r0   r0   r1   get_underline_thickness   s    zFonts.get_underline_thicknessc                 C   s   | j S )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;   r0   r0   r1   get_used_characters   s    zFonts.get_used_charactersc                    sD   | j ||  }| jtj| kr@tj j| dd}|r@|  |S )z
        Get the data needed by the backend to render the math
        expression.  The return value is backend-specific.
        r9   )Zsince)r5   get_resultsrk   r<   TruetypeFonts__get__r   Zdeprecate_method_override)r7   boxresultr<   	__class__r0   r1   rl      s    zFonts.get_resultsc                 C   s
   ||fgS )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   fontnamerL   r0   r0   r1   !get_sized_alternatives_for_symbol   s    z'Fonts.get_sized_alternatives_for_symbol)T)__name__
__module____qualname____doc__r8   r   
deprecatedr<   rG   rO   rU   Zrename_parameterr^   ra   ri   rj   rk   rl   ru   __classcell__r0   r0   rq   r1   r3   H   s   
	
)	
	r3   c                       sl   e Zd ZdZ fddZed fddZdd Zd	d
 Z	dddZ
dd Zdd Z fddZ  ZS )rm   za
    A generic base class for all font setups that use Truetype fonts
    (through FT2Font).
    c                    sB   t  || i | _i | _t|}t|}|| jd< || jd< d S )Ndefaultregular)superr8   glyphd_fontsr!   r"   )r7   r4   r5   filenamedefault_fontrq   r0   r1   r8      s    
zTruetypeFonts.__init__r9   c                    s   d | _ t   d S N)r   r~   r<   r;   rq   r0   r1   r<      s    zTruetypeFonts.destroyc                 C   sl   || j v r| j | }n|}| j|}|d u rhtj|rht|}|| j|< || j|j< || j|j < |S r   )	fontmapr   getospathexistsr"   postscript_namelower)r7   rJ   basenamecached_fontr0   r0   r1   	_get_font   s    

zTruetypeFonts._get_fontc                 C   s,   |j dkr(|jd d |d | d  S dS )NZCmex10@         H   r=   )r   rS   )r7   rJ   glyphrM   rF   r0   r0   r1   _get_offset   s    
zTruetypeFonts._get_offsetTc                 C   s   |||||f}| j |}|d ur&|S | |||||\}	}
}}}|	|| |	j|
| j d}dd |jD \}}}}| |	|||}t	j
|jd |jd |jd |||| || |jd | |d	}t	j
|	||	j|||
||d }| j |< |S )N)flagsc                 S   s   g | ]}|d  qS )      P@r0   .0valr0   r0   r1   
<listcomp>      z+TruetypeFonts._get_info.<locals>.<listcomp>g      @r   )	advancerS   rR   xminxmaxyminymaxicebergslantedrJ   rM   r   rI   symbol_namer]   r   offset)r   r   
_get_glyphset_sizeZ	load_charr5   Zget_hinting_typeZbboxr   typesSimpleNamespaceZlinearHoriAdvancerS   rR   ZhoriBearingYr   )r7   rt   rK   rL   rM   rF   r.   keyZbunchrJ   r]   r   r   r   r   r   r   r   r   rI   rp   r0   r0   r1   rH     sF    
zTruetypeFonts._get_infoc                 C   sf   |  |}||| |d}|d u rF| |tjd d||}|jS |d d |d  |d  }|S )Npcltmathtext.defaultxxHeightr   g      (@g      Y@)r   r   Zget_sfnt_tablerO   mplrcParamsr   )r7   rt   rM   rF   rJ   r   rI   r   r0   r0   r1   ri   .  s    

zTruetypeFonts.get_xheightc                 C   s   d| | d S )Ng      ?g      R@r0   rh   r0   r0   r1   rj   :  s    z%TruetypeFonts.get_underline_thicknessc
                    sl   ||krP||krP|  |||||	}
|  |||||	}|
j}||
j|jtd S t |||||||||		S )Nr   )rH   rJ   get_kerningr]   r#   r~   rG   r7   r>   r?   r@   rA   rB   rC   rD   rE   rF   Zinfo1Zinfo2rJ   rq   r0   r1   rG   @  s    
zTruetypeFonts.get_kern)T)rv   rw   rx   ry   r8   r   rz   r<   r   r   rH   ri   rj   rG   r{   r0   r0   rq   r1   rm      s   

)rm   c                       s   e Zd ZdZdddddddd	Z fd
dZed Zd)ddZ	g dg dg dg dg dg dg dg dg dg dg dg dg dg dg dg dg d d!d"gd#d$gd%Z
d&D ]\ZZe
e e
e< qd'd( Z  ZS )*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exc                    s\   t |i || _t j|i | i | _| j D ]$\}}t|}|| j|< || j|< q2d S r   )	StixFonts_stix_fallbackr~   r8   r   _fontmapitemsr!   )r7   argskwargsr   r   fullpathrq   r0   r1   r8   \  s    
zBakomaFonts.__init__
\int \ointTc                 C   s   d }d }|| j v rD|tv rDt| \}}	|dkp6|| jv }
| |}n.t|dkrr|dk}
| |}|d urrt|}	|d ur||	}|dkr||}|d u r| j	|||||S ||	|||
fS )Nr   r   r   r   )
r   r   _slanted_symbolsr   lenr'   get_char_indexget_glyph_namer   r   )r7   rt   rK   rL   rM   r.   r   rJ   r   r]   r   gidr0   r0   r1   r   h  s(    



zBakomaFonts._get_glyph))r   ()r      ¡)r      ³)r      µ)r      Ã))r   ))r      ¢)r      ´)r      ¶)r   !))r   {)r      ©)r   n)r      ½)r   r   ))r   })r      ª)r   o)r      ¾)r   r   ))r   [)r      £)r   rW   )r   "))r   ])r      ¤)r   i)r   #))r      ¥)r   j)r      ¹)r   $))r      ¦)r   k)r      º)r   %))r      §)r   l)r      »)r   &))r      ¨)r   m)r      ¼)r   '))r      ­r   D)r      ¿)r   *))r      ®r   E)r      À)r   +))r   p)r   q)r   r)r   s))r      ²)r   /)r      Â)r   r$   ))r   r  )r      ±)r   .)r      Ë)r   ,))r   ^)r   b)r   c)r   rX   ))r   ~)r   e)r   f)r   g)r   rW   r   )r   r   r   )r   r   r   r   r   r   z\lfloorz\rfloorz\lceilz\rceilz\langlez\rangle	\__sqrt__z
\backslashr  z\widehatz
\widetilde<>)
)z
\leftparenr   )z\rightparentr   )z
\leftbracer   )z\rightbracer   )z\leftbracketr   )z\rightbracketr   )\{r   )\}r   )\[r   )\]r   c                 C   s   | j |||fgS r   )_size_alternativesr   rs   r0   r0   r1   ru     s    z-BakomaFonts.get_sized_alternatives_for_symbol)T)rv   rw   rx   ry   r   r8   r[   splitr   r   r  aliastargetru   r{   r0   r0   rq   r1   r   K  sF   


)
r   c                       sJ   e Zd ZdZdZ fddZed Zdd Z	ddd	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   t jd }tttd|}|r.||i |nd | _t j|i | i | _	d
 D ]$}t jd|  }t|}|| j	|< qTtd}t|}|| j	d< t| jtrddd	d
ddd}| D ]$\}	}
t|
}|| j	|	< || j	|
< qd S )Nzmathtext.fallback)ZstixZstixsanscmzcal rm tt it bf sfz	mathtext.r   r   STIXGeneralSTIXSizeOneSymSTIXSizeTwoSymSTIXSizeThreeSymSTIXSizeFourSymSTIXSizeFiveSym)r   r   r   r         )r   r   r   StixSansFontsr   r   cm_fallbackr~   r8   r   r  r!   r    
isinstancer   )r7   r   r   Zfallback_rcZfont_clsZtexfontproprJ   Zstixsizedaltfontssizenamer   rq   r0   r1   r8     s:    


zUnicodeFonts.__init__r   c                 C   s   ||fS r   r0   )r7   rt   rK   uniindexr0   r0   r1   _map_virtual_font  s    zUnicodeFonts._map_virtual_fontc                 C   s  zt ||}d}W n. ty@   td}d}td| Y n0 | |||\}}|}|r|dkr|dk rt|}	t	|	d dkst
|	d	rd
}|dkp|| jv }
d}| |}|d ur|jdkr|dkrttd}d}||}|dkrd}|s| jrl|dv r&t| jtr&d
}| j||||}|d j}|ttj v rZd}td|| |S |dv rt| tr| d
|||S td||| d
}| |}d}||}d}
||}|||||
fS )NT?Fz#No TeX to unicode mapping for {!a}.r   i   r   LzGREEK CAPITALr   r   r%   zfonts/ttf/cmsy10.ttf   )r   r}   zComputer ModernzSubstituting symbol %s from %szTFont {!r} does not have a glyph for {!a} [U+{:x}], substituting with a dummy symbol.   )r2   r+   r'   _logwarningr,   r/  chrunicodedatacategoryr-  
startswithr   r   family_namer"   r   _get_data_pathr   r)  r*  r   r   listr   r   valuesrN   r   )r7   rt   rK   rL   rM   r.   r.  found_symbolZnew_fontnamecharr   rJ   
glyphindexr  rZ   r   r0   r0   r1   r     st    










zUnicodeFonts._get_glyphc                 C   s   | j r| j ||S ||fgS r   )r)  ru   rs   r0   r0   r1   ru   2  s
    z.UnicodeFonts.get_sized_alternatives_for_symbol)T)rv   rw   rx   ry   use_cmexr8   r[   r  r   r/  r   ru   r{   r0   r0   rq   r1   r    s   
"
Br  c                       s*   e Zd ZdZdd Zd fdd	Z  ZS )DejaVuFontsFc                 O   s   t | trt|i || _nt|i || _t|i || _tj| g|R i | i | _	| j
dddddd | j
 D ]$\}}t|}|| j	|< || j	|< q|d S )Nr!  r"  r#  r$  r%  )r   r   r   r&  r'  )r*  DejaVuSerifFontsr   r)  r(  r   bakomarm   r8   r   r   updater   r!   r7   r   r   r   r-  r   r0   r0   r1   r8   <  s"    

zDejaVuFonts.__init__Tc           	         st   |dkr| j |||||S t|}| d}|d ur\||}|dkr\t d||||S t |||||S d S )N\primer   r   )rD  r   r2   r   r   r~   )	r7   rt   rK   rL   rM   r.   r.  rJ   r@  rq   r0   r1   r   R  s    




zDejaVuFonts._get_glyph)T)rv   rw   rx   rA  r8   r   r{   r0   r0   rq   r1   rB  9  s   rB  c                   @   s$   e Zd ZdZddddddddZd	S )
rC  zv
    A font handling class for the DejaVu Serif fonts

    If a glyph is not found it will fallback to Stix Serif
    DejaVu SerifzDejaVu Serif:italiczDejaVu Serif:weight=boldDejaVu SansDejaVu Sans MonozDejaVu Serif Displayr   r   r   r   r   r   r   Nrv   rw   rx   ry   r   r0   r0   r0   r1   rC  e  s   rC  c                   @   s$   e Zd ZdZddddddddZdS )	DejaVuSansFontszt
    A font handling class for the DejaVu Sans fonts

    If a glyph is not found it will fallback to Stix Sans
    rI  zDejaVu Sans:italiczDejaVu Sans:weight=boldrJ  zDejaVu Sans DisplayrK  NrL  r0   r0   r0   r1   rM  v  s   rM  c                   @   sZ   e Zd ZdZddddddddd	d
dddZdZdZdZdd Zdd Z	e
 dd ZdS )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.
    r   zSTIXGeneral:italiczSTIXGeneral:weight=boldSTIXNonUnicodezSTIXNonUnicode:italiczSTIXNonUnicode:weight=boldr!  r"  r#  r$  r%  )r   r   r   ZnonunirmZnonuniitZnonunibfr   r   r   r   r&  r'  Fc                 O   sR   t j| g|R i | i | _| j D ]$\}}t|}|| j|< || j|< q(d S r   )rm   r8   r   r   r   r!   rF  r0   r0   r1   r8     s    
zStixFonts.__init__c           
      C   sb  t |}| jr.|d u r.|dvr.t d }d}nd}|d urt|trnz|| }W n tyl   |d }Y n0 d}t|}||k r|| d }|| }	||	d k r|}qz||	d krqqz|d }qz|	d |  kr|	d krn n||	d  |	d	  }|	d }n|sd}tjd
 }|dv r,t	||}|dv rZd|  krNdkrZn nd| }||fS )N)r}   r|   r   TFr   r   r   r   r   r   )r   r   )r   r   r   i   i  Znonuni)
r   r   _sansr*  dictr*   r   r   r   r   )
r7   rt   rK   r.  mappingZdoing_sans_conversionlohiZmidranger0   r0   r1   r/    sD    



"


&zStixFonts._map_virtual_fontc                    sx   ddddddd}| ||}zt|W n tyF   ||fg Y S 0  fdd	td
D }|dkrt|d d }|S )Nr   r   r   r   u   ⟨u   ⟩)r  r  r  r  r  r  c                    s,   g | ]$}  |d kr|tfqS )r   )r   r   r6  )r   r   r7   r.  r0   r1   r     s   z?StixFonts.get_sized_alternatives_for_symbol.<locals>.<listcomp>   r  )r   r2   r+   rT  )r7   rt   rL   fixesalternativesr0   rU  r1   ru     s    z+StixFonts.get_sized_alternatives_for_symbolN)rv   rw   rx   ry   r   rA  r)  rO  r8   r/  	functools	lru_cacheru   r0   r0   r0   r1   r     s*   1r   c                   @   s   e Zd ZdZdZdS )r(  zd
    A font handling class for the STIX fonts (that uses sans-serif
    characters by default).
    TN)rv   rw   rx   ry   rO  r0   r0   r0   r1   r(    s   r(  c                       s   e Zd ZdZeedZddddddd	d
Zd fdd	Z	e
dedd Zdd ZdddZ fddZdd Zdd Z  ZS )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/afmZpzcmi8aZpncr8aZpcrr8aZpncri8aZphvr8aZpncb8aZpsyr)r   r   r   r   r   r   NNc                    s   |d u rddl m} | }t || i | _i | _t|d| jd}|d u r^tdd| jd}t	|d}t
|}W d    n1 s0    Y  ||_|| jd< || jd< d S )	Nr   )mathtextafm)Zfontext	directoryZ	Helveticarbr|   r}   ) r]  ZMathtextBackendPathr~   r8   r   fontsr!   basepathopenr   rZ   )r7   r4   r5   r]  r   fdr   rq   r0   r1   r8     s$    &
zStandardPsFonts.__init__r9   c                 C   s   t  S r   r   r;   r0   r0   r1   <lambda>%  r   zStandardPsFonts.<lambda>c                 C   s   || j v r| j | }n|}| j|}|d u rtj| j|d }t|d}t|}W d    n1 sj0    Y  ||_	|| j|< || j|
 < |S )Nz.afmr`  )r   rb  r   r   r   joinrc  rd  r   rZ   get_fontname)r7   rJ   r   r   rZ   re  r0   r0   r1   r   '  s    
&
zStandardPsFonts._get_fontTc                    s  ||||f}| j |}|dur$|S |dkrLt|dksHt|dsLd}d}	|tv rrt| \}}
t|
}d}	n.t|dkr|}t|}
d}	nt	
d| |dk}| |}|	rz||}W n, ty   t	
d	| | d}	Y n0 |	sd
}t|}
||}d}d|   fdd||D \}}}}tj||  ||  ||  |||| || || |d	}tj||| |||
||d| j |< | j | S )z0Load the cmfont, metrics and glyph with caching.Nr   r   r1  r   FTz.No TeX to built-in Postscript mapping for {!r}z2No glyph in standard Postscript font {!r} for {!r}r0  r   MbP?c                    s   g | ]}|  qS r0   r0   r   Zscaler0   r1   r   i  s   z-StandardPsFonts._get_info.<locals>.<listcomp>)	r   rR   rS   r   r   r   r   r   r   r   )r   r   r   r7  r8  r9  r   r6  r'   r4  r5  r,   r   Zget_name_charr*   rh  Zget_bbox_charr   r   Zget_width_charZget_height_char)r7   rt   rK   rL   rM   rF   r.   r   tupr>  r]   r   r   rJ   r   r   r   r   r   r   rI   r0   rj  r1   rH   7  s    




zStandardPsFonts._get_infoc
                    sn   ||krR||krR|  |||||	}
|  |||||	}|
j}||
j|jd | S t |||||||||		S Nri  )rH   rJ   Zget_kern_distr   r~   rG   r   rq   r0   r1   rG     s    
zStandardPsFonts.get_kernc                 C   s   |  |}| d | S rl  )r   ri   rh   r0   r0   r1   ri     s    
zStandardPsFonts.get_xheightc                 C   s   |  |}| d | S rl  )r   rj   rh   r0   r0   r1   rj     s    
z'StandardPsFonts.get_underline_thickness)N)T)rv   rw   rx   ry   strr   r;  rc  r   r8   r   rz   propertyZpswriterr   rH   rG   ri   rj   r{   r0   r0   rq   r1   r\    s"   

Nr\  ffffff?rV  c                   @   s0   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
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?ro  333333?      ?g?皙?皙?N)rv   rw   rx   ry   script_spacesubdropsup1sub1sub2deltadelta_slanteddelta_integralr0   r0   r0   r1   rp    s   rp  c                   @   s,   e Zd ZdZdZdZdZdZdZdZ	dZ
dS )ComputerModernFontConstantsg333333?rt  g?rr  N)rv   rw   rx   rv  rw  rx  ry  rz  r{  r|  r}  r0   r0   r0   r1   r~    s   r~  c                   @   s$   e Zd ZdZdZdZdZdZdZdS )STIXFontConstantsru  皙?333333?rq  rr  N)	rv   rw   rx   rv  rx  rz  r{  r|  r}  r0   r0   r0   r1   r    s   r  c                   @   s   e Zd ZdZdZdZdZdS )STIXSansFontConstantsrq  r  r  rr  N)rv   rw   rx   rv  rx  r|  r}  r0   r0   r0   r1   r    s   r  c                   @   s   e Zd ZdS )DejaVuSerifFontConstantsNrv   rw   rx   r0   r0   r0   r1   r    s   r  c                   @   s   e Zd ZdS )DejaVuSansFontConstantsNr  r0   r0   r0   r1   r    s   r  )rI  rJ  rH  r   r   r   r   r   r   r   r   rN  r%  r$  r#  r"  r!  zBitstream Vera SanszBitstream Verac                 C   s4   t | j| jjt}|tu r0t| jt	r0t
S |S r   )_font_constant_mappingr   font_outputr   rJ   r:  rp  r  r*  r(  r  )state	constantsr0   r0   r1   _get_font_constant_set  s    
r  c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )NodezA node in the TeX box model.c                 C   s
   d| _ d S Nr   r,  r;   r0   r0   r1   r8   )  s    zNode.__init__c                 C   s   | j jS r   )rr   rv   r;   r0   r0   r1   __repr__,  s    zNode.__repr__c                 C   s   dS Nr=   r0   )r7   nextr0   r0   r1   r   /  s    zNode.get_kerningc                 C   s   |  j d7  _ dS )z
        Shrinks one level smaller.  There are only three levels of
        sizes, after which things will no longer get smaller.
        r   Nr  r;   r0   r0   r1   shrink2  s    zNode.shrinkc                 C   s   |  j d8  _ dS )zb
        Grows one level larger.  There is no limit to how big
        something can get.
        r   Nr  r;   r0   r0   r1   grow9  s    z	Node.growc                 C   s   d S r   r0   r7   r   yr0   r0   r1   render@  s    zNode.renderN)
rv   rw   rx   ry   r8   r  r   r  r  r  r0   r0   r0   r1   r  &  s   r  c                       s@   e Zd ZdZ fddZ fddZ fddZdd	 Z  ZS )
Boxz A node with a physical location.c                    s    t    || _|| _|| _d S r   )r~   r8   rR   rS   rT   )r7   rR   rS   rT   rq   r0   r1   r8   G  s    
zBox.__init__c                    sB   t    | jtk r>|  jt9  _|  jt9  _|  jt9  _d S r   )r~   r  r,  NUM_SIZE_LEVELSrR   SHRINK_FACTORrS   rT   r;   rq   r0   r1   r  M  s
    

z
Box.shrinkc                    s8   t    |  jt9  _|  jt9  _|  jt9  _d S r   )r~   r  rR   GROW_FACTORrS   rT   r;   rq   r0   r1   r  T  s    
zBox.growc                 C   s   d S r   r0   rb   r0   r0   r1   r  Z  s    z
Box.render)	rv   rw   rx   ry   r8   r  r  r  r{   r0   r0   rq   r1   r  D  s
   r  c                       s    e Zd ZdZ fddZ  ZS )Vboxz$A box with only height (zero width).c                    s   t  d|| d S r  r~   r8   )r7   rS   rT   rq   r0   r1   r8   a  s    zVbox.__init__rv   rw   rx   ry   r8   r{   r0   r0   rq   r1   r  ^  s   r  c                       s    e Zd ZdZ fddZ  ZS )Hboxz.A box with only width (zero height and depth).c                    s   t  |dd d S r  r  r7   rR   rq   r0   r1   r8   h  s    zHbox.__init__r  r0   r0   rq   r1   r  e  s   r  c                       sb   e Zd ZdZd fdd	Zdd Zdd Zd	d
 Zdd Zdd Z	 fddZ
 fdd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`.
    Tc                    sJ   t    || _|j| _|j| _|j| _|j| _|j| _|| _| 	  d S r   )
r~   r8   r  r  rJ   rK   rM   rF   r.   _update_metrics)r7   r  r  r.   rq   r0   r1   r8   y  s    
zChar.__init__c                 C   s
   d| j  S )Nz`%s`)r  r;   r0   r0   r1   r    s    zChar.__repr__c                 C   s`   | j | j| j| j| j| j| j }| _| jdkr<|j	| _
n|j
| _
|j| _|j|j  | _d S )N )r  rO   rJ   rK   r  rM   rF   r.   _metricsr   rR   r   rS   rT   r7   rI   r0   r0   r1   r    s    


zChar._update_metricsc                 C   s   | j jS r   )r  r   r;   r0   r0   r1   
is_slanted  s    zChar.is_slantedc                 C   sR   | j j| j }d}t|trJ| 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   rR   r*  r  r  rG   rJ   rK   r  rM   rF   )r7   r  r   kernr0   r0   r1   r     s    
zChar.get_kerningc              	   C   s&   | j ||| j| j| j| j| j dS )z4
        Render the character to the canvas
        N)r  r^   rJ   rK   r  rM   rF   r  r0   r0   r1   r    s    zChar.renderc                    sP   t    | jtk rL|  jt9  _|  jt9  _|  jt9  _|  jt9  _d S r   )	r~   r  r,  r  rM   r  rR   rS   rT   r;   rq   r0   r1   r    s    

zChar.shrinkc                    sF   t    |  jt9  _|  jt9  _|  jt9  _|  jt9  _d S r   )r~   r  rM   r  rR   rS   rT   r;   rq   r0   r1   r    s
    
z	Char.grow)T)rv   rw   rx   ry   r8   r  r  r  r   r  r  r  r{   r0   r0   rq   r1   r  l  s   r  c                       s<   e Zd ZdZdd Z fddZ fddZdd	 Z  ZS )
Accentz
    The font metrics need to be dealt with differently for accents,
    since they are already offset correctly from the baseline in
    TrueType fonts.
    c                 C   sJ   | j | j| j| j| j| j }| _|j|j	 | _
|j|j | _d| _d S r  )r  rO   rJ   rK   r  rM   rF   r  r   r   rR   r   r   rS   rT   r  r0   r0   r1   r    s    
zAccent._update_metricsc                    s   t    |   d S r   )r~   r  r  r;   rq   r0   r1   r    s    
zAccent.shrinkc                    s   t    |   d S r   )r~   r  r  r;   rq   r0   r1   r    s    
zAccent.growc              	   C   s6   | j || jj || jj | j| j| j| j| j	 dS )z5
        Render the character to the canvas.
        N)
r  r^   r  r   r   rJ   rK   r  rM   rF   r  r0   r0   r1   r    s    zAccent.render)	rv   rw   rx   ry   r  r  r  r  r{   r0   r0   rq   r1   r    s
   r  c                       sX   e Zd ZdZ fddZ fddZedd Zdd	 Z fd
dZ	 fddZ
  ZS )Listz0A list of nodes (either horizontal or vertical).c                    s2   t  ddd d| _|| _d| _d| _d| _d S )Nr=   r   )r~   r8   shift_amountchildrenglue_set	glue_sign
glue_orderr7   elementsrq   r0   r1   r8     s    zList.__init__c              
      s4   dt   | j| j| j| jddd | jD f S )Nz![%s <%.02f %.02f %.02f %.02f> %s]r  c                 S   s   g | ]}t |qS r0   )reprr   r   r0   r0   r1   r     r   z!List.__repr__.<locals>.<listcomp>)r~   r  rR   rS   rT   r  rg  r  r;   rq   r0   r1   r    s    zList.__repr__c                 C   s4   t t| ddd D ]}| | dkr|  S qdS )z
        Determine the highest order of glue used by the members of this list.

        Helper function used by vpack and hpack.
        NrW  r   )rT  r   )totalsr   r0   r0   r1   _determine_order  s    
zList._determine_orderc                 C   sh   |  |}|| _|| _|| dkr2|||  | _nd| _d| _|dkrdt| jrdtd|| j	j
|  d S )Nr=   r   z	%s %s: %r)r  r  r  r  
glue_ratior   r  r4  r5  rr   rv   )r7   r   signr  Z
error_typer   r0   r0   r1   	_set_glue  s    


zList._set_gluec                    sH   | j D ]}|  qt   | jtk rD|  jt9  _|  jt9  _d S r   )r  r  r~   r,  r  r  r  r  r7   childrq   r0   r1   r  
  s    



zList.shrinkc                    s>   | j D ]}|  qt   |  jt9  _|  jt9  _d S r   )r  r  r~   r  r  r  r  rq   r0   r1   r    s
    


z	List.grow)rv   rw   rx   ry   r8   r  staticmethodr  r  r  r  r{   r0   r0   rq   r1   r    s   	
r  c                       s4   e Zd ZdZd fdd	Zdd Zdd	d
Z  ZS )HlistzA horizontal list of boxes.r=   
additionalTc                    s$   t  | |r|   |   d S r   )r~   r8   r  hpack)r7   r  rV   r   do_kernrq   r0   r1   r8     s    zHlist.__init__c                 C   s   g }t | j}|r~t|D ]\}| j| }||d k rD| j|d  }nd}|| ||}|dkrt|}|| q|| _dS )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.
        r   Nr=   )r   r  rT  appendr   Kern)r7   new_childrenZnum_childrenr   elemr  Zkerning_distancer  r0   r0   r1   r  #  s    



z
Hlist.kernc                 C   s  d}d}d}dgd }dgd }| j D ]}t|trX||j7 }t||j}t||j}q&t|tr||j7 }t	|jst	|jst
|dd}	t||j|	 }t||j|	 }q&t|tr|j}
||
j7 }||
j  |
j7  < ||
j  |
j7  < q&t|tr&||j7 }q&|| _|| _|dkr*||7 }|| _|| }|dkrXd| _d| _d| _dS |dkrt| |d|d n| |d	|d
 dS )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  r   Nr   OverfullrW  	Underfull)r  r*  r  rR   maxrS   rT   r  rP   isinfgetattrGlue	glue_specstretch_orderstretchshrink_orderr  r  r  r  r  r  )r7   rV   r   rW   rX   r   total_stretchtotal_shrinkr  r  r  r0   r0   r1   r  J  sJ    












zHlist.hpack)r=   r  T)r=   r  )rv   rw   rx   ry   r8   r  r  r{   r0   r0   rq   r1   r    s   'r  c                       s4   e Zd ZdZd fdd	ZddejfddZ  ZS )	VlistzA vertical list of boxes.r=   r  c                    s   t  | |   d S r   )r~   r8   vpack)r7   r  rW   r   rq   r0   r1   r8     s    zVlist.__init__c                 C   s  d}d}d}dgd }dgd }| j D ]}	t|	trr|||	j 7 }|	j}t|	jst|	dd}
t	||	j|
 }q&t|	t
r||7 }d}|	j}||j7 }||j  |j7  < ||j  |j7  < q&t|	tr|||	j 7 }d}q&t|	tr&tdq&|| _||kr||| 7 }|| _n|| _|dkr0||7 }|| _|| }|dkr^d| _d| _d| _dS |dkrz| |d|d	 n| |d
|d dS )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  r   Nr   r  rW  r  )r  r*  r  rS   rT   rP   r  rR   r  r  r  r  r  r  r  r  r  r  RuntimeErrorr  r  r  r  )r7   rW   r   r   rV   rX   r   r  r  r  r  r  r0   r0   r1   r    sV    











zVlist.vpack)r=   r  )	rv   rw   rx   ry   r8   rP   infr  r{   r0   r0   rq   r1   r    s   r  c                       s(   e Zd ZdZ fddZdd Z  ZS )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`.
    c                    s   t  ||| |j| _d S r   )r~   r8   r  )r7   rR   rS   rT   r  rq   r0   r1   r8     s    zRule.__init__c                 C   s   | j |||| ||  d S r   )r  ra   )r7   r   r  rV   rW   r0   r0   r1   r    s    zRule.render)rv   rw   rx   ry   r8   r  r{   r0   r0   rq   r1   r    s   
r  c                       s"   e Zd ZdZd fdd	Z  ZS )Hrulez.Convenience class to create a horizontal rule.Nc                    sB   |d u r|j |j|j|j}|d  }}t tj||| d S )Nrs  	r  rj   rJ   rM   rF   r~   r8   rP   r  )r7   r  	thicknessrS   rT   rq   r0   r1   r8     s    zHrule.__init__)Nr  r0   r0   rq   r1   r    s   r  c                       s    e Zd ZdZ fddZ  ZS )Vrulez,Convenience class to create a vertical rule.c                    s0   |j |j|j|j}t |tjtj| d S r   r  )r7   r  r  rq   r0   r1   r8     s    zVrule.__init__r  r0   r0   rq   r1   r    s   r  	_GlueSpecz/width stretch stretch_order shrink shrink_orderr=         ?r   r   g      )ZfilfillZfilllZneg_filZneg_fillZ	neg_filllemptyssc                       s8   e Zd ZdZ fddZ fddZ fddZ  ZS )r  a  
    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.)
    c                    sB   t    t|tr tj| }nt|tr0|}ntd|| _d S )Nz.glue_type must be a glue spec name or instance)r~   r8   r*  rm  r  _namedr+   r  )r7   Z	glue_typer  rq   r0   r1   r8     s    


zGlue.__init__c                    s2   t    | jtk r.| j}|j|jt d| _d S NrR   )r~   r  r,  r  r  _replacerR   r  r7   r  rq   r0   r1   r  !  s    

zGlue.shrinkc                    s(   t    | j}|j|jt d| _d S r  )r~   r  r  r  rR   r  r  rq   r0   r1   r  '  s    
z	Glue.grow)rv   rw   rx   ry   r8   r  r  r{   r0   r0   rq   r1   r    s   
r  c                       s    e Zd ZdZ fddZ  ZS )	HCenteredzl
    A convenience class to create an `Hlist` whose contents are
    centered within its enclosing box.
    c                    s&   t  jtdg|tddd d S )Nr  Fr  r~   r8   r  r  rq   r0   r1   r8   3  s    zHCentered.__init__r  r0   r0   rq   r1   r  -  s   r  c                       s    e Zd ZdZ fddZ  ZS )	VCenteredzk
    A convenience class to create a `Vlist` whose contents are
    centered within its enclosing box.
    c                    s"   t  tdg|td d S )Nr  r  r  rq   r0   r1   r8   =  s    zVCentered.__init__r  r0   r0   rq   r1   r  7  s   r  c                       sH   e Zd ZdZdZdZ fddZdd Z fddZ fd	d
Z	  Z
S )r  a  
    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.
    r   c                    s   t    || _d S r   )r~   r8   rR   r  rq   r0   r1   r8   O  s    
zKern.__init__c                 C   s
   d| j  S )Nzk%.02fr  r;   r0   r0   r1   r  S  s    zKern.__repr__c                    s&   t    | jtk r"|  jt9  _d S r   )r~   r  r,  r  rR   r  r;   rq   r0   r1   r  V  s    

zKern.shrinkc                    s   t    |  jt9  _d S r   )r~   r  rR   r  r;   rq   r0   r1   r  [  s    
z	Kern.grow)rv   rw   rx   ry   rS   rT   r8   r  r  r  r{   r0   r0   rq   r1   r  A  s   
r  c                       s    e Zd ZdZ fddZ  ZS )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.
    c                    s"   d | _ d | _d | _t g  d S r   )nucleussubr~   r8   r;   rq   r0   r1   r8   h  s    zSubSuperCluster.__init__r  r0   r0   rq   r1   r  `  s   r  c                       s"   e Zd ZdZd fdd	Z  ZS )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.
    FNc                    s   |j |j|}|j |j|j|j}| }|| }	|D ]4\}
}|
|_t||}|j|j	 |	d|  kr: qpq:d}|jdkr|d u r|	|j|j	  }| j|9  _t||}||j	 }t
 |g || _d S )Nrt  r   )r  ru   rJ   ri   rM   rF   copyr  rS   rT   r~   r8   r  )r7   r  rS   rT   r  alwaysfactorrY  r   Ztarget_totalrt   rL   r?  shiftrq   r0   r1   r8   x  s,    



zAutoHeightChar.__init__)FNr  r0   r0   rq   r1   r  o  s   r  c                       s&   e Zd ZdZdef fdd	Z  ZS )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.
    Fc                    s   |j |j|}| }|D ]&\}}||_|||}	|	j|kr qDq||	j }
| j|
9  _|||}	t |	g |	j| _d S r   )r  ru   rJ   r  rR   rM   r~   r8   )r7   r  rR   r  r  
char_classrY  rt   rL   r?  r  rq   r0   r1   r8     s    



zAutoWidthChar.__init__)rv   rw   rx   ry   r  r8   r{   r0   r0   rq   r1   r    s   r  c                   @   s4   e Zd ZdZdd Zedd Zdd Zdd	 Zd
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.
    c                 C   s8   d| _ d| _d| _d| _|| _||j | _| | d S )Nr   r=   )max_pushcur_scur_vcur_hoff_hrS   off_v	hlist_out)r7   r_   r`   ro   r0   r0   r1   __call__  s    zShip.__call__c                 C   s   | dk rdS | dkrdS | S )Ng    eg    eAr0   )valuer0   r0   r1   clamp  s
    z
Ship.clampc                 C   sV  d}d}|j }|j}| j}| j}|  jd7  _t| j| j| _| j}|jD ]}	t	|	t
r|	| j| j | j| j  |  j|	j7  _qJt	|	tr|  j|	j7  _qJt	|	trt|	jdkr|  j|	j7  _nD| j}
||	j | _t	|	tr| |	 n
| |	 |
|	j | _|| _qJt	|	tr|	j}|	j}|	j}t|rF|j}t|rX|j}|dkr|dkr|| | _|	| j| j | j| j || || _|  j|7  _qJt	|	trJ|	j}|j| }|dkr,|dkr|j|kr,||j7 }t||j | }n(|j!|kr,||j"7 }t||j | }||7 }|  j|7  _qJ|  jd8  _d S )Nr   r=   r   )#r  r  r  r  r  r  r  r  r  r*  r  r  r  r  rR   r  r  r   r  r  r  	vlist_outr  rS   rT   rP   r  r  r  r  r  roundr  r  r  )r7   ro   cur_gcur_gluer  r  Z	base_line	left_edger  r  Zedgerule_height
rule_depth
rule_widthr  r0   r0   r1   r    sn    











zShip.hlist_outc                 C   sH  d}d}|j }|j}|  jd7  _t| j| j| _| j}|  j|j8  _| j}| j}|j	D ]}	t
|	tr||  j|	j7  _qZt
|	trt|	j	dkr|  j|	j|	j 7  _n\|  j|	j7  _||	j | _| j}
|j|	_t
|	tr| |	 n
| |	 |
|	j | _|| _qZt
|	tr|	j}|	j}|	j}t|r<|j}||7 }|dkr4|dkr4|  j|7  _|	| j| j | j| j || qZt
|	tr"|	j}|j| }|dkr
|dkr|j|kr
||j7 }t||j| }n(|j |kr
||j!7 }t||j| }||7 }|  j|7  _qZt
|	t"rZt#dqZ|  jd8  _d S )Nr   r=   r   z1Internal mathtext error: Char node found in vlist)$r  r  r  r  r  r  r  rS   r  r  r*  r  rR   r  r   rT   r  r  r  r  r  rP   r  r  r  r  r  r  r  r  r  r  r  r  r  r  )r7   ro   r  r  r  r  r  Ztop_edger  r  Zsave_vr  r  r   r  r0   r0   r1   r    sp    









zShip.vlist_outN)	rv   rw   rx   ry   r  r  r  r  r  r0   r0   r0   r1   r    s   
	
?r  c                    s     fdd}t  }|| |S )z$Helper class to raise parser errors.c                    s   t | | d S r   r   )r  loctoksmsgr0   r1   raise_errorR  s    zError.<locals>.raise_error)r   setParseAction)r  r  r  r0   r  r1   ErrorP  s    
r  c                       s  e Zd ZdZG dd dejZed Z	ed Z
ed Ze	e
B eB Zed Zed Zed	 Zed
 Zed Zed Zed Zed Zed Zdd Zdd ZG dd dZdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$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&d7d8iZ'd9d: Z(d;d<d=d>d?d@dAdBdCdDdEdBd>d?d@dAd;dFdGdHdIZ)edJ Z*dKdL ee)Z+dMdN Z,dOdP Z-dQdR Z.dSdT Z/dUdV Z0e0 Z1Z2dWdX Z3dYdZ Z4d[d\ Z5d]d^ Z6d_d` Z7dadb Z8 fdcddZ9dedf Z:dgdh Z;didj Z<dkdl Z=dmdn Z>dodp Z?e? Z@ZAdqdr ZBdsdt ZCdudv ZDdwdx ZE  ZFS )y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,   e Zd Ze Ze Ze Ze ZdS )zParser._MathStyleN)	rv   rw   rx   enumautoDISPLAYSTYLE	TEXTSTYLEZSCRIPTSTYLEZSCRIPTSCRIPTSTYLEr0   r0   r0   r1   
_MathStylec  s   r  a  
      + * -
      \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
       zlim 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              
   C   sH	  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  _| jt7dK  _| jt8d9 K  _| j t8d9 K  _ | jt8d9 K  _| j!t8d9 K  _!| jt8dK  _| j)t:t;| j<K  _)| j
t=t8d	|j|j |j  t>d
B  K  _
d}| j't7d| K  _'| j(t=|jt:| j? K  _(| j/t@|jt:t;tA t=t7dB  K  _/| j.|j'|j/B B K  _.| jt7dK  _| j	t=|jt:t;| jC K  _	| jtDt=|jt:g | jE| jF t=tGtH  |j K  _| jt=|jt:t;| jI K  _| j+tG|j|j K  _+| j|j J K  _| j&tD|jtK|j0 |j  K  _&| j"tD|jtL|j0 |j  K  _"| jtD|j+tK|j0 |j K  _| jt=|jt:t;| jM K  _| jt=|jt:dd | jMD  K  _| jtDt=t8d|j"|j" t>dB  K  _| jtDt=t8d|j"|j" t>dB  K  _| jtDt=t8d|j"|j" t>dB  K  _| jt:t;| jNK  _| jt:t;| jOK  _| j#t:t;| jPK  _#| j$t:g | jPdh dK  _$| jtDt=t8d|jtG|j|jB dd |j  |jtG|j|j$B dd |j   |j|j |j   |j& |j" |j" t>dB  K  _| j*tDt=t8dtDtG|jtL|j! |j0  |j! |j" t>dB  K  _*| jtDt=t8d|j"t>dB  K  _| jtDt=t8d |j&|j& t>d!B  K  _| j1tDt=t8d"|j&|j& t>d#B  K  _1| j2t@|jt7d$ K  _2| jtDt=t8d%|jtK|j%|j2B  |j  t>d&B  K  _| j|j(|jB |j.B |j	B |jB |jB |jB |jB |jB |jB |jB |j1B |j*B |jB |jB K  _| j%|j)|j
B |jB |j,B K  _%| j-t:dd'gK  _-| j,tDtG|jtL|j-|j  tG|j |jtG|j B |jB K  _,| j0|j%|jB |j2B K  _0| jt=t8d(|j|jB t>d)B  tDtK|j%|jB  t=t8d* |j#|jB t>d)B  K  _| jtL|j0K  _| jtQd+dd,d-K  _| jt7d.B K  _| j|jtK|j|j  tR  K  _t3|4 D ]2\}}|5d	s tS| |	r |TtU| | 	q |j| _V|j| _Wd S )/N_z[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)z[-+]?[0-9]+r   r   r   r   r&   z\hspacezExpected \hspace{n}u   -🿿z;([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])z(?=[^A-Za-z]|$)z'+c                 S   s   g | ]}d | qS r.   r0   r  r0   r0   r1   r   !  r   z#Parser.__init__.<locals>.<listcomp>z\fraczExpected \frac{num}{den}z\dfraczExpected \dfrac{num}{den}z\binomzExpected \binom{num}{den}r  z\genfracra  )r|   z<Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}z\sqrtzExpected \sqrt{value}z	\overlinezExpected \overline{value}z\oversetz#Expected \overset{body}{annotation}z	\undersetz$Expected \underset{body}{annotation}z	[A-Za-z]*z\operatornamezExpected \operatorname{value}r  z\leftzExpected a delimiterz\rightr   F)unquoteResultsz(?:(?:\\[$])|[^$])*)Xr   r   r   accentZ
ambi_delimZ
apostrophe
auto_delimbinomZbslashc_over_ccustomspace	end_groupZfloat_literalrJ   fracdfracfunctiongenfracgroupZint_literalZ	latexfontZlbracketZ
left_delimZlbracemainr.   math_stringnon_mathoperatornameoverlineoversetZ	placeablerbraceZrbracketrequired_groupZright_delimZright_delim_safesimplesimple_groupZsingle_symbolaccentprefixedspacesqrtstart_groupsubsuperZ
subsuperopr-   r   tokenundersetunknown_symbolvarsr   r9  setNamer   r	   suppressr
   r<  _space_widthsr   r  _accentprefixedr   r   leaveWhitespace_char_over_charsr   _accent_map_wide_accentsr   r   _function_namesr  r   r   
_fontnames_ambi_delim_left_delim_right_delimr   r   hasattrr  r  _expression_math_expression)r7   r  r   r   Zunicode_ranger0   r0   r1   r8     s>   
$$"





"







	





zParser.__init__c                 C   s   |  |dd||g| _i | _z| j|}W nP ty| } z8tdd|jd|j	d  d t
|g|W Y d}~n
d}~0 0 d| _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   
ra  r  r   r  Nr   )State_state_stack_em_width_cacher>  parseStringr   r+   rg  linecolumnrm  
resetCache)r7   r  Zfonts_objectrM   rF   rp   r/   r0   r0   r1   parse  s"    
zParser.parsec                   @   s:   e Zd ZdZdd Zdd Zedd Zejdd Zd	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.
        c                 C   s"   || _ || _|| _|| _|| _d S r   )r  _fontrK   rM   rF   )r7   r  rJ   rK   rM   rF   r0   r0   r1   r8     s
    zParser.State.__init__c                 C   s   t | j| j| j| j| jS r   )r	  rA  r  rJ   rK   rM   rF   r;   r0   r0   r1   r    s    zParser.State.copyc                 C   s   | j S r   )rI  r;   r0   r0   r1   rJ     s    zParser.State.fontc                 C   s   |dv r|| _ || _d S )N)r   r   r   )rK   rI  )r7   r-  r0   r0   r1   rJ     s    N)	rv   rw   rx   ry   r8   r  rn  rJ   setterr0   r0   r0   r1   rA    s   
rA  c                 C   s
   | j d S )z&Get the current `State` of the parser.rW  )rB  r;   r0   r0   r1   	get_state  s    zParser.get_statec                 C   s   | j   dS )zPop a `State` off of the stack.N)rB  popr;   r0   r0   r1   	pop_state  s    zParser.pop_statec                 C   s   | j |    dS )z=Push a new `State` onto the stack, copying the current state.N)rB  r  rK  r  r;   r0   r0   r1   
push_state  s    zParser.push_statec                 C   s
   t |gS r   r  r7   r  r  r  r0   r0   r1   r    s    zParser.mainc                 C   s   | j |d dd S )Nr   r   rW  )r?  rD  rP  r0   r0   r1   r    s    zParser.math_stringc                 C   s   t |}|   |gS r   )r  rM  r7   r  r  r  hlistr0   r0   r1   r.     s    zParser.mathc                    sH   |d  dd} fdd|D }t|}   tjd   _|gS )Nr   z\$r   c                    s   g | ]}t |  d dqS )Fr  )r  rK  r   r  r;   r0   r1   r   	  r   z#Parser.non_math.<locals>.<listcomp>r   )replacer  rN  r   r   rK  rJ   )r7   r  r  r  symbolsrR  r0   r;   r1   r  	  s    zParser.non_mathc                 C   sh   |   }|j|j|jf}| j|}|d u r\|j|jtj	d d|j|j}|j
}|| j|< t|| S )Nr   r   )rK  rJ   rM   rF   rC  r   r  rO   r   r   r   r  )r7   
percentager  r   rR   rI   r0   r0   r1   _make_space	  s    
zParser._make_spacegKqU?g0Bxq?g%?g1ZGU?rs  r   r   gKqUſ)\,z
\thinspacez\/z\>z\:z\;z\ r  z\enspacez\quadz\qquadz\!c                 C   s    |\}| j | }| |}|gS r   )r2  rW  )r7   r  r  r  tokr]   ro   r0   r0   r1   r(  (	  s    

zParser.spacec                 C   s   |  t|d gS r  )rW  floatrP  r0   r0   r1   r  .	  s    zParser.customspacec           	   
   C   s  |\}zt ||  }W n6 tyN } zt||d| |W Y d }~n
d }~0 0 || jv rtdd |d | d d d D d}|| jv rt|d |  dks|dks|| j	v r|gS t
| d|| dgd	d
gS n|| jv r|dkrRtdd |d | d d d D d}tdd ||d d  D d}|dkrR|dkrR|gS |dkr||d   r||d   r|gS t
|| dgd	d
gS |gS )NUnknown symbol: %sc                 s   s   | ]}|d kr|V  qdS r  Nr0   rS  r0   r0   r1   	<genexpr><	  r   z Parser.symbol.<locals>.<genexpr>rW  ra  r   r   rt  Tr  r  c                 s   s   | ]}|d kr|V  qdS r\  r0   rS  r0   r0   r1   r]  K	  r   c                 s   s   | ]}|d kr|V  qdS r\  r0   rS  r0   r0   r1   r]  L	  r   r   r   r	  )r  rK  r+   r   _spaced_symbolsr  _binary_operatorsr   r  r;  r  rW  _punctuation_symbolsisdigit)	r7   r  r  r  r  r?  r/   Z	prev_char	next_charr0   r0   r1   r-   1	  sF    
&



& .zParser.symbolc                 C   s   |\}t ||d| d S )Nr[  r  )r7   r  r  r  r  r0   r0   r1   r.  Y	  s    zParser.unknown_symbolZAA))r   Ar  )N\circrs  r=   c                 C   s  |\}|   }|j|j|j|j}| j|d\}}}	|d u rHtd|	 }
|d d urf|d |
_|
 j|d 9  _t
|d |
}|	 }|d d ur|d |_| j|d 9  _t|d |}t|j|j}t|g}||d t|g}||d t|td||	 |gS )N)NNr=   zError parsing symbolr   r   r   exactlyr=   )rK  r  rj   rJ   rM   rF   r5  r   r   r  r  r  r  rR   r  r  r  r  )r7   r  r  r  rL   r  r  Z
under_descZ	over_descr(  Z
over_stateZoverZunder_stateZunderrR   Zover_centeredZunder_centeredr0   r0   r1   r  d	  s:    



zParser.c_over_cz\circumflexaccentz\combiningbrevez\combiningoverlinez\combininggraveaccentz\combiningacuteaccentz\combiningtildez\combiningdotabovez\combiningdiaeresisz\combiningthreedotsabovez\combiningfourdotsabovez\combiningrightarrowabovez\rightarrowz
\leftarrowrd  )ZhatZbrevebarZgraveacutetildedotZddotZdddotZddddotZvecr   `r   r  r	  r  ZoverrightarrowZoverleftarrowmathringzwidehat widetilde widebarc                    s    fddt D S )Nc                    s&   g | ] t  fd dD r qS )c                 3   s    | ]}  |o| kV  qd S r   )r9  )r   ar  r0   r1   r]  	  r   z-Parser.<lambda>.<locals>.<listcomp>.<genexpr>)any)r   amrm  r1   r   	  s   z#Parser.<lambda>.<locals>.<listcomp>)r   ro  r0   ro  r1   rf  	  s   
zParser.<lambda>c           
      C   s   |   }|j|j|j|j}|\\}}|| jv rJtd| |j|t	d}nt	| j
| |}|dkrr|  |  tt|jd |g}	|	|jd t|	td|d t|ggS )Nr&   )r  rk  g      @re  r=          @)rK  r  rj   rJ   rM   rF   r7  r  rR   r  r6  r  r  r  r  r  r  r  )
r7   r  r  r  r  r  r  rL   Z
accent_boxZcenteredr0   r0   r1   r  	  s(    

zParser.accentc                 C   s   |  |||}|\|_|S r   )r   function_namerQ  r0   r0   r1   r  	  s    zParser.functionc           
      C   s  |    |  }d|_g }|d D ]N}t|trJd|_|  || q"t|trf|t|| q"|| q"|t|d  d }t|d t	r|td7 }t
dd ||d  D d}| j| jB | jB }	|	dd	hO }	||	vr
|d | jvr
|| | jd
 g7 }|   t|S )Nr   r   r   zoperatorname{}c                 s   s   | ]}|d kr|V  qdS r\  r0   rS  r0   r0   r1   r]  	  r   z&Parser.operatorname.<locals>.<genexpr>ra  r  r  rX  )rN  rK  rJ   r*  r  r  r  rm  r   r   r  r;  r:  r<  _overunder_functionsrW  r2  rM  r  )
r7   r  r  r  r  Z
hlist_listr  Znext_char_locrb  
delimitersr0   r0   r1   r   	  s0    


zParser.operatornamec                 C   s*   |    t|r&|d dd  |  _g S )Nr   r&  )rN  r   rK  rJ   rP  r0   r0   r1   r*  	  s    zParser.start_groupc                 C   s   t |d }|gS r  rO  )r7   r  r  r  grpr0   r0   r1   r  	  s    zParser.groupc                 C   s   |    g S r   )rM  rP  r0   r0   r1   r  	  s    zParser.end_groupc                 C   s   |\}||   _g S r   )rK  rJ   )r7   r  r  r  r-  r0   r0   r1   rJ   	  s    
zParser.fontc                 C   s:   t |tr|j| jv S t |tr6t|dr6|j| jv S dS )Nrr  F)r*  r  r  _overunder_symbolsr  r=  rr  rs  r7   r  r0   r0   r1   is_overunder	  s
    
zParser.is_overunderc                 C   s   t |tr|j| jv S dS NF)r*  r  r  _dropsub_symbolsrw  r0   r0   r1   
is_dropsub	  s    
zParser.is_dropsubc                 C   s   t |tr| S dS ry  )r*  r  r  rw  r0   r0   r1   r  	  s    
zParser.is_slantedc                 C   s   dS ry  r0   )r7   r  r  r0   r0   r1   is_between_brackets
  s    zParser.is_between_bracketsc           &         s  t |dksJ d }d }d }d}g }|d D ]L}	t|	trP|	dvrP|t |	7 }q,t|	trn|	jdkrn|d7 }q,||	 q,|}t |dkr|sJ td} nt |dkr|s|d S |d }nt |dv rt |dkr|d ntd}|dd  \}
}|
d	kr
|}n|}nt |d
v rt |dkr4|d ntd}|dd  \}}}}||krv|d	krntdntd|d	kr|}|}n|}|}ntd|  }|j	
|j|j|j}|j	|j|j|j}|r |d u rtg }t|D ]}|j| ||dg q|  |  | |r4g }d}|j}|d urX|  t||j}|d urv|  t||j}|d }|d urt|g}||d ||td|g t|g}||d || |d urt|g}||d |td||g |j| }t|}||j |_t|g}|gS |}t|tr|j}t |rt|d t rt!|d dr|d d }|d }t!|dr|j"j#|_t|dd}n t|tr|j"j#|_t|g}t$|}|j}d}| %|r|j}|j&| }|j&| } | '|rr||j&| 7 }||j(||d d   7 }| %|rnd|j& |j) | } d|j& |j) | }nd} |d u rtt | |g}!|!  | %|r||j*|  }"n
|j+| }"|"|!_ntt ||g}!|!  | %|r||j*|  }#n
|j,| }#|d u r|# |!_ntt | |g}$|$  | %|rH||j*|  }"n
|j-| }"d| |#|!j |$j|"   }%|%dkr|#|%7 }#t|!t |#|!j |$j|"  |$g}!|"|!_| %|s|! j|j.| 7  _t||!g}|gS )Nr   r   )r  r  r   r=   )r   r   r   r  )r&  r'  r'  zDouble subscriptzDouble superscriptzOSubscript/superscript sequence is too long. Use braces { } to remove ambiguity.rG        @re  rW  r  Fr  rq  )/r   r*  rm  r  r  r  r  r   rK  r  rj   rJ   rM   rF   ri   r  rT  r  extendr-   r  r  rx  rR   r  r  r  r  rS   r  rT   r  r  r=  r  r   r  r{  r{  r  r|  r}  rw  ry  rx  rz  rv  )&r7   r  r  r  r  r  r~   ZnapostrophesZnew_toksrY  opr  Zop1Znext1Zop2Znext2r  Zrule_thicknessr   r   vlistr  rR   vgaprR  rp   	last_charr  r  Z	lc_heightZlc_baselineZ	superkernZsubkernr   Z
shift_downZshift_upr  Zclrrq   r0   r1   r+  
  s6   

















	












zParser.subsuperc                 C   s<  |   }|j|j|j|j}t|}|| jjurB|	  |	  t
|g}	t
|g}
t|j|j}|	|d |
|d t|	td|d t||td|d |
g}|j|jtjd d|j|j}|
j|j|j d |d   }||_t|t|d gg}|s|r8|dkrd	}|dkr*d	}| |||S |S )
Nre  r   rq  r   =r   r  ra  r	  )rK  r  rj   rJ   rM   rF   rZ  r  r  r  r  r  rR   r  r  r  r  rO   r   r   rS   r   r   r  r  r  _auto_sized_delimiter)r7   ZldelimZrdelimZrulestyler]   denr  r  ZcnumZcdenrR   r  rI   r  rp   r0   r0   r1   _genfrac
  sJ    

	


zParser._genfracc                 C   s   |\}| j | S r   )r  )r7   r  r  r  r   r0   r0   r1   r  
  s    zParser.genfracc                 C   s@   |   }|j|j|j|j}|\\}}| dd|| jj||S Nra  )	rK  r  rj   rJ   rM   rF   r  r  r  r7   r  r  r  r  r  r]   r  r0   r0   r1   r  
  s    
zParser.fracc                 C   s@   |   }|j|j|j|j}|\\}}| dd|| jj||S r  )	rK  r  rj   rJ   rM   rF   r  r  r  r  r0   r0   r1   r  
  s    
zParser.dfracc                 C   s"   |\\}}|  ddd| jj||S )Nr   r   r=   )r  r  r  )r7   r  r  r  r]   r  r0   r0   r1   r    s    
zParser.binomc                 C   s   |\\}}|   }|j|j|j|j}|  t|g}t|g}	t|j	|	j	}
|
|
d |	
|
d |d }||d  dkrt|	td||g}|	j|j | |_nt|td||	g}|S )Nre  r   r   ur   )rK  r  rj   rJ   rM   rF   r  r  r  rR   r  r  r  rT   rS   r  )r7   r  r  r  
annotationbodyr  r  ZcannotationZcbodyrR   r  r  r0   r0   r1   _genset  s.    


zParser._gensetc                 C   s2  |\\}}|   }|j|j|j|j}|j|j |d  }|j|j }	t	d||	|dd}
|
j|
j }|
j|
j }	t
td| |td| g}tt|td|g}|||j|j d  d|	 |st|
jd	 d
d
}nt
|}|  |  tt
|gg}| d |_t
|t|
j d	 |
|g}|gS )Ng      @r  T)r  r   r       @re  rs  r=   r  )rK  r  rj   rJ   rM   rF   rS   r  rT   r  r  r  r  r  r  r  r  rR   r  r  )r7   r  r  r  rootr  r  r  rS   rT   checkZpadded_body	rightsideZ
root_vlistrR  r0   r0   r1   r)  )  s8    
zParser.sqrtc                 C   s   |\\}|   }|j|j|j|j}|j|j |d  }|j|j }t	t
|tdt|gg}	|	||j|j d  d| t|	g}
|
gS )Nr  r  r  re  )rK  r  rj   rJ   rM   rF   rS   r  rT   r  r  r  r  r  )r7   r  r  r  r  r  r  rS   rT   r  rR  r0   r0   r1   r!  Q  s    
zParser.overlinec           
   	   C   s   |   }t|r:tdd |D }tdd |D }d }nd}d}d}g }|dkrj|t|||||d || |dkr|t|||||d t|}	|	S )Nc                 s   s   | ]}|j V  qd S r   )rS   r  r0   r0   r1   r]  h  r   z/Parser._auto_sized_delimiter.<locals>.<genexpr>c                 s   s   | ]}|j V  qd S r   )rT   r  r0   r0   r1   r]  i  r   r   r  r	  )r  )rK  r   r  r  r  r  r  )
r7   frontmiddlebackr  rS   rT   r  partsrR  r0   r0   r1   r  e  s(    
zParser._auto_sized_delimiterc                 C   s   |\}}}|  || |S r   )r  asList)r7   r  r  r  r  r  r  r0   r0   r1   r  {  s    
zParser.auto_delim)Grv   rw   rx   ry   r
  Enumr  r[   r  r_  Z_relation_symbolsZ_arrow_symbolsr^  r`  rv  rs  rz  r9  r8  r:  r;  r<  r8   rH  rA  rK  rM  rN  r  r  r.   r  rW  r2  r(  r  r-   r'  r.  r5  r  r6  r7  r3  r  r  r   r*  r  r$  r&  r  rJ   rx  r{  r  r|  r+  r  r  r  r  r  r  r"  r-  r)  r!  r  r  r{   r0   r0   rq   r1   r	  Z  s      	&& @)(r	  )T)ery   collectionsr   r
  rZ  ior   loggingr   r   r7  ZnumpyrP   	pyparsingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   Z
matplotlibr   ra  r   r   Z_mathtext_datar   r   r   r   r   r^  r   Zfont_managerr    r!   r"   Zft2fontr#   enablePackrat	getLoggerr4  r2   r3   rm   r   r  rB  rC  rM  r   r(  r\  r  r  r  rp  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Zshipr  r	  r0   r0   r0   r1   <module>   s   P

" lq},l 9$	S=qO	

' 
