Ë
    ¨eh¿  ã                   ó
  — d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	Z	ddl
mZmZ ddlZddlmZmZ ddlmZ  G d	„ d
ej&                  ej(                  «      Zd„ Zi g fd„Zeedœe_         G d„ de«      Zdd„Zd„ Zd„ Zd„ Zy)aø  
A role and directive to display mathtext in Sphinx
==================================================

The ``mathmpl`` Sphinx extension creates a mathtext image in Matplotlib and
shows it in html output. Thus, it is a true and faithful representation of what
you will see if you pass a given LaTeX string to Matplotlib (see
:ref:`mathtext`).

.. warning::
    In most cases, you will likely want to use one of `Sphinx's builtin Math
    extensions
    <https://www.sphinx-doc.org/en/master/usage/extensions/math.html>`__
    instead of this one. The builtin Sphinx math directive uses MathJax to
    render mathematical expressions, and addresses accessibility concerns that
    ``mathmpl`` doesn't address.

Mathtext may be included in two ways:

1. Inline, using the role::

     This text uses inline math: :mathmpl:`\alpha > \beta`.

   which produces:

     This text uses inline math: :mathmpl:`\alpha > \beta`.

2. Standalone, using the directive::

     Here is some standalone math:

     .. mathmpl::

         \alpha > \beta

   which produces:

     Here is some standalone math:

     .. mathmpl::

         \alpha > \beta

Options
-------

The ``mathmpl`` role and directive both support the following options:

fontset : str, default: 'cm'
    The font set to use when displaying math. See :rc:`mathtext.fontset`.

fontsize : float
    The font size, in points. Defaults to the value from the extension
    configuration option defined below.

Configuration options
---------------------

The mathtext extension has the following configuration options:

mathmpl_fontsize : float, default: 10.0
    Default font size, in points.

mathmpl_srcset : list of str, default: []
    Additional image sizes to generate when embedding in HTML, to support
    `responsive resolution images
    <https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images>`__.
    The list should contain additional x-descriptors (``'1.5x'``, ``'2x'``,
    etc.) to generate (1x is the default and always included.)

