使用<math>标签编写化学方程式在语义上是正确的吗?

huangapple go评论62阅读模式
英文:

Is using the <math> tag to write chemical equations semantically correct?

问题

I have been writing chemical equations in HTML files using the <math> element.

For example, to display MnSO4, I would type:

<math>
    <mi>M</mi>
    <mi>n</mi>
    <mi>S</mi>
    <msub>
        <mi>O</mi>
        <mn>4</mn>
    </msub>
</math>

Is this semantically correct? And if not, could you recommend an alternative?

英文:

I have been writing chemical equations in HTML files using the &lt;math&gt; element.

For example, to display MnSO4, I would type:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;math&gt;
    &lt;mi&gt;M&lt;/mi&gt;
    &lt;mi&gt;n&lt;/mi&gt;
    &lt;mi&gt;S&lt;/mi&gt;
    &lt;msub&gt;
        &lt;mi&gt;O&lt;/mi&gt;
        &lt;mn&gt;4&lt;/mn&gt;
    &lt;/msub&gt;
&lt;/math&gt;

<!-- end snippet -->

Is this semantically correct? And if not, could you recommend an alternative?

答案1

得分: 9

MathML是“用于描述数学符号的基于XML的语言”。它的开发是因为数学符号需要超过一行排版的符号,因此在纯文本中表示起来很困难。

相比之下,化学式总是“限制在单一排版行中的符号,可能包括下标和上标”。

由于MathML用于数学(而非化学),化学式永远不需要超过单一文本行,使用HTML原生的&lt;sup&gt;(上标)&lt;sub&gt;(下标)元素更符合语义。

<!-- 开始片段: js 隐藏: false 控制台: false Babel: false -->

<!-- 语言: lang-html -->

&lt;p&gt;植物需要CO&lt;sub&gt;2&lt;/sub&gt;进行光合作用。&lt;/p&gt;

<!-- 结束片段 -->

如果需要语义化地标注化学名称,您还可以考虑结合使用&lt;abbr&gt;缩写元素

<!-- 开始片段: js 隐藏: false 控制台: false Babel: false -->

<!-- 语言: lang-html -->

&lt;p&gt;植物需要&lt;abbr title=&quot;二氧化碳&quot;&gt;CO&lt;sub&gt;2&lt;/sub&gt;&lt;/abbr&gt;进行光合作用。&lt;/p&gt;

<!-- 结束片段 -->

您还可以考虑使用&lt;i&gt;成语文本将化学方程式与其他文本区分开。该元素用于表示“与正常文本有所区别的文本范围,例如成语文本、技术术语、分类学名称等”。

<!-- 开始片段: js 隐藏: false 控制台: false Babel: false -->

<!-- 语言: lang-html -->

&lt;p&gt;氢气和氧气可以结合形成水:&lt;i&gt;2H&lt;sub&gt;2&lt;/sub&gt; + O&lt;sub&gt;2&lt;/sub&gt; → 2H&lt;sub&gt;2&lt;/sub&gt;O&lt;/i&gt;&lt;/p&gt;

<!-- 结束片段 -->

英文:

MathML is "an XML-based language for describing mathematical notation". It was developed because mathematical notation requires more than a single line of typographic symbols, and is therefore difficult to represent in just text.

In contrast, chemical formulae are always "limited to a single typographic line of symbols, which may include subscripts and superscripts."

Because MathML is for math (not chemistry) and a chemical formula never needs more than a single line of text, it would be more semantic to use the &lt;sup&gt; (Superscript) and &lt;sub&gt; (Subscript) elements that are native to HTML.

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;p&gt;Plants require CO&lt;sub&gt;2&lt;/sub&gt; for photosynthesis.&lt;/p&gt;

<!-- end snippet -->

You could also consider combining this with an &lt;abbr&gt; abbreviation element if you need to semantically note the name of a chemical.

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;p&gt;Plants require &lt;abbr title=&quot;carbon dioxide&quot;&gt;CO&lt;sub&gt;2&lt;/sub&gt;&lt;/abbr&gt; for photosynthesis.&lt;/p&gt;

<!-- end snippet -->

You could also consider using an &lt;i&gt; Idiomatic Text to offset chemical equations from other text. This element is used to represent "a range of text that is set off from the normal text for some reason, such as idiomatic text, technical terms, taxonomical designations, among others."

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;p&gt;Hydrogen and oxygen can combine to form water: &lt;i&gt;2H&lt;sub&gt;2&lt;/sub&gt; + O&lt;sub&gt;2&lt;/sub&gt; → 2H&lt;sub&gt;2&lt;/sub&gt;O&lt;/i&gt;&lt;/p&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年5月6日 22:50:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76189526.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定