Python (LaTeX) - Do I have to use %g formatting, or can I create nice equations with F-string?

Viewed 26

I would like to use F-string because it's much cleaner, but I'm not sure how to mix strings with integers inside curly brackets (maybe it's not possible).

I know you can use double {{x + 3}} but I want to use x as a variable. Till now I used %g which works great as you can see in the picture.

Is it possible to use F-string and mix int with str inside curly brackets?

x = 7
y = -2
z = 5
answer = -y - (x + 8) // z

display(Math(f"{y} - \\frac{x + 8}{z} = {answer}")) # How to turn + 8 to string? and have the same results as %g

display(Math("%g - \\frac{%g + 8}{%g} = %g" %(y,x,z,answer))) # Works great

results

0 Answers
Related