Sorry, the str(...) is not required since self._latex_() returns a string.
So SageObject._repr_latex_ can be simplified to:
def _repr_latex_(self):
try:
return '$' + self._latex_() + '$'
except AttributeError:
return None # if None is returned, plain text is used
Le mercredi 24 mars 2021 à 10:43:40 UTC+1, Eric Gourgoulhon a écrit :
> A small update: using the method _latex_ pointed out by Kwankyu, the
> implementation of _repr_latex_ in the class SageObject could become:
>
> def _repr_latex_(self):
> try:
> return '$' + str(self._latex_()) + '$'
> except AttributeError:
> return None # if None is returned, plain text is used
>
>
> Le mardi 23 mars 2021 à 21:49:41 UTC+1, Eric Gourgoulhon a écrit :
>
>> Le mardi 23 mars 2021 à 20:28:45 UTC+1, [email protected] a écrit :
>>
>>> Because I created this years before Jupyter started...
>>>
>>
>> Ah yes!
>>
>> it would be great to redo it.
>>>
>>
>> As a starting point, it would suffice to endow the class SageObject with
>> a method _repr_latex_ defined as something like
>>
>> def _repr_latex_(self):
>> try:
>> return '$' + str(latex(self)) + '$'
>> except ...:
>> return None # if None is returned, the plain text is used
>>
>> Certainly, this would require some fine tuning and the treatment of
>> specific cases.
>>
>> Similar things could be done with _repr_svg_, _repr_png_, etc...
>>
>> Eric.
>>
>>
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sage-devel/4ea3388a-b876-430b-81d3-0748866507e0n%40googlegroups.com.