ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 29 Nov 2015 14:20:48 -0600present sage output as "normal" mathematicshttps://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/ Hello,
I am new to sage and I have the following question. Here is a minimal working example:
x,y=var('x,y')
f=x^2-3*y; f
f.diff(x)
g=f.diff(x);g
The output of it is 2*x, but I wonder if there is a way to say to sage that I want to present the output g=2x.
Thanks in advanceSun, 22 Nov 2015 16:47:51 -0600https://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/Answer by A.P. for <p>Hello,</p>
<p>I am new to sage and I have the following question. Here is a minimal working example:</p>
<pre><code>x,y=var('x,y')
f=x^2-3*y; f
f.diff(x)
g=f.diff(x);g
</code></pre>
<p>The output of it is 2*x, but I wonder if there is a way to say to sage that I want to present the output g=2x.</p>
<p>Thanks in advance</p>
https://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/?answer=31186#post-id-31186If you're working from the *notebook* you can use the `pretty_print` function. In your example
pretty_print(g)
will display `2x` as rendered LaTeX. I doesn't just typeset mathematics, either: you can also use it to prettify other objects, like long lists or dictionaries. Here's a more interesting example
![pretty print the derivative of a function involving tangents and fractions](http://s2.postimg.org/6ex1z66bd/pretty_print_example.png)Sun, 29 Nov 2015 14:20:48 -0600https://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/?answer=31186#post-id-31186Answer by vdelecroix for <p>Hello,</p>
<p>I am new to sage and I have the following question. Here is a minimal working example:</p>
<pre><code>x,y=var('x,y')
f=x^2-3*y; f
f.diff(x)
g=f.diff(x);g
</code></pre>
<p>The output of it is 2*x, but I wonder if there is a way to say to sage that I want to present the output g=2x.</p>
<p>Thanks in advance</p>
https://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/?answer=30995#post-id-30995Short answer: yes with
print "g = %r" % g
Other short answer: no, you cannot (easily) do that automatically.
Note that you can define g as a symbolic function
sage: g(x,y) = f.diff(x)
sage: g
(x, y) |--> 2*xMon, 23 Nov 2015 17:39:48 -0600https://ask.sagemath.org/question/30975/present-sage-output-as-normal-mathematics/?answer=30995#post-id-30995