How to use sympy.latex and sympy.sympify to produce unevaluated parameterized expression fr'frac{{3}}{{{i}}}'?

Question:

How to use sympy.latex() and sympy.sympify() to produce unevaluated parameterized expression fr'frac{{3}}{{{i}}}'?

from IPython.display import display,  Math
import sympy as sym
for i in range(-1,2):
    display(Math(fr'frac{{3}}{{{i}}}'))
for i in range(-1,2):
    display(Math(sym.latex(sym.sympify(f'3/{i}'))))

enter image description here

Edit

The objective is to generate:

fr'frac{{3}}{{{-1}}}'
fr'frac{{3}}{{{0}}}'
fr'frac{{3}}{{{1}}}'

with sympy.latex() and sympy.sympify() (or its variant).

Asked By: The Real Masochist

||

Answers:

Just set evaluate=False into sympify:

for i in range(-1,2):
    display(Math(sym.latex(sym.sympify(f'3/{i}', evaluate=False))))
Answered By: Davide_sd
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.