Search code examples
latexexpressioninfix-notation

Converting LaTeX expression to infix expression


Let us assume we have an expression in LaTeX form:

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

So output required is:

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

I tried out an example as stated in the link: Convert LaTeX to dynamic Javascript function but I am getting the output of the above latex as:

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

How can I get the expression converted properly? Thanks in advance!


Solution

  • solution of the above problem

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