U
    L?h<  ã                   @   sh   d Z ddlmZ ddlmZ ddgiZdd„ Zdd	„ Zd
d„ Zedddd„ ƒZ	eddddd„ƒZ
dS )z‰Module with some functions for MathML, like transforming MathML
content in MathML presentation.

To use this module, you will need lxml.
é    )ÚPath)Údoctest_depends_on)Ú	apply_xslÚc2pÚlxmlc                 C   s   d|  d S )Nzì<math xmlns:mml="http://www.w3.org/1998/Math/MathML"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.w3.org/1998/Math/MathML
        http://www.w3.org/Math/XMLSchema/mathml2/mathml2.xsd">z</math>© )Úsr   r   úQ/var/www/html/venv/lib/python3.8/site-packages/sympy/utilities/mathml/__init__.pyÚadd_mathml_headers   s
    ýýr
   c                 C   sJ   dd l }|jdkr0ddlm} || ƒ |¡ ¡ S ddlm} || |ƒS d S )Nr   )é   é
   )Úfiles)Úread_binary)ÚsysÚversion_infoÚimportlib.resourcesr   ÚjoinpathÚ
read_bytesr   )ÚpkgnameÚfilenamer   r   r   r   r   r	   Ú_read_binary   s    
r   c                 C   sL   | dkrd} n| dkrd} n| dkr(d} | dkr<t d| ƒ}nt| ƒ ¡ }|S )	Númathml/data/simple_mmlctop.xslúsimple_mmlctop.xslúmathml/data/mmlctop.xslúmmlctop.xslzmathml/data/mmltex.xslú
mmltex.xsl)r   r   r   zsympy.utilities.mathml.data)r   r   r   )ÚxslZxslbytesr   r   r	   Ú	_read_xsl#   s    r   )r   )Úmodulesc           	      C   sb   ddl m} |jdd}|jj}|jt|ƒ|d}|j||d}|j| |d}||ƒ}t|ƒ}|S )a*  Apply a xsl to a MathML string.

    Parameters
    ==========

    mml
        A string with MathML code.
    xsl
        A string giving the name of an xsl (xml stylesheet) file which can be
        found in sympy/utilities/mathml/data. The following files are supplied
        with SymPy:

        - mmlctop.xsl
        - mmltex.xsl
        - simple_mmlctop.xsl

        Alternatively, a full path to an xsl file can be given.

    Examples
    ========

    >>> from sympy.utilities.mathml import apply_xsl
    >>> xsl = 'simple_mmlctop.xsl'
    >>> mml = '<apply> <plus/> <ci>a</ci> <ci>b</ci> </apply>'
    >>> res = apply_xsl(mml,xsl)
    >>> print(res)
    <?xml version="1.0"?>
    <mrow xmlns="http://www.w3.org/1998/Math/MathML">
      <mi>a</mi>
      <mo> + </mo>
      <mi>b</mi>
    </mrow>
    r   )ÚetreeF)Zresolve_entities)Úparser)Zaccess_control)	r   r   Z	XMLParserZXSLTAccessControlZDENY_ALLÚXMLr   ÚXSLTÚstr)	Úmmlr   r   r    Úacr   Z	transformÚdocÚresultr   r   r	   r   4   s    #r   Fc                 C   s*   |   d¡st| ƒ} |r t| dƒS t| dƒS )ar  Transforms a document in MathML content (like the one that sympy produces)
    in one document in MathML presentation, more suitable for printing, and more
    widely accepted

    Examples
    ========

    >>> from sympy.utilities.mathml import c2p
    >>> mml = '<apply> <exp/> <cn>2</cn> </apply>'
    >>> c2p(mml,simple=True) != c2p(mml,simple=False)
    True

    z<mathr   r   )Ú
startswithr
   r   )r$   Úsimpler   r   r	   r   d   s
    

r   N)F)Ú__doc__Úpathlibr   Zsympy.utilities.decoratorr   Z__doctest_requires__r
   r   r   r   r   r   r   r   r	   Ú<module>   s   

/