I'm feeding sympy.latex
a string involving fractions and I'd like to get its latex representation with fractions "folded", i.e., typeset as 3/2 rather than as \frac{3}{2}. I'm setting the fold_short_fractions
keyword argument to True
, but the results I'm getting are inconsistent:
>>> from sympy.parsing.sympy_parser import parse_exp
>>> from sympy import latex
>>>
>>> print(latex(parse_expr("3*x**2/y"))) # OK
\frac{3 x^{2}}{y}
>>> print(latex(parse_expr("3*x**2/y"), fold_short_frac=True)) # OK
3 x^{2} / y
>>>
>>> print(latex(parse_expr("3/2"))) # OK
\frac{3}{2}
>>> print(latex(parse_expr("3/2"), fold_short_frac=True)) # No!!
\frac{3}{2}
As you can see, it refuses to fold the numerical fraction 3/2, although it seems to be okay with symbolic expressions. Does anyone have an explanation/fix/workaround for this? Thanks!