# latex typesetting for derivatives like g'

When i try:

f(x) = function('f',x)

g = diff(f(x),x)

latex(g)

I get: D[0]\left(f\right)\left(x\right)

But i would like to get something like: g'\left(x\right)

How can i do this with sage?

edit retag close merge delete

Sort by ยป oldest newest most voted

You can try to apply the patch attached to ticket #6344.

The patch review walk through contains instructions on how to apply patches.

more

Thanks! Will try...

( 2011-06-18 04:49:10 -0600 )edit

A workaround is:

sage: f = function('f')(x)
sage: g = diff(f, x)
sage: f
f(x)
sage: g
diff(f(x), x)
sage: eq = g + f == x - 1
sage: eq
f(x) + diff(f(x), x) == x - 1
sage: f_1 = function("f'")(x)
sage: f_1
f'(x)
sage: eq_a = eq.substitute({g: f_1})
sage: eq_a
f(x) + f'(x) == x - 1

more

Obviously it is possible to assign any latex text to derivatives by using the ' derivative_func' -option of the 'function'- procedure. Below I have addad an example that I have executed in the SAGE V63 environment.

var('z')

def dfx(self,args,*kwds):return dfxdz(z)

def dfy(self,args,*kwds):return dfydz(z)

fx=function('fx',derivative_func=dfx,latex_name='x')

fy=function('fy',derivative_func=dfy,latex_name='y')

dfxdz=function('dfxdz',latex_name='\frac{\operatorname{d}{x}}{\operatorname{d}{z}}')

dfydz=function('dfydz',latex_name='\frac{\operatorname{d}{y}}{\operatorname{d}{z}}')

dgdx=function('dgdx',latex_name='\frac{\partial{g}}{\partial{x}}')

dgdy=function('dgdy',latex_name='\frac{\partial{g}}{\partial{y}}')

pdev=[dgdx(fx(z)),dgdy(fy(z))]

xf=fx(z)

yf=fy(z)

def pderivg(self, args, *kwds): print "args:",args; print "kwds:",kwds,pdev[kwds['diff_param']]; return pdev[int(kwds['diff_param'])]

gf = function('gf', latex_name='g',nargs=2, derivative_func=pderivg)

g=gf(xf,yf)

deriv=g.derivative(z)

show(deriv)

more