Opened 12 years ago
Last modified 6 years ago
#11428 new enhancement
Customizable latex for functions
Reported by: | Simon King | Owned by: | Burcin Erocal |
---|---|---|---|
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 12 years ago by
Changed 12 years ago by
Attachment: | trac11428_customize_latex_for_functions.patch added |
---|
Preliminary patch: Change latex/repr of a function. But the custom names are not propagated.
comment:2 Changed 12 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 10 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 9 years ago by
Milestone: | sage-5.11 → sage-5.12 |
---|
comment:5 Changed 9 years ago by
Milestone: | sage-6.1 → sage-6.2 |
---|
comment:6 Changed 9 years ago by
Milestone: | sage-6.2 → sage-6.3 |
---|
comment:7 Changed 8 years ago by
Milestone: | sage-6.3 → sage-6.4 |
---|
comment:8 Changed 6 years ago by
I think it would be more consistent to simply allow the same mechanism as with BuiltinFunction
s. This should pose no problem, since there it is already channeled through Pynac. Effectively, if there is not a LaTeX print function defined in Pynac then the Python _print_latex_
member should be tried.
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 :)