Opened 10 years ago

Customizable latex for functions

Reported by: Owned by: SimonKing burcin major sage-6.4 symbolics N/A

Description

There should be a way to customize how a function is printed and how it is translated into Latex, as requested on ask-sage.

I suggest, as a first step, to add methods set_name() and set_latex_name() that change the value of the cdefined attributes _name used for printing and _latex_name used for translation to latex. Then, the following would work:

sage: tan.set_name('tg')
sage: tan
tg
sage: tan.set_latex_name(r'\tg')
sage: latex(tan)
\tg


However, that can really only be the first step. Because, when I did so, I still got

sage: tan(x)
tan(x)
sage: latex(tan(x))
\tan\left(x\right)


Hence, in addition to that, the given latex name should be propagated to expressions.

comment:1 Changed 10 years ago by kcrisman

The SR stuff does come from Ginac, as I thought I remembered. Maybe Burcin will have a brief comment to put us on the right track for that; I don't quite understand how it works, though I think I once nearly figured it out :)

Changed 10 years ago by SimonKing

Preliminary patch: Change latex/repr of a function. But the custom names are not propagated.

comment:2 Changed 10 years ago by SimonKing

Patch's up.

With it, this works

sage: tan.set_latex_name(r'\tg')
sage: latex(tan)
\tg
sage: tan.set_name('tg')
sage: tan
tg


but this doesn't

sage: tan(x)
tan(x)
sage: latex(tan(x))
\tan\left(x\right)


comment:3 Changed 8 years ago by kcrisman

For reference for anyone implementing this correctly, in this thread on sage-support, Burcin recommends

It needs to go through the
registry of functions stored in Pynac and update the name or the
printing functions there.


comment:4 Changed 8 years ago by jdemeyer

• Milestone changed from sage-5.11 to sage-5.12

comment:5 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.1 to sage-6.2

comment:6 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.2 to sage-6.3

comment:7 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.3 to sage-6.4