ó
¡¼™\c           @  sé   d  Z  d d l m Z m Z d d l Z d d l m Z d d l m	 Z	 d d l
 m Z d d l
 m Z d d l m Z d d	 l m Z d
 „  Z d „  Z d „  Z e Z e d d d d d e d e d d d d e d d d d „ Z d S(   s7   Tools for setting up printing in interactive sessions. iÿÿÿÿ(   t   print_functiont   divisionN(   t   LooseVersion(   t   BytesIO(   t   latex(   t   preview(   t   integer_types(   t   debugc           s>   d d l  } d d l m ‰  ‡  ‡ ‡ f d †  } | | _ d S(   s.   Setup printing in Python interactive session. iÿÿÿÿN(   t   builtinsc           s8   |  d k	 r4 d ˆ  _ t ˆ |  ˆ  ƒ |  ˆ  _ n  d S(   s‘   Python's pretty-printer display hook.

           This function was adapted from:

            http://www.python.org/dev/peps/pep-0217/

        N(   t   Nonet   _t   print(   t   arg(   R   t   settingst   stringify_func(    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _displayhook   s    	(   t   syst   sympy.core.compatibilityR   t   displayhook(   R   R   R   R   (    (   R   R   R   s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _init_python_printing   s    c
            s  y d d l  m ‰ Wn t k
 r' n Xd ‰ | r= d } n d } ˆ | | f ‰ d } d } d } d	 | | | | | f } | j ƒ  ‰ t d
 ˆ ƒ t d ˆ ƒ |	 p­ t ‰ ‡  ‡ ‡ f d †  } ‡ ‡ f d †  ‰ ‡ f d †  ‰ d d l m } d d l m	 } d d l
 m } m } d d l m } | | | | | f ‰ ‡ ‡	 ‡ f d †  ‰ ‡ ‡ ‡ ‡ ‡ ‡
 f d †  } ‡ ‡ ‡ ‡
 f d †  } ‡ ‡ ‡ ‡
 f d †  } ‡ f d †  } d d l ‰  t ˆ  j ƒ d k r
d d l m } d d l m	 } d d l
 m } m } d d l m } | | t t t t t t | | | g t t ƒ } |  j j d } x | D] } | j | | ƒ qbW|  j j d } | t d f k rÌt d ƒ x˜ | D] } | j | | ƒ q¯Wnw | d k rt d ƒ x^ | D] } | j | | ƒ qéWn= t d  ƒ x0 | D]( } | | j k r| j j  | ƒ qqW|  j j d! } | t d" f k r°t d# ƒ x | D] } | j | | ƒ qvWxt ˆ D] } | j! | _" q—Wqt d$ ƒ x0 | D]( } | | j k rÁ| j j  | ƒ qÁqÁWx* ˆ D] } d | _" qôWn |  j$ d% | ƒ d S(&   s/   Setup printing in IPython interactive session. iÿÿÿÿ(   t   latex_to_pngsW   \documentclass[varwidth,%s]{standalone}
