o
    §â±bÿ  ã                   @   sT   d Z ddlZdZddd„Zddd„Zdd	d
„Zedkr(dZeeeƒ 	d¡ƒ dS dS )zšWrappers for TeX->MathML conversion by external tools

This module is provisional:
the API is not settled and may change with any minor Docutils version.
é    NzP\documentclass{article}
\usepackage{amsmath}
\begin{document}
%s
\end{document}
c           
      C   s&  t jg d¢t jt jt jdd}|j t|   d¡¡ |j ¡  |j 	¡ }|j
 	¡  d¡}|r<| d¡dks7|s<| |¡ t jg d¢t jt jt jdd}|j |¡ |j ¡  |j 	¡  d¡}|j
 	¡  d¡}|rv| d¡dksq|sv| |¡ | d¡| d	¡d
 }}	|||	… }d|v r‘t|ƒ‚|S )zdConvert LaTeX math code to MathML with LaTeXML_

    .. _LaTeXML: http://dlmf.nist.gov/LaTeXML/
    )Úlatexmlú-z--inputencoding=utf8T©ÚstdinÚstdoutÚstderrÚ	close_fdsúutf-8ÚErrorr   )Zlatexmlpostr   z--nonumbersectionsz--format=xhtmlz--ú<mathú</math>é   zclass="ltx_ERROR)Ú
subprocessÚPopenÚPIPEr   ÚwriteÚdocument_templateÚencodeÚcloser   Úreadr   ÚdecodeÚfindÚerrorÚSyntaxError)
Ú	math_codeÚreporterÚpZlatexml_codeZlatexml_errZpost_pÚresultZ
post_p_errÚstartÚend© r    úIusr/lib/python3.10/site-packages/docutils/utils/math/tex2mathml_extern.pyr      s:   
ø	



ö

r   c                 C   sÐ   t jg d¢t jt jt jdd}|j t|   d¡¡ |j ¡  |j 	¡ }|j
 	¡  d¡}| d¡dkrEd dd	„ | ¡ D ƒ¡}td
| ƒ‚|rN| d¡dksP|sU| |¡ | d¡| d¡d }}|||… S )zgConvert LaTeX math code to MathML with TtM_

    .. _TtM: http://hutchinson.belmont.ma.us/tth/mml/
    )Úttmz-uz-rTr   r	   z**** Unknownr   Ú
c                 s   s    | ]
}|  d ¡r|V  qdS )z****N)Ú
startswith)Ú.0Úliner    r    r!   Ú	<genexpr>_   s   € ÿzttm.<locals>.<genexpr>z&
Message from external converter TtM:
ú
**** Errorr   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   ÚjoinÚ
splitlinesr   r   )r   r   r   r   ÚerrÚmsgr   r   r    r    r!   r"   L   s"   
ø	


r"   Tc                 C   s  g d¢}|r	d}nd}|  d¡ tjdg| tjtjtjdd}|j |  d¡¡ |j ¡  |j 	¡  
d¡}|j 	¡  
d¡}| d	¡d
krY|| d¡d | d¡… }td| ƒ‚|ri| d¡d
ksd|si| |¡ | d¡d | d¡}	}
d|||	|
… f }|S )zlConvert LaTeX math code to MathML with blahtexml_

    .. _blahtexml: http://gva.noekeon.org/blahtexml/
    )
z--mathmlz
--indentedz	--spacingZmoderatez--mathml-encodingÚrawz--other-encodingr-   z--doctype-xhtml+mathmlz--annotate-TeXÚ zmode="display"z--displaymathÚ	blahtexmlTr   r	   z<error>r   z	<message>é	   z
</message>z.
Message from external converter blahtexml:
%sr(   z<markup>z	</markup>z><math xmlns="http://www.w3.org/1998/Math/MathML"%s>
%s</math>
)Úappendr   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   Úinliner   ÚoptionsZmathmode_argr   r   r+   r,   r   r   r    r    r!   r/   h   s6   
ü
ÿ
ÿr/   Ú__main__uG   \frac{\partial \sin^2(\alpha)}{\partial \vec r}\varpi \, \text{GrÃ¼ÃŸe}r	   )N)TN)
Ú__doc__r   r   r   r"   r/   Ú__name__ÚexampleÚprintr   r    r    r    r!   Ú<module>   s   

/
+û