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

Viz*_*ler 6 latex expression infix-notation

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

var latex =\frac{x}{\frac{y}{y}}
Run Code Online (Sandbox Code Playgroud)

所以需要的输出是:

output= (x)/((y)/(y));
Run Code Online (Sandbox Code Playgroud)

我尝试了一个示例,如链接中所述:将LaTeX转换为动态Javascript函数,但我得到上述乳胶的输出为:

(x)/(\frac{y){y}}`
Run Code Online (Sandbox Code Playgroud)

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

use*_*843 2

上述问题的解决方案

var func = '\frac{x}{\frac{y}{y}}';
func = func.replace(/}{/g, ")/(").replace(/\frac{/g, "(").replace(/}/g, ")")
console.log(func);
Run Code Online (Sandbox Code Playgroud)
  1. 输入 = \frac{x}{\frac{y}{y}}
  2. 输出 = (x)/((y)/(y))