Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#6290 closed enhancement (fixed)

[with patch, positive review] Allow keywords such as latex_name=LaTeX while defining symbolic function

Reported by: gmhossain Owned by:
Priority: major Milestone: sage-4.1
Component: symbolics Keywords: latex_name, symbolic function
Cc: was Merged in: 4.1.alpha0
Authors: Golam Mortuza Hossain Reviewers: Nick Alexander
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by gmhossain)

In new symbolics, underlying "sage.symbolic.function.SFunction" class allows one to pass the keywords such as "latex_name=LaTeX". It would be really good if we expose this feature at the user interface level. This will directly allow LaTeX customization by users according to their need.

Currently, Sage (4.0.1) raises error if one tries to do so.

Couple of example usage:

(1) Define symbolic function with its latex representaion

riemann(x) = function('riemann', x, latex_name="\\mathcal{R}")
latex( riemann(x) )
\mathcal{R}\left(x\right)

(2) Printing arguments of a symbolic functions as its indices.

mu,nu = var('mu,nu')
def my_latex_print(*args): 
    return "\psi_{%s}"%(', '.join(map(latex, args)))

psi(mu,nu) = function('psi', mu,nu, print_latex_func=my_latex_print)

latex(psi(mu,nu))
\psi_{\mu, \nu}

Attached patch allows keyword arguments while defining symbolic functions.

Attachments (1)

allow-keyword-arguments-such-as-latex_name-in-symbolic-functions.patch (3.8 KB) - added by gmhossain 6 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by gmhossain

  • Description modified (diff)

comment:2 Changed 6 years ago by gmhossain

  • Description modified (diff)
  • Summary changed from Allow latex_name=LaTeX keyword while defining symbolic function to [with patch, needs review] Allow keywords such as latex_name=LaTeX while defining symbolic function

comment:3 follow-up: Changed 6 years ago by was

  • Summary changed from [with patch, needs review] Allow keywords such as latex_name=LaTeX while defining symbolic function to [with patch, needs work] Allow keywords such as latex_name=LaTeX while defining symbolic function

Nice. Could you add more to the docstring for function (at least the one that I get by default when I do function? from the sage prompt) that explains what happens to all kwds arguments? You do give a nice example (with riemann), but a sentence or two explaining what is going on would be very nice.

comment:4 in reply to: ↑ 3 Changed 6 years ago by gmhossain

  • Cc was added
  • Summary changed from [with patch, needs work] Allow keywords such as latex_name=LaTeX while defining symbolic function to [with patch, needs review] Allow keywords such as latex_name=LaTeX while defining symbolic function

Replying to was:

Nice. Could you add more to the docstring for function (at least the one that I get by default when I do function? from the sage prompt) that explains what happens to all kwds arguments?

Thanks for your comments! As you suggested, I have updated the patch with expanded docstrings.

comment:5 Changed 6 years ago by ncalexan

  • Summary changed from [with patch, needs review] Allow keywords such as latex_name=LaTeX while defining symbolic function to [with patch, positive review] Allow keywords such as latex_name=LaTeX while defining symbolic function

Looks good to me.

comment:6 Changed 6 years ago by rlm

  • Milestone set to sage-4.1
  • Resolution set to fixed
  • Status changed from new to closed

Merged in sage-4.1.alpha0.

comment:7 Changed 6 years ago by mvngu

  • Authors set to Golam Mortuza Hossain
  • Merged in set to 4.1.alpha0
  • Reviewers set to Nick Alexander

comment:8 follow-up: Changed 6 years ago by schymans

Would something similar be possible whenever a variable is defined?
E.g. if I want to use multiple subscripts, I would like to define
var('A_gs', latex_name="A_{gs}").

That would make it really flexible.

comment:9 in reply to: ↑ 8 Changed 6 years ago by gmhossain

Replying to schymans:

Would something similar be possible whenever a variable is defined?
E.g. if I want to use multiple subscripts, I would like to define
var('A_gs', latex_name="A_{gs}").

Hmmm, thats a great suggestion. Could you please post this to sage-devel?

Note: See TracTickets for help on using tickets.