[Tex/LaTex] Convert latex math to matlab math

conversionMATLAB

This may seem like a weird question, but the reason I'm asking is as follows. If I type a long list of equations in latex, and then want to turn them into matlab expressions, I basically have to convert text such as :

x=\frac 1 {f(t)} \cdot y

into

x=(1/f(t))*y

The problem with this is, that if I have a long list of expressions (>20 equations), it is easy to make a mistake somewhere, and hard to parse.
Latex on the other hand, can easily be checked for errors, since we can simply execute the latex file and see symbolic expressions.

Therefore my thought is: if we can automate the transition from latex to matlab, then I can error-check the math in symbolic form in the pdf output of latex, and then be confident that the matlab code is correct.

Does such a program exist? if not, does it exist between other similar languages?

Best Answer

the following document typesets as

enter image description here

and puts

MATLAB
x=(1)/(f(t))) *y

on the terminal and log file.

\documentclass{article}

\def\zzz#1{%
\[#1\]
{\def\frac##1##2{(##1)/(##2))}
 \def\cdot{*}
 \typeout{^^JMATLAB^^J#1^^J}}}

\begin{document}



\zzz{x=\frac 1 {f(t)} \cdot y}


\end{document}
Related Question