\usepackage{amsmath,amsfonts}%s\begin{document}s   \usepackage{euler}t    t   tights   0cm,0cmi–   s   -T %s -D %d -bg %s -fg %s -O %ss   init_printing: DVIOPTIONS:s   init_printing: PREAMBLE:c           sB   ˆ |  ƒ r" | j  ˆ |  ƒ ƒ n | j  ˆ  j j j |  ƒ ƒ d S(   s*   caller for pretty, for use in IPython 0.11N(   t   textt   libt   pretty(   R   t   pt   cycle(   t   IPythont   _can_print_latexR   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _print_plain@   s    c           sn   t  ƒ  } y, t |  d d d d d | d ˆ d ˆ  ƒWn, t k
 rc } t d d	 t | ƒ ƒ ‚  n X| j ƒ  S(
   Nt   outputt   pngt   viewerR   t   outputbuffert   preamblet
   dvioptionss   png printing:s"   _preview_wrapper exception raised:(   R   R   t	   ExceptionR   t   reprt   getvalue(   t   ot
   exprbuffert   e(   R$   R#   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _preview_wrapperG   s    		c           s`   |  j  d d ƒ }  |  j  d d ƒ }  y ˆ  |  ƒ SWn' t k
 r[ } t d t | ƒ ƒ d  SXd  S(   Ns   \operatornameR   s	   \overlines   \bars   matplotlib exception caught:(   t   replacet
   ValueErrorR   R&   R	   (   R(   R*   (   R   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _matplotlib_wrapperT   s    (   t   Basic(   t
   MatrixBase(   t   Vectort   Dyadic(   t	   NDimArrayc           s  yö t  t t t f } t ˆ  | ƒ r€ t ˆ  ƒ j d „  | Dƒ k sb t ˆ  ƒ j d „  | Dƒ k rf t St	 ‡ f d †  ˆ  Dƒ ƒ St ˆ  t
 ƒ r¬ t	 ‡ ‡  f d †  ˆ  Dƒ ƒ St ˆ  t ƒ r¿ t St ˆ  ˆ ƒ rÒ t St ˆ  t t f ƒ rñ ˆ rñ t St SWn t k
 r
t SXd S(   s®   Return True if type o can be printed with LaTeX.

        If o is a container type, this is True if and only if every element of
        o can be printed with LaTeX.
        c         s  s   |  ] } | j  Vq d  S(   N(   t   __str__(   t   .0t   i(    (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pys	   <genexpr>{   s    c         s  s   |  ] } | j  Vq d  S(   N(   t   __repr__(   R5   R6   (    (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pys	   <genexpr>|   s    c         3  s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   R5   R6   (   R   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pys	   <genexpr>~   s    c         3  s+   |  ]! } ˆ  | ƒ o" ˆ  ˆ | ƒ Vq d  S(   N(    (   R5   R6   (   R   R(   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pys	   <genexpr>€   s    N(   t   listt   tuplet   sett	   frozensett
   isinstancet   typeR4   R7   t   Falset   allt   dictt   boolt   Truet   floatR   t   RuntimeError(   R(   t   builtin_types(   R   t   print_builtint   sympy_latex_types(   R(   s9   lib/python2.7/site-packages/sympy/interactive/printing.pyR   l   s$    c           s¦   ˆ  |  ƒ r¢ ˆ |  d ˆ ˆ } ˆ d k r: d | } n  y ˆ | ƒ SWq¢ t  k
 rž } t d t | ƒ d ƒ ˆ d k r” ˆ |  d d ˆ } n  ˆ | ƒ SXn  d S(   sˆ   
        A function that returns a png rendered by an external latex
        distribution, falling back to matplotlib rendering
        t   modet   plains   $\displaystyle %s$s   preview failed with:s#    Falling back to matplotlib backendt   inlineN(   RD   R   R&   (   R(   t   sR*   (   R   R.   R+   R   t
   latex_modeR   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _print_latex_png   s    c           s/   ˆ  |  ƒ r+ ˆ |  d d ˆ } ˆ | ƒ Sd S(   sD   
        A function that returns a png rendered by mathtext
        RH   RJ   N(    (   R(   RK   (   R   R.   R   R   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _print_latex_matplotlib¢   s    c           s=   ˆ  |  ƒ r9 ˆ |  d ˆ ˆ } ˆ d k r5 d | S| Sd S(   sW   
        A function to generate the latex representation of sympy expressions.
        RH   RI   s   $\displaystyle %s$N(    (   R(   RK   (   R   R   RL   R   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _print_latex_textª   s
    c           sL   |  j  j r8 ˆ  | ƒ } d | k r+ t n  t | ƒ n t t | ƒ ƒ d S(   sž   IPython's pretty-printer display hook, for use in IPython 0.10

           This function was adapted from:

            ipython/IPython/hooks.py:155

        s   
N(   t   rct   pprintR   R&   (   t   selfR   t   out(   R   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _result_display´   s    Ns   0.11s
   text/plains	   image/pngR    s"   init_printing: using png formattert
   matplotlibs)   init_printing: using matplotlib formatters*   init_printing: not using any png formatters
   text/latext   mathjaxs&   init_printing: using mathjax formatters-   init_printing: not using text/latex formattert   result_display(%   t   IPython.lib.latextoolsR   t   ImportErrort   splitR   t   default_latext   sympyR/   t   sympy.matricesR0   t   sympy.physics.vectorR1   R2   t   sympy.tensor.arrayR3   R   t   Vt   __version__t   sympy.core.basict   sympy.matrices.matricesRC   R9   R8   R:   R;   R@   R   t   display_formattert
   formatterst   for_typeRB   t   type_printerst   popt   _repr_latex_origt   _repr_latex_R	   t   set_hook(    t   ipR   t	   use_latext   eulert	   forecolort	   backcolort   fontsizeRL   RF   t   latex_printerR   t   addpackagest	   imagesizet   offsett
   resolutiont   dviR   R/   R0   R1   R2   R3   RM   RN   RO   RT   t   printable_typest   plaintext_formattert   clst   png_formattert   latex_formattert   typ(    (   R   R   R.   R+   R$   R   RL   R   R#   RF   R   R   RG   s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _init_ipython_printing$   sŠ    	$





c         C  sq   d t  j k r t Sy d d l m } Wn: t k
 rc y d d l m } Wqd t k
 r_ t SXn Xt |  | ƒ S(   s%   Is a shell instance an IPython shell?R   iÿÿÿÿ(   t   InteractiveShell(   R   t   modulesR>   t   IPython.core.interactiveshellR   RY   t   IPython.iplibR<   (   t   shellR   (    (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   _is_ipythonû   s    	t   Blackt   Transparentt   10ptRI   c           s  d d l  } d d l m } |  rJ | d k	 r7 | } qo d d l m } n% | d k	 r_ | } n d d l m } t } | d k r± y t ƒ  } Wn t	 k
 r¡ q± X| d k	 } n  | rÍ | rÍ t
 | ƒ } n  | r·|  r·yX d d l } t | j ƒ d k rd d l m } n d d l m } d d l m } Wn t k
 rDq·Xt | | | f ƒ r·d	 d
 j | j ƒ k r·ˆ d k r’t d ƒ t ‰ n  | d k r´t d ƒ t } q´q·n  t rê| rê| j d ˆ d ˆ d ˆ d ˆ ƒ n< | ‰  |  r‡  ‡ ‡ ‡ ‡ f d †  } n ‡  ‡ f d †  } | r|| j d d ƒ } | rQt d ƒ n  t | | | | |	 |
 | | | | | 
 n t | |  d S(   s%  
    Initializes pretty-printer depending on the environment.

    Parameters
    ==========

    pretty_print: boolean
        If True, use pretty_print to stringify or the provided pretty
        printer; if False, use sstrrepr to stringify or the provided string
        printer.
    order: string or None
        There are a few different settings for this parameter:
        lex (default), which is lexographic order;
        grlex, which is graded lexographic order;
        grevlex, which is reversed graded lexographic order;
        old, which is used for compatibility reasons and for long expressions;
        None, which sets it to lex.
    use_unicode: boolean or None
        If True, use unicode characters;
        if False, do not use unicode characters.
    use_latex: string, boolean, or None
        If True, use default latex rendering in GUI interfaces (png and
        mathjax);
        if False, do not use latex rendering;
        if 'png', enable latex rendering with an external latex compiler,
        falling back to matplotlib if external compilation fails;
        if 'matplotlib', enable latex rendering with matplotlib;
        if 'mathjax', enable latex text generation, for example MathJax
        rendering in IPython notebook or text rendering in LaTeX documents
    wrap_line: boolean
        If True, lines will wrap at the end; if False, they will not wrap
        but continue as one line. This is only relevant if `pretty_print` is
        True.
    num_columns: int or None
        If int, number of columns before wrapping is set to num_columns; if
        None, number of columns before wrapping is set to terminal width.
        This is only relevant if `pretty_print` is True.
    no_global: boolean
        If True, the settings become system wide;
        if False, use just for this console/session.
    ip: An interactive console
        This can either be an instance of IPython,
        or a class that derives from code.InteractiveConsole.
    euler: boolean, optional, default=False
        Loads the euler package in the LaTeX preamble for handwritten style
        fonts (http://www.ctan.org/pkg/euler).
    forecolor: string, optional, default='Black'
        DVI setting for foreground color.
    backcolor: string, optional, default='Transparent'
        DVI setting for background color.
    fontsize: string, optional, default='10pt'
        A font size to pass to the LaTeX documentclass function in the
        preamble.
    latex_mode: string, optional, default='plain'
        The mode used in the LaTeX printer. Can be one of:
        {'inline'|'plain'|'equation'|'equation*'}.
    print_builtin: boolean, optional, default=True
        If true then floats and integers will be printed. If false the
        printer will only print SymPy types.
    str_printer: function, optional, default=None
        A custom string printer function. This should mimic
        sympy.printing.sstrrepr().
    pretty_printer: function, optional, default=None
        A custom pretty printer. This should mimic sympy.printing.pretty().
    latex_printer: function, optional, default=None
        A custom LaTeX printer. This should mimic sympy.printing.latex().

    Examples
    ========

    >>> from sympy.interactive import init_printing
    >>> from sympy import Symbol, sqrt
    >>> from sympy.abc import x, y
    >>> sqrt(5)
    sqrt(5)
    >>> init_printing(pretty_print=True) # doctest: +SKIP
    >>> sqrt(5) # doctest: +SKIP
      ___
    \/ 5
    >>> theta = Symbol('theta') # doctest: +SKIP
    >>> init_printing(use_unicode=True) # doctest: +SKIP
    >>> theta # doctest: +SKIP
    \u03b8
    >>> init_printing(use_unicode=False) # doctest: +SKIP
    >>> theta # doctest: +SKIP
    theta
    >>> init_printing(order='lex') # doctest: +SKIP
    >>> str(y + x + y**2 + x**2) # doctest: +SKIP
    x**2 + x + y**2 + y
    >>> init_printing(order='grlex') # doctest: +SKIP
    >>> str(y + x + y**2 + x**2) # doctest: +SKIP
    x**2 + x + y**2 + y
    >>> init_printing(order='grevlex') # doctest: +SKIP
    >>> str(y * x**2 + x * y**2) # doctest: +SKIP
    x**2*y + x*y**2
    >>> init_printing(order='old') # doctest: +SKIP
    >>> str(x**2 + y**2 + x + y) # doctest: +SKIP
    x**2 + x + y**2 + y
    >>> init_printing(num_columns=10) # doctest: +SKIP
    >>> x**2 + x + y**2 + y # doctest: +SKIP
    x + y +
    x**2 + y**2
    iÿÿÿÿN(   t   Printer(   R   (   t   sstrreprs   1.0(   t   TerminalInteractiveShell(   t   InteractiveConsoles   ipython-consoleR   s*   init_printing: Setting use_unicode to Trues(   init_printing: Setting use_latex to Truet   ordert   use_unicodet	   wrap_linet   num_columnsc      
     s"   ˆ  |  d ˆ d ˆ d ˆ d ˆ ƒS(   NRŒ   R   RŽ   R   (    (   t   expr(   t   _stringify_funcR   RŒ   R   RŽ   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   <lambda>·  s    c           s   ˆ  |  d ˆ ƒS(   NRŒ   (    (   R   (   R‘   RŒ   (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyR’   ½  R   RH   sM   init_printing: Mode is not able to be set due to internalsof IPython printing(   R   t   sympy.printing.printerRˆ   R	   t   sympy.printingR   R‰   R>   t   get_ipythont	   NameErrorR„   R   R`   Ra   t!   IPython.terminal.interactiveshellRŠ   t*   IPython.frontend.terminal.interactiveshellt   codeR‹   RY   R<   t   joint   argvR   RB   t	   NO_GLOBALt   set_global_settingsRh   R~   R   (   t   pretty_printRŒ   R   Rm   RŽ   R   t	   no_globalRl   Rn   Ro   Rp   Rq   RL   RF   t   str_printert   pretty_printerRr   R   R   Rˆ   R   t
   in_ipythonR   RŠ   R‹   t   mode_in_settings(    (   R‘   R   RŒ   R   RŽ   s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   init_printing  sd    n		
	
(   t   __doc__t
   __future__R    R   R   t   distutils.versionR   R`   t   ioR   R\   R   R[   R   R   R   t   sympy.utilities.miscR   R   R~   R„   R>   Rœ   RB   R	   R¤   (    (    (    s9   lib/python2.7/site-packages/sympy/interactive/printing.pyt   <module>   s&   		×			