!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) riangleq frac{-b + sqrt{b^{2} - 4ac}}{2a}
(operatorname{solve}(a, b, c) riangleq 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) riangleq left{ egin{array}{ll} 1, & mathrm{if} x=0 \ frac{sin{left({x}
ight)}}{x}, & mathrm{otherwise} end{array}
ight.
[operatorname{sinc}(x) riangleq left{ egin{array}{ll} 1, & mathrm{if} x=0 \ frac{sin{left({x}
ight)}}{x}, & mathrm{otherwise} end{array}
ight.
]
# 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) riangleq left{ egin{array}{ll} 1, & mathrm{if} x=0 \ 1, & mathrm{if} x=1 \ operatorname{fib}left(x - 1
ight) + operatorname{fib}left(x - 2
ight), & mathrm{otherwise} end{array}
ight.
[operatorname{fib}(x) riangleq left{ egin{array}{ll} 1, & mathrm{if} x=0 \ 1, & mathrm{if} x=1 \ operatorname{fib}left(x - 1
ight) + operatorname{fib}left(x - 2
ight), & mathrm{otherwise} end{array}
ight.
]