Ask Your Question
1

latex typesetting for derivatives like g'

asked 2011-06-17 14:29:02 +0200

roah gravatar image

updated 2023-05-20 14:39:46 +0200

slelievre gravatar image

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 flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
1

answered 2011-06-17 19:36:45 +0200

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

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

edit flag offensive delete link more

Comments

Thanks! Will try...

roah gravatar imageroah ( 2011-06-18 11:49:10 +0200 )edit
1

answered 2018-03-21 14:45:08 +0200

slelievre gravatar image

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
edit flag offensive delete link more
0

answered 2014-10-31 19:28:36 +0200

bekalph gravatar image

updated 2023-05-20 14:36:48 +0200

slelievre gravatar image

Obviously it is possible to assign any latex text to derivatives by using the derivative_func option of the function function.

Below I have added an example that I have executed in Sage 6.3.

(Note: edited to make print python3-compatible. Now works in Sage 9.8.)

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=r'\frac{\operatorname{d}{x}}{\operatorname{d}{z}}')
dfydz = function('dfydz', latex_name=r'\frac{\operatorname{d}{y}}{\operatorname{d}{z}}')

dgdx = function('dgdx', latex_name=r'\frac{\partial{g}}{\partial{x}}')
dgdy = function('dgdy', latex_name=r'\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)
edit flag offensive delete link more

Comments

Sorry but your code doesn't work

Cyrille gravatar imageCyrille ( 2023-05-12 16:04:33 +0200 )edit

Now it does.

slelievre gravatar imageslelievre ( 2023-05-19 21:49:39 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2011-06-17 14:29:02 +0200

Seen: 1,464 times

Last updated: May 20 '23