Beispiel #1
0
    def try_format_obj(self, obj):
        """
        Format non-graphics object.

        OUTPUT:

        A string representation or ``None``. The latter means that no
        Sage-specific formatting is defined and the default should be
        used.

        TESTS::

            sage: from sage.misc.displayhook import DisplayHookBase
            sage: dhb = DisplayHookBase()
            sage: dhb.try_format_obj('Hello, world!')
        """
        if self.simple:
            return self.simple_format_obj(obj)
        if self.ascii_art:
            from sage.misc.ascii_art import ascii_art
            return ascii_art(obj)
        if self.typeset:
            from sage.misc.latex import pretty_print
            pretty_print(obj)
            return ''
        assert(False)
Beispiel #2
0
    def __call__(self, obj, p, cycle):
        r"""
        Return typeset format.

        INPUT:

        - ``obj`` -- anything. Object to format.

        - ``p`` -- PrettyPrinter instance.

        - ``cycle`` -- boolean. Whether there is a cycle.

        OUTPUT:

        Boolean. Whether the representer is applicable to ``obj``. If
        ``True``, the string representation is appended to ``p``.

        EXAMPLES::

            sage: from sage.repl.display.fancy_repr import TypesetRepr
            sage: pp = TypesetRepr()
            sage: pp.format_string(x/2)
            <html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{2} \, x</script></html>
            ''
        """
        # We should probably return that as string, but
        # latex.pretty_print doesn't give us a useful interface
        from sage.misc.latex import pretty_print
        pretty_print(obj)
        return True
Beispiel #3
0
    def __call__(self, obj, p, cycle):
        r"""
        Return typeset format.

        INPUT:

        - ``obj`` -- anything. Object to format.

        - ``p`` -- PrettyPrinter instance.

        - ``cycle`` -- boolean. Whether there is a cycle.

        OUTPUT:

        Boolean. Whether the representer is applicable to ``obj``. If
        ``True``, the string representation is appended to ``p``.

        EXAMPLES::

            sage: from sage.repl.display.fancy_repr import TypesetRepr
            sage: pp = TypesetRepr()
            sage: pp.format_string(x/2)
            <html><script type="math/tex">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{2} \, x</script></html>
            ''
        """
        # We should probably return that as string, but
        # latex.pretty_print doesn't give us a useful interface
        from sage.misc.latex import pretty_print
        pretty_print(obj)
        return True