pythonic生物人

Python优雅地书写LaTeX

这里分享两个Python LaTex工具latexify和handcalcs。

Image

latexify生成LaTeX 数学公式

import math
import latexify
@latexify.with_latex #调用latexify的装饰器
def solve(a, b, c):
  return (-b + math.sqrt(b**2 - 4*a*c)) / (2*a)

solve

Image

更多例子.......

ImageImage


handcalcs生成LaTeX 数学公式

  • 一个求积分公式,借助scipy的quad
import handcalcs.render
from scipy.integrate import quad #借助scipy.quad实现积分

%%render
a = 2
b = 6
n=100
z = quad(f,a,b)

Image
  • 一个混合公式,借助math模块,
from math import sqrt,cos,sin,tan,asin
import handcalcs.render

%%render
#symbolic
f = a-c**2 / b + sqrt(cos(sin(b- 2 / c))) + tan(a/b) - asin(a/c) #Comment part

Image

ref

https://github.com/google/latexify_py https://github.com/connorferster/handcalcs>


推荐阅读:
👉《Python可视化教程》,优惠中!