
Qc        &   @   s.  d  Z  d d l j j j Z i d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z i d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6Z e j Z e j	 Z
 e
 j e j  e
 j e j  e
 j e j  e
 j e j  e
 j e j  e
 j e j  d3 j g  d4 d5 d6 d7 g D] Z e
 e ^ qZ Z d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT dU dV dW dX dY dZ d[ d\ d] g& Z i d^ d_ 6d` da 6db dc 6dd de 6df dg 6dh di 6dj dk 6dl dm 6dn do 6dp dq 6dr ds 6dt du 6dv dw 6dx dy 6dz d{ 6d| d} 6d~ d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z i4 d d_ 6d da 6d dc 6d de 6d dg 6d di 6d dk 6d dm 6d do 6d dq 6d ds 6d du 6d dw 6d dy 6d d{ 6d d} 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z i d d 6d d 6d d 6Z d dd     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ  d e f d     YZ! d e f d     YZ" d e f d     YZ# d e f d     YZ$ d e f d    YZ% de f d    YZ& de f d    YZ' de f d    YZ( de f d	    YZ) d
e f d    YZ* de f d    YZ+ de f d    YZ, de f d    YZ- e. d Z/ d  Z0 d S(  s2   Convert LaTex math code into presentational MathMLiNu   ´t   acuteu   ¯t   baru   ˘t   breveu   ˇt   checku   ˙t   dotu   ¨t   ddotu   ⃛t   dddotu   `t   graveu   ^t   hatu   ˚t   mathringu   ⃡t   overleftrightarrowu   ˜t   tildeu   ⃗t   vecu   Φt   Phiu   Ξt   Xiu   Σt   Sigmau   Ψt   Psiu   Δt   Deltau   Θt   Thetau   ϒt   Upsilonu   Πt   Piu   Ωt   Omegau   Γt   Gammau   Λt   Lambdat    t   sumt   intt   ointt   prodt   arccost   arcsint   arctant   argt   cost   cosht   cott   cotht   csct   degt   dett   dimt   expt   gcdt   homt   inft   kert   lgt   limt   liminft   limsupt   lnt   logt   maxt   mint   Prt   sect   sint   sinht   supt   tant   tanht   injlimt	   varinjlimt	   varlimsupt   projlimt	   varliminft
   varprojlimu   𝔸t   Au   𝔹t   Bu   ℂt   Cu   𝔻t   Du   𝔼t   Eu   𝔽t   Fu   𝔾t   Gu   ℍt   Hu   𝕀t   Iu   𝕁t   Ju   𝕂t   Ku   𝕃t   Lu   𝕄t   Mu   ℕt   Nu   𝕆t   Ou   ℙt   Pu   ℚt   Qu   ℝt   Ru   𝕊t   Su   𝕋t   Tu   𝕌t   Uu   𝕍t   Vu   𝕎t   Wu   𝕏t   Xu   𝕐t   Yu   ℤt   Zu   𝒜u   ℬu   𝒞u   𝒟u   ℰu   ℱu   𝒢u   ℋu   ℐu   𝒥u   𝒦u   ℒu   ℳu   𝒩u   𝒪u   𝒫u   𝒬u   ℛu   𝒮u   𝒯u   𝒰u   𝒱u   𝒲u   𝒳u   𝒴u   𝒵u   𝒶t   au   𝒷t   bu   𝒸t   cu   𝒹t   du   ℯt   eu   𝒻t   fu   ℊt   gu   𝒽t   hu   𝒾t   iu   𝒿t   ju   𝓀t   ku   𝓁t   lu   𝓂t   mu   𝓃t   nu   ℴt   ou   𝓅t   pu   𝓆t   qu   𝓇t   ru   𝓈t   su   𝓉t   tu   𝓊t   uu   𝓋t   vu   𝓌t   wu   𝓍t   xu   𝓎t   yu   𝓏t   zu   ≠t   =u   ∉s   \inu   ≢s   \equivt   mathc           B   st   e  Z d  Z d Z d d d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z RS(   s   Base class for MathML elements.i@B c         C   st   g  |  _  | d k	 rX t |  t k rH x+ | D] } |  j |  q. WqX |  j |  n  | d k	 rp | |  _ n  d S(   s\   math([children]) -> MathML element

        children can be one child or a list of children.N(   t   childrent   Nonet   typet   listt   appendt   inline(   t   selfRy   R~   t   child(    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyt   __init__   s    	c         C   sT   t  |  d  rF |  j j d d j g  |  j D] } t |  ^ q+  S|  j j Sd  S(   NRy   s   (%s)t   ,(   t   hasattrt	   __class__t   __name__t   joinRy   t   repr(   R   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyt   __repr__   s    +c         C   s   t  |  j  |  j k S(   s   Room for more children?(   t   lenRy   t	   nchildren(   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyt   full   s    c         C   sR   |  j    s t  |  j j |  |  | _ |  } x | j    rM | j } q5 W| S(   sv   append(child) -> element

        Appends child and returns self if self is not full or first
        non-full parent.(   R   t   AssertionErrorRy   R}   t   parent(   R   R   t   node(    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR}      s    	c         C   s   |  j  d } |  j  d =| S(   sA   delete_child() -> child

        Delete last child and return it.i(   Ry   (   R   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyt   delete_child   s    
c         C   s)   |  j  } x | j   r$ | j  } q W| S(   sK   close() -> parent

        Close element and return first non-full element.(   R   R   (   R   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyt   close   s    	c         C   s   |  j    |  j   |  j   S(   s   xml() -> xml-string(   t	   xml_startt   xml_bodyt   xml_end(   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyt   xml   s    c         C   sI   t  |  d  s  d |  j j g Sd } |  j r: d | g Sd | g Sd  S(   NR~   s   <%s>s"   http://www.w3.org/1998/Math/MathMLs   <math xmlns="%s">s    <math xmlns="%s" mode="display">(   R   R   R   R~   (   R   t   xmlns(    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR      s    	c         C   s   d |  j  j g S(   Ns   </%s>(   R   R   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR      s    c         C   s1   g  } x$ |  j  D] } | j | j    q W| S(   N(   Ry   t   extendR   (   R   R   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR      s    N(   R   t
   __module__t   __doc__R   Rz   R   R   R   R}   R   R   R   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyRx      s   						
				t   mrowc           B   s   e  Z d    Z RS(   c         C   s   d |  j  j g S(   Ns   
<%s>(   R   R   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR      s    (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR      s   t   mtablec           B   s   e  Z d    Z RS(   c         C   s   d |  j  j g S(   Ns   
<%s>(   R   R   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR      s    (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR      s   t   mtrc           B   s   e  Z RS(    (   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s    t   mtdc           B   s   e  Z RS(    (   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s    t   mxc           B   s&   e  Z d  Z d Z d   Z d   Z RS(   s   Base class for mo, mi, and mni    c         C   s   | |  _  d  S(   N(   t   data(   R   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s    c         C   s
   |  j  g S(   N(   R   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s    (   R   R   R   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s   	t   moc           B   s%   e  Z i d  d 6d d 6Z d   Z RS(   s   &lt;t   <s   &gt;t   >c         C   s   |  j  j |  j |  j  g S(   N(   t   translationt   getR   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s    (   R   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s   t   mic           B   s   e  Z RS(    (   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s    t   mnc           B   s   e  Z RS(    (   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s    t   msubc           B   s   e  Z d  Z RS(   i   (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s   t   msupc           B   s   e  Z d  Z RS(   i   (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s   t   msqrtc           B   s   e  Z d  Z RS(   i   (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s   t   mrootc           B   s   e  Z d  Z RS(   i   (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s   t   mfracc           B   s   e  Z d  Z RS(   i   (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   "  s   t   msubsupc           B   s&   e  Z d  Z d e d  Z d   Z RS(   i   c         C   s   | |  _  t j |  |  d  S(   N(   t   reversedRx   R   (   R   Ry   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   '  s    	c         C   sF   |  j  r9 |  j d |  j d g |  j d d +t |  _  n  t j |   S(   Ni   i   i   (   R   Ry   t   FalseRx   R   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   +  s    	$N(   R   R   R   Rz   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   %  s   t   mfencedc           B   sC   e  Z i d  d 6d d 6d d 6d d 6d d	 6Z d
   Z d   Z RS(   t   {s   \{u   〈s   \langlet   }s   \}u   〉s   \rangleR   t   .c         C   s   | |  _  t j |   d  S(   N(   t   openparRx   R   (   R   t   par(    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   6  s    	c         C   sG   |  j  j |  j |  j  } |  j  j |  j |  j  } d | | f g S(   Ns   <mfenced open="%s" close="%s">(   R   R   R   t   closepar(   R   t   openR   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   :  s    (   R   R   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   2  s
   
	t   mspacec           B   s   e  Z d  Z RS(   i    (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   ?  s   t   mstylec           B   s    e  Z d d d   Z d   Z RS(   c         K   s5   | d  k	 r | |  _ n  t j |  |  | |  _ d  S(   N(   Rz   R   Rx   R   t   attrs(   R   Ry   R   t   kwargs(    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   C  s    c         C   s2   d g g  |  j  j   D] } d | ^ q d g S(   Ns   <mstyle s   %s="%s"R   (   R   t   items(   R   t   item(    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   I  s    N(   R   R   Rz   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   B  s   t   moverc           B   s&   e  Z d  Z d e d  Z d   Z RS(   i   c         C   s   | |  _  t j |  |  d  S(   N(   R   Rx   R   (   R   Ry   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   O  s    	c         C   s/   |  j  r" |  j j   t |  _  n  t j |   S(   N(   R   Ry   t   reverseR   Rx   R   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   S  s    	N(   R   R   R   Rz   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   M  s   t   munderc           B   s   e  Z d  Z RS(   i   (   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   Y  s   t
   munderoverc           B   s   e  Z d  Z d d  Z RS(   i   c         C   s   t  j |  |  d  S(   N(   Rx   R   (   R   Ry   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   ^  s    N(   R   R   R   Rz   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   \  s   t   mtextc           B   s    e  Z d  Z d   Z d   Z RS(   i    c         C   s   | |  _  d  S(   N(   t   text(   R   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   c  s    c         C   s
   |  j  g S(   N(   R   (   R   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   f  s    (   R   R   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR   a  s   	c         C   sl  d j  |  j    }  | r9 t   } t | d t } n' t   } t t t |   d t } xt	 |   d k rgt	 |   } |  d } d } | d k r |  d } n d } | d k r n| d k r| d k r | j
 t |   } d } qZ| d k r| j
 t    } d } qZ| d	 k rC| j
 t    } d } qZ| j   rd } x* | | k  r|  | j   r| d 7} qXW|  d | !}	 t |	 | |  |  \ } } | | 7} qZ| d k rt   }
 t |
  } | j   j   j
 |  |
 } d } qZt d
 | | f   n@| j   r>| j
 t |   } n| j   rb| j
 t |   } n| d k r| j
 t |   } n| d k r| j   } t | t  rt | j d t } n9 t | t  r| j t k rt |  } n t |  } | j
 |  | } nF| d k r| j   } t | t  rMt | j  } np t | t  rz| j t k rzt |  } nC t | t  r| j d j t k rt | j  } n t |  } | j
 |  | } n | d k rt   } | j
 |  | } n\ | d k r| j   } nA | d k rJt   }
 | j   j
 |
  |
 } n t d |   |  | }  qc W| S(   s   parse_latex_math(string [,inline]) -> MathML-tree

    Returns a MathML-tree parsed from string.  inline=True is for
    inline math and inline=False is for displayed math.

    tree is the whole tree and node is the current element.t    R~   i    i   R   s   \s   {}i   R   u   Syntax error: "%s%s"s   +-*/=()[]|<>,.!?':;@t   _R   t   ^R   R   t   &u   Illegal character: "%s"(   R   t   splitR   Rx   t   TrueR   R   R   R   R   R}   R   R   t   isalphat   handle_keywordR   t   SyntaxErrorR   t   isdigitR   R   t
   isinstanceR   R   Ry   R   t
   sumintprodR   R   R   R   (   t   stringR~   R   t   treeRj   R_   t   skipt   c2Re   t   namet   entryt   rowR   t   subR:   (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyt   parse_latex_mathi  s    			
											c         C   sq  d } t  |  d k r; | d d k r; | d } d } n  |  d k r | j d  se t d   n  | d 7} t   } t t |   } | j |  | } n|  d k r | j d  s t d	   n  | d 7} | j   j   j   } nx|  d1 k rq| d d k rt d   n  | j d  } | d k rDt d   n  | j t	 | d | !  } | | d 7} n|  d k rt
   } | j |  | } n|  d k rt   } | j |  | } n|  d k r]x? d d d d d d g D] }	 | j |	  rPqqWt d   t |	  }
 | j |
  t   } |
 j |  | } | t  |	  7} n
|  d k rx? d d d d d d g D] }	 | j |	  rPqqWt d   | j   } |	 | _ | j   } | t  |	  7} n|  d  k rGx- t D] } | j |  rPqqWt d!   | j t t |   } | t  |  7} n |  d" k r~t d# d d$ d%  } | j |  | } n|  d& k r| d d k s| d j   s| d' d k rt d(   n  | j t t | d   } | d) 7} ns|  d2 k rY| d d k s | d' d k r/t d,   n  | j t t | d   } | d) 7} n|  d- k r}| j t d.   } n |  t k r| j t t |    } n |  t k r| j t t |    } n |  t k r| j t t |    } nr |  t k r| j t |    } nN |  t k rWt t t |   d/ t } | j |  | } n t d0 |    | | f S(3   Ni    R   i   t   begins   {matrix}u;   Environment not supported! Supported environment: "matrix".i   t   endu   Expected "\end{matrix}"!R   t   mathrmR   u   Expected "\text{...}"!R   it   sqrtt   fract   leftt   (t   [t   |s   \{s   \langleR   u   Missing left-brace!t   rightt   )t   ]s   \}s   \rangleu   Missing right-brace!t   notu)   Expected something to negate: "\not ..."!t   mathbfR   t
   fontweightt   boldt   mathbbi   u%   Expected something like "\mathbb{A}"!i   t   mathscrt   mathcalu&   Expected something like "\mathscr{A}"!t   colont   :R   u   Unknown LaTeX command: (   s   textR   (   s   mathscrR   (   R   t
   startswithR   R   R   R   R}   R   t   findR   R   R   R   R   R   t
   negatablesR   R   t   isupperR   R   R   t   Greekt   letterst   specialt	   functionst   overR   R   (   R   R   R   R   R   t   tableRe   R   R   R   t   fencedR   t   operatort   stylet   ovr(    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyR     s    "
	
		
							1 	(    (1   R   t   docutils.utils.math.tex2unichart   utilsRx   t   tex2unicharR   R   t	   mathalphaR   t   mathbinR   t   updatet   mathrelt   mathordt   mathopt   mathopent	   mathcloset	   mathfenceR   t   symbolR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sD   /usr/lib/python2.7/dist-packages/docutils/utils/math/latex2mathml.pyt   <module>   s   

			)	



[
e