I want a command \simp which takes an algebraic expression E_1 and outputs E_1 = E_2 where E_2 is the simplified form of E_2. To do so I tried to use sagetex like this:
\documentclass{article}
\usepackage{sagetex}
\newcommand{\simp}[1]{$\sage{#1} = \sage{simplify(#1)}$}
\pagestyle{empty}
\begin{document}
\simp{3*x^(7-2) + 3*x^5}
\end{document}
Which results in

and not in
.
Any idea how to fix this? Solving this from the sage point of view doesn't seem to be so easy because sage seems to lack a global hold feature: http://trac.sagemath.org/ticket/10035
So is there any idea how to solve this in an elegant way from the LaTeX side?
There are two other minor issues about this approach:
I want that
*is printed as a\cdotwhen one has something like3*(x + y)but that it is not printed at all if one has3*xI am not sure about the correct spacing (see the difference in my second output) and how to get it.
I also really want to use sage for this simplification and not a handmade latex-solution because I plan to do similar but more complex things in the future such that it is a good idea to have the power of a computer algebra-system in the background.


\newcommand{\simp}[1]{$#1 = \sage{simplify(#1)}$}? – projetmbc Oct 06 '13 at 08:29