Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can attributes of sage classes be changed?

I want to change the way vectors are rendered in sagetex. For example, consider v = vector([1, 2, 3]). In sagetex, the command $v=\sage{v}$ renders as $$ v=(1, 2, 3) $$ Instead, I want my vectors to take the form $$ v=\left[\begin{array}{rrr}1&2&3\end{array}\right]^\intercal $$ I thought I could do this by resetting the _latex_ method of the sage.modules.free_module_element.FreeModuleElement class as follows.

def my_vector_latex(self):
    return matrix(v)._latex_() + r'^\intercal'

setattr(sage.modules.free_module_element.FreeModuleElement, '_latex_', my_vector_latex)

However, this code throws the following error:

TypeError: can't set attributes of built-in/extension type 'sage.modules.free_module_element.FreeModuleElement'

So, it looks like I can't modify the methods of FreeModuleElement in this way. Is there anything else I could do?