ó
±éRc           @  s:  d  d l  m Z d  d l Z d  d l Z y d  d l m Z Wn! e k
 r_ d  d l m Z n Xd  d l m Z d  d l	 m
 Z
 d  d l Z d  d l m Z d  d l m Z d e d	 <e d
 ƒ Z d e j e j f d „  ƒ  YZ d „  Z i e d 6Z i  g  d „ Z e e _ d „  Z d d „ Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   print_functionN(   t   md5(   t   nodes(   t
   directives(   t   rcParams(   t   MathTextParsert   cms   mathtext.fontsett   Bitmapt
   latex_mathc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyR      s   c         C  s   t  j |  d d d g ƒ S(   NR   t   stixt   stixsans(   R   t   choice(   t   arg(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   fontset_choice   s    t   fontsetc   
      C  sY   | j  d ƒ } | | d d !} t | ƒ }	 | |	 d <| j d d ƒ |	 d <|	 g g  f S(   Nt   `i   iÿÿÿÿt   latexR   R   (   t   findR   t   get(
   t   rolet   rawtextt   textt   linenot   inlinert   optionst   contentt   iR   t   node(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt	   math_role   s    
c	         C  sB   d j  | ƒ }	 t | ƒ }
 |	 |
 d <| j d d ƒ |
 d <|
 g S(   Nt    R   R   R   (   t   joinR   R   (   t   namet	   argumentsR   R   R   t   content_offsett
   block_textt   statet   state_machineR   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   math_directive%   s
    
c         C  s³   d |  }  t  d } | t  d <t j j | ƒ rH t j |  d d ƒ} n@ y t j | |  d d ƒ} Wn! t j d |  t	 ƒ d } n X| t  d <t
 j j d ƒ t
 j j ƒ  | S(   Ns   $%s$s   mathtext.fontsett   dpiid   s#   Could not render math expression %si    t   #(   R   t   ost   patht   existst   mathtext_parsert	   get_deptht   to_pngt   warningst   warnt   Warningt   syst   stdoutt   writet   flush(   R   t   filenameR   t   orig_fontsett   depth(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt	   latex2png.   s    




c         C  s!  t  |  j t j ƒ } |  d } d t | j ƒ  ƒ j ƒ  d } t j j	 t
 j j j d d ƒ } t j j | ƒ s‚ t j | ƒ n  t j j	 | d | ƒ } t j j	 t
 j j j d ƒ } t | | |  d ƒ } | rÞ d }	 n d	 }	 | r| d
 k rd | d }
 n d }
 d | | |	 |
 f S(   NR   s   math-%siöÿÿÿt   _imagest   mathmpls   %s.pngR   R   s   class="center" i    s)   style="position: relative; bottom: -%dpx"i   s   <img src="%s/%s.png" %s%s/>(   t
   isinstancet   parentR   t   TextElementR   t   encodet	   hexdigestR*   R+   R    t   setupt   appt   buildert   outdirR,   t   makedirst   imgpathR:   (   R   t   sourcet   inlineR   R!   t   destdirt   destR+   R9   t   clst   style(    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt
   latex2htmlA   s     
 !	c         C  s©   |  t  _ |  j t ƒ |  j d t ƒ d „  } d „  } d „  } d „  } |  j t d | | f ƒ|  j t d | | f ƒ|  j d t ƒ |  j d t t d	 t	 � d  S(
   Nt   mathc         S  s-   |  j  j d } |  j j t | | ƒ ƒ d  S(   NRH   (   t   documentt
   attributest   bodyt   appendRN   (   t   selfR   RH   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   visit_latex_math_html`   s    c         S  s   d  S(   N(    (   RT   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   depart_latex_math_htmlc   s    c         S  sW   t  | j t j ƒ } | r6 |  j j d | d ƒ n |  j j d | d d g ƒ d  S(   Ns   $%s$R   s   \begin{equation}s   \end{equation}(   R=   R>   R   R?   RR   RS   t   extend(   RT   R   RI   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   visit_latex_math_latexg   s    c         S  s   d  S(   N(    (   RT   R   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   depart_latex_math_latexo   s    t   htmlR   i    (   i    i    i    (
   RB   RC   t   add_nodeR   t   add_roleR   t   add_directiveR'   t   Truet   options_spec(   RC   RU   RV   RX   RY   (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyRB   Y   s    					

(   t
   __future__R    R*   R3   t   hashlibR   t   ImportErrort   docutilsR   t   docutils.parsers.rstR   R0   t
   matplotlibR   t   matplotlib.mathtextR   R-   t   Generalt   ElementR   R   R_   R   R   R'   R:   RN   RB   (    (    (    sV   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   <module>   s,   
					