o
    g                     @   s   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	Z
d dl	mZmZ G dd dejejZdd	 Zi g fd
dZdeie_G dd deZdddZdd Zdd ZdS )    N)Path)nodes)	Directive
directives)_apimathtextc                   @   s   e Zd ZdS )
latex_mathN)__name__
__module____qualname__ r   r   Z/home/ubuntu/cloudmapper/venv/lib/python3.10/site-packages/matplotlib/sphinxext/mathmpl.pyr      s    r   c                 C   s   t | tjjS N)r   choicer   MathTextParser_font_type_mapping)argr   r   r   fontset_choice   s   r   c           
      C   sD   | d}||d d }t|}	||	d< |dd|	d< |	gg fS )N`   latexfontsetcm)findr   get)
rolerawtexttextlinenoinlineroptionscontentir   noder   r   r   	math_role   s   

r%   r   c                   @   s,   e Zd ZdZdZdZdZdeiZdd Z	dS )MathDirectiveTr   Fr   c                 C   s6   d | j}t| j}||d< | jdd|d< |gS )N r   r   r   )joinr"   r   
block_textr!   r   )selfr   r$   r   r   r   run'   s
   
zMathDirective.runN)
r	   r
   r   has_contentrequired_argumentsoptional_argumentsfinal_argument_whitespacer   option_specr+   r   r   r   r   r&       s    r&   r   c              	   C   s   d|  } t d|i0 ztj| |ddd}W n ty*   td|   d}Y n	w W d    |S W d    |S 1 s>w   Y  |S )N$%s$zmathtext.fontsetd   png)dpiformatz!Could not render math expression r   )mpl
rc_contextr   math_to_image	Exceptionr   warn_external)r   filenamer   depthr   r   r   	latex2png0   s$   


r=   c                 C   s   t | jtj}| d }| d }dt||   dd  }t	t
jjjdd}|jddd || d	 }t|||}|rCd
}	nd}	|rR|dkrRd|d  }
nd
}
dt
jjj d| d|	 |
 dS )Nr   r   zmath-{}i_imagesmathmplT)parentsexist_okz.pngr'   zclass="center" r   z)style="position: relative; bottom: -%dpx"r   z
<img src="z	/mathmpl/z.png" z/>)
isinstanceparentr   TextElementr5   hashlibmd5encode	hexdigestr   setupappbuilderoutdirmkdirr=   imgpath)r$   sourceinliner   r   namedestdirdestr<   clsstyler   r   r   
latex2html=   s*   rV   c                 C   s   | t _dd }dd }dd }dd }| jt||f||fd	 | d
t | d
t tj	dk r<| dt | dt ddd}|S )Nc                 S   s"   | j jd }| jt|| d S )NrO   )document
attributesbodyappendrV   )r*   r$   rO   r   r   r   visit_latex_math_html[   s   z$setup.<locals>.visit_latex_math_htmlc                 S      d S r   r   r*   r$   r   r   r   depart_latex_math_html_      z%setup.<locals>.depart_latex_math_htmlc                 S   sD   t |jtj}|r| jd|d   d S | jd|d dg d S )Nr1   r   z\begin{equation}z\end{equation})rB   rC   r   rD   rY   rZ   extend)r*   r$   rP   r   r   r   visit_latex_math_latexc   s   
z%setup.<locals>.visit_latex_math_latexc                 S   r\   r   r   r]   r   r   r   depart_latex_math_latexl   r_   z&setup.<locals>.depart_latex_math_latex)htmlr   r?   )r      mathT)parallel_read_safeparallel_write_safe)
rI   rJ   add_noder   add_roler%   add_directiver&   sphinxversion_info)rJ   r[   r^   ra   rb   metadatar   r   r   rI   W   s    	

rI   )r   )rE   pathlibr   docutilsr   docutils.parsers.rstr   r   rk   
matplotlibr6   r   r   GeneralElementr   r   r%   r!   r&   r=   rV   rI   r   r   r   r   <module>   s     


