
    h                        S r SSKrSSKJr  SSKJr  SSKJrJr  SSK	r	SSK
JrJr  SSKrSSKJrJr  SSKJr   " S	 S
\R&                  \R(                  5      rS r0 / 4S jr\\S.\l         " S S\5      rSS jrS rS rS rg)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                       \ rS rSrSrg)
latex_mathW    N)__name__
__module____qualname____firstlineno____static_attributes__r       N/var/www/html/env/lib/python3.13/site-packages/matplotlib/sphinxext/mathmpl.pyr   r   W   s    r   r   c                 `    [         R                  " U [        R                  R                  5      $ N)r   choicer
   MathTextParser_font_type_mapping)args    r   fontset_choicer   [   s!    S("9"9"L"LMMr   c                     UR                  S5      nXS-   S n[        U5      n	XS'   UR                  SS5      U	S'   UR                  S[        R                  R
                  R                  5      U	S'   U	// 4$ )N`   latexfontsetcmfontsize)findr   getsetupappconfigmathmpl_fontsize)
rolerawtexttextlinenoinlineroptionscontentir"   nodes
             r   	math_roler5   _   sw    SAaCOEgDMkk)T2DO{{:#(99#3#3#D#DFD62:r   r#   r%   c                   8    \ rS rSrSrSrSrSrSr\	\
S.rS rSrg	)
MathDirectivem   zJ
The ``.. mathmpl::`` directive, as documented in the module's docstring.
Tr   Fr6   c                 0   SR                  U R                  5      n[        U R                  5      nXS'   U R                  R                  SS5      US'   U R                  R                  S[        R                  R                  R                  5      US'   U/$ )N r"   r#   r$   r%   )
joinr2   r   
block_textr1   r'   r(   r)   r*   r+   )selfr"   r4   s      r   runMathDirective.runx   sy    %$//*W,,**9d;Y<<++J,1II,<,<,M,MOZvr   r   N)r   r   r   r   __doc__has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   r   option_specr?   r   r   r   r   r8   r8   m   s2     K %,57Kr   r8   c                     [         R                  " X#S.5          [        R                  " SU  S3XSS9nS S S 5        U$ ! [         a    [
        R                  " SU  35        Sn N1f = f! , (       d  f       W$ = f)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%   rJ   depths         r   	latex2pngrS      s    	WL	M	**E7!h?E 
N L  	!B5'JKE		 
N	M Ls&   A*?%A'$A*&A''A**
A9c                    [        U R                  [        R                  5      nU S   nU S   nU S   nSR	                  [
        R                  " U U U 3R                  5       SS9R                  5       SS  5      n[        [        R                  R                  R                  SS	5      nUR                  S
S
S9  Xv S3-  n[        X8XES9n	/ n
[        R                  R                   R"                   Hs  nU SUR%                  SS5       S3n[        X7U-  XES['        US S 5      -  S9  U
R)                  [        R                  R                  R*                   SU SU 35        Mu     U
(       a@  S[        R                  R                  R*                   SU S3SR-                  U
5      -   S-   n
U(       a  SnOSnU(       a  U	S:w  a	  SU	S-   -  nOSnS[        R                  R                  R*                   SU S U
 U U S!3	$ )"Nr"   r#   r%   zmath-{}F)usedforsecurityi_imagesmathmplT)parentsexist_okz.png)r%   -._d   r!   )r%   rJ   z	/mathmpl/ zsrcset="z.png, z, z" r;   zclass="center" r   z)style="position: relative; bottom: -%dpx"r    z
<img src="z.png" z/>)
isinstanceparentr   TextElementrK   hashlibsha256encode	hexdigestr   r(   r)   builderoutdirmkdirrS   r*   mathmpl_srcsetreplacefloatappendimgpathr<   )r4   sourceinliner"   r#   r%   namedestdirdestrR   srcsetsizerQ   clsstyles                  r   
latex2htmlrw      s   U%6%67FME9oGJHggYxj)002!	
 )+cd	D 599$$++Y	BGMM$M.vT]"De7>EF		  //V1T\\#s34D9%8+WE$s),,	.yy  (()8*AdVD	F	 0 UYY..667yfM))F#$&*+ %1*;uqyI**2239TF CxuUG2' (r   c                     [        U R                  R                  5       H-  u  p#US   S:X  a   [        US S 5        M  [        SU< S35      e   g ! [         a    [        SU< S35      ef = f)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*   ri   rk   
ValueErrorr   )r)   r*   r3   rt   s       r   _config_initedr|      s    SZZ6678s?Id3Bi  >th GD DE E 8  I!B4( KH HI IIs   AA-c                    U [         l        U R                  SSS5        U R                  S/ S5         U R                  S[        5        S nS	 nS
 nS nU R                  [        X4X44S9  U R                  S[        5        U R                  S[        5        [        R                  S:  a,  U R                  S[        5        U R                  S[        5        SSS.nU$ ! [
         a    U R                  SS 5         Nf = f)Nr+   g      $@Tri   zconfig-initedzenv-updatedc                     [        U S 5      $ r   )r|   )r)   envs     r   <lambda>setup.<locals>.<lambda>   s    N34Mr   c                 ~    U R                   R                  S   nU R                  R                  [	        X5      5        g )Nrn   )document
attributesbodyrl   rw   )r>   r4   rn   s      r   visit_latex_math_html$setup.<locals>.visit_latex_math_html   s-    ))(3		D12r   c                     g r   r   r>   r4   s     r   depart_latex_math_html%setup.<locals>.depart_latex_math_html       r   c                     [        UR                  [        R                  5      nU(       a"  U R                  R                  SUS   -  5        g U R                  R                  SUS   S/5        g )Nz$%s$r"   z\begin{equation}z\end{equation})r_   r`   r   ra   r   rl   extend)r>   r4   ro   s      r   visit_latex_math_latex%setup.<locals>.visit_latex_math_latex   sZ    DKK):):;IIVd7m34II1"7m/1 2r   c                     g r   r   r   s     r   depart_latex_math_latex&setup.<locals>.depart_latex_math_latex   r   r   )htmlr"   rW   )r       math)parallel_read_safeparallel_write_safe)r(   r)   add_config_valueconnectr|   r   add_noder   add_roler5   add_directiver8   sphinxversion_info)r)   r   r   r   r   metadatas         r   r(   r(      s    EI+T48)2t4OO^4
32 LL,E.H  J LLI&i/V#VY'&-0&*4HHOE  OM#MNOs   C C?>C?)r$   
   r]   )rA   rb   pathlibr   docutilsr   docutils.parsers.rstr   r   r   sphinx.errorsr   r   
matplotlibrL   r	   r
   matplotlib.rcsetupr   GeneralElementr   r   r5   r1   r8   rS   rw   r|   r(   r   r   r   <module>r      s   FP    6  5  % 5	 	N
 "	 !/!79	 I ,&(RE$(r   