gpt4 book ai didi

c# - MathML 的数学表达式

转载 作者:太空狗 更新时间:2023-10-30 01:18:40 25 4
gpt4 key购买 nike

我正在尝试构建与 this site 相同的功能用户将在文本区域中输入数学表达式并将其呈现为 MathML 格式。

例子:

Input expression string: cos(x^3)

Then the expression should be converted to MathML as:

<math xmlns='http://www.w3.org/1998/Math/MathML'>
<mrow>
<mi>cos</mi>
<mo>&#8289;</mo>
<mo>(</mo>
<msup>
<mi>x</mi>
<mn>3</mn>
</msup>
<mo>)</mo>
</mrow>
</math>

什么是 C# 解决方案?

最佳答案

我从我之前的解析器创建了一个基本表达式到 MathML 解析器。您可以下载或 fork result here at BitBucket . (左侧的下载链接)。

使用 Parser 类的 ToMathML(expression) 方法将表达式转换为 MathML。

它还附带了一个命令行测试程序,用于测试解析器,生成MathML的命令是ml:

calc ~:> ml cos(x^3)
<math xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mi>cos</mi><mrow><mrow><mo>(</mo><mrow><msup><mi>x</mi><mn>3</mn></msup></mrow><mo>)</mo></mrow></mrow></mrow></math>
calc ~:> ml 1/(x-1)
<math xmlns='http://www.w3.org/1998/Math/MathML'><mrow><mfrac><mn>1</mn><mrow><mrow><mo>(</mo><mrow><mi>x</mi><mo>-</mo><mn>1</mn></mrow><mo>)</mo></mrow></mrow></mfrac></mrow></math>
calc ~:>

解析器中没有隐含的乘法,因此您必须始终在表达式中使用 *(如 2*x)。

希望它对您的场景有用。我想这取决于您需要它的功能有多全面。在当前形式下,解析器会将表达式转换为 MathML 的一个非常基本的子集。

请随意 fork 并继续努力。

关于c# - MathML 的数学表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26276325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com