Thank you all for your replies! I was overwhelmed by your fast and
helpful replies!

I may should have described my desired result in more detail:
I don't wanna display/print out the line
  a = \frac{{2 q}}{3}
but I would like to Sage display it, as if it was processed by latex
(the look of a formula in a math book).

@ Neal Holtz
> sage: def vshow(_v):
> ....:     print '%s = %s\n' % (_v,latex(globals()[_v]))

Your solution works nice, as long as there is a symbolic variable.
i.e.
sage: var('q')
sage: a = 3*q/2
sage: vshow('a')
a = \frac{{3 q}}{2}

but if there is no symbolic variable included, it's not working:
sage: b = 2/3
sage: vshow('b')
b

And as mentioned above, I desire s.t. a little bit different. Maybe
this output can be changed to that of show(). I tried, but did not
succeed:
sage: show(latex(2/3))
( as well as show(2/3) )
produces a nice formated fraction, but
sage: show(latex(b = 2/3))
only displays the fraction - what actually makes sense.

@ Georg
> >>> def ashow(**args):
>
> ...     for key in args:
> ...             print key,'=',args[key]

works quite nice! Output of ashow(a=a):
a =
                                      2 q
                                      ---
                                       3
this looks like the output of show() when entered in the terminal into
sage.

@ Jason Grout
> Once a_2 is passed to the show function, I don't think the show
> function knows where it came from, i.e., the show function has access to
> the *value* of a_2, but doesn't know what variable name was actually passed.
>
> The other solutions had the variable name passed to the function as a
> string, which, of course, would be different because there you are
> passing in a string, the name of the variable.

I think thats the key issue:
Is there a way to make a variable return its name as a string (s.t.
like a.name())?
Or is there a way to access the content of a variable, when you only
have a string with its name? Well, I think Neal Holtz did this with
globals()[_v]
but since I'm a novice with sage and a total novice with python, I
really don't have a clue.
My modification of his function messed up the order of the output and
did not lead to the desired result...:
sage: def vshow(_v):
sage:    print '%s = %s\n' % (_v,show(globals()[_v]))


thanks again for all your valuable help!

Samuel
--~--~---------~--~----~------------~-------~--~----~
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-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to