Member-only story
Displaying LaTeX Mathematical Expressions in Python Using SymPy and IPython
2 min readSep 7, 2024
1. Quadratic Equation
from IPython.display import display, Math
import sympy as sp
x = sp.Symbol('x')
# Define the quadratic equation
equation = sp.Eq(x**2 + 2*x + 1, 0)
latex_equation = sp.latex(equation)
# Display the equation
display(Math(latex_equation))
x2+2x+1=0x2+2x+1=0
2. Pythagorean Theorem
from IPython.display import display, Math
import sympy as sp
a, b, c = sp.symbols('a b c')
# Define the Pythagorean theorem
equation = sp.Eq(a**2 + b**2, c**2)
latex_equation = sp.latex(equation)
# Display the equation
display(Math(latex_equation))('a b c')
a2+b2=c2a2+b2=c2
3. Derivative of a Function
from IPython.display import display, Math
import sympy as sp
x = sp.Symbol('x')
f = sp.Function('f')(x)
# Define the derivative of a function
derivative = sp.Derivative(f, x)…