HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/sphinx/ext/__pycache__/imgmath.cpython-310.pyc
o

�W�a
4�@s�dZddlZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
mZmZm
Z
mZddlmZddlmZddlZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZmZddl m!Z!m"Z"ddl#m$Z$m%Z%ddl&m'Z'ddl(m)Z)m*Z*ddl+m,Z,ddl-m.Z.e!�/e0�Z1e�2edd�Z3Gdd�de�Z4Gdd�de�Z5dZ6e�7d�Z8e�7d�Z9e�7d�Z:de;de<fd d!�Z=de;d"e<ddfd#d$�Z>	%dKd&e;d'e;d(ed)e;de;f
d*d+�Z?d,ede;fd-d.�Z@d/e;d,ede;fd0d1�ZAd2e
e;d3e;dee;e;ffd4d5�ZBd6e;d,edee;e<ffd7d8�ZCd6e;d,edee;e<ffd9d:�ZDd;e.d'e;dee;e<ffd<d=�ZEd>ed?eFddfd@dA�ZGd;e.dBede;fdCdD�ZHd;e.dBejIddfdEdF�ZJd;e.dBejKddfdGdH�ZLd>edee;effdIdJ�ZMdS)Lz�
    sphinx.ext.imgmath
    ~~~~~~~~~~~~~~~~~~

    Render math in HTML via dvipng or dvisvgm.

    :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
�N)�path)�PIPE�CalledProcessError)�Any�Dict�List�Tuple)�nodes)�Element)�package_dir)�Sphinx)�Builder)�Config)�SphinxError)�_�__)�logging�sha1)�get_node_equation_number�wrap_displaymath)�	ensuredir)�read_png_depth�write_png_depth)�
LaTeXRenderer)�HTMLTranslator�	templates�imgmathc	s4eZdZdZd	dedededdf�fdd�
Z�ZS)
�MathExtErrorzMath extension errorN�msg�stderr�stdout�returncs0|r|d|7}|r|d|7}t��|�dS)Nz

[stderr]
z

[stdout]
)�super�__init__)�selfrrr ��	__class__��4/usr/lib/python3/dist-packages/sphinx/ext/imgmath.pyr#-s
zMathExtError.__init__�NN)�__name__�
__module__�__qualname__�category�strr#�
__classcell__r'r'r%r(r*s(rc@seZdZdZdS)�InvokeErrorzerrors on invoking converters.N)r*r+r,�__doc__r'r'r'r(r05sr0)�png�svgz\[\d+ depth=(-?\d+)\]z.*, depth=(.*)ptz<!-- DEPTH=(-?\d+) -->�filenamer!cCsdt|��$}|D]}qt�|�}|rt|�d��Wd�S	Wd�dS1s+wYdS)z9Read the depth from comment at last line of SVG file
    �N)�open�depthsvgcomment_re�match�int�group)r4�f�line�matchedr'r'r(�read_svg_depth@s

�$�r>�depthcCs>t|d��}|�d|�Wd�dS1swYdS)z<Write the depth to SVG file as a comment at end of file
    �az
<!-- DEPTH=%s -->N)r6�write)r4r?r;r'r'r(�write_svg_depthMs"�rB��image_format�math�config�confdircCs�|jtt|jd��|j|dkrdnd|d�}|jrd}nd}|jD]}t�|||�}t�|�r9t	��
||�Sq"t	t��
||�S)zGenerate LaTeX macro.g333333�?r2rCz
,tightpage)�fontsize�baselineskip�preamble�	tightpagerEz
preview.tex_tztemplate.tex_t)�imgmath_font_sizer9�round�imgmath_latex_preamble�imgmath_use_preview�templates_pathr�join�existsr�render)rDrErFrG�	variables�
template_name�template_dir�templater'r'r(�generate_latex_macroTs�

�rX�buildercCst|d�s
t��|_|jS)z�Create temporary directory.

    use only one tempdir per build -- the use of a directory is cleaner
    than using temporary files, since we can clean up everything at once
    just removing the whole directory (see cleanup_tempdir)
    �_imgmath_tempdir)�hasattr�tempfile�mkdtemprZ)rYr'r'r(�ensure_tempdirls

r^�latexc
Cs�t|�}t�|d�}t|ddd��
}|�|�Wd�n1s!wY|jjdg}|�|jj�|�	d�zt
j|tt|ddd	�t�|d
�WSt
yc}z
t�td�|jj�t|�d}~wtyw}z	td|j|j�|�d}~ww)
z%Compile LaTeX macros for math to DVI.zmath.tex�wzutf-8)�encodingNz--interaction=nonstopmodeT�ascii)r r�cwd�checkrazmath.dvizYLaTeX command %r cannot be run (needed for math display), check the imgmath_latex settingzlatex exited with error)r^rrQr6rArF�
imgmath_latex�extend�imgmath_latex_args�append�
subprocess�runr�OSError�logger�warningrr0rrrr )r_rY�tempdirr4r;�command�excr'r'r(�compile_mathys.�
�
����rqro�namec
Cs�ztj|ttddd�}|j|jfWSty,}zt�td�||d|�t	|�d}~wt
yB}ztd||j|j�|�d}~ww)z*Convert DVI file to specific image format.Trb)r rrdrazS%s command %r cannot be run (needed for math display), check the imgmath_%s settingrNz%s exited with error)rirjrr rrkrlrmrr0rr)rorr�retrpr'r'r(�convert_dvi_to_image�s

����rt�dvipathcCs�t|�}t�|d�}d}|jjd|dddg}|�|jj�|jjr&|�d�|�|�t	||�\}}d}|jjrW|�
�D]}	t�|	�}
|
rVt
|
�d	��}t||�||fSq<||fS)
zConvert DVI file to PNG image.zmath.png�dvipng�-oz-T�tightz-z9z--depthNr5)r^rrQrF�imgmath_dvipngrf�imgmath_dvipng_argsrOrhrt�
splitlines�depth_rer8r9r:r�rurYrnr4rrror rr?r<r=r'r'r(�convert_dvi_to_png�s(



�r~cCs�t|�}t�|d�}d}|jjd|g}|�|jj�|�|�t||�\}}d}|jj	rQ|�
�D] }	t�|	�}
|
rPt
t|
�d��dd�}t||�||fSq0||fS)zConvert DVI file to SVG image.zmath.svg�dvisvgmrwNr5�dg�z�GR@)r^rrQrF�imgmath_dvisvgmrf�imgmath_dvisvgm_argsrhrtrOr{�depthsvg_rer8rM�floatr:rBr}r'r'r(�convert_dvi_to_svg�s$


�r�r$c
Csp|jjj��}|tvrtd��t|||jj|jj�}dt|�	���
�|f}t�|jj
d|�}t�|jj|jjd|�}t�|�rX|dkrLt|�}||fS|dkrTt|�}||fSt|jd�sdt|jd�rfdSzt||j�}Wnty|d	|j_YdSwz|dkr�t||j�\}	}n|dkr�t||j�\}	}Wnty�d	|j_YdSwtt�|��t�|	|�||fS)
a�Render the LaTeX math expression *math* using latex and dvipng or
    dvisvgm.

    Return the filename relative to the built document and the "depth",
    that is, the distance of image bottom and baseline in pixels, if the
    option to use preview_latex is switched on.

    Error handling may seem strange, but follows a pattern: if LaTeX or dvipng
    (dvisvgm) aren't available, only a warning is generated (since that enables
    people on machines without these programs to at least build the rest of the
    docs successfully).  If the programs are there, however, they may not fail
    since that indicates a problem in the math source.
    z2imgmath_image_format must be either "png" or "svg"z%s.%srEr2r3�_imgmath_warned_latex� _imgmath_warned_image_translatorr)T)rYrF�imgmath_image_format�lower�SUPPORT_FORMATrrXrGr�encode�	hexdigest�	posixpathrQ�imgpathr�outdir�imagedir�isfilerr>r[rqr0r�r~r�r�r�dirname�shutil�move)
