Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have found a workaround: save the expression as a string and evaluate the string after reading it in in a new session.

Code block saving:

var('y')
fx = function('fx',latex_name=r'f_x')
eq=fx(y)+fx(y).diff(y)
eq_str = str(eq)
with open('test.txt', 'w') as f:
    eqs_str = f.write(eq_str)

Code block reading:

var('y')
fx = function('fx',latex_name=r'f_x')
with open('test.txt', 'r') as f:
    eq_str = f.read();
eq=sage_eval(eq_str, locals={'y':y, 'fx':fx})

then I get

print(latex(eq))
f_x\left(y\right) + \frac{\partial}{\partial y}f_x\left(y\right)

with the correct 'f_x' latex expression! The only drawback is that it is rather cumbersome to have to write down the locals-dictionary. I have around 15 variables and functions.