Skip to main content
  1. Posts/

latexify_py: Convert Python Functions to LaTeX with One Decorator

··220 words·2 mins·

🔢 latexify_py: From Python to LaTeX with a Single Line
#

Need to display readable mathematical formulas from your Python code? latexify_py by Google does it with a single decorator.

✨ What Does It Do?
#

It automatically transforms Python functions into LaTeX expressions, keeping your code always in sync with your formulas.

import latexify

@latexify.expression
def solve(a, b, c):
    return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)

solve  # Displays the rendered LaTeX formula in Jupyter

🎯 Three Available Modes
#

📐 @latexify.expression – Just the mathematical expression. 📋 @latexify.function – Full equation with the function name. 📝 @latexify.algorithmic – LaTeX-style pseudocode.

🔑 Key Features
#

🔄 Always in sync – The formula updates automatically with your code. 📓 Jupyter integration – Renders LaTeX directly in the notebook cell. ✅ Function still works – You can call it normally; the decorator doesn’t alter execution.

💡 In Simple Terms
#

Imagine writing the quadratic formula in Python. Normally you’d have to copy it to LaTeX manually. With latexify_py, just decorate the function and the pretty formula appears in your notebook — no extra work needed.

More information at the link 👇

Also published on LinkedIn.
Juan Pedro Bretti Mandarano
Author
Juan Pedro Bretti Mandarano