doujiaochan7317 2017-09-15 16:47 采纳率: 0%
浏览 482

如何将latex转换为可以在JS或PHP中计算的字符串

I'm using mathquill that allows users to enter equations and save them. the output from mathquill is LaTex, how would one go about parsing this to an expression that can be evaluated.

var mathFieldSpan = document.getElementById('math-field');
var latexSpan = document.getElementById('latex');
var MQ = MathQuill.getInterface(2); // for backcompat
var mathField = MQ.MathField(mathFieldSpan, {
    spaceBehavesLikeTab: true, // configurable
    handlers: {
        edit: function() { // useful event handlers
            latexSpan.textContent = mathField.latex(); // simple API
        }
    }
});
  • 写回答

1条回答 默认 最新

  • xxxli 2023-04-13 22:37
    关注

    https://npmmirror.com/package/algebra-latex
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Example
    const AlgebraLatex = require('algebra-latex')

    // Parse from LaTeX ...
    const latexInput = '\frac{1}{\sqrt{2}}\cdot x=10'
    const algebraObj = new AlgebraLatex().parseLatex(latexInput)

    // ... or parse from regular math string
    const mathInput = '1/sqrt(2)*x=10'
    const algebraObj = new AlgebraLatex().parseMath(mathInput)

    console.log(algebraObj.toMath()) // output: 1/sqrt(2)*x=10
    console.log(algebraObj.toLatex()) // output: \frac{1}{\sqrt{2}}\cdot x=10

    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器