Follow and star to learn new Python skills every day
Due to changes in the public account’s push rules, please click “View” and star to get exciting technical shares at the first time
Source: Internet

<span>latexify</span> is a Python library for generating LaTeX mathematical formulas. LaTeX is a typesetting system based on TeX, which excels at displaying complex mathematical formulas. This project allows you to easily generate complex LaTeX mathematical formula descriptions using Python functions.
# 1. Install the Library
pip install latexify-py

Check the version number
import math # optional
import numpy as np # optional
import latexify
latexify.__version__
‘0.4.2’
# 2. Example Demonstration
We need to use it in the form of a decorator, taking the quadratic formula as an example:
def solve(a, b, c):
return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)
print(solve(1, 4, 3))
print(solve)
The output is as follows:
-1.0
<function solve at 0x1124f28e0>
After using the decorator:
@latexify.function
def solve(a, b, c):
return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)
print(solve(1, 4, 3))
print(solve)
The output is as follows:
-1.0
\mathrm{solve}(a, b, c) = \frac{-b + \sqrt{ b^{2} - 4 a c }}{2 a}
View the <span>solve</span> function separately:

You can also directly use the decorator <span>@latexify.expression</span>

Other example effects:



# 3. Further Information
More information can be found at: https://github.com/google/latexify_py

Long press or scan the QR code below to get free Python public courses and hundreds of gigabytes of learning materials organized by experts, including but not limited to Python e-books, tutorials, project orders, source code, etc.
▲ Scan the QR code - Get it for free
Recommended Reading
Don't use loc/iloc in pandas loops anymore!
If you still use `print` for Python debugging, you're OUT!
These 15 habits made my Python performance soar
See how I perform Python object injection exploitation
Click Read the original to learn more