Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to use LaTex formulas in a programming language to make a real calculation [closed]

We may write down the calculation formula of a distance measurement with the following LaTex string:

dist_{12} = \sqrt{ x^2 + y^2 }
dist_{13} = \sqrt{ z_{33}^2 + y^2 }

total = dist_{12} + dist_{13}

This looks good so far. If I really need to make a computer calculate these equations, then I need the following - eg. Python - code:

x = 1
y = 2
z_33 = 3
dist_12 = sqrt(x**2 + y**2)
dist_13 = sqrt(z_33**2 + y**2)
total = dist_12 + dist_13
print "Total distance is: ", total

As a result, I spent as twice as the effort actually needed.

However, if there was a way to use exact same LaTex formula (which may include integrals, derivatives, limits etc.) in a programming language (preferably Python, Javascript and Julia) we would re-use our efforts later in our real-world applications.

Is there any way to make this happen?

like image 530
mesut Avatar asked Jan 23 '26 16:01

mesut


1 Answers

You can

  1. Use latex2sympy to translate latex equations to SymPy objects
  2. Just use SymPy printing tools to get the same equations as latex

Both alternatives avoid you having to re-type the equations.

like image 53
Felipe Lema Avatar answered Jan 25 '26 05:01

Felipe Lema



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!