sagemath / sagetex

Embed code, results of computations, and plots from the Sage mathematics software suite (https://www.sagemath.org) into LaTeX documents. Source repository for https://pypi.org/project/sagetex/ and https://ctan.org/pkg/sagetex
https://ctan.org/pkg/sagetex
Other
58 stars 23 forks source link

sagetex does not convert number * symbol properly. #12

Open kwangkim opened 7 years ago

kwangkim commented 7 years ago
\documentclass{article}
\usepackage{sagetex}
\begin{document}
\begin{sagesilent}
from sympy import *
x=Symbol('x')
expr1= 4*x**2+1
expr2= x**2*4+1
\end{sagesilent}
$$\sagestr{latex(expr1)}$$
$$\sagestr{srepr(expr1)}$$
$$\sagestr{latex(expr2)}$$
$$\sagestr{srepr(expr2)}$$
\end{document}

Shows screen shot 2017-06-11 at 7 19 31 pm Which means sagetex does not convert '4*x**2+1' properly? I did it using cocalc.com

Could you give me an advice?

kcrisman commented 5 years ago

Something analogous happens with just sage instead of sagestr, where one gets (as expected) the latex() results above.

The really interesting part is that the strings returned by Sage seem to be identical:

sage: latex(expr1)
'4 x^{2} + 1'
sage: latex(expr2)
'4 x^{2} + 1'
sage: srepr(expr1)
"Add(Mul(Integer(4), Pow(Symbol('x'), Integer(2))), Integer(1))"
sage: srepr(expr2)
"Add(Mul(Integer(4), Pow(Symbol('x'), Integer(2))), Integer(1))"

but nonetheless somehow they are not coming out the same; maybe the internal representation, but I traversed both expression trees for these in Sage as well and can't find a difference. This would be worth investigating, but is relatively low priority since just avoiding Sympy (which after all isn't what SageTeX is designed for) would solve this particular issue.