
If you've ever moved complex math from Python code into documentation, Javadoc, or a scientific paper, you know the pain. Manually typesetting multi-story formulas in LaTeX is a special kind of masochism, where one forgotten
} costs twenty minutes of debugging.The latexify package does exactly one thing: translates Python functions into LaTeX mathematical formulas.
This is not another LLM wrapper. The library works in a maximally deterministic way: it uses the built-in
ast module to parse the abstract syntax tree of your Python function, and translates AST nodes into LaTeX markup according to strict rules.What it can do at the AST level:
🟢 Recognizes and converts
math and numpy modules (math.sqrt becomes \sqrt, math.gamma becomes \Gamma).🟢 Expands
if/elif/else into beautiful piecewise functions.🟢 Renders NumPy matrices.
🟢 Understands set operations (
&, | turn into \cap, \cup if you set use_set_symbols=True).🟢 Can generate not only formulas but also pseudocode (decorator
@latexify.algorithmic).In Jupyter Notebook or Colab, the
@latexify.function decorator automatically makes the cell render a beautiful formula. You don't even need to call print().🔗 Source code is on GitHub, and you can try it live in Google Colab.
#годный_опенсорс
Comments
0No comments yet.