Opened 10 years ago
Last modified 5 years ago
#11428 new enhancement
Customizable latex for functions
Reported by: | SimonKing | Owned by: | burcin |
---|---|---|---|
Priority: | major | Milestone: | sage-6.4 |
Component: | symbolics | Keywords: | |
Cc: | Merged in: | ||
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
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.
Attachments (1)
Change History (9)
comment:1 Changed 10 years ago by
Changed 10 years ago by
Preliminary patch: Change latex/repr of a function. But the custom names are not propagated.
comment:2 Changed 10 years ago by
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 9 years ago by
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
- Milestone changed from sage-5.11 to sage-5.12
comment:5 Changed 8 years ago by
- Milestone changed from sage-6.1 to sage-6.2
comment:6 Changed 7 years ago by
- Milestone changed from sage-6.2 to sage-6.3
comment:7 Changed 7 years ago by
- Milestone changed from sage-6.3 to sage-6.4
Please upload that preliminary patch so others can work with it!
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 :)