将LaTeX表达式转换为中缀表达式

时间:2015-07-23 12:53:01

标签: latex expression infix-notation

让我们假设我们有一个LaTeX形式的表达式:

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

所需输出是:

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

我尝试了一个例子,如链接Convert LaTeX to dynamic Javascript function中所述,但我得到上述乳胶的输出:

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

如何正确转换表达式? 提前谢谢!

1 个答案:

答案 0 :(得分:2)

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. 输出=(x)/((y)/(y))