Convert LaTeX expression to infix expression

Suppose we have an expression in the form of LaTeX:

var latex =\frac{x}{\frac{y}{y}} 

Thus, the required result:

 output= (x)/((y)/(y)); 

I tried the example provided in the link: Convert LaTeX to a dynamic Javascript function , but I get the output of the above latex as:

 (x)/(\frac{y){y}}` 

How can I convert the expression correctly? Thanks in advance!

+6
source share
1 answer

solution to the above problem

 var func = '\frac{x}{\frac{y}{y}}'; func = func.replace(/}{/g, ")/(").replace(/\frac{/g, "(").replace(/}/g, ")") console.log(func); 
  • innput = \ frac {x} {\ frac {y} {y}}
  • output = (x) / ((y) / (y))
+2
source

All Articles