MathJax在MathML中渲染HTML输入字段 [英] MathJax Rendering HTML input fields in MathML

查看:1717
本文介绍了MathJax在MathML中渲染HTML输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < input id =txtBoxtype =我试图包含html输入字段, textsize =1style =text-align:center> 

在mathML方程中。当我最初在Firefox本地创建和测试它们时,一切看起来都不错(本地呈现内容)。但是,现在我已经将它上传到我们的网站,该网站使用mathjax 2.01来呈现内容,在输入框应该是处处都会出现未知节点类型:输入错误。我目前已将这些箱子包装在

 < annotation> 

标签在另一篇文章中描述过,但我仍然收到相同的错误。

 < script type =math / mml> 
< math>
< mstyle displaystyle =true>
< msup>
< mi> x< / mi>
< semantics>
< annotation-xml encoding =application / xhtml + xml>
< input xmlns =http://www.w3.org/1999/xhtmlstyle =text-align:righttype =textsize =2name =n/> gt ;< /输入>
< / annotation-xml>
< /语义>
< / msup>
< mo> +< / mo>
< semantics>
< annotation-xml encoding =application / xhtml + xml>
< input xmlns =http://www.w3.org/1999/xhtmltype =textsize =2name =b/>< / input>
< / annotation-xml>
< /语义>
< / mstyle>
< / math>
< / script>


解决方案

MathML3.0规范不提供HTML元素直接嵌入到MathML中。例如,HTML5扩展了定义以允许MathML中的标记元素中的HTML标记,如< mtext> 。然而,MathJax是在HTML5完成之前开发的,它遵循MathML3.0规范,因此一般不允许使用HTML标签。



然而,使用< semantics> < annotation-xml> 元素在MathML中包含HTML。请注意,< annotation> < annotation-xml> 只能显示为< semantics> ,所以你需要两个。此外,< annotation> 标签的正文应该是纯文本,而不是HTML标签,因此要包含HTML,您必须使用< ; annotation-xml> not < annotation> 。最后,您需要为< annotation-xml> 标签提供编码属性,以及注释需要 xmlns 属性来确保它在popper命名空间中被解析。



这是一个例子,适用于MathJax以及Firefox中的本地MathML:

 < script type =math / mml> 
< math>
< mstyle displaystyle =true>
< msup>
< mi> x< / mi>
< semantics>
< annotation-xml encoding =application / xhtml + xml>
< input xmlns =http://www.w3.org/1999/xhtmlstyle =text-align:righttype =textsize =2name =n/> gt ;
< / annotation-xml>
< /语义>
< / msup>
< mo> +< / mo>
< semantics>
< annotation-xml encoding =application / xhtml + xml>
< input xmlns =http://www.w3.org/1999/xhtmltype =textsize =2name =b/>
< / annotation-xml>
< /语义>
< / mstyle>
< / math>
< / script>

我们希望改善未来MathJax版本的情况,但现在这是唯一的替代。我希望这对你有用。


I'm attempting to include html input fields such as:

<input id="txtBox" type="text" size="1" style="text-align: center">

Within mathML equations. When I was originally creating and testing them locally on Firefox everything looked fine (natively renders the content). However, now that I've uploaded it to our site, which uses mathjax 2.01 to render the content I get 'Unknown node type: input' errors everywhere an input box should be. I currently have the boxes wrapped in

 <annotation> 

tags as described in another post here however I'm still receiving the same error.

<script type="math/mml">
<math>
  <mstyle displaystyle="true">
    <msup>
      <mi>x</mi>
      <semantics>
        <annotation-xml encoding="application/xhtml+xml">
         <input xmlns="http://www.w3.org/1999/xhtml" style="text-align:right" type="text" size="2" name="n" /></input>
    </annotation-xml>
  </semantics>
</msup>
<mo>+</mo>
<semantics>
  <annotation-xml encoding="application/xhtml+xml">
    <input xmlns="http://www.w3.org/1999/xhtml" type="text" size="2" name="b" /></input>
  </annotation-xml>
 </semantics>
</mstyle>
</math>
</script>

解决方案

The MathML3.0 specification doesn't provide for HTML elements embedded directly in the MathML. HTML5 extended the definition to allow HTML tags within token elements in MathML, like <mtext>, for example. MathJax, however, was developed before HTML5 was complete, and it follows the MathML3.0 specification, so HTML tags are not allowed in general.

It is possible, however, to use the <semantics> and <annotation-xml> elements to include HTML within MathML. Note that <annotation> and <annotation-xml> can only appear as children of <semantics>, so you need both. Also, the body of an <annotation> tag is supposed to be plain text, not HTML tags, so to include HTML, you must use <annotation-xml> not <annotation>. Finally, you need to provide the encoding attribute for the <annotation-xml> tag, and the contents of the annotation needs an xmlns attribute to make sure that it is parsed in the popper namespace.

Here is an example that works with MathJax as well as native MathML in Firefox:

<script type="math/mml">
<math>
  <mstyle displaystyle="true">
    <msup>
      <mi>x</mi>
      <semantics>
        <annotation-xml encoding="application/xhtml+xml">
          <input xmlns="http://www.w3.org/1999/xhtml" style="text-align:right" type="text" size="2" name="n" />
        </annotation-xml>
      </semantics>
    </msup>
    <mo>+</mo>
    <semantics>
      <annotation-xml encoding="application/xhtml+xml">
        <input xmlns="http://www.w3.org/1999/xhtml" type="text" size="2" name="b" />
      </annotation-xml>
    </semantics>
  </mstyle>
</math>
</script>

We do hope to improve the situation in a future version of MathJax, but right now this is the only alternative. I hope that works for you.

这篇关于MathJax在MathML中渲染HTML输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