σ
ίΘ[c           @` s   d  Z  d d l m Z m Z m Z m Z d d l Z d d l m	 Z	 m
 Z
 m Z d d l m Z d e	 j f d	     YZ d
 e f d     YZ d S(   u"   
Handles the "LaTeX" unit format.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   baset   coret   utilsi   (   t   zipt   Latexc           B` sk   e  Z d  Z e d    Z e d    Z e d    Z e d    Z e d    Z e d d   Z	 RS(   uΌ   
    Output LaTeX to display the unit based on IAU style guidelines.

    Attempts to follow the `IAU Style Manual
    <https://www.iau.org/static/publications/stylemanual1989.pdf>`_.
    c         C` s   | j  d d  S(   Nu   _u   \_(   t   replace(   t   clst   name(    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyt   _latex_escape   s    c         C` s/   | j  d  } | | j k r+ |  j |  S| S(   Nu   latex(   t   get_format_nameR   R   (   R
   t   unitR   (    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyt   _get_unit_name   s    c         C` sz   g  } xd | D]\ \ } } | d k r> | j  |  j |   q | j  d j |  j |  t j |    q Wd j |  S(   Ni   u   {0}^{{{1}}}u   \,(   t   appendR   t   formatR   t   format_powert   join(   R
   t   unitst   outR   t   power(    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyt   _format_unit_list&   s    c         C` s   t  j | j | j  \ } } t |  rr t |  rH |  j |  } n d } |  j |  } d j | |  } n |  j |  } | } | S(   Nu   1u   \frac{{{0}}}{{{1}}}(   R   t   get_grouped_by_powerst   basest   powerst   lenR   R   (   R
   R   t	   positivest	   negativest   s(    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyt   _format_bases2   s    c         C` sΫ   d  } t | d  r* | j j d  } n  | d  k	 r? | } n t | t j  r§ | j d k ri d } n |  j | j  d } t	 | j
  rΞ | |  j |  7} qΞ n' t | t j  rΞ |  j | j  } n  d j |  S(   Nu   _formatu   latexi   u    u   \,u   $\mathrm{{{0}}}$(   t   Nonet   hasattrt   _formatt   gett
   isinstanceR   t   CompositeUnitt   scalet   format_exponential_notationR   R   R   t	   NamedUnitR   R   R   (   R
   R   t
   latex_nameR   (    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyt	   to_stringD   s    		u   .8gc         C` s   t  j |  ro t j | |  \ } } g  } | rC | j |  n  | rb | j d j |   n  d j |  St  j |  r d S| d k r d Sd Sd S(   u  
        Formats a value in exponential notation for LaTeX.

        Parameters
        ----------
        val : number
            The value to be formatted

        format_spec : str, optional
            Format used to split up mantissa and exponent

        Returns
        -------
        latex_string : str
            The value in exponential notation in a format suitable for LaTeX.
        u
   10^{{{0}}}u    \times u	   {\rm NaN}i    u   \inftyu   -\inftyN(   t   npt   isfiniteR   t   split_mantissa_exponentR   R   R   t   isnan(   R
   t   valt   format_spect   mt   ext   parts(    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyR'   Z   s    (
   t   __name__t
   __module__t   __doc__t   classmethodR   R   R   R   R*   R'   (    (    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyR      s   t   LatexInlinec           B` s#   e  Z d  Z d Z e d    Z RS(   u1  
    Output LaTeX to display the unit based on IAU style guidelines with negative
    powers.

    Attempts to follow the `IAU Style Manual
    <https://www.iau.org/static/publications/stylemanual1989.pdf>`_ and the
    `ApJ and AJ style guide
    <http://journals.aas.org/authors/manuscript.html>`_.
    u   latex_inlinec         C` s   |  j  t | j | j   S(   N(   R   R   R   R   (   R
   R   (    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyR      s    (   R4   R5   R6   R   R7   R   (    (    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyR8      s   	(   R6   t
   __future__R    R   R   R   t   numpyR+   t    R   R   R   t   extern.six.movesR   t   BaseR   R8   (    (    (    s9   lib/python2.7/site-packages/astropy/units/format/latex.pyt   <module>   s   "q