
    h                         S r SSKrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
  SSKJrJrJr  \R                  " \5      r\\l         " S S	5      rSSS
.S jjrg)a   
A module for parsing a subset of the TeX math syntax and rendering it to a
Matplotlib backend.

For a tutorial of its usage, see :ref:`mathtext`.  This
document is primarily concerned with implementation details.

The module uses pyparsing_ to parse the TeX expression.

.. _pyparsing: https://pypi.org/project/pyparsing/

The Bakoma distribution of the TeX Computer Modern fonts, and STIX
fonts are supported.  There is experimental support for using
arbitrary fonts, but results may vary without proper tweaking and
metrics for those fonts.
    N)_api	_mathtext)	LoadFlags)FontProperties   )RasterParseVectorParseget_unicode_indexc                       \ rS rSrSr\R                  \R                  \R                  \R                  \R                  \R                  S.rS rS
SS.S jjr\R                   " S5      S 5       rS	rg)MathTextParser%   N)cmdejavuserif
dejavusansstixstixsanscustomc                 \    [         R                  " SSSS.UR                  5       S9U l        g)z
Create a MathTextParser for the given backend *output*.

Parameters
----------
output : {"path", "agg"}
    Whether to return a `VectorParse` ("path") or a
    `RasterParse` ("agg", or its synonym "macosx").
vectorraster)pathaggmacosx)outputN)r   check_getitemlower_output_type)selfr   s     E/var/www/html/env/lib/python3.13/site-packages/matplotlib/mathtext.py__init__MathTextParser.__init__0   s*     !..h(C<<>#    antialiasedc                    Ub  UR                  5       OSn[        R                  " US5      nSSKJn  [
        R                  UR                  5       S.U R                     nU R                  XX4U5      $ )a  
Parse the given math expression *s* at the given *dpi*.  If *prop* is
provided, it is a `.FontProperties` object specifying the "default"
font to use in the math expression, used for all non-math text.

The results are cached, so multiple calls to `parse`
with the same expression should be fast.

Depending on the *output* type, this returns either a `VectorParse` or
a `RasterParse`.
Nztext.antialiasedr   )backend_agg)r   r   )
copympl
_val_or_rcmatplotlib.backendsr&   r   
NO_HINTINGget_hinting_flagr   _parse_cached)r   sdpipropr$   r&   load_glyph_flagss          r   parseMathTextParser.parse>   so    " #.tyy{Dnn[2DE3**!224
 

 !!!$=MNNr"   2   c                    Uc
  [        5       n[        R                  " U R                  UR	                  5       S9nU" X55      nUR                  5       nU R                  c$  [        R                  " 5       U R                  l        U R                  R                  XX5      n	[        R                  " U	5      n
U R                  S:X  a  U
R                  5       $ U R                  S:X  a  U
R                  US9$ g )N)fontsetr   r   r#   )r   r   r   _font_type_mappingget_math_fontfamilyget_size_in_points_parserr   Parser	__class__r2   shipr   	to_vector	to_raster)r   r.   r/   r0   r$   r1   fontset_classr6   fontsizeboxr   s              r   r-   MathTextParser._parse_cachedX   s    <!#D**##T-E-E-GI7**,<<%.%5%5%7DNN"ll  X;$(##%%(*###<< +r"   )r   )H   N)__name__
__module____qualname____firstlineno__r:   r   BakomaFontsDejaVuSerifFontsDejaVuSansFonts	StixFontsStixSansFontsUnicodeFontsr7   r    r2   	functools	lru_cacher-   __static_attributes__ r"   r   r   r   %   sw    G ,, 11 00 ** .. --#O O4 = =r"   r   )colorc                    SSK Jn  [        S5      nUR                  U SUS9u  pn
  nUR	                  US-  U	S-  4S9nUR                  SX-  XUS9  UR                  XUS	9  U
$ )
a  
Given a math expression, renders it in a closely-clipped bounding
box to an image file.

Parameters
----------
s : str
    A math expression.  The math portion must be enclosed in dollar signs.
filename_or_obj : str or path-like or file-like
    Where to write the image data.
prop : `.FontProperties`, optional
    The size and style of the text.
dpi : float, optional
    The output dpi.  If not set, the dpi is determined as for
    `.Figure.savefig`.
format : str, optional
    The output format, e.g., 'svg', 'pdf', 'ps' or 'png'.  If not set, the
    format is determined as for `.Figure.savefig`.
color : str, optional
    Foreground color, defaults to :rc:`text.color`.
r   )figurer   rD   )r/   r0   g      R@)figsize)fontpropertiesrS   )r/   format)
matplotlibrU   r   r2   Figuretextsavefig)r.   filename_or_objr0   r/   rX   rS   rU   parserwidthheightdepth_figs                r   math_to_imagerd   l   sv    . "F#F!'aRd!CE5!Q
--v} =-
>CHHQaEHBKKK8Lr"   )NNN)__doc__rO   loggingrY   r(   r   r   matplotlib.ft2fontr   matplotlib.font_managerr   r   r	   r
   	getLoggerrE   _logrF   r   rd   rR   r"   r   <module>rk      s_   "    & ( 21 1 "  (  D= D=N  r"   