ó
 m[c           @` s0  d  d l  m Z m Z m Z m Z d  d l Z d  d l Z d  d l Z d  d l m	 Z	 d  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   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   md5(   t   nodes(   t
   directives(   t   rcParams(   t   MathTextParseru   cmu   mathtext.fontsetu   Bitmapt
   latex_mathc           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s;   lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyR	      s   c         C` s   t  j |  d d d g ƒ S(   Nu   cmu   stixu   stixsans(   R   t   choice(   t   arg(    (    s;   lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   fontset_choice   s    u   fontsetc   
      C` sY   | j  d ƒ } | | d d !} t | ƒ }	 | |	 d <| j d d ƒ |	 d <|	 g g  f S(   Nu   `i   iÿÿÿÿu   latexu   fontsetu   cm(   t   findR	   t   get(
   t   rolet   rawtextt   textt   linenot   inlinert   optionst   contentt   it   latext   node(    (    s;   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(   Nu    u   latexu   fontsetu   cm(   t   joinR	   R   (   t   namet	   argumentsR   R   R   t   content_offsett
   block_textt   statet   state_machineR   R   (    (    s;   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(   Nu   $%s$u   mathtext.fontsett   dpiid   u#   Could not render math expression %si    u   #(   R   t   ost   patht   existst   mathtext_parsert	   get_deptht   to_pngt   warningst   warnt   Warningt   syst   stdoutt   writet   flush(   R   t   filenamet   fontsett   orig_fontsett   depth(    (    s;   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 | ƒ } d j	 t
 j j j d f ƒ } t | | |  d ƒ } | rÞ d	 }	 n d
 }	 | r| d k rd | d }
 n d	 }
 d | | |	 |
 f S(   Nu   latexu   math-%siöÿÿÿu   _imagesu   mathmplu   %s.pngu   /u   fontsetu    u   class="center" i    u)   style="position: relative; bottom: -%dpx"i   u   <img src="%s/%s.png" %s%s/>(   t
   isinstancet   parentR   t   TextElementR   t   encodet	   hexdigestR%   R&   R   t   setupt   appt   buildert   outdirR'   t   makedirst   imgpathR6   (   R   t   sourcet   inlineR   R   t   destdirt   destR&   R5   t   clst   style(    (    s;   lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt
   latex2htmlB   s     
 !	c         C` s“   |  t  _ d „  } d „  } d „  } d „  } |  j t d | | f d | | f ƒ|  j d t ƒ |  j d t t d t	  i t d	 6t d
 6} | S(   Nc         S` s-   |  j  j d } |  j j t | | ƒ ƒ d  S(   Nu   source(   t   documentt
   attributest   bodyt   appendRH   (   t   selfR   RB   (    (    s;   lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   visit_latex_math_html_   s    c         S` s   d  S(   N(    (   RM   R   (    (    s;   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(   Nu   $%s$u   latexu   \begin{equation}u   \end{equation}(   R7   R8   R   R9   RK   RL   t   extend(   RM   R   RC   (    (    s;   lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   visit_latex_math_latexg   s    c         S` s   d  S(   N(    (   RM   R   (    (    s;   lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   depart_latex_math_latexp   s    t   htmlR   u   mathi    u   parallel_read_safeu   parallel_write_safe(   i    i    i    (
   R<   R=   t   add_nodeR	   t   add_roleR   t   add_directiveR#   t   Truet   options_spec(   R=   RN   RO   RQ   RR   t   metadata(    (    s;   lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyR<   [   s    						(   t
   __future__R    R   R   R   t   sixR%   R.   t   hashlibR   t   docutilsR   t   docutils.parsers.rstR   R+   t
   matplotlibR   t   matplotlib.mathtextR   R(   t   Generalt   ElementR	   R   RX   R   R   R#   R6   RH   R<   (    (    (    s;   lib/python2.7/site-packages/matplotlib/sphinxext/mathmpl.pyt   <module>   s(   "
					