<commit_before>"""Tools for setting up printing in interactive sessions. """

from cStringIO import StringIO

from sympy import latex
from sympy import preview


def _init_python_printing(stringify_func):
    """Setup printing in Python interactive session. """
    import __builtin__
    import sys

    def _displayhook(arg):
        """Python's pretty-printer display hook.

           This function was adapted from:

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

        """
        if arg is not None:
            __builtin__._ = None
            print stringify_func(arg)
            __builtin__._ = arg

    sys.displayhook = _displayhook


def _init_ipython_printing(ip, stringify_func, use_latex, euler,
                           forecolor, backcolor, fontsize, latex_mode):
    """Setup printing in IPython interactive session. """

    preamble = "\\documentclass[%s]{article}\n" \
               "\\pagestyle{empty}\n" \
               "\\usepackage{amsmath,amsfonts}%s\\begin{document}"
    if euler:
        addpackages = '\\usepackage{euler}'
    else:
        addpackages = ''
    preamble = preamble % (fontsize, addpackages)

    imagesize = 'tight'
    offset = "0cm,0cm"
    resolution = 150
    dvi = r"-T %s -D %d -bg %s -fg %s -O %s" % (
        imagesize, resolution, backcolor, forecolor, offset)
    dvioptions = dvi.split()
    # print "DVIOPTIONS", dvioptions
    # print "PREAMBLE", preamble

    def _print_plain(arg, p, cycle):
        """caller for pretty, for use in IPython 0.11"""
        p.text(stringify_func(arg))

    def _preview_wrapper(o):
        exprbuffer = StringIO()
        preview(o, output='png', viewer='StringIO', outputbuffer=exprbuffer,
                preamble=preamble, dvioptions=dvioptions)
        return exprbuffer.getvalue()

    def _print_latex_png(o):
        s = latex(o, mode=mode)
        return _preview_wrapper(s)

    #not used
    def _print_latex_inline_png(o):
        """
        A function to display sympy expressions using inline style LaTeX in PNG.
        """
        s = latex(o, mode='inline')
        return _preview_wrapper(s)

    #not used
    def _print_latex_display_png(o):
        """
        A function to display sympy expression using display style LaTeX in PNG.
        """
        s = latex(o, mode='plain')
        return _preview_wrapper('$' + s + '$')<commit_msg>_print_latex_png should also use the _can_print_latex logic.<commit_after>"""Tools for setting up printing in interactive sessions. """

from cStringIO import StringIO

from sympy import latex
from sympy import preview


def _init_python_printing(stringify_func):
    """Setup printing in Python interactive session. """
    import __builtin__
    import sys

    def _displayhook(arg):
        """Python's pretty-printer display hook.

           This function was adapted from:

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

        """
        if arg is not None:
            __builtin__._ = None
            print stringify_func(arg)
            __builtin__._ = arg

    sys.displayhook = _displayhook


def _init_ipython_printing(ip, stringify_func, use_latex, euler,
                           forecolor, backcolor, fontsize, latex_mode):
    """Setup printing in IPython interactive session. """

    preamble = "\\documentclass[%s]{article}\n" \
               "\\pagestyle{empty}\n" \
               "\\usepackage{amsmath,amsfonts}%s\\begin{document}"
    if euler:
        addpackages = '\\usepackage{euler}'
    else:
        addpackages = ''
    preamble = preamble % (fontsize, addpackages)

    imagesize = 'tight'
    offset = "0cm,0cm"
    resolution = 150
    dvi = r"-T %s -D %d -bg %s -fg %s -O %s" % (
        imagesize, resolution, backcolor, forecolor, offset)
    dvioptions = dvi.split()
    # print "DVIOPTIONS", dvioptions
    # print "PREAMBLE", preamble

    def _print_plain(arg, p, cycle):
        """caller for pretty, for use in IPython 0.11"""
        p.text(stringify_func(arg))

    def _preview_wrapper(o):
        exprbuffer = StringIO()
        preview(o, output='png', viewer='StringIO', outputbuffer=exprbuffer,
                preamble=preamble, dvioptions=dvioptions)
        return exprbuffer.getvalue()

    def _print_latex_png(o):
        if _can_print_latex(o):
            s = latex(o, mode=latex_mode)
            return _preview_wrapper(s)
        return None

    #not used
    def _print_latex_inline_png(o):
        """
        A function to display sympy expressions using inline style LaTeX in PNG.
        """
        s = latex(o, mode='inline')
        return _preview_wrapper(s)

    #not used
    def _print_latex_display_png(o):
        """
        A function to display sympy expression using display style LaTeX in PNG.
        """
        s = latex(o, mode='plain')
        return _preview_wrapper('$' + s + '$')
{'fraction_non_alphanumeric': 0.10756233257778694, 'fraction_numerical': 0.00494539460127756, 'mean_word_length': 2.3944055944055944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7461373', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1450, 'n_words': 392}