Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 591
VizardCrawler Avatar asked Jul 23 '15 12:07

VizardCrawler


1 Answers

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))
like image 69
user2981843 Avatar answered Nov 11 '22 01:11

user2981843