é    N)ÚPath)Únodes)Ú	DirectiveÚ
directives)ÚConfigErrorÚExtensionError)Ú_apiÚmathtext)Úvalidate_float_or_Nonec                   ó   — e Zd Zy)Ú
latex_mathN)Ú__name__Ú
__module__Ú__qualname__© ó    úZ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/matplotlib/sphinxext/mathmpl.pyr   r   W   s   „ Ør   r   c                 ó^   — t        j                  | t        j                  j                  «      S ©N)r   Úchoicer
   ÚMathTextParserÚ_font_type_mapping)Úargs    r   Úfontset_choicer   [   s!   € Ü×Ñ˜S¤(×"9Ñ"9×"LÑ"LÓMÐMr   c                 óö   — |j                  d«      }||dz   d }t        |«      }	||	d<   |j                  dd«      |	d<   |j                  dt        j                  j
                  j                  «      |	d<   |	gg fS )Nú`é   éÿÿÿÿÚlatexÚfontsetÚcmÚfontsize)Úfindr   ÚgetÚsetupÚappÚconfigÚmathmpl_fontsize)
ÚroleÚrawtextÚtextÚlinenoÚinlinerÚoptionsÚcontentÚir   Únodes
             r   Ú	math_roler2   _   s{   € à�‰�SÓ€AØ�A�a‘C˜ˆO€EÜ�gÓ€DØ€Dˆ�MØ—k‘k )¨TÓ2€Dˆ�OØ—{‘{ :Ü#(§9¡9×#3Ñ#3×#DÑ#DóF€DˆÑàˆ6�2ˆ:Ðr   ©r    r"   c                   ó0   — e Zd ZdZdZdZdZdZee	dœZ
d„ Zy)ÚMathDirectivezR
    The ``.. mathmpl::`` directive, as documented in the module's docstring.
    Tr   Fr3   c                 ó2  — dj                  | j                  «      }t        | j                  «      }||d<   | j                  j                  dd«      |d<   | j                  j                  dt        j                  j                  j                  «      |d<   |gS )NÚ r   r    r!   r"   )
Újoinr/   r   Ú
block_textr.   r$   r%   r&   r'   r(   )Úselfr   r1   s      r   ÚrunzMathDirective.runx   s{   € Ø—‘˜Ÿ™Ó%ˆÜ˜$Ÿ/™/Ó*ˆØˆˆW‰ØŸ,™,×*Ñ*¨9°dÓ;ˆˆY‰ØŸ<™<×+Ñ+¨JÜ,1¯I©I×,<Ñ,<×,MÑ,MóOˆˆZÑàˆvˆr   N)r   r   r   Ú__doc__Úhas_contentÚrequired_argumentsÚoptional_argumentsÚfinal_argument_whitespacer   r   Úoption_specr;   r   r   r   r5   r5   m   s2   „ ñð €KØÐØÐØ %ÐØ,Ø5ñ7€Kór   r5   c                 óð   — t        j                  ||dœ«      5  	 t        j                  d| › d�||d¬«      }d d d «       |S # t        $ r t        j                  d| › �«       d}Y Œ/w xY w# 1 sw Y   S xY w)N)zmathtext.fontsetz	font.sizeú$Úpng)ÚdpiÚformatz!Could not render math expression r   )ÚmplÚ
rc_contextr
   Úmath_to_imageÚ	Exceptionr	   Úwarn_external)r   Úfilenamer    r"   rE   Údepths         r   Ú	latex2pngrN   ƒ   sƒ   € Ü	�‰¨WÀ8ÑLÓ	Mñ ð	Ü×*Ñ*Ø�E�7˜!�˜h¨C¸ô?ˆE÷ð €Løô ò 	Ü×ÑÐ!BÀ5À'ÐJÔKØŠEð	ú÷	ð €Lús(   ™A+›AÁ#A(Á%A+Á'A(Á(A+Á+A5c                 ó
  — t        | j                  t        j                  «      }| d   }| d   }| d   }dj	                  t        j                  |› |› |› �j                  «       d¬«      j                  «       dd  «      }t        t        j                  j                  j                  dd	«      }|j                  d
d
¬«       ||› d�z  }t        ||||¬«      }	g }
t        j                  j                   j"                  D ]w  }|› d|j%                  dd«      › d�}t        |||z  ||dt'        |d d «      z  ¬«       |
j)                  t        j                  j                  j*                  › d|› d|› �«       Œy |
r@dt        j                  j                  j*                  › d|› d�dj-                  |
«      z   dz   }
|rd}nd}|r|	dk7  r	d|	dz   z  }nd}dt        j                  j                  j*                  › d|› d |
› |› |› d!�	S )"Nr   r    r"   zmath-{}F)ÚusedforsecurityiöÿÿÿÚ_imagesÚmathmplT)ÚparentsÚexist_okz.png)r"   ú-ú.Ú_éd   r   )r"   rE   z	/mathmpl/ú zsrcset="z.png, z, z" r7   zclass="center" r   z)style="position: relative; bottom: -%dpx"r   z
<img src="z.png" z/>)Ú
isinstanceÚparentr   ÚTextElementrF   ÚhashlibÚsha256ÚencodeÚ	hexdigestr   r%   r&   ÚbuilderÚoutdirÚmkdirrN   r'   Úmathmpl_srcsetÚreplaceÚfloatÚappendÚimgpathr8   )r1   ÚsourceÚinliner   r    r"   ÚnameÚdestdirÚdestrM   ÚsrcsetÚsizerL   ÚclsÚstyles                  r   Ú
latex2htmlrr   �   s  € Ü˜Ÿ™¤U×%6Ñ%6Ó7€FØ�‰M€EØ�9‰o€GØ�JÑ€HØ×ÑÜ�‰Øˆg�g�Y˜x˜jÐ)×0Ñ0Ó2Ø!ô	
÷ ‰)‹+�c�dð	ó€Dô ”5—9‘9×$Ñ$×+Ñ+¨Y¸	ÓB€GØ‡M�M˜$¨€MÔ.à˜�v˜T�]Ñ"€DÜ�e˜T 7°XÔ>€Eà€FÜ—	‘	× Ñ ×/Ñ/ò FˆØ�V˜1˜TŸ\™\¨#¨sÓ3Ð4°DÐ9ˆÜ�%˜ 8Ñ+¨W¸xØœE $ s¨ )Ó,Ñ,õ	.à�‰Ü�y‰y× Ñ ×(Ñ(Ð)¨°8°*¸A¸d¸VÐDõ	Fð	Fñ ØœUŸY™Y×.Ñ.×6Ñ6Ð7°yÀÀÀfÐMØ—)‘)˜FÓ#ñ$Ø&*ñ+ˆñ Ø‰àˆÙ�%˜1’*Ø;¸uÀq¹yÑI‰àˆàœŸ™×*Ñ*×2Ñ2Ð3°9¸T¸Fð CØˆx˜�u˜U˜G 2ð'ð (r   c                 óÖ   — t        | j                  j                  «      D ]+  \  }}|d   dk(  r	 t        |d d «       Œt        d|›d�«      ‚ y # t        $ r t        d|›d�«      ‚w xY w)Nr   Úxz,Invalid value for mathmpl_srcset parameter: ze. Must be a list of strings with the multiplicative factor followed by an "x".  e.g. ["2.0x", "1.5x"])Ú	enumerater'   rd   rf   Ú
ValueErrorr   )r&   r'   r0   ro   s       r   Ú_config_initedrw   ¸   s    € ä˜SŸZ™Z×6Ñ6Ó7ò E‰ˆˆ4Ø�‰8�sŠ?ðIÜ�d˜3˜B�iÕ ô Ø>¸t¸hð GDð DóEð EñEøô ò IÜ!ØBÀ4À(ð KHð HóIð IðIús   ¯AÁA(c                 ó
  — | t         _        | j                  ddd«       | j                  dg d«       	 | j                  dt        «       d„ }d	„ }d
„ }d„ }| j                  t        ||f||f¬«       | j                  dt        «       | j                  dt        «       t        j                  dk  r,| j                  dt        «       | j                  dt        «       dddœ}|S # t
        $ r | j                  dd„ «       Y Œ¸w xY w)Nr(   g      $@Trd   zconfig-initedzenv-updatedc                 ó   — t        | d «      S r   )rw   )r&   Úenvs     r   ú<lambda>zsetup.<locals>.<lambda>Ñ   s   € ´NÀ3ÈÓ4M€ r   c                 ó€   — | j                   j                  d   }| j                  j                  t	        ||«      «       y )Nri   )ÚdocumentÚ
attributesÚbodyrg   rr   )r:   r1   ri   s      r   Úvisit_latex_math_htmlz$setup.<locals>.visit_latex_math_htmlÔ   s/   € Ø—‘×)Ñ)¨(Ñ3ˆØ�	‰	×Ñœ D¨&Ó1Õ2r   c                  ó   — y r   r   ©r:   r1   s     r   Údepart_latex_math_htmlz%setup.<locals>.depart_latex_math_htmlØ   ó   € Ør   c                 óÖ   — t        |j                  t        j                  «      }|r"| j                  j                  d|d   z  «       y | j                  j                  d|d   dg«       y )Nz$%s$r   z\begin{equation}z\end{equation})rZ   r[   r   r\   r   rg   Úextend)r:   r1   rj   s      r   Úvisit_latex_math_latexz%setup.<locals>.visit_latex_math_latexÜ   sZ   € Ü˜DŸK™K¬×):Ñ):Ó;ˆÙØ�I‰I×Ñ˜V d¨7¡mÑ3Õ4à�I‰I×ÑÐ1Ø" 7™mØ/ð1õ 2r   c                  ó   — y r   r   r‚   s     r   Údepart_latex_math_latexz&setup.<locals>.depart_latex_math_latexå   r„   r   )Úhtmlr   rR   )r   é   Úmath)Úparallel_read_safeÚparallel_write_safe)r%   r&   Úadd_config_valueÚconnectrw   r   Úadd_noder   Úadd_roler2   Úadd_directiver5   ÚsphinxÚversion_info)r&   r€   rƒ   r‡   r‰   Úmetadatas         r   r%   r%   Ê   sý   € Ø„E„IØ×ÑÐ+¨T°4Ô8Ø×ÑÐ)¨2¨tÔ4ðOØ�‰�O¤^Ô4ò
3òò2òð ‡L�L”Ø,Ð.DÐEØ.Ð0GÐHð ô Jð ‡L�L�œIÔ&Ø×Ñ�i¤Ô/Ü×Ñ˜VÒ#Ø�‰�VœYÔ'Ø×Ñ˜&¤-Ô0à&*À4ÑH€HØ€OøôE ò OØ�‰�MÑ#MÖNðOús   ³C# Ã#DÄD)r!   é
   rX   )r<   r]   Úpathlibr   Údocutilsr   Údocutils.parsers.rstr   r   r”   Úsphinx.errorsr   r   Ú
matplotlibrG   r	   r
   Úmatplotlib.rcsetupr   ÚGeneralÚElementr   r   r2   r.   r5   rN   rr   rw   r%   r   r   r   ú<module>r       s…   ðñFóP Ý å ß 6Û ß 5ã ß %Ý 5ô	�—‘ §¡ô 	òNð
  "ó	ð !/Ø!7ñ9€	Ô ô�Iô ó,ò&(òREó$(r   