欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python转LaTeX

程序员文章站 2022-03-28 17:51:01
!rm -rf latexify_py!git clone https://github.com/odashi/latexify_py -b develop!pip install -e latexify_py# Before running following cells, restart the runtime so that the installed# module is......
!rm -rf latexify_py
!git clone https://github.com/odashi/latexify_py -b develop
!pip install -e latexify_py
# Before running following cells, restart the runtime so that the installed
# module is activated.
import math
import latexify
@latexify.with_latex
def solve(a, b, c):
    return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)

print(solve(1, 4, 3))
print(solve)
print()
solve
-1.0
\operatorname{solve}(a, b, c) \triangleq \frac{-b + \sqrt{b^{2} - 4ac}}{2a}

\(\operatorname{solve}(a, b, c) \triangleq \frac{-b + \sqrt{b^{2} - 4ac}}{2a}\)

@latexify.with_latex
def sinc(x):
    if x == 0:
        return 1
    else:
        return math.sin(x) / x

print(sinc)
\operatorname{sinc}(x) \triangleq \left\{ \begin{array}{ll} 1, & \mathrm{if} \ x=0 \\ \frac{\sin{\left({x}\right)}}{x}, & \mathrm{otherwise} \end{array} \right.

\[\operatorname{sinc}(x) \triangleq \left\{ \begin{array}{ll} 1, & \mathrm{if} \ x=0 \\ \frac{\sin{\left({x}\right)}}{x}, & \mathrm{otherwise} \end{array} \right. \]
# Elif or nested else-if are unrolled.
@latexify.with_latex
def fib(x):
    if x == 0:
        return 1
    elif x == 1:
        return 1
    else:
        return fib(x-1) + fib(x-2)

print(fib)
\operatorname{fib}(x) \triangleq \left\{ \begin{array}{ll} 1, & \mathrm{if} \ x=0 \\ 1, & \mathrm{if} \ x=1 \\ \operatorname{fib}\left(x - 1\right) + \operatorname{fib}\left(x - 2\right), & \mathrm{otherwise} \end{array} \right.

\[\operatorname{fib}(x) \triangleq \left\{ \begin{array}{ll} 1, & \mathrm{if} \ x=0 \\ 1, & \mathrm{if} \ x=1 \\ \operatorname{fib}\left(x - 1\right) + \operatorname{fib}\left(x - 2\right), & \mathrm{otherwise} \end{array} \right. \]

本文地址:https://blog.csdn.net/Xiao_CangTian/article/details/107652180