# 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


1  1  """ 
2  2  Wrapping Sage or Python objects as Sage elements 
3  3  
4   WARNING: This class has serious issues that can lead to subtle 
5   segfaults. Do not use it unless you read trac 8200 first: 
 4  WARNING: This class has serious issues that can lead to subtle 
 5  segfaults. Do not use it unless you read trac 8200 first: 
6  6  http://trac.sagemath.org/sage_trac/ticket/8200 
7  7  """ 
8  8  #***************************************************************************** 
… 
… 
class ElementWrapper(Element): 
19  19  r""" 
20  20  A class for wrapping Sage or Python objects as Sage elements 
21  21  
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: 
24  24  http://trac.sagemath.org/sage_trac/ticket/8200 
25  25  
26  26  EXAMPLES:: 
… 
… 
class ElementWrapper(Element): 
103  103  EXAMPLES:: 
104  104  
105  105  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 
107  107  1 
108  108  """ 
109  109  return repr(self.value) 
110  110  
 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  
111  124  def __hash__(self): 
112  125  """ 
113  126  Returns the same hash as for the wrapped element 
… 
… 
class DummyParent(UniqueRepresentation, 
331  344  EXAMPLES:: 
332  345  
333  346  sage: from sage.structure.element_wrapper import DummyParent 
334   sage: DummyParent("A Parent") 
 347  sage: DummyParent("A Parent") # indirect doctest 
335  348  A Parent 
336  349  """ 
337  350  return self.name 
… 
… 
class ElementWrapperTester(ElementWrappe 
388  401  sage: x = ElementWrapperTester 
389  402  sage: x = ElementWrapperTester(); x 
390  403  [n=0, value=[]] 
391   sage: x.value = [2,32]; x 
 404  sage: x.value = [2,32]; x # indirect doctest 
392  405  [n=0, value=[2, 32]] 
393  406  """ 
394  407  return "[n=%s, value=%s]"%(self.n, self.value) 