gpt4 book ai didi

javascript - 在 MathML 渲染中使用命名空间

转载 作者:行者123 更新时间:2023-11-27 23:52:36 26 4
gpt4 key购买 nike

现在没有命名空间的 mathML 可以正常渲染,但如果我添加命名空间如 m: 或 mml:,则渲染无法正常工作。任何帮助提前致谢。

下面是我用过的代码。

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:mml="http://www.w3.org/1998/Math/MathML">
<head>
<script type="text/javascript" src="file:/P:/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head>
<body>
<h3>MathML Previewer</h3>

Paste your MathML:<br/>
<textarea id="myMath" style="resize: none; height:250px; width:850px">
</textarea>

<button type="button" onclick="myclear()">Reset</button>
<p>Click the button to get output</p>
<button type="button" onclick="myFunction()">Output</button>
<div id="demo">
</div>

<script>
function myFunction() {

var x = document.getElementById("myMath").value;
document.getElementById("demo").innerHTML = x;
MathJax.Hub.Typeset("demo");
}
</script>
<script>
function myclear() {
var x = document.getElementById("myMath").value =' ';
//document.getElementById("demo").innerHTML = x;

}
</script>

</body>
</html>

数学:

命名空间不渲染

 <m:math display="block" xmlns:m="http://www.w3.org/1998/Math/MathML"><m:mrow><m:mi>r</m:mi><m:mo>=</m:mo><m:mfrac><m:mrow><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mrow><m:mi>x</m:mi><m:mi>y</m:mi><m:mo>-</m:mo><m:mfrac><m:mrow><m:mo stretchy='false'>(</m:mo><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mi>x</m:mi></m:mstyle><m:mo stretchy='false'>)</m:mo><m:mo stretchy='false'>(</m:mo><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mi>y</m:mi></m:mstyle><m:mo stretchy='false'>)</m:mo></m:mrow><m:mi>n</m:mi></m:mfrac></m:mrow></m:mstyle></m:mrow><m:mrow><m:msqrt><m:mrow><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mrow><m:msup><m:mi>x</m:mi><m:mn>2</m:mn></m:msup><m:mo>-</m:mo><m:mfrac><m:mrow><m:msup><m:mrow><m:mo stretchy='false'>(</m:mo><m:mstyle displaystyle='true'><m:mo>&#x03A3;</m:mo><m:mi>x</m:mi></m:mstyle><m:mo stretchy='false'>)</m:mo></m:mrow><m:mn>2</m:mn></m:msup></m:mrow><m:mi>n</m:mi></m:mfrac></m:mrow></m:mstyle></m:mrow></m:msqrt></m:mrow></m:mfrac></m:mrow></m:math>

没有按要求渲染命名空间。

 <math display="block" xmlns:m="http://www.w3.org/1998/Math/MathML"><mrow><mi>r</mi><mo>=</mo><mfrac><mrow><mstyle displaystyle='true'><mo>&#x03A3;</mo><mrow><mi>x</mi><mi>y</mi><mo>-</mo><mfrac><mrow><mo stretchy='false'>(</mo><mstyle displaystyle='true'><mo>&#x03A3;</mo><mi>x</mi></mstyle><mo stretchy='false'>)</mo><mo stretchy='false'>(</mo><mstyle displaystyle='true'><mo>&#x03A3;</mo><mi>y</mi></mstyle><mo stretchy='false'>)</mo></mrow><mi>n</mi></mfrac></mrow></mstyle></mrow><mrow><msqrt><mrow><mstyle displaystyle='true'><mo>&#x03A3;</mo><mrow><msup><mi>x</mi><mn>2</mn></msup><mo>-</mo><mfrac><mrow><msup><mrow><mo stretchy='false'>(</mo><mstyle displaystyle='true'><mo>&#x03A3;</mo><mi>x</mi></mstyle><mo stretchy='false'>)</mo></mrow><mn>2</mn></msup></mrow><mi>n</mi></mfrac></mrow></mstyle></mrow></msqrt></mrow></mfrac></mrow></math>

最佳答案

为了正确处理命名空间,您需要在 <html> 中声明它们标签。例如,

<html xmlns:m="http://www.w3.org/1998/Math/MathML">

如果您想同时处理 m: 和 mml:,请将两者都添加为 namespace 。

<html xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:mml="http://www.w3.org/1998/Math/MathML">

这对于 XHTML 文档是必需的,但对于 HTML5 则不是。

关于javascript - 在 MathML 渲染中使用命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26093182/

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