英文:
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 <math>
element.
For example, to display MnSO4, I would type:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
<math>
<mi>M</mi>
<mi>n</mi>
<mi>S</mi>
<msub>
<mi>O</mi>
<mn>4</mn>
</msub>
</math>
<!-- end snippet -->
Is this semantically correct? And if not, could you recommend an alternative?
答案1
得分: 9
MathML是“用于描述数学符号的基于XML的语言”。它的开发是因为数学符号需要超过一行排版的符号,因此在纯文本中表示起来很困难。
相比之下,化学式总是“限制在单一排版行中的符号,可能包括下标和上标”。
由于MathML用于数学(而非化学),化学式永远不需要超过单一文本行,使用HTML原生的<sup>
(上标)和<sub>
(下标)元素更符合语义。
<!-- 开始片段: js 隐藏: false 控制台: false Babel: false -->
<!-- 语言: lang-html -->
<p>植物需要CO<sub>2</sub>进行光合作用。</p>
<!-- 结束片段 -->
如果需要语义化地标注化学名称,您还可以考虑结合使用<abbr>
缩写元素。
<!-- 开始片段: js 隐藏: false 控制台: false Babel: false -->
<!-- 语言: lang-html -->
<p>植物需要<abbr title="二氧化碳">CO<sub>2</sub></abbr>进行光合作用。</p>
<!-- 结束片段 -->
您还可以考虑使用<i>
成语文本将化学方程式与其他文本区分开。该元素用于表示“与正常文本有所区别的文本范围,例如成语文本、技术术语、分类学名称等”。
<!-- 开始片段: js 隐藏: false 控制台: false Babel: false -->
<!-- 语言: lang-html -->
<p>氢气和氧气可以结合形成水:<i>2H<sub>2</sub> + O<sub>2</sub> → 2H<sub>2</sub>O</i></p>
<!-- 结束片段 -->
英文:
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 <sup>
(Superscript) and <sub>
(Subscript) elements that are native to HTML.
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-html -->
<p>Plants require CO<sub>2</sub> for photosynthesis.</p>
<!-- end snippet -->
You could also consider combining this with an <abbr>
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 -->
<p>Plants require <abbr title="carbon dioxide">CO<sub>2</sub></abbr> for photosynthesis.</p>
<!-- end snippet -->
You could also consider using an <i>
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 -->
<p>Hydrogen and oxygen can combine to form water: <i>2H<sub>2</sub> + O<sub>2</sub> → 2H<sub>2</sub>O</i></p>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论