
    ddh                     `    d Z ddlZdZd
dZd
dZddZd
dZedk(  rd	Z e	 ee             yy)zWrappers 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                 ^   t        j                  g dt         j                  t         j                  t         j                  d      }|j                  j	                  t
        | z  j                  d             |j                  j                          |j                  j                         }|j                  j                         j                  d      }|r'|j                  d      dk\  s|s|j                  |       t        j                  g dt         j                  t         j                  t         j                  d      }|j                  j	                  |       |j                  j                          |j                  j                         j                  d      }|j                  j                         j                  d      }|r'|j                  d      dk\  s|s|j                  |       |j                  d      |j                  d	      d
z   }	}|||	 }d|v rt        |      |S )zdConvert LaTeX math code to MathML with LaTeXML_

    .. _LaTeXML: http://dlmf.nist.gov/LaTeXML/
    )latexml-z--preload=amsfontsz--preload=amsmathz--inputencoding=utf8Tstdinstdoutstderr	close_fdsutf-8Errorr   )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platexml_codelatexml_errpost_presult
post_p_errstartends
             G/usr/lib/python3/dist-packages/docutils/utils/math/tex2mathml_extern.pyr   r      s   
 	   * * *#'		)A GGMM$y088ABGGMMO88==?L((--/((1K[%%g.!3<{# ! %/OO%/__%/__(,
.F LL|$
LL]]!((1F##%,,W5JZ__W-2&z" W%v{{9'=a'?3EE#FV#&!!M    c                    t        j                  g dt         j                  t         j                  t         j                  d      }|j                  j	                  t
        | z  j                  d             |j                  j                          |j                  j                         }|j                  j                         j                  d      }|j                  d      dk\  r4dj                  d |j                         D              }t        d	|z         |r|j                  d
      dk\  s|s|j!                  |       |j                  d      |j                  d      dz   }}||| S )zgConvert LaTeX math code to MathML with TtM_

    .. _TtM: http://hutchinson.belmont.ma.us/tth/mml/
    )ttmz-uz-rTr   r   z**** Unknownr   
c              3   B   K   | ]  }|j                  d       r|  yw)z****N)
startswith).0lines     r'   	<genexpr>zttm.<locals>.<genexpr>_   s#      4??62  4s   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&   s           r'   r*   r*   L   s   
 	 
  * * *#'	)A GGMM$y088ABGGMMOXX]]_F
((--/
 
 
)C
xx1$ii 4)9 4 4DSHIICHH\*a/vsW%v{{9'=a'?3E%r(   c                 >   g d}|rd}nd}|j                  d       t        j                  dg|z   t        j                  t        j                  t        j                  d      }|j                  j                  | j                  d             |j                  j                          |j                  j                         j                  d      }|j                  j                         j                  d      }|j                  d	      d
k\  r4||j                  d      dz   |j                  d       }t        d|z        |r'|j                  d      d
k\  s|s|j                  |       |j                  d      dz   |j                  d      }
}	d|d||	|
 d}|S )zlConvert LaTeX math code to MathML with blahtexml_

    .. _blahtexml: http://gva.noekeon.org/blahtexml/
    )
--mathmlz
--indentedz	--spacingmoderatez--mathml-encodingrawz--other-encodingr9   z--doctype-xhtml+mathmlz--annotate-TeX z display="block"z--displaymath	blahtexmlTr   r   z<error>r   z	<message>	   z
</message>z.
Message from external converter blahtexml:
%sr1   z<markup>z	</markup>z0<math xmlns="http://www.w3.org/1998/Math/MathML"z>
z</math>
)appendr   r   r   r   r   r   r   r   r   r   r	   r   r   r   )r   inliner   optionsmathmode_argr   r#   r4   r5   r%   r&   s              r'   r;   r;   h   sY   
G )'+w.) * *#'		)A
 GGMM)""7+,GGMMOXX]]_##G,F
((--/
 
 
)C{{9"V[[-a/L0IJL  ! 	!SXXl+q0sZ(*FKK,D3E ,fU3.?AFMr(   c                    t        j                  g dt         j                  t         j                  t         j                  d      }|j                  j	                  | j                  d             |j                  j                          |j                  j                         j                  d      }|j                  j                         j                  d      j                         }|j                         }|r!|r|j                  |       t        d|z        |dk7  rt        d|z        |j                  d      |j                  d	      d
z   }}||| S )zXConvert LaTeX math code to MathML with pandoc_

    .. _pandoc: https://pandoc.org/
    )pandocr7   z--from=latexTr   r   z1
Error message from external converter pandoc:
%sr   z.
Error code from external converter pandoc:
%sr   r   r   )r   r   r   r   r   r   r   r   r   r   r	   stripwaitr   r   r   )r   r   r   r#   r4   xr%   r&   s           r'   rB   rB      s   
 	   * * *#'	)A GGMM)""7+,GGMMOXX]]_##G,F
((--/
 
 
)
/
/
1C	A
NN3O  ! 	!AvL  	 W%v{{9'=a'?3E%r(   __main__uR   \frac{\partial \sin^2(\alpha)}{\partial \vec r}\varpi \mathbb{R} \, \text{Grüße})N)TN)
__doc__r   r   r   r*   r;   rB   __name__exampleprint r(   r'   <module>rL      sS     -`8&RD z9G 
)G
 r(   