【问题标题】:Convert TeX to a plain string for use on http://api.mathjs.org/v4将 TeX 转换为纯字符串以在 http://api.mathjs.org/v4 上使用
【发布时间】:2018-10-31 14:34:57
【问题描述】:

我对 TeX 非常陌生,事实上我是在过去一个小时内发现它的。我想知道我是否可以转换这样的东西:

$$ (3\times10^{-9})\times(7\times10^{3})  $$

变成这样:

(8*10^−9)*(7*10^3)

我一直在研究有关 MathJax 的一些内容,但我不确定它是否适合我。我计划使用 math.js REST API 给我一个 TeX 的答案,但是我不确定如何将 TeX 转换为纯字符串。希望这是有道理的。

它需要在 Javascript 中。

谢谢。

【问题讨论】:

  • 是的,使用 JavaScript 库。 MathJax 就是其中之一。 Google 是您的朋友。
  • @duffymo 我不确定我将如何使用 MathJax。这是我唯一关心的问题。
  • 这是一个 JavaScript 库。将其包含在您的页面中并让它呈现方程式。
  • 想想 katex:katex.org

标签: javascript api math tex converters


【解决方案1】:

这很难看,但它完成了简单表达式所需的功能:

var myString = '$$ (3\times10^{4})\times(7\times10^{2})  $$';
var myRegexp = /\^{([^}]*)}/g;

var myOutput = myString.replace(/\times/g, 'x');
myOutput = myOutput.replace(/\$\$/g, '');

myOutput = myOutput.replace(myRegexp, "^$1");

console.log(myOutput);

如果你的 Tex 表达式会更复杂,你可以试试math-expressions。它有一个fromLatex 功能,虽然我还没有测试它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 2012-07-19
    • 1970-01-01
    相关资源
    最近更新 更多