Customizing sage objects latex behaviour

asked 2021-03-08 14:06:24 +0200

Felix Blix gravatar image

I'm a recent user of Sage, and am really enjoing it. I use it through jupyter, mixing a lot of markdown/latex and computations. After this initial period, I have one major annoyance:
In some cases it would be really nice to be able to modify the latex representation of built-in objects.
I am fully aware one can easily create functions that create the desired latex from an object, but this requires you to type this function every time the given datatype is in play which is impractical. This becomes even worse when using the %display text latex cell magic.
I have two concrete examples to show what kind of behaviour change I'm after:

  1. Typeset vectors as column vectors rather than row vectors.
  2. Typeset RealField numbers similar to what you would get from 1.23.str(skip_zeroes=True, truncate=True)

I have googled quite a bit but always come up short, but I am new to sage and might be missing something.
Some select elements can be configured, such as the RealField.scientific_notation method or the latex.matrix_delimiters, but wrapping or modifying the _latex_ method or something to the same effect would be much more flexible, albeit one could argue it would also be more _hacky_ ;)

Thanks for your help!

edit retag flag offensive close merge delete

Comments

For vectors: I don't see a non-hacky way to do it currently, but looking at the implementation of _latex_ with v._latex_?? for a vector object v shows that it would be easy to implement. Just to mention some functionality that I wasn't aware of before I searched for it: you can do vector([1,2,3]).column().

rburing gravatar imagerburing ( 2021-03-08 22:42:55 +0200 )edit

@rburing: Well at least it helps to know that there's nothing to do about it :) I have been using the column method, which works fine. But again it is just extra typing, and makes the code just a little more cluttered.

Felix Blix gravatar imageFelix Blix ( 2021-03-15 08:59:20 +0200 )edit