r$rErDr_r4�relfn�outfnr?rur�r'r'r(�render_math�sR�
�
����r��apprpcCsB|rdSt|jd�sdSz
t�|jj�WdSty YdSw)NrZ)r[rYr��rmtree�_mathpng_tempdir�	Exception)r�rpr'r'r(�cleanup_tempdirs�r��nodecCs$|jjjrd|�|�����SdS)Nz	 alt="%s"rC)rYrF�imgmath_add_tooltipsr��astext�strip)r$r�r'r'r(�get_tooltips
r�c
Cs�zt|d|��d�\}}Wn0ty?}z$t|�}tj|ddg|��d�}|�|�t�t	d�|��|�tj
|�d}~ww|durV|j�d|�
|������tj
�d|t||�}|durj|d|7}|j�|d	�tj
�)
N�$�WARNING���type�level�backrefs�sourcezdisplay latex %r: %sz<span class="math">%s</span>z<img class="math" src="%s"z style="vertical-align: %dpx"z/>)r�r�rr.r	�system_message�	walkaboutrlrmr�SkipNode�bodyrhr�r�r�)r$r��fnamer?rpr�sm�cr'r'r(�html_visit_math$s,
�
����r�c	
CsH|dr	|��}nt|��dd�}z	t||�\}}Wn0tyJ}z$t|�}tj|ddg|��d�}|�|�t�	t
d�|��|�tj|�d}~ww|j�
|j|ddd	��|j�
d
�|dr|t||�}|j�
d|�|�|td
��|j�
d�|dur�|j�
d|�|������tj�|j�
d|t||�d�tj�)N�nowrapFr�r�r�zinline latex %r: %s�divrE)�CLASSz<p>�numberz<span class="eqno">(%s)zPermalink to this equationz</span>z'<span class="math">%s</span></p>
</div>z
<img src="%s"z
/></p>
</div>)r�rr�rr.r	r�r�rlrmrr�r�rh�starttagr�add_permalink_refrr�r�r�)	r$r�r_r�r?rprr�r�r'r'r(�html_visit_displaymath:s>

�
��
���r�cCs�|�dtdftdf�|�ddd�|�ddd�|�ddd�|�d	d
d�|�ddd�|�d
gd�d�|�ddgd�|�dgd�|�ddd�|�ddd�|�ddd�|�dt�tjdd�S)Nrr�r2�htmlryrvr�rrer_rOFrz)z-gammaz1.5z-D�110z-bg�Transparentr�z
--no-fontsrgrNrCr�TrL�zbuild-finished)�version�parallel_read_safe)�add_html_math_rendererr�r��add_config_value�connectr��sphinx�__display_version__)r�r'r'r(�setupYs(��r�)rC)Nr1r��rer�rir\�osrrr�typingrrrr�docutilsr	�docutils.nodesr
r�r�sphinx.applicationr�sphinx.buildersr
�
sphinx.configr�
sphinx.errorsr�
sphinx.localerr�sphinx.utilrr�sphinx.util.mathrr�sphinx.util.osutilr�sphinx.util.pngrr�sphinx.util.templater�sphinx.writers.htmlr�	getLoggerr*rlrQrPrr0r��compiler|r�r7r.r9r>rBrXr^rqrtr~r�r�r�r�r�rEr��
math_blockr�r�r'r'r'r(�<module>sn





����
�
">