Ticket #13734: trac_13734-latex_for_element_wrapper-cs.patch

File trac_13734-latex_for_element_wrapper-cs.patch, 2.9 KB (added by stumpc5, 9 years ago)
  • sage/structure/element_wrapper.py

    # HG changeset patch
    # User Christian Stump <christian.stump at gmail.com>
    # Date 1353495614 -3600
    # Node ID 0dafe7d438e1b30baaf53383ab0a548933851836
    # Parent  3c1c6f994cd17c511ff6ab0a4611d521205867ff
    trac 13734: implements latex method for ElementWrapper
    
    diff --git a/sage/structure/element_wrapper.py b/sage/structure/element_wrapper.py
    a b  
    11"""
    22Wrapping Sage or Python objects as Sage elements
    33
    4 WARNING: This class has serious issues that can lead to subtle 
    5 segfaults.  Do not use it unless you read trac 8200 first: 
     4WARNING: This class has serious issues that can lead to subtle
     5segfaults.  Do not use it unless you read trac 8200 first:
    66http://trac.sagemath.org/sage_trac/ticket/8200
    77"""
    88#*****************************************************************************
    class ElementWrapper(Element): 
    1919    r"""
    2020    A class for wrapping Sage or Python objects as Sage elements
    2121
    22     WARNING: This class has serious issues that can lead to subtle 
    23     segfaults.  Do not use it unless you read trac 8200 first: 
     22    WARNING: This class has serious issues that can lead to subtle
     23    segfaults.  Do not use it unless you read trac 8200 first:
    2424    http://trac.sagemath.org/sage_trac/ticket/8200
    2525
    2626    EXAMPLES::
    class ElementWrapper(Element): 
    103103        EXAMPLES::
    104104
    105105            sage: from sage.structure.element_wrapper import DummyParent
    106             sage: ElementWrapper(1, parent = DummyParent("A parent"))
     106            sage: ElementWrapper(1, parent = DummyParent("A parent")) # indirect doctest
    107107            1
    108108        """
    109109        return repr(self.value)
    110110
     111    def _latex_(self):
     112        """
     113        EXAMPLES::
     114
     115            sage: from sage.structure.element_wrapper import DummyParent
     116            sage: ElementWrapper(1, parent = DummyParent("A parent"))._latex_()
     117            1
     118            sage: ElementWrapper(3/5, parent = DummyParent("A parent"))._latex_()
     119            \frac{3}{5}
     120        """
     121        from sage.misc.latex import latex
     122        return latex(self.value)
     123
    111124    def __hash__(self):
    112125        """
    113126        Returns the same hash as for the wrapped element
    class DummyParent(UniqueRepresentation,  
    331344        EXAMPLES::
    332345
    333346            sage: from sage.structure.element_wrapper import DummyParent
    334             sage: DummyParent("A Parent")
     347            sage: DummyParent("A Parent") # indirect doctest
    335348            A Parent
    336349        """
    337350        return self.name
    class ElementWrapperTester(ElementWrappe 
    388401            sage: x = ElementWrapperTester
    389402            sage: x = ElementWrapperTester(); x
    390403            [n=0, value=[]]
    391             sage: x.value = [2,32]; x
     404            sage: x.value = [2,32]; x # indirect doctest
    392405            [n=0, value=[2, 32]]
    393406        """
    394407        return "[n=%s, value=%s]"%(self.n, self.value)