Hi Golam,
This looks good. Would the following work as well?
-----------------------------------------
sui.set_latex('s_{u,i}')
sui(x) = function('sui',x)
latex(sui(x))
----
s_{u,i}\left(x\right)
-----------------------------------------
Or would the function assignment sui(x) = function('sui',x) overwrite
the previous set_latex command? In other words, my question is whether
the latex definition for sui would automatically be applied to sui(x) or
whether I would have to explicitly give a latex definition for sui(x).
In the latter case, would I have to define the function first and then
its latex representation as you did, or could it also be done the other
way round?
I like the user_defined_latex_dict idea. Good work!
Cheers,
Stan
Golam Mortuza Hossain wrote:
> Hi,
>
> On Fri, Mar 27, 2009 at 5:58 AM, Stan Schymanski <[email protected]> wrote:
>
>> I was thinking of custom defined latex representations of different
>> variables or functions, similar to the example I showed in my first
>> email in this thread. Basically, I would like to be able to give
>> working names to variables (e.g. sui), but display them as I would in
>> a paper if I use the show command (e.g. $s_{u,i}$). I can define this
>> by
>>
>> var('sui')
>> sui._latex_ = lambda: 's_{u,i}'
>>
>> but as soon as define the variable as a function, e.g.
>>
>> var('t')
>> sui(t) = function('sui',t)
>>
>> show(sui) does not display correctly any more. So I think that the
>> problem with the latex representation of functions is not limited to
>> greek letters,
>>
>
> After playing with the issue, I feel that using existing _latex_ method
> to define a custom-latex-expression for symbolic functions is bit tricky.
>
> However, I could easily write a new method which works as follows
> -----------------------------------------
> sui(x) = function('sui',x)
> sui(x).set_latex('s_{u,i}')
> latex(sui(x))
> ----
> s_{u,i}\left(x\right)
> -----------------------------------------
> It seems to work well. set_latex method is defined as
>
> -----
> def set_latex(self, expr=None):
> """
> Set custom LaTeX representation for a symbolic function
> """
> from sage.misc.latex import user_defined_latex_dict as ldict
> key = self._f._name
> if expr is not None:
> ldict[key] = expr
> elif key in ldict:
> del ldict[key]
> return None
> -----
> To construct latex symbols for symbolic functions,
> new "latex_function_name" now checks whether
> "user_defined_latex_dict" has any key for the given function.
>
> Feel free to post if you have further suggestions.
>
> Cheers,
> Golam
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---