The key is to use Ex.input_form()
. Here's an example. Writing an expression ex1
and ex2
to a file ex.txt
(in the directory from which you started Cadabra; use a full path if necessary) is done as in:
ex1:=A_{m n} \sin{x};
ex2:= B_{m n};
with open("ex.txt", "w") as file:
file.write( ex1.input_form()+"\n" )
file.write( ex2.input_form()+"\n" )
You can then read them back in later using
with open("ex.txt", "r") as file:
ex1=Ex( file.readline() )
ex2=Ex( file.readline() )