You can use sympy.latex
with eval
:
s = "1+2**(x+y)"
sympy.latex(eval(s)) # prints '$1 + {2}^{x + y}$'
You still have to declare the variables as symbols, but if this is really a problem, it's much easier to write a parser to do this than to parse everything and generate the latex from scratch.