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


This Content is from Stack Overflow. Question asked by N00bDev

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



This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?