Hi, On Jun 25, 9:05 am, Burcin Erocal <bur...@erocal.org> wrote: > On Thu, 25 Jun 2009 13:22:46 +0200 > > Stan Schymanski <schym...@gmail.com> wrote: > > > I have been asked to forward the below to the sage-devel list. Ticket > > #6290 introduced a way to custom-define thelatexstyle of functions, > > but it would be great if something similar was made possible for any > > variable. Is there a way for this already? I used to do it in the > > following way, but now I get an error message: > > > sage: var('hi kunsati delyui') > > sage: hi._latex_ = lambda: 'h_i' # Matric suction > > head in layer i (=pcapvec) > > sage: kunsati._latex_ = lambda: 'K_{unsat,i}' # Unsaturated > > hydraulic conductivity in layer i > > sage: delyui._latex_ = lambda: '\delta_{yu,i}' # Soil layer > > thickness in layer i > > Traceback (most recent call last): > > ... > > AttributeError: 'sage.symbolic.expression.Expression' object attribute > > '_latex_' is read-only > > Since Expression is a cython class, you cannot overwrite the _latex_() > method. > > Pynac supports settinglatexnames forvariablesat creation, but this > functionality is not exposed in the wrapper. Another solution by > hacking latex_variable_name() might be possible, but I would like to > avoid that if possible.
I was looking into Pynac/Ginac code to see how difficult it would be to expose the Ginac's Tex_name feature for variables. (1) Pynac allows to specify Tex_name while defining variables. (2) Currently, pynac is patched to effectively use latex_variable_name for printing latex as it is better than Ginac's default print_latex for variables I suggest following changes: (1) Compute latex string for variable using Sage's "latex_variable_name" while defining it unless user provides a latex string. (2) Store this latex string in Ginac symbol framework and use Ginac's print_latex method. This would be more efficient than the current approach. For example, if variable "alpha123" appears 10 times in an expression, currently "latex_variable_name" function is called 10 times to typeset the the same as "\\alpha_{123}". On the other hand, if we store the string in Ginac then we need to call "latex_variable_name" just once regardless of how many times the variable appears in the expression. BTW, I already have a hackish but working implementation for above. Cheers, Golam --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---