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:

Status badges

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)

trac11428_customize_latex_for_functions.patch (1.1 KB) - added by Simon King 12 years ago.
Preliminary patch: Change latex/repr of a function. But the custom names are not propagated.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 12 years ago by Karl-Dieter Crisman

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 :)

Changed 12 years ago by Simon King

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

comment:2 Changed 12 years ago by Simon King

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 Karl-Dieter Crisman

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 Jeroen Demeyer

Milestone: sage-5.11sage-5.12

comment:5 Changed 9 years ago by For batch modifications

Milestone: sage-6.1sage-6.2

comment:6 Changed 9 years ago by For batch modifications

Milestone: sage-6.2sage-6.3

comment:7 Changed 8 years ago by For batch modifications

Milestone: sage-6.3sage-6.4

comment:8 Changed 6 years ago by Ralf Stephan

I think it would be more consistent to simply allow the same mechanism as with BuiltinFunctions. 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.

Version 0, edited 6 years ago by Ralf Stephan (next)
Note: See TracTickets for help on using tickets.