MathML 数学元素上的 display='inline' 和 style="display: 'inline';" 有区别吗?
Is there a difference between display='inline' and style="display: 'inline';" on the MathML math element?
和
有区别吗
<math display="inline"></math>
和
<math style="display: inline;"></math>
?
谢谢!
不,先生,它们完全一样你可以看看 Mozilla 开发者网络上的 Math 标签文档 here
虽然 display="inline"
和 style="display:inline"
通常表现相似,但 MathML 的 display
属性和 CSS 的 display
属性 是非常不同的东西.
虽然两者都应该影响 "external" 布局(即 MathML 表达式如何适应其周围的上下文),但它们最终是不相关的,并且在发生冲突时会以意想不到的方式相互作用。这也许并不奇怪,因为它们是在完全不同的标准中指定的,并且它们的交互在任何地方都没有指定;有关某些示例,请参阅末尾的代码片段。虽然 SVG(另一种 XML 语言并入 HTML5)看到 SVG 和 CSS 工作组的积极发展以保持一致,但 MathML 不再处于积极发展中,因此不会'将来不会与 CSS 保持一致。
重要的区别大概有以下几点:
MathML 的属性只有两个值(inline
和 block
),而 CSS 提供 a large variety of display
attributes;这主要是由于 MathML 对其上下文不可知(因为它是一种 XML 语言)。这意味着您经常需要设置这两个值,这可能会导致维护问题。
MathML 的 display
属性影响表达式的内部布局。这是因为它影响了 MathML 的 displaystyle
属性,例如,导致可移动限制的排版不同;有关详细信息,请参阅 https://www.w3.org/Math/draft-spec/mathml.html#chapter2_interf.toplevel.atts。
此外,MathML 对 polyfill 的需求使事情变得更加复杂,因为它们可能会以不同的方式处理交互(如下面的示例中使用按钮加载 MathJax 时所示)。既然没有具体说明,这里当然没有对错之分。
var button = document.getElementById('button');
var loadMathJax = function() {
script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=MML_CHTML-full';
document.head.appendChild(script);
}
button.onclick = loadMathJax;
<button id="button">Render with MathJax</button>
<h1>MathML inline, CSS inline</h1>
Hello <math xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML inline, CSS block</h1>
Hello.
<math style="display:block" xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML block, CSS inline</h1>
Hello <math display="block" style="display:inline" xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML inline with displaystyle, CSS inline</h1>
Hello <math xmlns="http://www.w3.org/1998/Math/MathML" displaystyle="true">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML inline with displaystyle, CSS block</h1>
Hello.
<math style="display:block" displaystyle="true" xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML block without displaystyle, CSS inline</h1>
Hello <math display="block" displaystyle="false" style="display:inline" xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
和
有区别吗<math display="inline"></math>
和
<math style="display: inline;"></math>
?
谢谢!
不,先生,它们完全一样你可以看看 Mozilla 开发者网络上的 Math 标签文档 here
虽然 display="inline"
和 style="display:inline"
通常表现相似,但 MathML 的 display
属性和 CSS 的 display
属性 是非常不同的东西.
虽然两者都应该影响 "external" 布局(即 MathML 表达式如何适应其周围的上下文),但它们最终是不相关的,并且在发生冲突时会以意想不到的方式相互作用。这也许并不奇怪,因为它们是在完全不同的标准中指定的,并且它们的交互在任何地方都没有指定;有关某些示例,请参阅末尾的代码片段。虽然 SVG(另一种 XML 语言并入 HTML5)看到 SVG 和 CSS 工作组的积极发展以保持一致,但 MathML 不再处于积极发展中,因此不会'将来不会与 CSS 保持一致。
重要的区别大概有以下几点:
MathML 的属性只有两个值(
inline
和block
),而 CSS 提供 a large variety ofdisplay
attributes;这主要是由于 MathML 对其上下文不可知(因为它是一种 XML 语言)。这意味着您经常需要设置这两个值,这可能会导致维护问题。MathML 的
display
属性影响表达式的内部布局。这是因为它影响了 MathML 的displaystyle
属性,例如,导致可移动限制的排版不同;有关详细信息,请参阅 https://www.w3.org/Math/draft-spec/mathml.html#chapter2_interf.toplevel.atts。
此外,MathML 对 polyfill 的需求使事情变得更加复杂,因为它们可能会以不同的方式处理交互(如下面的示例中使用按钮加载 MathJax 时所示)。既然没有具体说明,这里当然没有对错之分。
var button = document.getElementById('button');
var loadMathJax = function() {
script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=MML_CHTML-full';
document.head.appendChild(script);
}
button.onclick = loadMathJax;
<button id="button">Render with MathJax</button>
<h1>MathML inline, CSS inline</h1>
Hello <math xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML inline, CSS block</h1>
Hello.
<math style="display:block" xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML block, CSS inline</h1>
Hello <math display="block" style="display:inline" xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML inline with displaystyle, CSS inline</h1>
Hello <math xmlns="http://www.w3.org/1998/Math/MathML" displaystyle="true">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML inline with displaystyle, CSS block</h1>
Hello.
<math style="display:block" displaystyle="true" xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.
<h1>MathML block without displaystyle, CSS inline</h1>
Hello <math display="block" displaystyle="false" style="display:inline" xmlns="http://www.w3.org/1998/Math/MathML">
<msup>
<mrow>
<mo>(</mo>
<mrow>
<munderover>
<mo>∑<!-- ∑ --></mo>
<mrow class="MJX-TeXAtom-ORD">
<mi>k</mi>
<mo>=</mo>
<mn>1</mn>
</mrow>
<mi>n</mi>
</munderover>
<msub>
<mi>a</mi>
<mi>k</mi>
</msub>
<msub>
<mi>b</mi>
<mi>k</mi>
</msub>
</mrow>
<mo>)</mo>
</mrow>
<mrow class="MJX-TeXAtom-ORD">
<mn>2</mn>
</mrow>
</msup>
</math>
World.