rL i dZddlZddlmZddlmZddlmZmZddl Z ddl m Z m Z ddl Zddl mZmZddlmZGd d ej&ej(Zd Zigfd Zeed e_GddeZddZdZdZdZy)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 `__ 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 `__. 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) ConfigErrorExtensionError)_apimathtext)validate_float_or_Nonec eZdZy) latex_mathN)__name__ __module__ __qualname__b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/matplotlib/sphinxext/mathmpl.pyr r Wsrr c^tj|tjjSN)rchoicer MathTextParser_font_type_mapping)args rfontset_choicer[s!   S("9"9"L"L MMrc|jd}||dzd}t|} || d<|jdd| d<|jdtjj j | d<| ggfS)N`latexfontsetcmfontsize)findr getsetupappconfigmathmpl_fontsize) rolerawtexttextlinenoinlineroptionscontentirnodes r math_roler2_s{ SA AaCOE g DDMkk)T2DO{{:#(99#3#3#D#DFD 62:rr r"c0eZdZdZdZdZdZdZee dZ dZ y) MathDirectivezR The ``.. mathmpl::`` directive, as documented in the module's docstring. TrFr3c2dj|j}t|j}||d<|jj dd|d<|jj dt jjj|d<|gS)Nrr r!r") joinr/r block_textr.r$r%r&r'r()selfrr1s rrunzMathDirective.runxs{ %$//*W ,,**9d;Y<<++J,1II,<,<,M,MOZv rN) rrr__doc__ has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacerr option_specr;rrrr5r5ms2K %,57Krr5ctj||d5 tjd|d||d}ddd|S#t$rt j d|d}Y/wxYw#1swYSxYw)N)zmathtext.fontsetz font.size$png)dpiformatz!Could not render math expression r)mpl rc_contextr math_to_image Exceptionr warn_external)rfilenamer r"rEdepths r latex2pngrNs W8L M **E7! hC?E L    !B5'J KE   Ls(A+A#A(%A+'A((A++A5c  t|jtj}|d}|d}|d}dj t j |||jdjdd}ttjjjdd }|jd d ||d z }t|||| } g} tjj j"D]w} |d| j%ddd } t||| z ||dt'| ddz| j)tjjj*d| d| y| r@dtjjj*d|ddj-| zdz} |rd} nd} |r| dk7r d| dzz}nd}dtjjj*d|d | | |d! S)"Nrr r"zmath-{}F)usedforsecurityi_imagesmathmplT)parentsexist_okz.png)r"-._dr)r"rEz /mathmpl/ zsrcset="z.png, z, z" r7zclass="center" rz)style="position: relative; bottom: -%dpx"rz ) isinstanceparentr TextElementrFhashlibsha256encode hexdigestrr%r&builderoutdirmkdirrNr'mathmpl_srcsetreplacefloatappendimgpathr8)r1sourceinlinerr r"namedestdirdestrMsrcsetsizerLclsstyles r latex2htmlrrs  U%6%6 7F ME9oGJH   ggYxj ) 0 0 2!  )+cd  D 599$$++Y BG MM$M. vT] "D eT7X >E F   //FV1T\\#s34D9%8+WxE$s),, . yy  (()8*AdV D F F UYY..667yfM))F#$&*+ %1*;uqyI**2239TFCxuUG2 '(rct|jjD]+\}}|ddk(r t|ddt d|dy#t$rt d|dwxYw)Nrxz,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'rdrf ValueErrorr)r&r'r0ros r_config_initedrwsSZZ667 E4 8s? Id3Bi >thGDDE E E I!B4(KHHII Is AA(c |t_|jddd|jdgd |jdtd}d }d }d }|j t||f||f |jd t|jd ttjdkr,|jdt|jdtddd}|S#t $r|jddYwxYw)Nr(g$@Trdz config-initedz env-updatedct|dSr)rw)r&envs rzsetup..s N34Mrc|jjd}|jjt ||y)Nri)document attributesbodyrgrr)r:r1ris rvisit_latex_math_htmlz$setup..visit_latex_math_htmls/))(3 D&12rcyrrr:r1s rdepart_latex_math_htmlz%setup..depart_latex_math_html rct|jtj}|r"|jj d|dzy|jj d|ddgy)Nz$%s$rz\begin{equation}z\end{equation})rZr[rr\rrgextend)r:r1rjs rvisit_latex_math_latexz%setup..visit_latex_math_latexsZDKK):):;  II  Vd7m3 4 II  1"7m/1 2rcyrrrs rdepart_latex_math_latexz&setup..depart_latex_math_latexrr)htmlrrR)rmath)parallel_read_safeparallel_write_safe)r%r&add_config_valueconnectrwradd_noder add_roler2 add_directiver5sphinx version_info)r&rrrrmetadatas rr%r%sEI+T48)2t4O O^4 3 2 LL,.DE.0GHJLLI&i/ V# VY' &-0&*4HH OE O M#MNOsC##DD)r! rX)r<r]pathlibrdocutilsrdocutils.parsers.rstrrr sphinx.errorsrr matplotlibrGr r matplotlib.rcsetupr GeneralElementr rr2r.r5rNrrrwr%rrrrsFP6 5%5   N " !/!79 I,&(RE$(r